26#define RISCV_EXPAND_PSEUDO_NAME "RISC-V pseudo instruction expansion pass"
27#define RISCV_PRERA_EXPAND_PSEUDO_NAME "RISC-V Pre-RA pseudo instruction expansion pass"
74char RISCVExpandPseudo::ID = 0;
90 assert(OldSize >= NewSize);
114 switch (
MBBI->getOpcode()) {
115 case RISCV::PseudoMV_FPR16INX:
116 return expandMV_FPR16INX(
MBB,
MBBI);
117 case RISCV::PseudoMV_FPR32INX:
118 return expandMV_FPR32INX(
MBB,
MBBI);
119 case RISCV::PseudoRV32ZdinxSD:
120 return expandRV32ZdinxStore(
MBB,
MBBI);
121 case RISCV::PseudoRV32ZdinxLD:
122 return expandRV32ZdinxLoad(
MBB,
MBBI);
123 case RISCV::PseudoCCMOVGPRNoX0:
124 case RISCV::PseudoCCMOVGPR:
125 case RISCV::PseudoCCADD:
126 case RISCV::PseudoCCSUB:
127 case RISCV::PseudoCCAND:
128 case RISCV::PseudoCCOR:
129 case RISCV::PseudoCCXOR:
130 case RISCV::PseudoCCMAX:
131 case RISCV::PseudoCCMAXU:
132 case RISCV::PseudoCCMIN:
133 case RISCV::PseudoCCMINU:
134 case RISCV::PseudoCCMUL:
135 case RISCV::PseudoCCLUI:
136 case RISCV::PseudoCCQC_LI:
137 case RISCV::PseudoCCQC_E_LI:
138 case RISCV::PseudoCCADDW:
139 case RISCV::PseudoCCSUBW:
140 case RISCV::PseudoCCSLL:
141 case RISCV::PseudoCCSRL:
142 case RISCV::PseudoCCSRA:
143 case RISCV::PseudoCCADDI:
144 case RISCV::PseudoCCSLLI:
145 case RISCV::PseudoCCSRLI:
146 case RISCV::PseudoCCSRAI:
147 case RISCV::PseudoCCANDI:
148 case RISCV::PseudoCCORI:
149 case RISCV::PseudoCCXORI:
150 case RISCV::PseudoCCSLLW:
151 case RISCV::PseudoCCSRLW:
152 case RISCV::PseudoCCSRAW:
153 case RISCV::PseudoCCADDIW:
154 case RISCV::PseudoCCSLLIW:
155 case RISCV::PseudoCCSRLIW:
156 case RISCV::PseudoCCSRAIW:
157 case RISCV::PseudoCCANDN:
158 case RISCV::PseudoCCORN:
159 case RISCV::PseudoCCXNOR:
160 case RISCV::PseudoCCNDS_BFOS:
161 case RISCV::PseudoCCNDS_BFOZ:
162 return expandCCOp(
MBB,
MBBI, NextMBBI);
163 case RISCV::PseudoVMCLR_M_B1:
164 case RISCV::PseudoVMCLR_M_B2:
165 case RISCV::PseudoVMCLR_M_B4:
166 case RISCV::PseudoVMCLR_M_B8:
167 case RISCV::PseudoVMCLR_M_B16:
168 case RISCV::PseudoVMCLR_M_B32:
169 case RISCV::PseudoVMCLR_M_B64:
171 return expandVMSET_VMCLR(
MBB,
MBBI, RISCV::VMXOR_MM);
172 case RISCV::PseudoVMSET_M_B1:
173 case RISCV::PseudoVMSET_M_B2:
174 case RISCV::PseudoVMSET_M_B4:
175 case RISCV::PseudoVMSET_M_B8:
176 case RISCV::PseudoVMSET_M_B16:
177 case RISCV::PseudoVMSET_M_B32:
178 case RISCV::PseudoVMSET_M_B64:
180 return expandVMSET_VMCLR(
MBB,
MBBI, RISCV::VMXNOR_MM);
181 case RISCV::PseudoReadVLENBViaVSETVLIX0:
182 return expandPseudoReadVLENBViaVSETVLIX0(
MBB,
MBBI);
192 if (expandCCOpToCMov(
MBB,
MBBI))
218 assert(
MI.getOperand(4).getReg() == DestReg);
220 if (
MI.getOpcode() == RISCV::PseudoCCMOVGPR ||
221 MI.getOpcode() == RISCV::PseudoCCMOVGPRNoX0) {
224 .
add(
MI.getOperand(5))
229 switch (
MI.getOpcode()) {
232 case RISCV::PseudoCCADD: NewOpc = RISCV::ADD;
break;
233 case RISCV::PseudoCCSUB: NewOpc = RISCV::SUB;
break;
234 case RISCV::PseudoCCSLL: NewOpc = RISCV::SLL;
break;
235 case RISCV::PseudoCCSRL: NewOpc = RISCV::SRL;
break;
236 case RISCV::PseudoCCSRA: NewOpc = RISCV::SRA;
break;
237 case RISCV::PseudoCCAND: NewOpc = RISCV::AND;
break;
238 case RISCV::PseudoCCOR: NewOpc = RISCV::OR;
break;
239 case RISCV::PseudoCCXOR: NewOpc = RISCV::XOR;
break;
240 case RISCV::PseudoCCMAX: NewOpc = RISCV::MAX;
break;
241 case RISCV::PseudoCCMIN: NewOpc = RISCV::MIN;
break;
242 case RISCV::PseudoCCMAXU: NewOpc = RISCV::MAXU;
break;
243 case RISCV::PseudoCCMINU: NewOpc = RISCV::MINU;
break;
244 case RISCV::PseudoCCMUL: NewOpc = RISCV::MUL;
break;
245 case RISCV::PseudoCCLUI: NewOpc = RISCV::LUI;
break;
246 case RISCV::PseudoCCQC_LI: NewOpc = RISCV::QC_LI;
break;
247 case RISCV::PseudoCCQC_E_LI: NewOpc = RISCV::QC_E_LI;
break;
248 case RISCV::PseudoCCADDI: NewOpc = RISCV::ADDI;
break;
249 case RISCV::PseudoCCSLLI: NewOpc = RISCV::SLLI;
break;
250 case RISCV::PseudoCCSRLI: NewOpc = RISCV::SRLI;
break;
251 case RISCV::PseudoCCSRAI: NewOpc = RISCV::SRAI;
break;
252 case RISCV::PseudoCCANDI: NewOpc = RISCV::ANDI;
break;
253 case RISCV::PseudoCCORI: NewOpc = RISCV::ORI;
break;
254 case RISCV::PseudoCCXORI: NewOpc = RISCV::XORI;
break;
255 case RISCV::PseudoCCADDW: NewOpc = RISCV::ADDW;
break;
256 case RISCV::PseudoCCSUBW: NewOpc = RISCV::SUBW;
break;
257 case RISCV::PseudoCCSLLW: NewOpc = RISCV::SLLW;
break;
258 case RISCV::PseudoCCSRLW: NewOpc = RISCV::SRLW;
break;
259 case RISCV::PseudoCCSRAW: NewOpc = RISCV::SRAW;
break;
260 case RISCV::PseudoCCADDIW: NewOpc = RISCV::ADDIW;
break;
261 case RISCV::PseudoCCSLLIW: NewOpc = RISCV::SLLIW;
break;
262 case RISCV::PseudoCCSRLIW: NewOpc = RISCV::SRLIW;
break;
263 case RISCV::PseudoCCSRAIW: NewOpc = RISCV::SRAIW;
break;
264 case RISCV::PseudoCCANDN: NewOpc = RISCV::ANDN;
break;
265 case RISCV::PseudoCCORN: NewOpc = RISCV::ORN;
break;
266 case RISCV::PseudoCCXNOR: NewOpc = RISCV::XNOR;
break;
267 case RISCV::PseudoCCNDS_BFOS: NewOpc = RISCV::NDS_BFOS;
break;
268 case RISCV::PseudoCCNDS_BFOZ: NewOpc = RISCV::NDS_BFOZ;
break;
272 if (NewOpc == RISCV::NDS_BFOZ || NewOpc == RISCV::NDS_BFOS) {
274 .
add(
MI.getOperand(5))
275 .
add(
MI.getOperand(6))
276 .
add(
MI.getOperand(7));
277 }
else if (NewOpc == RISCV::LUI || NewOpc == RISCV::QC_LI ||
278 NewOpc == RISCV::QC_E_LI) {
282 .
add(
MI.getOperand(5))
283 .
add(
MI.getOperand(6));
292 MBB.addSuccessor(TrueBB);
293 MBB.addSuccessor(MergeBB);
295 NextMBBI =
MBB.end();
296 MI.eraseFromParent();
311 if (
MI.getOpcode() != RISCV::PseudoCCMOVGPR &&
312 MI.getOpcode() != RISCV::PseudoCCMOVGPRNoX0)
315 if (!STI->hasVendorXqcicm())
319 if (
MI.getOperand(1).getReg() == RISCV::X0 ||
320 MI.getOperand(4).getReg() == RISCV::X0 ||
321 MI.getOperand(5).getReg() == RISCV::X0)
326 unsigned CMovOpcode, CMovIOpcode;
331 CMovOpcode = RISCV::QC_MVEQ;
332 CMovIOpcode = RISCV::QC_MVEQI;
335 CMovOpcode = RISCV::QC_MVNE;
336 CMovIOpcode = RISCV::QC_MVNEI;
339 CMovOpcode = RISCV::QC_MVLT;
340 CMovIOpcode = RISCV::QC_MVLTI;
343 CMovOpcode = RISCV::QC_MVGE;
344 CMovIOpcode = RISCV::QC_MVGEI;
347 CMovOpcode = RISCV::QC_MVLTU;
348 CMovIOpcode = RISCV::QC_MVLTUI;
351 CMovOpcode = RISCV::QC_MVGEU;
352 CMovIOpcode = RISCV::QC_MVGEUI;
356 if (
MI.getOperand(2).getReg() == RISCV::X0) {
368 MI.eraseFromParent();
382 MI.eraseFromParent();
395 MBBI->eraseFromParent();
404 MBBI->getOperand(0).getReg(), RISCV::sub_16, &RISCV::GPRRegClass);
406 MBBI->getOperand(1).getReg(), RISCV::sub_16, &RISCV::GPRRegClass);
412 MBBI->eraseFromParent();
421 MBBI->getOperand(0).getReg(), RISCV::sub_32, &RISCV::GPRRegClass);
423 MBBI->getOperand(1).getReg(), RISCV::sub_32, &RISCV::GPRRegClass);
429 MBBI->eraseFromParent();
441 TRI->getSubReg(
MBBI->getOperand(0).getReg(), RISCV::sub_gpr_even);
443 TRI->getSubReg(
MBBI->getOperand(0).getReg(), RISCV::sub_gpr_odd);
444 if (
Hi == RISCV::DUMMY_REG_PAIR_WITH_X0)
453 if (
MBBI->getOperand(2).isGlobal() ||
MBBI->getOperand(2).isCPI()) {
454 assert(
MBBI->getOperand(2).getOffset() % 8 == 0);
455 MBBI->getOperand(2).setOffset(
MBBI->getOperand(2).getOffset() + 4);
475 MIBLo.setMemRefs(NewLoMMOs);
478 MBBI->eraseFromParent();
490 TRI->getSubReg(
MBBI->getOperand(0).getReg(), RISCV::sub_gpr_even);
492 TRI->getSubReg(
MBBI->getOperand(0).getReg(), RISCV::sub_gpr_odd);
493 assert(
Hi != RISCV::DUMMY_REG_PAIR_WITH_X0 &&
"Cannot write to X0_Pair");
499 bool IsOp1EqualToLo =
Lo ==
MBBI->getOperand(1).getReg();
501 if (!IsOp1EqualToLo) {
507 if (
MBBI->getOperand(2).isGlobal() ||
MBBI->getOperand(2).isCPI()) {
508 auto Offset =
MBBI->getOperand(2).getOffset();
523 if (IsOp1EqualToLo) {
539 MBBI->eraseFromParent();
543bool RISCVExpandPseudo::expandPseudoReadVLENBViaVSETVLIX0(
547 unsigned Mul =
MBBI->getOperand(1).getImm();
550 VLMUL, 8,
true,
true);
557 MBBI->eraseFromParent();
586 unsigned FlagsHi,
unsigned SecondOpcode);
614char RISCVPreRAExpandPseudo::ID = 0;
616bool RISCVPreRAExpandPseudo::runOnMachineFunction(
MachineFunction &MF) {
630 assert(OldSize >= NewSize);
652 switch (
MBBI->getOpcode()) {
653 case RISCV::PseudoLLA:
654 return expandLoadLocalAddress(
MBB,
MBBI, NextMBBI);
655 case RISCV::PseudoLGA:
656 return expandLoadGlobalAddress(
MBB,
MBBI, NextMBBI);
657 case RISCV::PseudoLA_TLS_IE:
658 return expandLoadTLSIEAddress(
MBB,
MBBI, NextMBBI);
659 case RISCV::PseudoLA_TLS_GD:
660 return expandLoadTLSGDAddress(
MBB,
MBBI, NextMBBI);
661 case RISCV::PseudoLA_TLSDESC:
662 return expandLoadTLSDescAddress(
MBB,
MBBI, NextMBBI);
667bool RISCVPreRAExpandPseudo::expandAuipcInstPair(
670 unsigned SecondOpcode) {
680 Symbol.setTargetFlags(FlagsHi);
692 if (
MI.hasOneMemOperand())
695 MI.eraseFromParent();
699bool RISCVPreRAExpandPseudo::expandLoadLocalAddress(
706bool RISCVPreRAExpandPseudo::expandLoadGlobalAddress(
709 unsigned SecondOpcode = STI->
is64Bit() ? RISCV::LD : RISCV::LW;
714bool RISCVPreRAExpandPseudo::expandLoadTLSIEAddress(
717 unsigned SecondOpcode = STI->
is64Bit() ? RISCV::LD : RISCV::LW;
722bool RISCVPreRAExpandPseudo::expandLoadTLSGDAddress(
729bool RISCVPreRAExpandPseudo::expandLoadTLSDescAddress(
737 unsigned SecondOpcode = STI.
is64Bit() ? RISCV::LD : RISCV::LW;
739 Register FinalReg =
MI.getOperand(0).getReg();
770 MI.eraseFromParent();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define RISCV_PRERA_EXPAND_PSEUDO_NAME
#define RISCV_EXPAND_PSEUDO_NAME
static unsigned getInstSizeInBytes(const MachineInstr &MI, const SystemZInstrInfo *TII)
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.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_ABI MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Describe properties that are true of each instruction in the target description file.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_ABI void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
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.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
LLVM_ABI void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
LLVM_ABI void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
Wrapper class representing virtual and physical registers.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
CondCode getInverseBranchCondition(CondCode)
unsigned getBrCond(CondCode CC, unsigned SelectOpc=0)
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
@ Define
Register definition.
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
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.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
unsigned getKillRegState(bool B)
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
FunctionPass * createRISCVExpandPseudoPass()
FunctionPass * createRISCVPreRAExpandPseudoPass()