Go to the documentation of this file.
26 #define DEBUG_TYPE "arm-block-placement"
27 #define DEBUG_PREFIX "ARM Block Placement: "
33 std::unique_ptr<ARMBasicBlockUtils> BBUtils =
nullptr;
84 return findWLSInBlock(*Predecessor->
pred_begin());
107 WLS->getOperand(1).setIsKill(
false);
108 if (
WLS->getOpcode() == ARM::t2WhileLoopStartTP)
109 WLS->getOperand(2).setIsKill(
false);
125 TII->get(
WLS->getOpcode() == ARM::t2WhileLoopStartTP
126 ? ARM::t2DoLoopStartTP
127 : ARM::t2DoLoopStart));
128 MIB.
add(
WLS->getOperand(0));
129 MIB.
add(
WLS->getOperand(1));
130 if (
WLS->getOpcode() == ARM::t2WhileLoopStartTP)
131 MIB.
add(
WLS->getOperand(2));
134 <<
"Reverting While Loop to Do Loop: " << *
WLS <<
"\n");
142 BBUtils->computeAllBlockSizes();
143 BBUtils->adjustBBOffsetsAfter(Preheader);
190 if (WLSTarget == Predecessor) {
192 <<
"it would convert a WLS from forward to a "
193 <<
"backwards branching WLS\n");
194 RevertedWhileLoops.push_back(WlsInstr);
207 bool Changed =
false;
208 for (
auto *InnerML : *ML)
220 MLI = &getAnalysis<MachineLoopInfo>();
224 BBUtils->computeAllBlockSizes();
225 BBUtils->adjustBBOffsetsAfter(&MF.
front());
226 bool Changed =
false;
227 RevertedWhileLoops.
clear();
230 for (
auto *ML : *MLI)
234 for (
auto *WlsInstr : RevertedWhileLoops)
242 return BBUtils->getOffsetOf(
Other) > BBUtils->getOffsetOf(
BB);
251 assert(BBPrevious &&
"Cannot move the function entry basic block");
256 "Cannot move the given block to before the function entry block");
258 BB->moveBefore(Before);
265 <<
From->getName() <<
" to " << To->getName() <<
"\n");
267 "'To' is expected to be a successor of 'From'");
281 MIB.
addReg(ARM::NoRegister);
283 <<
From->getName() <<
" to " << To->getName() <<
": "
289 FixFallthrough(BBPrevious,
BB);
292 FixFallthrough(BeforePrev, Before);
294 if (BBNext &&
BB->isSuccessor(BBNext))
295 FixFallthrough(
BB, BBNext);
298 BBUtils->computeAllBlockSizes();
299 BBUtils->adjustBBOffsetsAfter(
BB);
pred_iterator pred_begin()
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
bool fixBackwardsWLS(MachineLoop *ML)
Checks if loop has a backwards branching WLS, and if possible, fixes it.
const MachineInstrBuilder & add(const MachineOperand &MO) const
BlockT * getLoopPredecessor() const
If the given loop's header has exactly one unique predecessor outside the loop, return it.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
bool processPostOrderLoops(MachineLoop *ML)
Updates ordering (of WLS BB and their loopExits) in inner loops first Returns true if any change was ...
void insert(iterator MBBI, MachineBasicBlock *MBB)
static bool isUncondBranchOpcode(int Opc)
iterator_range< iterator > terminators()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
unsigned pred_size() const
const MachineBasicBlock & front() const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineOperand & getOperand(unsigned i) const
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
Represent the analysis usage information of a pass.
MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it.
bool revertWhileToDoLoop(MachineInstr *WLS)
FunctionPass * createARMBlockPlacementPass()
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static bool isIndirectBranchOpcode(int Opc)
static MachineInstr * findWLS(MachineLoop *ML)
Find WhileLoopStart in the loop predecessor BB or otherwise in its only predecessor.
Representation of each machine instruction.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
INITIALIZE_PASS(ARMBlockPlacement, DEBUG_TYPE, "ARM block placement", false, false) static MachineInstr *findWLSInBlock(MachineBasicBlock *MBB)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
MachineBasicBlock * getMBB() const
std::string getFullName() const
Return a formatted string to identify this block and its parent function.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void RevertWhileLoopStartLR(MachineInstr *MI, const TargetInstrInfo *TII, unsigned BrOpc=ARM::t2Bcc, bool UseCmp=false)
self_iterator getIterator()
static bool isWhileLoopStart(const MachineInstr &MI)
MachineBasicBlock * getWhileLoopStartTargetBB(const MachineInstr &MI)
const MachineBasicBlock * getParent() const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
Function & getFunction()
Return the LLVM function that this machine code represents.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
bool isPredicated(const MachineInstr &MI) const override
bool blockIsBefore(MachineBasicBlock *BB, MachineBasicBlock *Other)
static bool isJumpTableBranchOpcode(int Opc)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void moveBasicBlock(MachineBasicBlock *BB, MachineBasicBlock *Before)
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
AnalysisUsage & addRequired()
BlockVerifier::State From
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
Optional< std::vector< StOtherPiece > > Other