10 #define DEBUG_TYPE "hexagon-brelax" 60 return "Hexagon Branch Relaxation";
86 "Hexagon Branch Relaxation",
false,
false)
89 return new HexagonBranchRelaxation();
92 bool HexagonBranchRelaxation::runOnMachineFunction(
MachineFunction &MF) {
97 HRI = HST.getRegisterInfo();
100 Changed = relaxBranches(MF);
107 unsigned InstOffset = 0;
109 if (
B.getAlignment()) {
113 int ByteAlign = (1u <<
B.getAlignment()) - 1;
114 InstOffset = (InstOffset + ByteAlign) & ~(ByteAlign);
116 OffsetMap[&
B] = InstOffset;
117 for (
auto &
MI :
B.instrs()) {
118 InstOffset += HII->getSize(
MI);
120 if (
MI.isBranch() && HII->isExtendable(
MI))
136 computeOffset(MF, BlockToInstOffset);
138 return reGenerateBranch(MF, BlockToInstOffset);
152 if (HII->isExtended(MI))
155 unsigned InstOffset = BlockToInstOffset[&
B];
156 unsigned Distance = 0;
167 if (HII->analyzeBranch(B, TBB, FBB, Cond,
false)) {
171 if (HII->isNewValueJump(*FirstTerm))
172 TBB = FirstTerm->getOperand(HII->getCExtOpNum(*FirstTerm)).getMBB();
174 if (TBB && &MI == &*FirstTerm) {
175 Distance =
std::abs((
long long)InstOffset - BlockToInstOffset[TBB])
177 return !HII->isJumpWithinBranchRange(*FirstTerm, Distance);
181 auto SecondTerm = std::next(FirstTerm);
183 (SecondTerm->isBranch() || SecondTerm->isCall()) &&
184 "Bad second terminator");
185 if (&MI != &*SecondTerm)
188 Distance =
std::abs((
long long)InstOffset - BlockToInstOffset[FBB])
190 return !HII->isJumpWithinBranchRange(*SecondTerm, Distance);
197 bool Changed =
false;
201 if (!MI.
isBranch() || !isJumpOutOfRange(MI, BlockToInstOffset))
204 << HII->isExtendable(MI) <<
") isConstExtended(" 205 << HII->isConstExtended(MI) <<
") " <<
MI);
209 if (!HII->isExtendable(MI) && !HII->isExtended(MI)) {
210 LLVM_DEBUG(
dbgs() <<
"\tUnderimplemented relax branch instruction.\n");
213 int ExtOpNum = HII->getCExtOpNum(MI);
218 assert(MO.
isMBB() &&
"Branch with unknown expandable field type");
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
instr_iterator instr_end()
This class represents lattice values for constants.
instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
#define HEXAGON_INSTR_SIZE
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void initializeHexagonBranchRelaxationPass(PassRegistry &)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
static cl::opt< uint32_t > BranchRelaxSafetyBuffer("branch-relax-safety-buffer", cl::init(200), cl::Hidden, cl::ZeroOrMore, cl::desc("safety buffer size"))
FunctionPass class - This class is used to implement most global optimizations.
INITIALIZE_PASS(HexagonBranchRelaxation, "hexagon-brelax", "Hexagon Branch Relaxation", false, false) FunctionPass *llvm
FunctionPass * createHexagonBranchRelaxation()
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
void addTargetFlag(unsigned F)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const HexagonInstrInfo * getInstrInfo() const override
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 isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
const MachineOperand & getOperand(unsigned i) const