llvm.org GIT mirror llvm / c6a2410
Track the BB's where each virtual register is used. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35135 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
2 changed file(s) with 28 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
7777 /// index.
7878 ///
7979 BitVector AliveBlocks;
80
81 /// UsedBlocks - Set of blocks of which this value is actually used. This
82 /// is a bit set which uses the basic block number as an index.
83 BitVector UsedBlocks;
8084
8185 /// Kills - List of MachineInstruction's which are the last use of this
8286 /// virtual register (kill it) in their basic block.
115119 BitVector ReservedRegisters;
116120
117121 private: // Intermediate data structures
122 MachineFunction *MF;
123
118124 const MRegisterInfo *RegInfo;
119125
120126 MachineInstr **PhysRegInfo;
4747 cerr << " Alive in blocks: ";
4848 for (unsigned i = 0, e = AliveBlocks.size(); i != e; ++i)
4949 if (AliveBlocks[i]) cerr << i << ", ";
50 cerr << " Used in blocks: ";
51 for (unsigned i = 0, e = UsedBlocks.size(); i != e; ++i)
52 if (UsedBlocks[i]) cerr << i << ", ";
5053 cerr << "\n Killed by:";
5154 if (Kills.empty())
5255 cerr << " No instructions.\n";
6770 else
6871 VirtRegInfo.resize(2*VirtRegInfo.size());
6972 }
70 return VirtRegInfo[RegIdx];
73 VarInfo &VI = VirtRegInfo[RegIdx];
74 VI.AliveBlocks.resize(MF->getNumBlockIDs());
75 VI.UsedBlocks.resize(MF->getNumBlockIDs());
76 return VI;
7177 }
7278
7379 bool LiveVariables::KillsRegister(MachineInstr *MI, unsigned Reg) const {
116122
117123 if (MBB == VRInfo.DefInst->getParent()) return; // Terminate recursion
118124
119 if (VRInfo.AliveBlocks.size() <= BBNum)
120 VRInfo.AliveBlocks.resize(BBNum+1); // Make space...
121
122125 if (VRInfo.AliveBlocks[BBNum])
123126 return; // We already know the block is live
124127
133136 void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
134137 MachineInstr *MI) {
135138 assert(VRInfo.DefInst && "Register use before def!");
139
140 unsigned BBNum = MBB->getNumber();
141
142 VRInfo.UsedBlocks[BBNum] = true;
136143
137144 // Check to see if this basic block is already a kill block...
138145 if (!VRInfo.Kills.empty() && VRInfo.Kills.back()->getParent() == MBB) {
151158 "Should have kill for defblock!");
152159
153160 // Add a new kill entry for this basic block.
154 unsigned BBNum = MBB->getNumber();
155161 // If this virtual register is already marked as alive in this basic block,
156162 // that means it is alive in at least one of the successor block, it's not
157163 // a kill.
158 if (VRInfo.AliveBlocks.size() <= BBNum || !VRInfo.AliveBlocks[BBNum])
164 if (!VRInfo.AliveBlocks[BBNum])
159165 VRInfo.Kills.push_back(MI);
160166
161167 // Update all dominating blocks to mark them known live.
219225 }
220226 }
221227
222 bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
223 const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
224 RegInfo = MF.getTarget().getRegisterInfo();
228 bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
229 MF = &mf;
230 const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
231 RegInfo = MF->getTarget().getRegisterInfo();
225232 assert(RegInfo && "Target doesn't have register information?");
226233
227 ReservedRegisters = RegInfo->getReservedRegs(MF);
234 ReservedRegisters = RegInfo->getReservedRegs(mf);
228235
229236 // PhysRegInfo - Keep track of which instruction was the last use of a
230237 // physical register. This is a purely local property, because all physical
238245 /// Get some space for a respectable number of registers...
239246 VirtRegInfo.resize(64);
240247
241 analyzePHINodes(MF);
248 analyzePHINodes(mf);
242249
243250 // Calculate live variable information in depth first order on the CFG of the
244251 // function. This guarantees that we will see the definition of a virtual
245252 // register before its uses due to dominance properties of SSA (except for PHI
246253 // nodes, which are treated as a special case).
247254 //
248 MachineBasicBlock *Entry = MF.begin();
255 MachineBasicBlock *Entry = MF->begin();
249256 std::set Visited;
250257 for (df_ext_iterator DFI = df_ext_begin(Entry, Visited),
251258 E = df_ext_end(Entry, Visited); DFI != E; ++DFI) {
325332 // it as using all of the live-out values in the function.
326333 if (!MBB->empty() && TII.isReturn(MBB->back().getOpcode())) {
327334 MachineInstr *Ret = &MBB->back();
328 for (MachineFunction::liveout_iterator I = MF.liveout_begin(),
329 E = MF.liveout_end(); I != E; ++I) {
335 for (MachineFunction::liveout_iterator I = MF->liveout_begin(),
336 E = MF->liveout_end(); I != E; ++I) {
330337 assert(MRegisterInfo::isPhysicalRegister(*I) &&
331338 "Cannot have a live-in virtual register!");
332339 HandlePhysRegUse(*I, Ret);
359366 // function. If so, it is due to a bug in the instruction selector or some
360367 // other part of the code generator if this happens.
361368 #ifndef NDEBUG
362 for(MachineFunction::iterator i = MF.begin(), e = MF.end(); i != e; ++i)
369 for(MachineFunction::iterator i = MF->begin(), e = MF->end(); i != e; ++i)
363370 assert(Visited.count(&*i) != 0 && "unreachable basic block found");
364371 #endif
365372