28 #define DEBUG_TYPE "hexagon_cfg"
49 const char *getPassName()
const override {
50 return "Hexagon CFG Optimizer";
58 static bool IsConditionalBranch(
int Opc) {
59 return (Opc == Hexagon::J2_jumpt) || (Opc == Hexagon::J2_jumpf)
60 || (Opc == Hexagon::J2_jumptnewpt) || (Opc == Hexagon::J2_jumpfnewpt);
64 static bool IsUnconditionalJump(
int Opc) {
65 return (Opc == Hexagon::J2_jump);
76 case Hexagon::J2_jumpt:
77 NewOpcode = Hexagon::J2_jumpf;
80 case Hexagon::J2_jumpf:
81 NewOpcode = Hexagon::J2_jumpt;
84 case Hexagon::J2_jumptnewpt:
85 NewOpcode = Hexagon::J2_jumpfnewpt;
88 case Hexagon::J2_jumpfnewpt:
89 NewOpcode = Hexagon::J2_jumptnewpt;
104 MBBb != MBBe; ++MBBb) {
109 if (MII != MBB->
end()) {
112 if (IsConditionalBranch(Opc)) {
151 LayoutSucc = FirstSucc;
152 JumpAroundTarget = SecondSucc;
154 LayoutSucc = SecondSucc;
155 JumpAroundTarget = FirstSucc;
163 if ((MI->
getOpcode() == Hexagon::J2_jumpt) ||
164 (MI->
getOpcode() == Hexagon::J2_jumpf)) {
168 if (!LayoutSucc || (CondBranchTarget != JumpAroundTarget)) {
172 if ((NumSuccs == 2) && LayoutSucc && (LayoutSucc->
pred_size() == 1)) {
175 if ((LayoutSucc->
size() == 1) &&
181 bool case2 = JumpAroundTarget->
isSuccessor(UncondTarget) &&
182 JumpAroundTarget->
size() >= 1 &&
187 if (case1 || case2) {
188 InvertAndChangeJumpTarget(MI, UncondTarget);
199 if (case2 && !case1) {
204 UncondTarget->
moveAfter(JumpAroundTarget);
213 std::vector<unsigned> OrigLiveIn(LayoutSucc->
livein_begin(),
215 std::vector<unsigned> NewLiveIn(JumpAroundTarget->
livein_begin(),
217 for (
unsigned i = 0; i < OrigLiveIn.size(); ++i) {
220 for (
unsigned i = 0; i < NewLiveIn.size(); ++i) {
240 &HexagonCFGOptimizer::ID,
nullptr,
false,
false);
249 return new HexagonCFGOptimizer();
unsigned succ_size() const
const MachineFunction * getParent() const
getParent - 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()
getFirstTerminator - returns an iterator to the first terminator instruction of this basic block...
A global registry used in conjunction with static constructors to make pluggable components (like tar...
void removeLiveIn(unsigned Reg)
removeLiveIn - Remove the specified register from the live in set.
void addLiveIn(unsigned Reg)
Adds the specified register as a live in.
void moveAfter(MachineBasicBlock *NewBefore)
livein_iterator livein_begin() const
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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::vector< MachineBasicBlock * >::iterator succ_iterator
bool canFallThrough()
canFallThrough - Return true if the block can implicitly transfer control to the block after it by fa...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
livein_iterator livein_end() const
const MachineOperand & getOperand(unsigned i) const
static void initializePassOnce(PassRegistry &Registry)
void setMBB(MachineBasicBlock *MBB)
FunctionPass class - This class is used to implement most global optimizations.
succ_iterator succ_begin()
PassInfo class - An instance of this class exists for every pass known by the system, and can be obtained from a live Pass by calling its getPassInfo() method.
void removeSuccessor(MachineBasicBlock *succ)
removeSuccessor - Remove successor from the successors list of this MachineBasicBlock.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
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
isSuccessor - Return true if the specified MBB is a successor of this block.
Representation of each machine instruction.
virtual const TargetInstrInfo * getInstrInfo() const
#define CALL_ONCE_INITIALIZATION(function)
void initializeHexagonCFGOptimizerPass(PassRegistry &)
BasicBlockListType::iterator iterator
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
isLayoutSuccessor - Return true if the specified MBB will be emitted immediately after this block...
void registerPass(const PassInfo &PI, bool ShouldFree=false)
registerPass - Register a pass (by means of its PassInfo) with the registry.
void addSuccessor(MachineBasicBlock *succ, uint32_t weight=0)
addSuccessor - Add succ as a successor of this MachineBasicBlock.
unsigned pred_size() const
FunctionPass * createHexagonCFGOptimizer()