30#define LOONGARCH_PRERA_EXPAND_PSEUDO_NAME \
31 "LoongArch Pre-RA pseudo instruction expansion pass"
61 unsigned FlagsHi,
unsigned SecondOpcode,
66 unsigned LastOpcode,
unsigned IdentifyingMO);
70 unsigned LastOpcode,
unsigned IdentifyingMO,
72 bool EraseFromParent);
102char LoongArchPreRAExpandPseudo::ID = 0;
104bool LoongArchPreRAExpandPseudo::runOnMachineFunction(
MachineFunction &MF) {
126bool LoongArchPreRAExpandPseudo::expandMI(
129 switch (
MBBI->getOpcode()) {
130 case LoongArch::PseudoLA_PCREL:
131 return expandLoadAddressPcrel(
MBB,
MBBI, NextMBBI);
132 case LoongArch::PseudoLA_PCREL_LARGE:
133 return expandLoadAddressPcrel(
MBB,
MBBI, NextMBBI,
true);
134 case LoongArch::PseudoLA_GOT:
135 return expandLoadAddressGot(
MBB,
MBBI, NextMBBI);
136 case LoongArch::PseudoLA_GOT_LARGE:
137 return expandLoadAddressGot(
MBB,
MBBI, NextMBBI,
true);
138 case LoongArch::PseudoLA_TLS_LE:
139 return expandLoadAddressTLSLE(
MBB,
MBBI, NextMBBI);
140 case LoongArch::PseudoLA_TLS_IE:
141 return expandLoadAddressTLSIE(
MBB,
MBBI, NextMBBI);
142 case LoongArch::PseudoLA_TLS_IE_LARGE:
143 return expandLoadAddressTLSIE(
MBB,
MBBI, NextMBBI,
true);
144 case LoongArch::PseudoLA_TLS_LD:
145 return expandLoadAddressTLSLD(
MBB,
MBBI, NextMBBI);
146 case LoongArch::PseudoLA_TLS_LD_LARGE:
147 return expandLoadAddressTLSLD(
MBB,
MBBI, NextMBBI,
true);
148 case LoongArch::PseudoLA_TLS_GD:
149 return expandLoadAddressTLSGD(
MBB,
MBBI, NextMBBI);
150 case LoongArch::PseudoLA_TLS_GD_LARGE:
151 return expandLoadAddressTLSGD(
MBB,
MBBI, NextMBBI,
true);
152 case LoongArch::PseudoCALL:
153 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
false);
154 case LoongArch::PseudoTAIL:
155 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
true);
160bool LoongArchPreRAExpandPseudo::expandPcalau12iInstPair(
163 unsigned SecondOpcode,
unsigned FlagsLo) {
181 if (
MI.hasOneMemOperand())
184 MI.eraseFromParent();
188bool LoongArchPreRAExpandPseudo::expandLargeAddressLoad(
191 unsigned IdentifyingMO) {
193 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LastOpcode, IdentifyingMO,
194 MI.getOperand(2),
MI.getOperand(0).getReg(),
198bool LoongArchPreRAExpandPseudo::expandLargeAddressLoad(
202 bool EraseFromParent) {
211 unsigned MO0, MO1, MO2, MO3;
212 switch (IdentifyingMO) {
243 "Large code model requires LA64");
273 const char *SymName = Symbol.getSymbolName();
274 Part0.addExternalSymbol(SymName, MO0);
275 Part1.addExternalSymbol(SymName, MO1);
276 Part2.addExternalSymbol(SymName, MO2);
277 Part3.addExternalSymbol(SymName, MO3);
279 Part0.addDisp(Symbol, 0, MO0);
280 Part1.addDisp(Symbol, 0, MO1);
281 Part2.addDisp(Symbol, 0, MO2);
282 Part3.addDisp(Symbol, 0, MO3);
286 MI.eraseFromParent();
291bool LoongArchPreRAExpandPseudo::expandLoadAddressPcrel(
297 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
305 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
310bool LoongArchPreRAExpandPseudo::expandLoadAddressGot(
316 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
324 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
329bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLE(
373 MI.eraseFromParent();
377bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSIE(
383 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
391 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
396bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLD(
402 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
410 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
415bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
421 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
429 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
434bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
453 Opcode = IsTailCall ? LoongArch::PseudoB_TAIL : LoongArch::BL;
465 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
473 if (Func.isSymbol()) {
474 const char *FnName = Func.getSymbolName();
479 assert(Func.isGlobal() &&
"Expected a GlobalValue at this time");
490 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
496 bool UseGOT = Func.isGlobal() && !Func.getGlobal()->isDSOLocal();
498 unsigned LAOpcode = UseGOT ? LoongArch::LDX_D : LoongArch::ADD_D;
499 expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LAOpcode, MO, Func, AddrReg,
507 CALL.copyImplicitOps(
MI);
510 CALL.setMIFlags(
MI.getFlags());
512 MI.eraseFromParent();
524 return new LoongArchPreRAExpandPseudo();
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.
#define LOONGARCH_PRERA_EXPAND_PSEUDO_NAME
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represent the analysis usage information of a pass.
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.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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 LLVMTargetMachine & 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 & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDisp(const MachineOperand &Disp, int64_t off, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
MachineOperand class - Representation of each machine instruction operand.
@ MO_ExternalSymbol
Name of external global symbol.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
StringRef - Represent a constant reference to a string, i.e.
CodeModel::Model getCodeModel() const
Returns the code model.
virtual const TargetInstrInfo * getInstrInfo() const
#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.
@ Kill
The last use of a register.
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.
void initializeLoongArchPreRAExpandPseudoPass(PassRegistry &)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
FunctionPass * createLoongArchPreRAExpandPseudoPass()