#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/PassSupport.h"
using namespace llvm;
MachineBasicBlock::iterator MII = MBB.begin();
MachineBasicBlock::iterator MIE = MBB.end();
while (MII != MIE) {
- InstOffset += HII->getSize(*MII);
+ unsigned InstSize = HII->getSize(*MII);
if (MII->isMetaInstruction()) {
++MII;
continue;
if (isHardwareLoop(*MII)) {
assert(MII->getOperand(0).isMBB() &&
"Expect a basic block as loop operand");
- int diff = InstOffset - BlockToInstOffset[MII->getOperand(0).getMBB()];
- if ((unsigned)abs(diff) > MaxLoopRange) {
+ MachineBasicBlock *TargetBB = MII->getOperand(0).getMBB();
+ unsigned Diff = AbsoluteDifference(InstOffset,
+ BlockToInstOffset[TargetBB]);
+ if (Diff > MaxLoopRange) {
useExtLoopInstr(MF, MII);
MII = MBB.erase(MII);
Changed = true;
} else {
++MII;
}
+ InstOffset += InstSize;
}
}