From 56c42ef3e43f8eb75c435e781d0ac8251c7588a1 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Mon, 23 Apr 2007 20:09:04 +0000 Subject: [PATCH] Make Thumb funcs containing islands 4-byte aligned. Fix bugs maintaining BBOffsets and BBSizes when adjusting conditional branches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36372 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMConstantIslandPass.cpp | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Target/ARM/ARMConstantIslandPass.cpp b/lib/Target/ARM/ARMConstantIslandPass.cpp index ecf91c74044..ae6afcee44d 100644 --- a/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -121,7 +121,6 @@ namespace { bool HasFarJump; const TargetInstrInfo *TII; - const ARMFunctionInfo *AFI; bool isThumb; public: virtual bool runOnMachineFunction(MachineFunction &Fn); @@ -173,9 +172,9 @@ FunctionPass *llvm::createARMConstantIslandPass() { bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) { MachineConstantPool &MCP = *Fn.getConstantPool(); + ARMFunctionInfo *AFI = Fn.getInfo(); TII = Fn.getTarget().getInstrInfo(); - AFI = Fn.getInfo(); isThumb = AFI->isThumbFunction(); HasFarJump = false; @@ -184,11 +183,18 @@ 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. + AFI->setAlign(isThumb ? 1U : 2U); + // Perform the initial placement of the constant pool entries. To start with, // we put them all at the end of the function. std::vector CPEMIs; - if (!MCP.isEmpty()) + if (!MCP.isEmpty()) { DoInitialPlacement(Fn, CPEMIs); + if (isThumb) + AFI->setAlign(2U); + } /// The next UID to take is the first unused one. NextUID = CPEMIs.size(); @@ -1071,6 +1077,9 @@ ARMConstantIslands::FixUpConditionalBr(MachineFunction &Fn, ImmBranch &Br) { SplitBlockBeforeInstr(MI); // No need for the branch to the next block. We're adding a unconditional // branch to the destination. + int delta = ARM::GetInstSize(&MBB->back()); + BBSizes[MBB->getNumber()] -= delta; + AdjustBBOffsetsAfter(MBB, -delta); MBB->back().eraseFromParent(); } MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB)); @@ -1079,18 +1088,22 @@ ARMConstantIslands::FixUpConditionalBr(MachineFunction &Fn, ImmBranch &Br) { << " also invert condition and change dest. to BB#" << NextBB->getNumber() << "\n"; - // Insert a unconditional branch and replace the conditional branch. + // Insert a new conditional branch and a new unconditional branch. // Also update the ImmBranch as well as adding a new entry for the new branch. BuildMI(MBB, TII->get(MI->getOpcode())).addMBB(NextBB).addImm(CC); Br.MI = &MBB->back(); + BBSizes[MBB->getNumber()] += ARM::GetInstSize(&MBB->back()); BuildMI(MBB, TII->get(Br.UncondBr)).addMBB(DestBB); + BBSizes[MBB->getNumber()] += ARM::GetInstSize(&MBB->back()); unsigned MaxDisp = getUnconditionalBrDisp(Br.UncondBr); ImmBranches.push_back(ImmBranch(&MBB->back(), MaxDisp, false, Br.UncondBr)); + + // Remove the old conditional branch. It may or may not still be in MBB. + BBSizes[MI->getParent()->getNumber()] -= ARM::GetInstSize(MI); MI->eraseFromParent(); - // Increase the size of MBB to account for the new unconditional branch. + // The net size change is an addition of one unconditional branch. int delta = ARM::GetInstSize(&MBB->back()); - BBSizes[MBB->getNumber()] += delta; AdjustBBOffsetsAfter(MBB, delta); return true; } -- 2.34.1