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,
68 unsigned LastOpcode,
unsigned IdentifyingMO);
72 unsigned LastOpcode,
unsigned IdentifyingMO,
74 bool EraseFromParent);
108char LoongArchPreRAExpandPseudo::ID = 0;
110bool LoongArchPreRAExpandPseudo::runOnMachineFunction(
MachineFunction &MF) {
132bool LoongArchPreRAExpandPseudo::expandMI(
135 switch (
MBBI->getOpcode()) {
136 case LoongArch::PseudoLA_PCREL:
137 return expandLoadAddressPcrel(
MBB,
MBBI, NextMBBI);
138 case LoongArch::PseudoLA_PCREL_LARGE:
139 return expandLoadAddressPcrel(
MBB,
MBBI, NextMBBI,
true);
140 case LoongArch::PseudoLA_GOT:
141 return expandLoadAddressGot(
MBB,
MBBI, NextMBBI);
142 case LoongArch::PseudoLA_GOT_LARGE:
143 return expandLoadAddressGot(
MBB,
MBBI, NextMBBI,
true);
144 case LoongArch::PseudoLA_TLS_LE:
145 return expandLoadAddressTLSLE(
MBB,
MBBI, NextMBBI);
146 case LoongArch::PseudoLA_TLS_IE:
147 return expandLoadAddressTLSIE(
MBB,
MBBI, NextMBBI);
148 case LoongArch::PseudoLA_TLS_IE_LARGE:
149 return expandLoadAddressTLSIE(
MBB,
MBBI, NextMBBI,
true);
150 case LoongArch::PseudoLA_TLS_LD:
151 return expandLoadAddressTLSLD(
MBB,
MBBI, NextMBBI);
152 case LoongArch::PseudoLA_TLS_LD_LARGE:
153 return expandLoadAddressTLSLD(
MBB,
MBBI, NextMBBI,
true);
154 case LoongArch::PseudoLA_TLS_GD:
155 return expandLoadAddressTLSGD(
MBB,
MBBI, NextMBBI);
156 case LoongArch::PseudoLA_TLS_GD_LARGE:
157 return expandLoadAddressTLSGD(
MBB,
MBBI, NextMBBI,
true);
158 case LoongArch::PseudoLA_TLS_DESC_PC:
159 return expandLoadAddressTLSDesc(
MBB,
MBBI, NextMBBI);
160 case LoongArch::PseudoLA_TLS_DESC_PC_LARGE:
161 return expandLoadAddressTLSDesc(
MBB,
MBBI, NextMBBI,
true);
162 case LoongArch::PseudoCALL:
163 case LoongArch::PseudoCALL_MEDIUM:
164 case LoongArch::PseudoCALL_LARGE:
165 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
false);
166 case LoongArch::PseudoTAIL:
167 case LoongArch::PseudoTAIL_MEDIUM:
168 case LoongArch::PseudoTAIL_LARGE:
169 return expandFunctionCALL(
MBB,
MBBI, NextMBBI,
true);
174bool LoongArchPreRAExpandPseudo::expandPcalau12iInstPair(
177 unsigned SecondOpcode,
unsigned FlagsLo) {
195 if (
MI.hasOneMemOperand())
198 MI.eraseFromParent();
202bool LoongArchPreRAExpandPseudo::expandLargeAddressLoad(
205 unsigned IdentifyingMO) {
207 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LastOpcode, IdentifyingMO,
208 MI.getOperand(2),
MI.getOperand(0).getReg(),
212bool LoongArchPreRAExpandPseudo::expandLargeAddressLoad(
216 bool EraseFromParent) {
225 unsigned MO0, MO1, MO2, MO3;
226 switch (IdentifyingMO) {
257 "Large code model requires LA64");
287 const char *SymName = Symbol.getSymbolName();
288 Part0.addExternalSymbol(SymName, MO0);
289 Part1.addExternalSymbol(SymName, MO1);
290 Part2.addExternalSymbol(SymName, MO2);
291 Part3.addExternalSymbol(SymName, MO3);
293 Part0.addDisp(Symbol, 0, MO0);
294 Part1.addDisp(Symbol, 0, MO1);
295 Part2.addDisp(Symbol, 0, MO2);
296 Part3.addDisp(Symbol, 0, MO3);
300 MI.eraseFromParent();
305bool LoongArchPreRAExpandPseudo::expandLoadAddressPcrel(
311 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
319 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
324bool LoongArchPreRAExpandPseudo::expandLoadAddressGot(
330 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
338 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
343bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLE(
387 MI.eraseFromParent();
391bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSIE(
397 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::LDX_D,
405 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
410bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSLD(
416 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
424 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
429bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
435 return expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LoongArch::ADD_D,
443 unsigned SecondOpcode = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
448bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSDesc(
456 unsigned ADD = STI.is64Bit() ? LoongArch::ADD_D : LoongArch::ADD_W;
457 unsigned ADDI = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
458 unsigned LD = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
480 "Large code model requires LA64");
521 MI.eraseFromParent();
525bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
544 Opcode = IsTailCall ? LoongArch::PseudoB_TAIL : LoongArch::BL;
556 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
578 IsTailCall ? LoongArch::PseudoJIRL_TAIL : LoongArch::PseudoJIRL_CALL;
584 bool UseGOT = Func.isGlobal() && !Func.getGlobal()->isDSOLocal();
586 unsigned LAOpcode = UseGOT ? LoongArch::LDX_D : LoongArch::ADD_D;
587 expandLargeAddressLoad(
MBB,
MBBI, NextMBBI, LAOpcode, MO, Func, AddrReg,
595 CALL.copyImplicitOps(
MI);
598 CALL.setMIFlags(
MI.getFlags());
600 MI.eraseFromParent();
627char LoongArchExpandPseudo::ID = 0;
656 switch (
MBBI->getOpcode()) {
657 case LoongArch::PseudoCopyCFR:
658 return expandCopyCFR(
MBB,
MBBI, NextMBBI);
664bool LoongArchExpandPseudo::expandCopyCFR(
685 MF->
insert(++FalseBB->getIterator(), SinkBB);
696 BuildMI(FalseBB,
DL,
TII->get(LoongArch::SET_CFR_TRUE), DestReg);
698 FalseBB->addSuccessor(SinkBB);
700 SinkBB->splice(SinkBB->end(), &
MBB,
MI,
MBB.
end());
701 SinkBB->transferSuccessors(&
MBB);
707 MI.eraseFromParent();
728 return new LoongArchPreRAExpandPseudo();
731 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.
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
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().