llvm.org GIT mirror llvm / 493a3d0
LiveVariables::VarInfo contains an AliveBlocks BitVector, which has as many entries as there are basic blocks in the function. LiveVariables::getVarInfo creates a VarInfo struct for every register in the function, leading to quadratic space use. This patch changes the BitVector to a SparseBitVector, which doesn't help the worst-case memory use but does reduce the actual use in very long functions with short-lived variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72426 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 11 years ago
4 changed file(s) with 17 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
3232 #include "llvm/ADT/BitVector.h"
3333 #include "llvm/ADT/DenseMap.h"
3434 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/ADT/SparseBitVector.h"
3536
3637 namespace llvm {
3738
7475 /// through. This is a bit set which uses the basic block number as an
7576 /// index.
7677 ///
77 BitVector AliveBlocks;
78 SparseBitVector<> AliveBlocks;
7879
7980 /// NumUses - Number of uses of this register across the entire function.
8081 ///
421421 // If the kill happens after the definition, we have an intra-block
422422 // live range.
423423 if (killIdx > defIndex) {
424 assert(vi.AliveBlocks.none() &&
424 assert(vi.AliveBlocks.empty() &&
425425 "Shouldn't be alive across any blocks!");
426426 LiveRange LR(defIndex, killIdx, ValNo);
427427 interval.addRange(LR);
442442 // Iterate over all of the blocks that the variable is completely
443443 // live in, adding [insrtIndex(begin), instrIndex(end)+4) to the
444444 // live interval.
445 for (int i = vi.AliveBlocks.find_first(); i != -1;
446 i = vi.AliveBlocks.find_next(i)) {
447 LiveRange LR(getMBBStartIdx(i),
448 getMBBEndIdx(i)+1, // MBB ends at -1.
445 for (SparseBitVector<>::iterator I = vi.AliveBlocks.begin(),
446 E = vi.AliveBlocks.end(); I != E; ++I) {
447 LiveRange LR(getMBBStartIdx(*I),
448 getMBBEndIdx(*I)+1, // MBB ends at -1.
449449 ValNo);
450450 interval.addRange(LR);
451451 DOUT << " +" << LR;
5151
5252 void LiveVariables::VarInfo::dump() const {
5353 cerr << " Alive in blocks: ";
54 for (int i = AliveBlocks.find_first(); i != -1; i = AliveBlocks.find_next(i))
55 cerr << i << ", ";
54 for (SparseBitVector<>::iterator I = AliveBlocks.begin(),
55 E = AliveBlocks.end(); I != E; ++I)
56 cerr << *I << ", ";
5657 cerr << "\n Killed by:";
5758 if (Kills.empty())
5859 cerr << " No instructions.\n";
7475 else
7576 VirtRegInfo.resize(2*VirtRegInfo.size());
7677 }
77 VarInfo &VI = VirtRegInfo[RegIdx];
78 VI.AliveBlocks.resize(MF->getNumBlockIDs());
79 return VI;
78 return VirtRegInfo[RegIdx];
8079 }
8180
8281 void LiveVariables::MarkVirtRegAliveInBlock(VarInfo& VRInfo,
9594
9695 if (MBB == DefBlock) return; // Terminate recursion
9796
98 if (VRInfo.AliveBlocks[BBNum])
97 if (VRInfo.AliveBlocks.test(BBNum))
9998 return; // We already know the block is live
10099
101100 // Mark the variable known alive in this bb
102 VRInfo.AliveBlocks[BBNum] = true;
101 VRInfo.AliveBlocks.set(BBNum);
103102
104103 for (MachineBasicBlock::const_pred_reverse_iterator PI = MBB->pred_rbegin(),
105104 E = MBB->pred_rend(); PI != E; ++PI)
162161 // Add a new kill entry for this basic block. If this virtual register is
163162 // already marked as alive in this basic block, that means it is alive in at
164163 // least one of the successor blocks, it's not a kill.
165 if (!VRInfo.AliveBlocks[BBNum])
164 if (!VRInfo.AliveBlocks.test(BBNum))
166165 VRInfo.Kills.push_back(MI);
167166
168167 // Update all dominating blocks to mark them as "known live".
174173 void LiveVariables::HandleVirtRegDef(unsigned Reg, MachineInstr *MI) {
175174 VarInfo &VRInfo = getVarInfo(Reg);
176175
177 if (VRInfo.AliveBlocks.none())
176 if (VRInfo.AliveBlocks.empty())
178177 // If vr is not alive in any block, then defaults to dead.
179178 VRInfo.Kills.push_back(MI);
180179 }
333333
334334 // Is it alive in this successor?
335335 unsigned SuccIdx = SuccMBB->getNumber();
336 if (SuccIdx < InRegVI.AliveBlocks.size() &&
337 InRegVI.AliveBlocks[SuccIdx]) {
336 if (InRegVI.AliveBlocks.test(SuccIdx)) {
338337 ValueIsLive = true;
339338 break;
340339 }
406405
407406 // This vreg no longer lives all of the way through opBlock.
408407 unsigned opBlockNum = opBlock.getNumber();
409 if (opBlockNum < InRegVI.AliveBlocks.size())
410 InRegVI.AliveBlocks[opBlockNum] = false;
408 InRegVI.AliveBlocks.reset(opBlockNum);
411409 }
412410 }
413411