14 #define DEBUG_TYPE "arc-branch-finalize" 47 return "ARC Branch Finalization Pass";
63 "ARC finalize branches",
false,
false)
96 return !(MI->
getOpcode() != ARC::BRcc_rr_p &&
104 return ARC::BRcc_ru6;
126 replaceWithCmpBcc(MI);
130 void ARCBranchFinalize::replaceWithCmpBcc(
MachineInstr *MI)
const {
146 std::vector<MachineInstr *> Branches;
147 bool Changed =
false;
148 unsigned MaxSize = 0;
150 std::map<MachineBasicBlock *, unsigned> BlockToPCMap;
151 std::vector<std::pair<MachineInstr *, unsigned>> BranchToPCList;
154 for (
auto &MBB : MF) {
155 BlockToPCMap.insert(std::make_pair(&MBB, PC));
156 for (
auto &MI : MBB) {
157 unsigned Size =
TII->getInstSizeInBytes(MI);
158 if (Size > 8 || Size == 0) {
159 LLVM_DEBUG(
dbgs() <<
"Unknown (or size 0) size for: " << MI <<
"\n");
164 Branches.push_back(&MI);
165 BranchToPCList.emplace_back(&MI, PC);
170 for (
auto P : BranchToPCList) {
172 isInt<9>(MaxSize) ? replaceWithBRcc(
P.first) : replaceWithCmpBcc(
P.first);
175 LLVM_DEBUG(
dbgs() <<
"Estimated function size for " << MF.getName() <<
": " 182 return new ARCBranchFinalize();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
MachineBasicBlock * getMBB() const
This class represents lattice values for constants.
arc branch ARC finalize branches
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
void initializeARCBranchFinalizePass(PassRegistry &Registry)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
static bool isBRccPseudo(MachineInstr *MI)
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
arc branch ARC finalize static false unsigned getCCForBRcc(unsigned CC)
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
FunctionPass class - This class is used to implement most global optimizations.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
INITIALIZE_PASS_BEGIN(ARCBranchFinalize, "arc-branch-finalize", "ARC finalize branches", false, false) INITIALIZE_PASS_END(ARCBranchFinalize
static unsigned getBRccForPseudo(MachineInstr *MI)
FunctionPass * createARCBranchFinalizePass()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
static unsigned getCmpForPseudo(MachineInstr *MI)
Representation of each machine instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
const MachineOperand & getOperand(unsigned i) const
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...