Chromium Code Reviews| 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 (!IsFullInit && !Var->hasReg() && !Var->getWeight().isInf())) | |
|
jvoung (off chromium)
2015/08/06 21:39:14
I wasn't sure if the extra conditions here:
(!IsFu
Jim Stichnoth
2015/08/06 22:38:50
Yikes, thanks! This change basically reverted tha
| |
| 97 RangeMask[VarIndex] = false; | |
| 91 } | 98 } |
| 92 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); | 99 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); |
| 93 | 100 |
| 101 // Fix up RangeMask for variables before FirstVar. | |
| 102 for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { | |
| 103 Variable *Var = *I; | |
| 104 SizeT VarIndex = Var->getIndex(); | |
| 105 if (Var->getIgnoreLiveness() || | |
| 106 (!IsFullInit && !Var->hasReg() && !Var->getWeight().isInf())) | |
| 107 RangeMask[VarIndex] = false; | |
| 108 } | |
| 109 | |
| 94 // Process each node. | 110 // Process each node. |
| 95 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { | 111 for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { |
| 96 LivenessNode &Node = Nodes[(*I)->getIndex()]; | 112 LivenessNode &Node = Nodes[(*I)->getIndex()]; |
| 97 // NumLocals, LiveToVarMap already initialized | 113 // NumLocals, LiveToVarMap already initialized |
| 98 Node.LiveIn.resize(NumGlobals); | 114 Node.LiveIn.resize(NumGlobals); |
| 99 Node.LiveOut.resize(NumGlobals); | 115 Node.LiveOut.resize(NumGlobals); |
| 100 // LiveBegin and LiveEnd are reinitialized before each pass over | 116 // LiveBegin and LiveEnd are reinitialized before each pass over |
| 101 // the block. | 117 // the block. |
| 102 } | 118 } |
| 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 } | 119 } |
| 115 | 120 |
| 116 void Liveness::init() { | 121 void Liveness::init() { |
| 117 constexpr bool IsFullInit = true; | 122 constexpr bool IsFullInit = true; |
| 118 NodeList::const_iterator FirstNode = Func->getNodes().begin(); | 123 NodeList::const_iterator FirstNode = Func->getNodes().begin(); |
| 119 VarList::const_iterator FirstVar = Func->getVariables().begin(); | 124 VarList::const_iterator FirstVar = Func->getVariables().begin(); |
| 120 initInternal(FirstNode, FirstVar, IsFullInit); | 125 initInternal(FirstNode, FirstVar, IsFullInit); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void Liveness::initPhiEdgeSplits(NodeList::const_iterator FirstNode, | 128 void Liveness::initPhiEdgeSplits(NodeList::const_iterator FirstNode, |
| 124 VarList::const_iterator FirstVar) { | 129 VarList::const_iterator FirstVar) { |
| 125 constexpr bool IsFullInit = false; | 130 constexpr bool IsFullInit = false; |
| 126 initInternal(FirstNode, FirstVar, IsFullInit); | 131 initInternal(FirstNode, FirstVar, IsFullInit); |
| 127 } | 132 } |
| 128 | 133 |
| 129 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { | 134 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { |
| 130 if (LiveIndex < NumGlobals) | 135 if (LiveIndex < NumGlobals) |
| 131 return LiveToVarMap[LiveIndex]; | 136 return LiveToVarMap[LiveIndex]; |
| 132 SizeT NodeIndex = Node->getIndex(); | 137 SizeT NodeIndex = Node->getIndex(); |
| 133 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; | 138 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; |
| 134 } | 139 } |
| 135 | 140 |
| 136 } // end of namespace Ice | 141 } // end of namespace Ice |
| OLD | NEW |