35#define DEBUG_TYPE "ppc-tls-dynamic-call"
47 bool NeedFence =
true;
50 bool Is64Bit = Subtarget.
isPPC64();
61 IsPCREL = isPCREL(
MI);
64 bool IsTLSTPRelMI =
MI.getOpcode() == PPC::GETtlsTpointer32AIX;
65 bool IsTLSLDAIXMI = (
MI.getOpcode() == PPC::TLSLDAIX8 ||
66 MI.getOpcode() == PPC::TLSLDAIX);
68 if (
MI.getOpcode() != PPC::ADDItlsgdLADDR &&
69 MI.getOpcode() != PPC::ADDItlsldLADDR &&
70 MI.getOpcode() != PPC::ADDItlsgdLADDR32 &&
71 MI.getOpcode() != PPC::ADDItlsldLADDR32 &&
72 MI.getOpcode() != PPC::TLSGDAIX &&
73 MI.getOpcode() != PPC::TLSGDAIX8 && !IsTLSTPRelMI && !IsPCREL &&
79 if (
MI.getOpcode() == PPC::ADJCALLSTACKDOWN)
81 else if (
MI.getOpcode() == PPC::ADJCALLSTACKUP)
92 Register GPR3 = Is64Bit ? PPC::X3 : PPC::R3;
93 Register GPR4 = Is64Bit ? PPC::X4 : PPC::R4;
94 if (!IsPCREL && !IsTLSTPRelMI)
95 InReg =
MI.getOperand(1).getReg();
99 switch (
MI.getOpcode()) {
102 case PPC::ADDItlsgdLADDR:
103 Opc1 = PPC::ADDItlsgdL;
104 Opc2 = PPC::GETtlsADDR;
106 case PPC::ADDItlsldLADDR:
107 Opc1 = PPC::ADDItlsldL;
108 Opc2 = PPC::GETtlsldADDR;
110 case PPC::ADDItlsgdLADDR32:
111 Opc1 = PPC::ADDItlsgdL32;
112 Opc2 = PPC::GETtlsADDR32;
114 case PPC::ADDItlsldLADDR32:
115 Opc1 = PPC::ADDItlsldL32;
116 Opc2 = PPC::GETtlsldADDR32;
121 Opc2 = PPC::GETtlsMOD32AIX;
126 Opc2 = PPC::GETtlsMOD64AIX;
131 Opc2 = PPC::GETtlsADDR64AIX;
136 Opc2 = PPC::GETtlsADDR32AIX;
138 case PPC::GETtlsTpointer32AIX:
142 Opc2 = PPC::GETtlsTpointer32AIX;
145 assert(IsPCREL &&
"Expecting General/Local Dynamic PCRel");
146 Opc1 = PPC::PADDI8pc;
147 Opc2 =
MI.getOperand(2).getTargetFlags() ==
149 ? PPC::GETtlsADDRPCREL
150 : PPC::GETtlsldADDRPCREL;
176 Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
177 : (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
178 if (!
RegInfo.use_empty(OutReg)) {
179 std::set<MachineInstr *>
Uses;
182 Uses.insert(MO.getParent());
188 if (
Uses.count(&*UseIter))
194 if (UseIter !=
MBB.
end()) {
197 std::set<MachineInstr *> LoadFromTocs;
199 if (MO.isReg() && MO.isUse()) {
201 if (
RegInfo.hasOneDef(MOReg)) {
203 RegInfo.getOneDef(MOReg)->getParent();
208 if (Temp == &
MI &&
RegInfo.hasOneDef(InReg))
209 Temp =
RegInfo.getOneDef(InReg)->getParent();
211 LoadFromTocs.insert(Temp);
214 LoadFromTocs.clear();
222 if (LoadFromTocs.size() == 2) {
231 if (LoadFromTocs.count(&*
I)) {
243 OffsetIter->moveBefore(&*UseIter);
253 }
else if (!IsTLSTPRelMI) {
273 assert(InReg != PPC::NoRegister &&
"Operand must be a register");
282 Call->addOperand(
MI.getOperand(2));
284 Call->addOperand(
MI.getOperand(3));
294 MI.removeFromParent();
304 return (
MI.getOpcode() == PPC::PADDI8pc) &&
305 (
MI.getOperand(2).getTargetFlags() ==
307 MI.getOperand(2).getTargetFlags() ==
314 bool Changed =
false;
332 "PowerPC TLS Dynamic Call Fixup",
false,
false)
338char 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
PowerPC TLS Dynamic Call Fixup
#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.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void setAdjustsStack(bool V)
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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
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,...
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
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.
@ Dynamic
Denotes mode unknown at compile time.