23#define DEBUG_TYPE "riscv-insert-read-write-csr"
24#define RISCV_INSERT_READ_WRITE_CSR_NAME "RISC-V Insert Read/Write CSR Pass"
54char RISCVInsertReadWriteCSR::ID = 0;
67 if (
MI.getOpcode() == RISCV::SwapFRMImm ||
68 MI.getOpcode() == RISCV::WriteFRMImm) {
69 CurrentRM =
MI.getOperand(0).getImm();
74 if (
MI.getOpcode() == RISCV::WriteFRM) {
80 if (
MI.isCall() ||
MI.isInlineAsm() ||
81 MI.readsRegister(RISCV::FRM,
nullptr)) {
91 assert(!
MI.modifiesRegister(RISCV::FRM,
nullptr) &&
92 "Expected that MI could not modify FRM.");
97 unsigned InstrRM =
MI.getOperand(FRMIdx).getImm();
107 if (InstrRM == CurrentRM)
126 assert(LastFRMChanger &&
"Expected valid pointer.");
127 MachineInstrBuilder MIB =
128 BuildMI(*MBB.getParent(), {},
TII->get(RISCV::WriteFRM))
130 MBB.insertAfter(LastFRMChanger, MIB);
140 for (MachineInstr &
MI :
MBB) {
145 unsigned FRMImm =
MI.getOperand(FRMIdx).getImm();
162 MachineInstrBuilder MIB =
170bool RISCVInsertReadWriteCSR::runOnMachineFunction(
MachineFunction &MF) {
173 if (!
ST.hasVInstructions())
176 TII =
ST.getInstrInfo();
180 for (MachineBasicBlock &
MBB : MF) {
181 if (!
ST.getCLOpts().frm_insert_opt)
191 return new RISCVInsertReadWriteCSR();
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
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
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,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
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.
FunctionPass * createRISCVInsertReadWriteCSRPass()