| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 VariablesMetadata *VMetadata = Func->getVMetadata(); | 43 VariablesMetadata *VMetadata = Func->getVMetadata(); |
| 44 Nodes.resize(NumNodes); | 44 Nodes.resize(NumNodes); |
| 45 VarToLiveMap.resize(NumVars); | 45 VarToLiveMap.resize(NumVars); |
| 46 | 46 |
| 47 // Count the number of globals, and the number of locals for each block. | 47 // Count the number of globals, and the number of locals for each block. |
| 48 SizeT TmpNumGlobals = 0; | 48 SizeT TmpNumGlobals = 0; |
| 49 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { | 49 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { |
| 50 Variable *Var = *I; | 50 Variable *Var = *I; |
| 51 if (VMetadata->isMultiBlock(Var)) { | 51 if (VMetadata->isMultiBlock(Var)) { |
| 52 ++TmpNumGlobals; | 52 ++TmpNumGlobals; |
| 53 } else { | 53 } else if (VMetadata->isSingleBlock(Var)) { |
| 54 SizeT Index = VMetadata->getLocalUseNode(Var)->getIndex(); | 54 SizeT Index = VMetadata->getLocalUseNode(Var)->getIndex(); |
| 55 ++Nodes[Index].NumLocals; | 55 ++Nodes[Index].NumLocals; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 if (IsFullInit) | 58 if (IsFullInit) |
| 59 NumGlobals = TmpNumGlobals; | 59 NumGlobals = TmpNumGlobals; |
| 60 else | 60 else |
| 61 assert(TmpNumGlobals == 0); | 61 assert(TmpNumGlobals == 0); |
| 62 | 62 |
| 63 // Resize each LivenessNode::LiveToVarMap, and the global LiveToVarMap. Reset | 63 // Resize each LivenessNode::LiveToVarMap, and the global LiveToVarMap. Reset |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 // Initialize the bitmask of which variables to track. | 74 // Initialize the bitmask of which variables to track. |
| 75 RangeMask.resize(NumVars); | 75 RangeMask.resize(NumVars); |
| 76 RangeMask.set(0, NumVars); // Track all variables by default. | 76 RangeMask.set(0, NumVars); // Track all variables by default. |
| 77 | 77 |
| 78 // Sort each variable into the appropriate LiveToVarMap. Set VarToLiveMap. | 78 // Sort each variable into the appropriate LiveToVarMap. Set VarToLiveMap. |
| 79 // Set RangeMask correctly for each variable. | 79 // Set RangeMask correctly for each variable. |
| 80 TmpNumGlobals = 0; | 80 TmpNumGlobals = 0; |
| 81 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { | 81 for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { |
| 82 Variable *Var = *I; | 82 Variable *Var = *I; |
| 83 SizeT VarIndex = Var->getIndex(); | 83 SizeT VarIndex = Var->getIndex(); |
| 84 SizeT LiveIndex; | 84 SizeT LiveIndex = InvalidLiveIndex; |
| 85 if (VMetadata->isMultiBlock(Var)) { | 85 if (VMetadata->isMultiBlock(Var)) { |
| 86 LiveIndex = TmpNumGlobals++; | 86 LiveIndex = TmpNumGlobals++; |
| 87 LiveToVarMap[LiveIndex] = Var; | 87 LiveToVarMap[LiveIndex] = Var; |
| 88 } else { | 88 } else if (VMetadata->isSingleBlock(Var)) { |
| 89 SizeT NodeIndex = VMetadata->getLocalUseNode(Var)->getIndex(); | 89 SizeT NodeIndex = VMetadata->getLocalUseNode(Var)->getIndex(); |
| 90 LiveIndex = Nodes[NodeIndex].NumLocals++; | 90 LiveIndex = Nodes[NodeIndex].NumLocals++; |
| 91 Nodes[NodeIndex].LiveToVarMap[LiveIndex] = Var; | 91 Nodes[NodeIndex].LiveToVarMap[LiveIndex] = Var; |
| 92 LiveIndex += NumGlobals; | 92 LiveIndex += NumGlobals; |
| 93 } | 93 } |
| 94 VarToLiveMap[VarIndex] = LiveIndex; | 94 VarToLiveMap[VarIndex] = LiveIndex; |
| 95 if (Var->getIgnoreLiveness()) | 95 if (LiveIndex == InvalidLiveIndex || Var->getIgnoreLiveness()) |
| 96 RangeMask[VarIndex] = false; | 96 RangeMask[VarIndex] = false; |
| 97 } | 97 } |
| 98 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); | 98 assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); |
| 99 | 99 |
| 100 // Fix up RangeMask for variables before FirstVar. | 100 // Fix up RangeMask for variables before FirstVar. |
| 101 for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { | 101 for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { |
| 102 Variable *Var = *I; | 102 Variable *Var = *I; |
| 103 SizeT VarIndex = Var->getIndex(); | 103 SizeT VarIndex = Var->getIndex(); |
| 104 if (Var->getIgnoreLiveness() || | 104 if (Var->getIgnoreLiveness() || |
| 105 (!IsFullInit && !Var->hasReg() && !Var->mustHaveReg())) | 105 (!IsFullInit && !Var->hasReg() && !Var->mustHaveReg())) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { | 135 Variable *Liveness::getVariable(SizeT LiveIndex, const CfgNode *Node) const { |
| 136 if (LiveIndex < NumGlobals) | 136 if (LiveIndex < NumGlobals) |
| 137 return LiveToVarMap[LiveIndex]; | 137 return LiveToVarMap[LiveIndex]; |
| 138 SizeT NodeIndex = Node->getIndex(); | 138 SizeT NodeIndex = Node->getIndex(); |
| 139 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; | 139 return Nodes[NodeIndex].LiveToVarMap[LiveIndex - NumGlobals]; |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // end of namespace Ice | 142 } // end of namespace Ice |
| OLD | NEW |