27 #define DEBUG_TYPE "hexagon_cfg"
49 StringRef getPassName()
const override {
return "Hexagon CFG Optimizer"; }
60 static bool IsConditionalBranch(
int Opc) {
62 case Hexagon::J2_jumpt:
63 case Hexagon::J2_jumptpt:
64 case Hexagon::J2_jumpf:
65 case Hexagon::J2_jumpfpt:
66 case Hexagon::J2_jumptnew:
67 case Hexagon::J2_jumpfnew:
68 case Hexagon::J2_jumptnewpt:
69 case Hexagon::J2_jumpfnewpt:
76 static bool IsUnconditionalJump(
int Opc) {
77 return (Opc == Hexagon::J2_jump);
80 void HexagonCFGOptimizer::InvertAndChangeJumpTarget(
86 case Hexagon::J2_jumpt:
87 NewOpcode = Hexagon::J2_jumpf;
90 case Hexagon::J2_jumpf:
91 NewOpcode = Hexagon::J2_jumpt;
94 case Hexagon::J2_jumptnewpt:
95 NewOpcode = Hexagon::J2_jumpfnewpt;
98 case Hexagon::J2_jumpfnewpt:
99 NewOpcode = Hexagon::J2_jumptnewpt;
114 if (PB->isLayoutSuccessor(MBB) && PB->canFallThrough())
125 MBBb != MBBe; ++MBBb) {
130 if (MII != MBB->
end()) {
133 if (IsConditionalBranch(Opc)) {
172 LayoutSucc = FirstSucc;
173 JumpAroundTarget = SecondSucc;
175 LayoutSucc = SecondSucc;
176 JumpAroundTarget = FirstSucc;
184 if (MI.
getOpcode() == Hexagon::J2_jumpt ||
189 if (!LayoutSucc || (CondBranchTarget != JumpAroundTarget)) {
193 if ((NumSuccs == 2) && LayoutSucc && (LayoutSucc->
pred_size() == 1)) {
195 if ((LayoutSucc->
size() == 1) &&
197 assert(JumpAroundTarget &&
"jump target is needed to process second basic block");
202 bool case2 = JumpAroundTarget->
isSuccessor(UncondTarget) &&
203 JumpAroundTarget->
size() >= 1 &&
208 if (case1 || case2) {
209 InvertAndChangeJumpTarget(MI, UncondTarget);
218 if (case2 && !case1) {
222 if (!isOnFallThroughPath(UncondTarget))
223 UncondTarget->
moveAfter(JumpAroundTarget);
231 std::vector<MachineBasicBlock::RegisterMaskPair> OrigLiveIn(
233 std::vector<MachineBasicBlock::RegisterMaskPair> NewLiveIn(
236 for (
const auto &OrigLI : OrigLiveIn)
238 for (
const auto &NewLI : NewLiveIn)
259 return new HexagonCFGOptimizer();
unsigned succ_size() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
MachineBasicBlock * getMBB() const
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
void moveAfter(MachineBasicBlock *NewBefore)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
livein_iterator livein_begin() const
livein_iterator livein_end() const
const MachineOperand & getOperand(unsigned i) const
void setMBB(MachineBasicBlock *MBB)
FunctionPass class - This class is used to implement most global optimizations.
iterator_range< pred_iterator > predecessors()
succ_iterator succ_begin()
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Iterator for intrusive lists based on ilist_node.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
llvm_unreachable("Unknown RegBank!")
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
INITIALIZE_PASS(HexagonCFGOptimizer,"hexagon-cfg","Hexagon CFG Optimizer", false, false) FunctionPass *llvm
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
void initializeHexagonCFGOptimizerPass(PassRegistry &)
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
unsigned pred_size() const
std::vector< MachineBasicBlock * >::iterator succ_iterator
Properties which a MachineFunction may have at a given point in time.
FunctionPass * createHexagonCFGOptimizer()