30#define LOONGARCH_PRERA_EXPAND_PSEUDO_NAME \
31 "LoongArch Pre-RA pseudo instruction expansion pass"
32#define LOONGARCH_EXPAND_PSEUDO_NAME \
33 "LoongArch pseudo instruction expansion pass"
63 unsigned FlagsHi,
unsigned SecondOpcode,
85char LoongArchPreRAExpandPseudo::ID = 0;
87bool LoongArchPreRAExpandPseudo::runOnMachineFunction(
MachineFunction &MF) {
109bool LoongArchPreRAExpandPseudo::expandMI(
112 switch (
MBBI->getOpcode()) {
113 case LoongArch::PseudoLA_PCREL:
114 return expandLoadAddressPcrel(
MBB,
MBBI, NextMBBI);
115 case LoongArch::PseudoLA_GOT:
116 return expandLoadAddressGot(
MBB,
MBBI, NextMBBI);
117 case LoongArch::PseudoLA_TLS_LE:
118 return expandLoadAddressTLSLE(
MBB,
MBBI, NextMBBI);
119 case LoongArch::PseudoLA_TLS_IE:
120 return expandLoadAddressTLSIE(
MBB,
MBBI, NextMBBI);
121 case LoongArch::PseudoLA_TLS_LD:
122 return expandLoadAddressTLSLD(
MBB,
MBBI, NextMBBI);
123 case LoongArch::PseudoLA_TLS_GD:
124 return expandLoadAddressTLSGD(
MBB,
MBBI, NextMBBI);
129bool LoongArchPreRAExpandPseudo::expandPcalau12iInstPair(
132 unsigned SecondOpcode,
unsigned FlagsLo) {
150 if (
MI.hasOneMemOperand())
153 MI.eraseFromParent();
157bool LoongArchPreRAExpandPseudo::expandLoadAddressPcrel(
165 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
170bool LoongArchPreRAExpandPseudo::expandLoadAddressGot(
178 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
183bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLE(
227 MI.eraseFromParent();
231bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSIE(
239 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
244bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLD(
252 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
257bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
265 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
294 unsigned LastOpcode,
unsigned IdentifyingMO);
298 unsigned LastOpcode,
unsigned IdentifyingMO,
300 bool EraseFromParent);
322char LoongArchExpandPseudo::ID = 0;
351 switch (
MBBI->getOpcode()) {
352 case LoongArch::PseudoCopyCFR:
353 return expandCopyCFR(
MBB,
MBBI, NextMBBI);
354 case LoongArch::PseudoLA_PCREL_LARGE:
355 return expandLoadAddressPcrelLarge(
MBB,
MBBI, NextMBBI);
356 case LoongArch::PseudoLA_GOT_LARGE:
357 return expandLoadAddressGotLarge(
MBB,
MBBI, NextMBBI);
358 case LoongArch::PseudoLA_TLS_IE_LARGE:
359 return expandLoadAddressTLSIELarge(
MBB,
MBBI, NextMBBI);
360 case LoongArch::PseudoLA_TLS_LD_LARGE:
361 return expandLoadAddressTLSLDLarge(
MBB,
MBBI, NextMBBI);
362 case LoongArch::PseudoLA_TLS_GD_LARGE:
363 return expandLoadAddressTLSGDLarge(
MBB,
MBBI, NextMBBI);
364 case LoongArch::PseudoCALL:
365 case LoongArch::PseudoCALL_MEDIUM:
366 case LoongArch::PseudoCALL_LARGE:
367 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
false);
368 case LoongArch::PseudoTAIL:
369 case LoongArch::PseudoTAIL_MEDIUM:
370 case LoongArch::PseudoTAIL_LARGE:
371 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
true);
377bool LoongArchExpandPseudo::expandCopyCFR(
398 MF->
insert(++FalseBB->getIterator(), SinkBB);
409 BuildMI(FalseBB,
DL,
TII->get(LoongArch::SET_CFR_TRUE), DestReg);
411 FalseBB->addSuccessor(SinkBB);
413 SinkBB->splice(SinkBB->end(), &
MBB,
MI,
MBB.
end());
414 SinkBB->transferSuccessors(&
MBB);
420 MI.eraseFromParent();
430bool LoongArchExpandPseudo::expandLargeAddressLoad(
433 unsigned IdentifyingMO) {
435 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LastOpcode, IdentifyingMO,
436 MI.getOperand(2),
MI.getOperand(0).getReg(),
440bool LoongArchExpandPseudo::expandLargeAddressLoad(
444 bool EraseFromParent) {
453 unsigned MO0, MO1, MO2, MO3;
454 switch (IdentifyingMO) {
482 Register ScratchReg = LoongArch::R20;
485 "Large code model requires LA64");
500 const char *SymName = Symbol.getSymbolName();
501 Part0.addExternalSymbol(SymName, MO0);
502 Part1.addExternalSymbol(SymName, MO1);
503 Part2.addExternalSymbol(SymName, MO2);
504 Part3.addExternalSymbol(SymName, MO3);
506 Part0.addDisp(Symbol, 0, MO0);
507 Part1.addDisp(Symbol, 0, MO1);
508 Part2.addDisp(Symbol, 0, MO2);
509 Part3.addDisp(Symbol, 0, MO3);
513 MI.eraseFromParent();
518bool LoongArchExpandPseudo::expandLoadAddressPcrelLarge(
523 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
527bool LoongArchExpandPseudo::expandLoadAddressGotLarge(
532 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
536bool LoongArchExpandPseudo::expandLoadAddressTLSIELarge(
541 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
545bool LoongArchExpandPseudo::expandLoadAddressTLSLDLarge(
550 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
554bool LoongArchExpandPseudo::expandLoadAddressTLSGDLarge(
559 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
563bool LoongArchExpandPseudo::expandFunctionCALL(
582 Opcode = IsTailCall ? LoongArch::PseudoB_TAIL : LoongArch::BL;
594 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
595 Register ScratchReg = IsTailCall ? LoongArch::R20 : LoongArch::R1;
613 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
614 Register AddrReg = IsTailCall ? LoongArch::R19 : LoongArch::R1;
616 bool UseGOT = Func.isGlobal() && !Func.getGlobal()->isDSOLocal();
618 unsigned LAOpcode = UseGOT ? LoongArch::LDX_D : LoongArch::ADD_D;
619 expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LAOpcode, MO, Func, AddrReg,
627 CALL.copyImplicitOps(
MI);
630 CALL.setMIFlags(
MI.getFlags());
632 MI.eraseFromParent();
647 return new LoongArchPreRAExpandPseudo();
650 return new LoongArchExpandPseudo();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static Expected< BitVector > expand(StringRef S, StringRef Original)
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define LOONGARCH_PRERA_EXPAND_PSEUDO_NAME
#define LOONGARCH_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:
LLVM Basic Block Representation.
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...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
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
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void insert(iterator MBBI, MachineBasicBlock *MBB)
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 & 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.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
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.
StringRef - Represent a constant reference to a string, i.e.
CodeModel::Model getCodeModel() const
Returns the code model.
virtual const TargetInstrInfo * getInstrInfo() const
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.
@ 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 initializeLoongArchExpandPseudoPass(PassRegistry &)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
FunctionPass * createLoongArchPreRAExpandPseudoPass()
FunctionPass * createLoongArchExpandPseudoPass()
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().