#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <memory>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumSplit, "Number of basic blocks split");
STATISTIC(NumConditionalRelaxed, "Number of conditional branches relaxed");
STATISTIC(NumUnconditionalRelaxed, "Number of unconditional branches relaxed");
#define BRANCH_RELAX_NAME …
namespace {
class BranchRelaxation : public MachineFunctionPass { … };
}
char BranchRelaxation::ID = …;
char &llvm::BranchRelaxationPassID = …;
INITIALIZE_PASS(…)
void BranchRelaxation::verify() { … }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void BranchRelaxation::dumpBBs() {
for (auto &MBB : *MF) {
const BasicBlockInfo &BBI = BlockInfo[MBB.getNumber()];
dbgs() << format("%%bb.%u\toffset=%08x\t", MBB.getNumber(), BBI.Offset)
<< format("size=%#x\n", BBI.Size);
}
}
#endif
void BranchRelaxation::scanFunction() { … }
uint64_t
BranchRelaxation::computeBlockSize(const MachineBasicBlock &MBB) const { … }
unsigned BranchRelaxation::getInstrOffset(const MachineInstr &MI) const { … }
void BranchRelaxation::adjustBlockOffsets(MachineBasicBlock &Start) { … }
void BranchRelaxation::adjustBlockOffsets(MachineBasicBlock &Start,
MachineFunction::iterator End) { … }
MachineBasicBlock *
BranchRelaxation::createNewBlockAfter(MachineBasicBlock &OrigBB) { … }
MachineBasicBlock *
BranchRelaxation::createNewBlockAfter(MachineBasicBlock &OrigMBB,
const BasicBlock *BB) { … }
MachineBasicBlock *
BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI,
MachineBasicBlock *DestBB) { … }
bool BranchRelaxation::isBlockInRange(const MachineInstr &MI,
const MachineBasicBlock &DestBB) const { … }
bool BranchRelaxation::fixupConditionalBranch(MachineInstr &MI) { … }
bool BranchRelaxation::fixupUnconditionalBranch(MachineInstr &MI) { … }
bool BranchRelaxation::relaxBranchInstructions() { … }
bool BranchRelaxation::runOnMachineFunction(MachineFunction &mf) { … }