36#define DEBUG_TYPE "ppc-tls-dynamic-call"
48 bool NeedFence =
true;
51 bool Is64Bit = Subtarget.isPPC64();
62 IsPCREL = isPCREL(
MI);
65 bool IsTLSTPRelMI =
MI.getOpcode() == PPC::GETtlsTpointer32AIX;
66 bool IsTLSLDAIXMI = (
MI.getOpcode() == PPC::TLSLDAIX8 ||
67 MI.getOpcode() == PPC::TLSLDAIX);
69 if (
MI.getOpcode() != PPC::ADDItlsgdLADDR &&
70 MI.getOpcode() != PPC::ADDItlsldLADDR &&
71 MI.getOpcode() != PPC::ADDItlsgdLADDR32 &&
72 MI.getOpcode() != PPC::ADDItlsldLADDR32 &&
73 MI.getOpcode() != PPC::TLSGDAIX &&
74 MI.getOpcode() != PPC::TLSGDAIX8 && !IsTLSTPRelMI && !IsPCREL &&
80 if (
MI.getOpcode() == PPC::ADJCALLSTACKDOWN)
82 else if (
MI.getOpcode() == PPC::ADJCALLSTACKUP)
93 Register GPR3 = Is64Bit ? PPC::X3 : PPC::R3;
94 Register GPR4 = Is64Bit ? PPC::X4 : PPC::R4;
95 if (!IsPCREL && !IsTLSTPRelMI)
96 InReg =
MI.getOperand(1).getReg();
100 switch (
MI.getOpcode()) {
103 case PPC::ADDItlsgdLADDR:
104 Opc1 = PPC::ADDItlsgdL;
105 Opc2 = PPC::GETtlsADDR;
107 case PPC::ADDItlsldLADDR:
108 Opc1 = PPC::ADDItlsldL;
109 Opc2 = PPC::GETtlsldADDR;
111 case PPC::ADDItlsgdLADDR32:
112 Opc1 = PPC::ADDItlsgdL32;
113 Opc2 = PPC::GETtlsADDR32;
115 case PPC::ADDItlsldLADDR32:
116 Opc1 = PPC::ADDItlsldL32;
117 Opc2 = PPC::GETtlsldADDR32;
122 Opc2 = PPC::GETtlsMOD32AIX;
127 Opc2 = PPC::GETtlsMOD64AIX;
132 Opc2 = PPC::GETtlsADDR64AIX;
137 Opc2 = PPC::GETtlsADDR32AIX;
139 case PPC::GETtlsTpointer32AIX:
143 Opc2 = PPC::GETtlsTpointer32AIX;
146 assert(IsPCREL &&
"Expecting General/Local Dynamic PCRel");
147 Opc1 = PPC::PADDI8pc;
148 Opc2 =
MI.getOperand(2).getTargetFlags() ==
150 ? PPC::GETtlsADDRPCREL
151 : PPC::GETtlsldADDRPCREL;
161 MBB.getParent()->getFrameInfo().setAdjustsStack(
true);
177 Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
178 : (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
179 if (!
RegInfo.use_empty(OutReg)) {
180 std::set<MachineInstr *>
Uses;
183 Uses.insert(MO.getParent());
189 if (
Uses.count(&*UseIter))
195 if (UseIter !=
MBB.end()) {
198 std::set<MachineInstr *> LoadFromTocs;
200 if (MO.isReg() && MO.isUse()) {
202 if (
RegInfo.hasOneDef(MOReg)) {
204 RegInfo.getOneDef(MOReg)->getParent();
209 if (Temp == &
MI &&
RegInfo.hasOneDef(InReg))
210 Temp =
RegInfo.getOneDef(InReg)->getParent();
212 LoadFromTocs.insert(Temp);
215 LoadFromTocs.clear();
223 if (LoadFromTocs.size() == 2) {
232 if (LoadFromTocs.count(&*
I)) {
243 if (TLSMLIter !=
MBB.end() && OffsetIter !=
MBB.end())
244 OffsetIter->moveBefore(&*UseIter);
254 }
else if (!IsTLSTPRelMI) {
274 assert(InReg != PPC::NoRegister &&
"Operand must be a register");
283 Call->addOperand(
MI.getOperand(2));
285 Call->addOperand(
MI.getOperand(3));
295 MI.removeFromParent();
305 return (
MI.getOpcode() == PPC::PADDI8pc) &&
306 (
MI.getOperand(2).getTargetFlags() ==
308 MI.getOperand(2).getTargetFlags() ==
333 "PowerPC TLS Dynamic Call Fixup",
false,
false)
339char PPCTLSDynamicCall::
ID = 0;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Remove Loads Into Fake Uses
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
FunctionPass class - This class is used to implement most global optimizations.
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const PPCTargetMachine & getTargetMachine() const
Wrapper class representing virtual and physical registers.
CodeModel::Model getCodeModel() const
Returns the code model.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
#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.
@ MO_GOT_TLSLD_PCREL_FLAG
MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
@ MO_GOT_TLSGD_PCREL_FLAG
MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
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.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
FunctionPass * createPPCTLSDynamicCallPass()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.