diff options
Diffstat (limited to 'llvm/lib/Target/ARM/ARMConstantIslandPass.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMConstantIslandPass.cpp | 74 |
1 files changed, 17 insertions, 57 deletions
diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp index 634fb89b8e89..195d0a89291b 100644 --- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -206,10 +206,6 @@ namespace { /// T2JumpTables - Keep track of all the Thumb2 jumptable instructions. SmallVector<MachineInstr*, 4> T2JumpTables; - /// HasFarJump - True if any far jump instruction has been emitted during - /// the branch fix up pass. - bool HasFarJump; - MachineFunction *MF; MachineConstantPool *MCP; const ARMBaseInstrInfo *TII; @@ -270,7 +266,6 @@ namespace { bool fixupImmediateBr(ImmBranch &Br); bool fixupConditionalBr(ImmBranch &Br); bool fixupUnconditionalBr(ImmBranch &Br); - bool undoLRSpillRestore(); bool optimizeThumb2Instructions(); bool optimizeThumb2Branches(); bool reorderThumb2JumpTables(); @@ -330,8 +325,8 @@ void ARMConstantIslands::verify() { #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// print block size and offset information - debugging LLVM_DUMP_METHOD void ARMConstantIslands::dumpBBs() { - BBInfoVector &BBInfo = BBUtils->getBBInfo(); LLVM_DEBUG({ + BBInfoVector &BBInfo = BBUtils->getBBInfo(); for (unsigned J = 0, E = BBInfo.size(); J !=E; ++J) { const BasicBlockInfo &BBI = BBInfo[J]; dbgs() << format("%08x %bb.%u\t", BBI.Offset, J) @@ -350,7 +345,7 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &mf) { LLVM_DEBUG(dbgs() << "***** ARMConstantIslands: " << MCP->getConstants().size() << " CP entries, aligned to " - << MCP->getConstantPoolAlignment() << " bytes *****\n"); + << MCP->getConstantPoolAlign().value() << " bytes *****\n"); STI = &static_cast<const ARMSubtarget &>(MF->getSubtarget()); TII = STI->getInstrInfo(); @@ -363,7 +358,6 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &mf) { isThumb1 = AFI->isThumb1OnlyFunction(); isThumb2 = AFI->isThumb2Function(); - HasFarJump = false; bool GenerateTBB = isThumb2 || (isThumb1 && SynthesizeThumb1TBB); // Renumber all of the machine basic blocks in the function, guaranteeing that @@ -456,11 +450,6 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &mf) { // After a while, this might be made debug-only, but it is not expensive. verify(); - // If LR has been forced spilled and no far jump (i.e. BL) has been issued, - // undo the spill / restore of LR if possible. - if (isThumb && !HasFarJump && AFI->isLRSpilledForFarJump()) - MadeChange |= undoLRSpillRestore(); - // Save the mapping between original and cloned constpool entries. for (unsigned i = 0, e = CPEntries.size(); i != e; ++i) { for (unsigned j = 0, je = CPEntries[i].size(); j != je; ++j) { @@ -494,7 +483,7 @@ ARMConstantIslands::doInitialConstPlacement(std::vector<MachineInstr*> &CPEMIs) MF->push_back(BB); // MachineConstantPool measures alignment in bytes. - const Align MaxAlign(MCP->getConstantPoolAlignment()); + const Align MaxAlign = MCP->getConstantPoolAlign(); const unsigned MaxLogAlign = Log2(MaxAlign); // Mark the basic block as required by the const-pool. @@ -518,14 +507,13 @@ ARMConstantIslands::doInitialConstPlacement(std::vector<MachineInstr*> &CPEMIs) const DataLayout &TD = MF->getDataLayout(); for (unsigned i = 0, e = CPs.size(); i != e; ++i) { unsigned Size = TD.getTypeAllocSize(CPs[i].getType()); - unsigned Align = CPs[i].getAlignment(); - assert(isPowerOf2_32(Align) && "Invalid alignment"); + Align Alignment = CPs[i].getAlign(); // Verify that all constant pool entries are a multiple of their alignment. // If not, we would have to pad them out so that instructions stay aligned. - assert((Size % Align) == 0 && "CP Entry not multiple of 4 bytes!"); + assert(isAligned(Alignment, Size) && "CP Entry not multiple of 4 bytes!"); // Insert CONSTPOOL_ENTRY before entries with a smaller alignment. - unsigned LogAlign = Log2_32(Align); + unsigned LogAlign = Log2(Alignment); MachineBasicBlock::iterator InsAt = InsPoint[LogAlign]; MachineInstr *CPEMI = BuildMI(*BB, InsAt, DebugLoc(), TII->get(ARM::CONSTPOOL_ENTRY)) @@ -542,7 +530,7 @@ ARMConstantIslands::doInitialConstPlacement(std::vector<MachineInstr*> &CPEMIs) CPEntries.emplace_back(1, CPEntry(CPEMI, i)); ++NumCPEs; LLVM_DEBUG(dbgs() << "Moved CPI#" << i << " to end of function, size = " - << Size << ", align = " << Align << '\n'); + << Size << ", align = " << Alignment.value() << '\n'); } LLVM_DEBUG(BB->dump()); } @@ -668,7 +656,7 @@ Align ARMConstantIslands::getCPEAlign(const MachineInstr *CPEMI) { unsigned CPI = getCombinedIndex(CPEMI); assert(CPI < MCP->getConstants().size() && "Invalid constant pool index."); - return Align(MCP->getConstants()[CPI].getAlignment()); + return MCP->getConstants()[CPI].getAlign(); } /// scanFunctionJumpTables - Do a scan of the function, building up @@ -1364,8 +1352,8 @@ void ARMConstantIslands::createNewWater(unsigned CPUserIndex, // displacement. MachineBasicBlock::iterator I = UserMI; ++I; - for (unsigned Offset = UserOffset + TII->getInstSizeInBytes(*UserMI), - PredReg = 0; + Register PredReg; + for (unsigned Offset = UserOffset + TII->getInstSizeInBytes(*UserMI); I->getOpcode() != ARM::t2IT && getITInstrPredicate(*I, PredReg) != ARMCC::AL; Offset += TII->getInstSizeInBytes(*I), I = std::next(I)) { @@ -1410,7 +1398,7 @@ void ARMConstantIslands::createNewWater(unsigned CPUserIndex, // Avoid splitting an IT block. if (LastIT) { - unsigned PredReg = 0; + Register PredReg; ARMCC::CondCodes CC = getITInstrPredicate(*MI, PredReg); if (CC != ARMCC::AL) MI = LastIT; @@ -1434,7 +1422,7 @@ void ARMConstantIslands::createNewWater(unsigned CPUserIndex, // We really must not split an IT block. #ifndef NDEBUG - unsigned PredReg; + Register PredReg; assert(!isThumb || getITInstrPredicate(*MI, PredReg) == ARMCC::AL); #endif NewMBB = splitBlockBeforeInstr(&*MI); @@ -1566,7 +1554,7 @@ void ARMConstantIslands::removeDeadCPEMI(MachineInstr *CPEMI) { BBInfo[CPEBB->getNumber()].Size = 0; // This block no longer needs to be aligned. - CPEBB->setAlignment(Align::None()); + CPEBB->setAlignment(Align(1)); } else { // Entries are sorted by descending alignment, so realign from the front. CPEBB->setAlignment(getCPEAlign(&*CPEBB->begin())); @@ -1633,7 +1621,6 @@ ARMConstantIslands::fixupUnconditionalBr(ImmBranch &Br) { BBInfoVector &BBInfo = BBUtils->getBBInfo(); BBInfo[MBB->getNumber()].Size += 2; BBUtils->adjustBBOffsetsAfter(MBB); - HasFarJump = true; ++NumUBrFixed; LLVM_DEBUG(dbgs() << " Changed B to long jump " << *MI); @@ -1735,34 +1722,6 @@ ARMConstantIslands::fixupConditionalBr(ImmBranch &Br) { return true; } -/// undoLRSpillRestore - Remove Thumb push / pop instructions that only spills -/// LR / restores LR to pc. FIXME: This is done here because it's only possible -/// to do this if tBfar is not used. -bool ARMConstantIslands::undoLRSpillRestore() { - bool MadeChange = false; - for (unsigned i = 0, e = PushPopMIs.size(); i != e; ++i) { - MachineInstr *MI = PushPopMIs[i]; - // First two operands are predicates. - if (MI->getOpcode() == ARM::tPOP_RET && - MI->getOperand(2).getReg() == ARM::PC && - MI->getNumExplicitOperands() == 3) { - // Create the new insn and copy the predicate from the old. - BuildMI(MI->getParent(), MI->getDebugLoc(), TII->get(ARM::tBX_RET)) - .add(MI->getOperand(0)) - .add(MI->getOperand(1)); - MI->eraseFromParent(); - MadeChange = true; - } else if (MI->getOpcode() == ARM::tPUSH && - MI->getOperand(2).getReg() == ARM::LR && - MI->getNumExplicitOperands() == 3) { - // Just remove the push. - MI->eraseFromParent(); - MadeChange = true; - } - } - return MadeChange; -} - bool ARMConstantIslands::optimizeThumb2Instructions() { bool MadeChange = false; @@ -1868,7 +1827,7 @@ bool ARMConstantIslands::optimizeThumb2Branches() { if (!Br.MI->killsRegister(ARM::CPSR)) return false; - unsigned PredReg = 0; + Register PredReg; unsigned NewOpc = 0; ARMCC::CondCodes Pred = getInstrPredicate(*Br.MI, PredReg); if (Pred == ARMCC::EQ) @@ -2402,6 +2361,7 @@ adjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB) { SmallVector<MachineOperand, 4> CondPrior; MachineFunction::iterator BBi = BB->getIterator(); MachineFunction::iterator OldPrior = std::prev(BBi); + MachineFunction::iterator OldNext = std::next(BBi); // If the block terminator isn't analyzable, don't try to move the block bool B = TII->analyzeBranch(*BB, TBB, FBB, Cond); @@ -2412,8 +2372,8 @@ adjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB) { if (!B && Cond.empty() && BB != &MF->front() && !TII->analyzeBranch(*OldPrior, TBB, FBB, CondPrior)) { BB->moveAfter(JTBB); - OldPrior->updateTerminator(); - BB->updateTerminator(); + OldPrior->updateTerminator(BB); + BB->updateTerminator(OldNext != MF->end() ? &*OldNext : nullptr); // Update numbering to account for the block being moved. MF->RenumberBlocks(); ++NumJTMoved; |