26#define DEBUG_TYPE "riscv-insert-read-write-csr"
27#define RISCV_INSERT_READ_WRITE_CSR_NAME "RISC-V Insert Read/Write CSR Pass"
51char RISCVInsertReadWriteCSRLegacy::ID = 0;
65 if (
MI.getOpcode() == RISCV::SwapFRMImm ||
66 MI.getOpcode() == RISCV::WriteFRMImm) {
72 if (
MI.getOpcode() == RISCV::WriteFRM) {
78 if (
MI.isCall() ||
MI.isInlineAsm() ||
79 MI.readsRegister(RISCV::FRM,
nullptr)) {
89 assert(!
MI.modifiesRegister(RISCV::FRM,
nullptr) &&
90 "Expected that MI could not modify FRM.");
95 unsigned InstrRM =
MI.getOperand(FRMIdx).getImm();
111 SavedFRM =
MRI->createVirtualRegister(&RISCV::GPRRegClass);
124 assert(LastFRMChanger &&
"Expected valid pointer.");
125 MachineInstrBuilder MIB =
126 BuildMI(*MBB.getParent(), {},
TII->get(RISCV::WriteFRM))
144 unsigned FRMImm =
MI.getOperand(FRMIdx).getImm();
164 MBB.insertAfter(
MI, MIB);
172 if (!ST.hasVInstructions())
180 if (!ST.getCLOpts().frm_insert_opt)
190 return new RISCVInsertReadWriteCSRLegacy();
193bool RISCVInsertReadWriteCSRLegacy::runOnMachineFunction(
MachineFunction &MF) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define RISCV_INSERT_READ_WRITE_CSR_NAME
static bool emitWriteRoundingMode(MachineBasicBlock &MBB, const TargetInstrInfo *TII)
static bool insertReadWriteCSROnMachineFunction(MachineFunction &MF)
MachineInstr * LastFRMChanger
MachineRegisterInfo & MRI
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Wrapper class representing virtual and physical registers.
Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
Pass manager infrastructure for declaring and invalidating analyses.
static int getFRMOpNum(const MCInstrDesc &Desc)
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createRISCVInsertReadWriteCSRLegacyPass()