| OLD | NEW |
| 1 //===- subzero/src/IceLiveness.cpp - Liveness analysis implementation -----===// | 1 //===- subzero/src/IceLiveness.cpp - Liveness analysis implementation -----===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // the counts to 0. | 64 // the counts to 0. |
| 65 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { | 65 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { |
| 66 LivenessNode &N = Nodes[(*I)->getIndex()]; | 66 LivenessNode &N = Nodes[(*I)->getIndex()]; |
| 67 N.LiveToVarMap.assign(N.NumLocals, nullptr); | 67 N.LiveToVarMap.assign(N.NumLocals, nullptr); |
| 68 N.NumLocals = 0; | 68 N.NumLocals = 0; |
| 69 N.NumNonDeadPhis = 0; | 69 N.NumNonDeadPhis = 0; |
| 70 } | 70 } |
| 71 if (IsFullInit) | 71 if (IsFullInit) |
| 72 LiveToVarMap.assign(NumGlobals, nullptr); | 72 LiveToVarMap.assign(NumGlobals, nullptr); |
| 73 | 73 |
| 74 // Sort each variable into the appropriate LiveToVarMap. Also set | 74 // Initialize the bitmask of which variables to track. |
| 75 // VarToLiveMap. | 75 RangeMask.resize(NumVars); |
| 76 RangeMask.set(0, NumVars); // Track all variables by default. |
| 77 |
| 78 // Sort each variable into the appropriate LiveToVarMap. Set VarToLiveMap. |
| 79 // Set RangeMask correctly for each variable. |
| 76 TmpNumGlobals = 0; | 80 TmpNumGlobals = 0; |
| 77 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { | 81 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { |
| 78 Variable *Var = *I; | 82 Variable *Var = *I; |
| 79 SizeT VarIndex = Var->getIndex(); | 83 SizeT VarIndex = Var->getIndex(); |
| 80 SizeT LiveIndex; | 84 SizeT LiveIndex; |
| 81 if (VMetadata->isMultiBlock(Var)) { | 85 if (VMetadata->isMultiBlock(Var)) { |
| 82 LiveIndex = TmpNumGlobals++; | 86 LiveIndex = TmpNumGlobals++; |
| 83 LiveToVarMap[LiveIndex] = Var; | 87 LiveToVarMap[LiveIndex] = Var; |
| 84 } else { | 88 } else { |
| 85 SizeT NodeIndex = VMetadata->getLocalUseNode(Var)->getIndex(); | 89 SizeT NodeIndex = VMetadata->getLocalUseNode(Var)->getIndex(); |
| 86 LiveIndex = Nodes[NodeIndex].NumLocals++; | 90 LiveIndex = Nodes[NodeIndex].NumLocals++; |
| 87 Nodes[NodeIndex].LiveToVarMap[LiveIndex] = Var; | 91 Nodes[NodeIndex].LiveToVarMap[LiveIndex] = Var; |
| 88 LiveIndex += NumGlobals; | 92 LiveIndex += NumGlobals; |
| 89 } | 93 } |
| 90 VarToLiveMap[VarIndex] = LiveIndex; | 94 VarToLiveMap[VarIndex] = LiveIndex; |
| 95 if (Var->getIgnoreLiveness()) |
| 96 RangeMask[VarIndex] = false; |
| 91 } | 97 } |
| 92 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); | 98 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); |
| 93 | 99 |
| 100 // Fix up RangeMask for variables before FirstVar. |
| 101 for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { |
| 102 Variable *Var = *I; |
| 103 SizeT VarIndex = Var->getIndex(); |
| 104 if (Var->getIgnoreLiveness() || |
| 105 (!IsFullInit && !Var->hasReg() && !Var->getWeight().isInf())) |
| 106 RangeMask[VarIndex] = false; |
| 107 } |
| 108 |
| 94 // Process each node. | 109 // Process each node. |
| 95 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { | 110 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { |
| 96 LivenessNode &Node = Nodes[(*I)->getIndex()]; | 111 LivenessNode &Node = Nodes[(*I)->getIndex()]; |
| 97 // NumLocals, LiveToVarMap already initialized | 112 // NumLocals, LiveToVarMap already initialized |
| 98 Node.LiveIn.resize(NumGlobals); | 113 Node.LiveIn.resize(NumGlobals); |
| 99 Node.LiveOut.resize(NumGlobals); | 114 Node.LiveOut.resize(NumGlobals); |
| 100 // LiveBegin and LiveEnd are reinitialized before each pass over | 115 // LiveBegin and LiveEnd are reinitialized before each pass over |
| 101 // the block. | 116 // the block. |
| 102 } | 117 } |
| 103 | |
| 104 // Initialize the bitmask of which variables to track. | |
| 105 RangeMask.resize(NumVars); | |
| 106 RangeMask.set(0, NumVars); | |
| 107 if (!IsFullInit) { | |
| 108 // Reset initial variables that are not pre-colored or infinite-weight. | |
| 109 for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { | |
| 110 Variable *Var = *I; | |
| 111 RangeMask[Var->getIndex()] = (Var->hasReg() || Var->getWeight().isInf()); | |
| 112 } | |
| 113 } | |
| 114 } | 118 } |
| 115 | 119 |
| 116 void Liveness::init() { | 120 void Liveness::init() { |
| 117 constexpr bool IsFullInit = true; | 121 constexpr bool IsFullInit = true; |
| 118 NodeList::const_iterator FirstNode = Func->getNodes().begin(); | 122 NodeList::const_iterator FirstNode = Func->getNodes().begin(); |
| 119 VarList::const_iterator FirstVar = Func->getVariables().begin(); | 123 VarList::const_iterator FirstVar = Func->getVariables().begin(); |
| 120 initInternal(FirstNode, FirstVar, IsFullInit); | 124 initInternal(FirstNode, FirstVar, IsFullInit); |
| 121 } | 125 } |
| 122 | 126 |
| 123 void Liveness::initPhiEdgeSplits(NodeList::const_iterator FirstNode, | 127 void Liveness::initPhiEdgeSplits(NodeList::const_iterator FirstNode, |
| 124 VarList::const_iterator FirstVar) { | 128 VarList::const_iterator FirstVar) { |
| 125 constexpr bool IsFullInit = false; | 129 constexpr bool IsFullInit = false; |
| 126 initInternal(FirstNode, FirstVar, IsFullInit); | 130 initInternal(FirstNode, FirstVar, IsFullInit); |
| 127 } | 131 } |
| 128 | 132 |
| 129 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { | 133 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { |
| 130 if (LiveIndex < NumGlobals) | 134 if (LiveIndex < NumGlobals) |
| 131 return LiveToVarMap[LiveIndex]; | 135 return LiveToVarMap[LiveIndex]; |
| 132 SizeT NodeIndex = Node->getIndex(); | 136 SizeT NodeIndex = Node->getIndex(); |
| 133 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; | 137 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; |
| 134 } | 138 } |
| 135 | 139 |
| 136 } // end of namespace Ice | 140 } // end of namespace Ice |
| OLD | NEW |