45#define DEBUG_TYPE "riscv-qc-relax-marking"
46#define RISCV_QC_RELAX_MARKING_NAME "RISC-V QC Relaxation Marking"
48STATISTIC(NumMarked,
"Number of Loads/Stores Marked");
64char RISCVQCRelaxMarking::ID = 0;
71 return new RISCVQCRelaxMarking();
87 return RISCV::GPRCRegClass.contains(MO.
getReg());
92 switch (
MI.getOpcode()) {
95 return RISCV::PseudoQCAccessLB;
97 if (STI.hasStdExtZcb() &&
isGPRC(
MI.getOperand(0)) &&
99 return RISCV::PseudoQCAccessC_LBU;
100 return RISCV::PseudoQCAccessLBU;
102 if (STI.hasStdExtZcb() &&
isGPRC(
MI.getOperand(0)) &&
104 return RISCV::PseudoQCAccessC_LH;
105 return RISCV::PseudoQCAccessLH;
107 if (STI.hasStdExtZcb() &&
isGPRC(
MI.getOperand(0)) &&
109 return RISCV::PseudoQCAccessC_LHU;
110 return RISCV::PseudoQCAccessLHU;
112 if (STI.hasStdExtZca() &&
isGPRC(
MI.getOperand(0)) &&
114 return RISCV::PseudoQCAccessC_LW;
115 return RISCV::PseudoQCAccessLW;
117 if (STI.hasStdExtZcb() &&
isGPRC(
MI.getOperand(0)) &&
119 return RISCV::PseudoQCAccessC_SB;
120 return RISCV::PseudoQCAccessSB;
122 if (STI.hasStdExtZcb() &&
isGPRC(
MI.getOperand(0)) &&
124 return RISCV::PseudoQCAccessC_SH;
125 return RISCV::PseudoQCAccessSH;
127 if (STI.hasStdExtZca() &&
isGPRC(
MI.getOperand(0)) &&
129 return RISCV::PseudoQCAccessC_SW;
130 return RISCV::PseudoQCAccessSW;
133 "Unhandled Opcode: No Corresponding Marked Opcode");
150 if (STI.is64Bit() || !STI.hasVendorXqcili() || !STI.enableLinkerRelax())
153 const RISCVInstrInfo *
TII = STI.getInstrInfo();
156 for (MachineBasicBlock &
MBB : MF) {
158 auto NextMI = std::next(
MI);
163 if (
MI->getOpcode() != RISCV::QC_E_LI ||
164 !(RISCVInstrInfo::isBaseLoad(*NextMI) ||
165 RISCVInstrInfo::isBaseStore(*NextMI)))
171 if (
MI->getOperand(0).getReg() != NextMI->getOperand(1).getReg())
173 if (!NextMI->getOperand(1).isKill())
177 if (RISCVInstrInfo::isBaseStore(*NextMI) &&
178 MI->getOperand(0).getReg() == NextMI->getOperand(0).getReg())
181 MachineOperand &SymOp =
MI->getOperand(1);
188 <<
" will become " <<
TII->getName(NewOpc) <<
"\n");
189 MachineInstrBuilder MIB =
190 BuildMI(
MBB, NextMI, NextMI->getDebugLoc(),
TII->get(NewOpc))
191 .
add(NextMI->getOperand(0))
192 .
add(NextMI->getOperand(1))
193 .
add(NextMI->getOperand(2))
206 }
else if (SymOp.
isCPI()) {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool isGPRC(const MachineOperand &MO)
static unsigned getQCMarkedOpcode(const MachineInstr &MI, const RISCVSubtarget &STI)
#define RISCV_QC_RELAX_MARKING_NAME
static bool isUImm2LSB0(const MachineOperand &MO)
static bool isUImm2(const MachineOperand &MO)
static bool isUImm7LSB000(const MachineOperand &MO)
This file declares the machine register scavenger class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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 TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Representation of each machine instruction.
LLVM_ABI MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
const GlobalValue * getGlobal() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
void setOffset(int64_t Offset)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
MCSymbol * getMCSymbol() const
int64_t getOffset() const
Return the offset from the symbol in this operand.
CodeModel::Model getCodeModel() const
Returns the code model.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
FunctionPass * createRISCVQCRelaxMarkingPass()