28 cl::desc(
"Restrict range of loopN instructions (testing only)"));
39 MachineFunctionProperties getRequiredProperties()
const override {
40 return MachineFunctionProperties().setNoVRegs();
43 StringRef getPassName()
const override {
44 return "Hexagon Hardware Loop Fixup";
47 void getAnalysisUsage(AnalysisUsage &AU)
const override {
64 char HexagonFixupHwLoops::ID = 0;
68 "Hexagon Hardware Loops Fixup",
false,
false)
71 return new HexagonFixupHwLoops();
76 return MI.getOpcode() == Hexagon::J2_loop0r ||
77 MI.getOpcode() == Hexagon::J2_loop0i ||
78 MI.getOpcode() == Hexagon::J2_loop1r ||
79 MI.getOpcode() == Hexagon::J2_loop1i;
85 return fixupLoopInstrs(MF);
99 unsigned InstOffset = 0;
101 DenseMap<const MachineBasicBlock *, unsigned> BlockToInstOffset;
103 const HexagonInstrInfo *HII =
104 static_cast<const HexagonInstrInfo *
>(MF.
getSubtarget().getInstrInfo());
107 for (
const MachineBasicBlock &
MBB : MF) {
115 BlockToInstOffset[&
MBB] = InstOffset;
116 for (
const MachineInstr &
MI :
MBB)
123 for (MachineBasicBlock &
MBB : MF) {
124 InstOffset = BlockToInstOffset[&
MBB];
130 unsigned InstSize = HII->
getSize(*MII);
131 if (MII->isMetaInstruction()) {
136 assert(MII->getOperand(0).isMBB() &&
137 "Expect a basic block as loop operand");
138 MachineBasicBlock *TargetBB = MII->getOperand(0).getMBB();
140 BlockToInstOffset[TargetBB]);
142 useExtLoopInstr(MF, MII);
151 InstOffset += InstSize;
162 MachineBasicBlock *
MBB = MII->getParent();
164 MachineInstrBuilder MIB;
166 switch (MII->getOpcode()) {
167 case Hexagon::J2_loop0r:
168 newOp = Hexagon::J2_loop0rext;
170 case Hexagon::J2_loop0i:
171 newOp = Hexagon::J2_loop0iext;
173 case Hexagon::J2_loop1r:
174 newOp = Hexagon::J2_loop1rext;
176 case Hexagon::J2_loop1i:
177 newOp = Hexagon::J2_loop1iext;
184 for (
unsigned i = 0; i < MII->getNumOperands(); ++i)
185 MIB.
add(MII->getOperand(i));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static cl::opt< unsigned > MaxLoopRange("hexagon-loop-range", cl::Hidden, cl::init(200), cl::desc("Restrict range of loopN instructions (testing only)"))
static bool isHardwareLoop(const MachineInstr &MI)
Returns true if the instruction is a hardware loop instruction.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
unsigned getSize(const MachineInstr &MI) const
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
Align getAlignment() const
Return alignment of the basic block.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
virtual const TargetInstrInfo * getInstrInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createHexagonFixupHwLoops()
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr T AbsoluteDifference(U X, V Y)
Subtract two unsigned integers, X and Y, of type T and return the absolute value of the result.