diff options
author | Bob Wilson <bob.wilson@apple.com> | 2009-05-12 17:09:30 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2009-05-12 17:09:30 +0000 |
commit | 8494526a2396fd9cde027ab6ae11dd28b54ac90e (patch) | |
tree | 5a56b24ee4730f0ec80aea3ec569629962861935 /lib | |
parent | f46ef0450f5136b4e5267c084451e3786f817b64 (diff) | |
download | external_llvm-8494526a2396fd9cde027ab6ae11dd28b54ac90e.zip external_llvm-8494526a2396fd9cde027ab6ae11dd28b54ac90e.tar.gz external_llvm-8494526a2396fd9cde027ab6ae11dd28b54ac90e.tar.bz2 |
Fix 80-col violations and remove trailing whitespace. No functional changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/ARM/ARMConstantIslandPass.cpp | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/lib/Target/ARM/ARMConstantIslandPass.cpp b/lib/Target/ARM/ARMConstantIslandPass.cpp index 89f77b2..c67141c 100644 --- a/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -52,7 +52,7 @@ namespace { /// counted as part of the following block (i.e., the offset and size for /// a padded block will both be ==2 mod 4). std::vector<unsigned> BBSizes; - + /// BBOffsets - the offset of each MBB in bytes, starting from 0. /// The two-byte pads required for Thumb alignment are counted as part of /// the following block. @@ -73,11 +73,11 @@ namespace { CPUser(MachineInstr *mi, MachineInstr *cpemi, unsigned maxdisp) : MI(mi), CPEMI(cpemi), MaxDisp(maxdisp) {} }; - + /// CPUsers - Keep track of all of the machine instructions that use various /// constant pools and their max displacement. std::vector<CPUser> CPUsers; - + /// CPEntry - One per constant pool entry, keeping the machine instruction /// pointer, the constpool index, and the number of CPUser's which /// reference this entry. @@ -95,7 +95,7 @@ namespace { /// Original elements are cloned as we go along; the clones are /// put in the vector of the original element, but have distinct CPIs. std::vector<std::vector<CPEntry> > CPEntries; - + /// ImmBranch - One per immediate branch, keeping the machine instruction /// pointer, conditional or unconditional, the max displacement, /// and (if isCond is true) the corresponding unconditional branch @@ -133,7 +133,7 @@ namespace { virtual const char *getPassName() const { return "ARM constant island placement and branch shortening pass"; } - + private: void DoInitialPlacement(MachineFunction &Fn, std::vector<MachineInstr*> &CPEMIs); @@ -145,16 +145,16 @@ namespace { void AdjustBBOffsetsAfter(MachineBasicBlock *BB, int delta); bool DecrementOldEntry(unsigned CPI, MachineInstr* CPEMI); int LookForExistingCPEntry(CPUser& U, unsigned UserOffset); - bool LookForWater(CPUser&U, unsigned UserOffset, + bool LookForWater(CPUser&U, unsigned UserOffset, MachineBasicBlock** NewMBB); - MachineBasicBlock* AcceptWater(MachineBasicBlock *WaterBB, + MachineBasicBlock* AcceptWater(MachineBasicBlock *WaterBB, std::vector<MachineBasicBlock*>::iterator IP); void CreateNewWater(unsigned CPUserIndex, unsigned UserOffset, MachineBasicBlock** NewMBB); bool HandleConstantPoolUser(MachineFunction &Fn, unsigned CPUserIndex); void RemoveDeadCPEMI(MachineInstr *CPEMI); bool RemoveUnusedCPEntries(); - bool CPEIsInRange(MachineInstr *MI, unsigned UserOffset, + bool CPEIsInRange(MachineInstr *MI, unsigned UserOffset, MachineInstr *CPEMI, unsigned Disp, bool DoDump); bool WaterIsInRange(unsigned UserOffset, MachineBasicBlock *Water, @@ -196,7 +196,7 @@ void ARMConstantIslands::verify(MachineFunction &Fn) { /// print block size and offset information - debugging void ARMConstantIslands::dumpBBs() { for (unsigned J = 0, E = BBOffsets.size(); J !=E; ++J) { - DOUT << "block " << J << " offset " << BBOffsets[J] << + DOUT << "block " << J << " offset " << BBOffsets[J] << " size " << BBSizes[J] << "\n"; } } @@ -209,7 +209,7 @@ FunctionPass *llvm::createARMConstantIslandPass() { bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) { MachineConstantPool &MCP = *Fn.getConstantPool(); - + TII = Fn.getTarget().getInstrInfo(); AFI = Fn.getInfo<ARMFunctionInfo>(); isThumb = AFI->isThumbFunction(); @@ -220,8 +220,9 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) { // the numbers agree with the position of the block in the function. Fn.RenumberBlocks(); - /// Thumb functions containing constant pools get 2-byte alignment. This is so - /// we can keep exact track of where the alignment padding goes. Set default. + /// Thumb functions containing constant pools get 2-byte alignment. + /// This is so we can keep exact track of where the alignment padding goes. + /// Set default. AFI->setAlign(isThumb ? 1U : 2U); // Perform the initial placement of the constant pool entries. To start with, @@ -232,16 +233,16 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) { if (isThumb) AFI->setAlign(2U); } - + /// The next UID to take is the first unused one. AFI->initConstPoolEntryUId(CPEMIs.size()); - + // Do the initial scan of the function, building up information about the // sizes of each block, the location of all the water, and finding all of the // constant pool users. InitialFunctionScan(Fn, CPEMIs); CPEMIs.clear(); - + /// Remove dead constant pool entries. RemoveUnusedCPEntries(); @@ -283,16 +284,16 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) { /// DoInitialPlacement - Perform the initial placement of the constant pool /// entries. To start with, we put them all at the end of the function. void ARMConstantIslands::DoInitialPlacement(MachineFunction &Fn, - std::vector<MachineInstr*> &CPEMIs){ + std::vector<MachineInstr*> &CPEMIs) { // Create the basic block to hold the CPE's. MachineBasicBlock *BB = Fn.CreateMachineBasicBlock(); Fn.push_back(BB); - + // Add all of the constants from the constant pool to the end block, use an // identity mapping of CPI's to CPE's. const std::vector<MachineConstantPoolEntry> &CPs = Fn.getConstantPool()->getConstants(); - + const TargetData &TD = *Fn.getTarget().getTargetData(); for (unsigned i = 0, e = CPs.size(); i != e; ++i) { unsigned Size = TD.getTypeAllocSize(CPs[i].getType()); @@ -321,13 +322,13 @@ static bool BBHasFallthrough(MachineBasicBlock *MBB) { MachineFunction::iterator MBBI = MBB; if (next(MBBI) == MBB->getParent()->end()) // Can't fall off end of function. return false; - + MachineBasicBlock *NextBB = next(MBBI); for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), E = MBB->succ_end(); I != E; ++I) if (*I == NextBB) return true; - + return false; } @@ -355,12 +356,12 @@ void ARMConstantIslands::InitialFunctionScan(MachineFunction &Fn, for (MachineFunction::iterator MBBI = Fn.begin(), E = Fn.end(); MBBI != E; ++MBBI) { MachineBasicBlock &MBB = *MBBI; - + // If this block doesn't fall through into the next MBB, then this is // 'water' that a constant pool island could be placed. if (!BBHasFallthrough(&MBB)) WaterList.push_back(&MBB); - + unsigned MBBSize = 0; for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I) { @@ -416,13 +417,13 @@ void ARMConstantIslands::InitialFunctionScan(MachineFunction &Fn, if (I->getOperand(op).isCPI()) { // We found one. The addressing mode tells us the max displacement // from the PC that this instruction permits. - + // Basic size info comes from the TSFlags field. unsigned Bits = 0; unsigned Scale = 1; unsigned TSFlags = I->getDesc().TSFlags; switch (TSFlags & ARMII::AddrModeMask) { - default: + default: // Constant pool entries can reach anything. if (I->getOpcode() == ARM::CONSTPOOL_ENTRY) continue; @@ -466,14 +467,14 @@ void ARMConstantIslands::InitialFunctionScan(MachineFunction &Fn, // Remember that this is a user of a CP entry. unsigned CPI = I->getOperand(op).getIndex(); MachineInstr *CPEMI = CPEMIs[CPI]; - unsigned MaxOffs = ((1 << Bits)-1) * Scale; + unsigned MaxOffs = ((1 << Bits)-1) * Scale; CPUsers.push_back(CPUser(I, CPEMI, MaxOffs)); // Increment corresponding CPEntry reference count. CPEntry *CPE = findConstPoolEntry(CPI, CPEMI); assert(CPE && "Cannot find a corresponding CPEntry!"); CPE->RefCount++; - + // Instructions can only use one CP entry, don't bother scanning the // rest of the operands. break; @@ -499,7 +500,7 @@ void ARMConstantIslands::InitialFunctionScan(MachineFunction &Fn, /// around inside the function. unsigned ARMConstantIslands::GetOffsetOf(MachineInstr *MI) const { MachineBasicBlock *MBB = MI->getParent(); - + // The offset is composed of two things: the sum of the sizes of all MBB's // before this instruction's block, and the offset from the start of the block // it is in. @@ -507,8 +508,8 @@ unsigned ARMConstantIslands::GetOffsetOf(MachineInstr *MI) const { // If we're looking for a CONSTPOOL_ENTRY in Thumb, see if this block has // alignment padding, and compensate if so. - if (isThumb && - MI->getOpcode() == ARM::CONSTPOOL_ENTRY && + if (isThumb && + MI->getOpcode() == ARM::CONSTPOOL_ENTRY && Offset%4 != 0) Offset += 2; @@ -533,15 +534,15 @@ static bool CompareMBBNumbers(const MachineBasicBlock *LHS, void ARMConstantIslands::UpdateForInsertedWaterBlock(MachineBasicBlock *NewBB) { // Renumber the MBB's to keep them consequtive. NewBB->getParent()->RenumberBlocks(NewBB); - + // Insert a size into BBSizes to align it properly with the (newly // renumbered) block numbers. BBSizes.insert(BBSizes.begin()+NewBB->getNumber(), 0); // Likewise for BBOffsets. BBOffsets.insert(BBOffsets.begin()+NewBB->getNumber(), 0); - - // Next, update WaterList. Specifically, we need to add NewMBB as having + + // Next, update WaterList. Specifically, we need to add NewMBB as having // available water after it. std::vector<MachineBasicBlock*>::iterator IP = std::lower_bound(WaterList.begin(), WaterList.end(), NewBB, @@ -558,13 +559,14 @@ MachineBasicBlock *ARMConstantIslands::SplitBlockBeforeInstr(MachineInstr *MI) { MachineFunction &MF = *OrigBB->getParent(); // Create a new MBB for the code after the OrigBB. - MachineBasicBlock *NewBB = MF.CreateMachineBasicBlock(OrigBB->getBasicBlock()); + MachineBasicBlock *NewBB = + MF.CreateMachineBasicBlock(OrigBB->getBasicBlock()); MachineFunction::iterator MBBI = OrigBB; ++MBBI; MF.insert(MBBI, NewBB); - + // Splice the instructions starting with MI over to NewBB. NewBB->splice(NewBB->end(), OrigBB, MI, OrigBB->end()); - + // Add an unconditional branch from OrigBB to NewBB. // Note the new unconditional branch is not being recorded. // There doesn't seem to be meaningful DebugInfo available; this doesn't @@ -572,35 +574,35 @@ MachineBasicBlock *ARMConstantIslands::SplitBlockBeforeInstr(MachineInstr *MI) { BuildMI(OrigBB, DebugLoc::getUnknownLoc(), TII->get(isThumb ? ARM::tB : ARM::B)).addMBB(NewBB); NumSplit++; - + // Update the CFG. All succs of OrigBB are now succs of NewBB. while (!OrigBB->succ_empty()) { MachineBasicBlock *Succ = *OrigBB->succ_begin(); OrigBB->removeSuccessor(Succ); NewBB->addSuccessor(Succ); - + // This pass should be run after register allocation, so there should be no // PHI nodes to update. assert((Succ->empty() || Succ->begin()->getOpcode() != TargetInstrInfo::PHI) && "PHI nodes should be eliminated by now!"); } - + // OrigBB branches to NewBB. OrigBB->addSuccessor(NewBB); - + // Update internal data structures to account for the newly inserted MBB. // This is almost the same as UpdateForInsertedWaterBlock, except that // the Water goes after OrigBB, not NewBB. MF.RenumberBlocks(NewBB); - + // Insert a size into BBSizes to align it properly with the (newly // renumbered) block numbers. BBSizes.insert(BBSizes.begin()+NewBB->getNumber(), 0); - + // Likewise for BBOffsets. BBOffsets.insert(BBOffsets.begin()+NewBB->getNumber(), 0); - // Next, update WaterList. Specifically, we need to add OrigMBB as having + // Next, update WaterList. Specifically, we need to add OrigMBB as having // available water after it (but not if it's already there, which happens // when splitting before a conditional branch that is followed by an // unconditional branch - in that case we want to insert NewBB). @@ -619,12 +621,12 @@ MachineBasicBlock *ARMConstantIslands::SplitBlockBeforeInstr(MachineInstr *MI) { for (MachineBasicBlock::iterator I = NewBB->begin(), E = NewBB->end(); I != E; ++I) NewBBSize += TII->GetInstSizeInBytes(I); - + unsigned OrigBBI = OrigBB->getNumber(); unsigned NewBBI = NewBB->getNumber(); // Set the size of NewBB in BBSizes. BBSizes[NewBBI] = NewBBSize; - + // We removed instructions from UserMBB, subtract that off from its size. // Add 2 or 4 to the block to count the unconditional branch we added to it. unsigned delta = isThumb ? 2 : 4; @@ -640,12 +642,12 @@ MachineBasicBlock *ARMConstantIslands::SplitBlockBeforeInstr(MachineInstr *MI) { } /// OffsetIsInRange - Checks whether UserOffset (the location of a constant pool -/// reference) is within MaxDisp of TrialOffset (a proposed location of a +/// reference) is within MaxDisp of TrialOffset (a proposed location of a /// constant pool entry). -bool ARMConstantIslands::OffsetIsInRange(unsigned UserOffset, +bool ARMConstantIslands::OffsetIsInRange(unsigned UserOffset, unsigned TrialOffset, unsigned MaxDisp, bool NegativeOK) { - // On Thumb offsets==2 mod 4 are rounded down by the hardware for - // purposes of the displacement computation; compensate for that here. + // On Thumb offsets==2 mod 4 are rounded down by the hardware for + // purposes of the displacement computation; compensate for that here. // Effectively, the valid range of displacements is 2 bytes smaller for such // references. if (isThumb && UserOffset%4 !=0) @@ -673,7 +675,7 @@ bool ARMConstantIslands::WaterIsInRange(unsigned UserOffset, { unsigned MaxDisp = U.MaxDisp; MachineFunction::iterator I = next(MachineFunction::iterator(Water)); - unsigned CPEOffset = BBOffsets[Water->getNumber()] + + unsigned CPEOffset = BBOffsets[Water->getNumber()] + BBSizes[Water->getNumber()]; // If the CPE is to be inserted before the instruction, that will raise @@ -720,7 +722,7 @@ static bool BBIsJumpedOver(MachineBasicBlock *MBB) { } #endif // NDEBUG -void ARMConstantIslands::AdjustBBOffsetsAfter(MachineBasicBlock *BB, +void ARMConstantIslands::AdjustBBOffsetsAfter(MachineBasicBlock *BB, int delta) { MachineFunction::iterator MBBI = BB; MBBI = next(MBBI); for(unsigned i=BB->getNumber()+1; i<BB->getParent()->getNumBlockIDs(); i++) { @@ -771,7 +773,7 @@ void ARMConstantIslands::AdjustBBOffsetsAfter(MachineBasicBlock *BB, /// DecrementOldEntry - find the constant pool entry with index CPI /// and instruction CPEMI, and decrement its refcount. If the refcount -/// becomes 0 remove the entry and instruction. Returns true if we removed +/// becomes 0 remove the entry and instruction. Returns true if we removed /// the entry, false if we didn't. bool ARMConstantIslands::DecrementOldEntry(unsigned CPI, MachineInstr *CPEMI) { @@ -842,7 +844,7 @@ static inline unsigned getUnconditionalBrDisp(int Opc) { /// AcceptWater - Small amount of common code factored out of the following. -MachineBasicBlock* ARMConstantIslands::AcceptWater(MachineBasicBlock *WaterBB, +MachineBasicBlock* ARMConstantIslands::AcceptWater(MachineBasicBlock *WaterBB, std::vector<MachineBasicBlock*>::iterator IP) { DOUT << "found water in range\n"; // Remove the original WaterList entry; we want subsequent @@ -872,7 +874,7 @@ bool ARMConstantIslands::LookForWater(CPUser &U, unsigned UserOffset, MachineBasicBlock* WaterBB = *IP; if (WaterIsInRange(UserOffset, WaterBB, U)) { if (isThumb && - (BBOffsets[WaterBB->getNumber()] + + (BBOffsets[WaterBB->getNumber()] + BBSizes[WaterBB->getNumber()])%4 != 0) { // This is valid Water, but would introduce padding. Remember // it in case we don't find any Water that doesn't do this. @@ -896,7 +898,7 @@ bool ARMConstantIslands::LookForWater(CPUser &U, unsigned UserOffset, return false; } -/// CreateNewWater - No existing WaterList entry will work for +/// CreateNewWater - No existing WaterList entry will work for /// CPUsers[CPUserIndex], so create a place to put the CPE. The end of the /// block is used if in range, and the conditional branch munged so control /// flow is correct. Otherwise the block is split to create a hole with an @@ -904,13 +906,13 @@ bool ARMConstantIslands::LookForWater(CPUser &U, unsigned UserOffset, /// block following which the new island can be inserted (the WaterList /// is not adjusted). -void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, +void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, unsigned UserOffset, MachineBasicBlock** NewMBB) { CPUser &U = CPUsers[CPUserIndex]; MachineInstr *UserMI = U.MI; MachineInstr *CPEMI = U.CPEMI; MachineBasicBlock *UserMBB = UserMI->getParent(); - unsigned OffsetOfNextBlock = BBOffsets[UserMBB->getNumber()] + + unsigned OffsetOfNextBlock = BBOffsets[UserMBB->getNumber()] + BBSizes[UserMBB->getNumber()]; assert(OffsetOfNextBlock== BBOffsets[UserMBB->getNumber()+1]); @@ -919,7 +921,7 @@ void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, // for the unconditional branch we will be adding: 4 bytes on ARM, // 2 on Thumb. Possible Thumb alignment padding is allowed for // inside OffsetIsInRange. - // If the block ends in an unconditional branch already, it is water, + // If the block ends in an unconditional branch already, it is water, // and is known to be out of range, so we'll always be adding a branch.) if (&UserMBB->back() == UserMI || OffsetIsInRange(UserOffset, OffsetOfNextBlock + (isThumb ? 2: 4), @@ -937,7 +939,7 @@ void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, BuildMI(UserMBB, DebugLoc::getUnknownLoc(), TII->get(UncondBr)).addMBB(*NewMBB); unsigned MaxDisp = getUnconditionalBrDisp(UncondBr); - ImmBranches.push_back(ImmBranch(&UserMBB->back(), + ImmBranches.push_back(ImmBranch(&UserMBB->back(), MaxDisp, false, UncondBr)); int delta = isThumb ? 2 : 4; BBSizes[UserMBB->getNumber()] += delta; @@ -965,7 +967,7 @@ void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, // in the water list. Back past any possible branches (allow for a // conditional and a maximally long unconditional). if (BaseInsertOffset >= BBOffsets[UserMBB->getNumber()+1]) - BaseInsertOffset = BBOffsets[UserMBB->getNumber()+1] - + BaseInsertOffset = BBOffsets[UserMBB->getNumber()+1] - (isThumb ? 6 : 8); unsigned EndInsertOffset = BaseInsertOffset + CPEMI->getOperand(2).getImm(); @@ -977,7 +979,7 @@ void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, Offset += TII->GetInstSizeInBytes(MI), MI = next(MI)) { if (CPUIndex < CPUsers.size() && CPUsers[CPUIndex].MI == MI) { - if (!OffsetIsInRange(Offset, EndInsertOffset, + if (!OffsetIsInRange(Offset, EndInsertOffset, CPUsers[CPUIndex].MaxDisp, !isThumb)) { BaseInsertOffset -= (isThumb ? 2 : 4); EndInsertOffset -= (isThumb ? 2 : 4); @@ -997,8 +999,8 @@ void ARMConstantIslands::CreateNewWater(unsigned CPUserIndex, /// is out-of-range. If so, pick it up the constant pool value and move it some /// place in-range. Return true if we changed any addresses (thus must run /// another pass of branch lengthening), false otherwise. -bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, - unsigned CPUserIndex){ +bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, + unsigned CPUserIndex) { CPUser &U = CPUsers[CPUserIndex]; MachineInstr *UserMI = U.MI; MachineInstr *CPEMI = U.CPEMI; @@ -1013,7 +1015,7 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, // second instruction. if (UserMI->getOpcode() == ARM::tLEApcrel) UserOffset += 2; - + // See if the current entry is within range, or there is a clone of it // in range. int result = LookForExistingCPEntry(U, UserOffset); @@ -1054,21 +1056,21 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, BBOffsets[NewIsland->getNumber()] = BBOffsets[NewMBB->getNumber()]; // Compensate for .align 2 in thumb mode. - if (isThumb && BBOffsets[NewIsland->getNumber()]%4 != 0) + if (isThumb && BBOffsets[NewIsland->getNumber()]%4 != 0) Size += 2; // Increase the size of the island block to account for the new entry. BBSizes[NewIsland->getNumber()] += Size; AdjustBBOffsetsAfter(NewIsland, Size); - + // Finally, change the CPI in the instruction operand to be ID. for (unsigned i = 0, e = UserMI->getNumOperands(); i != e; ++i) if (UserMI->getOperand(i).isCPI()) { UserMI->getOperand(i).setIndex(ID); break; } - + DOUT << " Moved CPE to #" << ID << " CPI=" << CPI << "\t" << *UserMI; - + return true; } @@ -1111,7 +1113,7 @@ bool ARMConstantIslands::RemoveUnusedCPEntries() { MadeChange = true; } } - } + } return MadeChange; } @@ -1238,7 +1240,7 @@ ARMConstantIslands::FixUpConditionalBr(MachineFunction &Fn, ImmBranch &Br) { // BBOffsets[SplitBB] is wrong temporarily, fixed below } MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB)); - + DOUT << " Insert B to BB#" << DestBB->getNumber() << " also invert condition and change dest. to BB#" << NextBB->getNumber() << "\n"; |