37#define DEBUG_TYPE "ppc-tls-dynamic-call"
51 bool NeedFence =
true;
54 bool Is64Bit = Subtarget.
isPPC64();
65 IsPCREL = isPCREL(
MI);
68 bool IsTLSTPRelMI =
MI.getOpcode() == PPC::GETtlsTpointer32AIX;
69 bool IsTLSLDAIXMI = (
MI.getOpcode() == PPC::TLSLDAIX8 ||
70 MI.getOpcode() == PPC::TLSLDAIX);
72 if (
MI.getOpcode() != PPC::ADDItlsgdLADDR &&
73 MI.getOpcode() != PPC::ADDItlsldLADDR &&
74 MI.getOpcode() != PPC::ADDItlsgdLADDR32 &&
75 MI.getOpcode() != PPC::ADDItlsldLADDR32 &&
76 MI.getOpcode() != PPC::TLSGDAIX &&
77 MI.getOpcode() != PPC::TLSGDAIX8 && !IsTLSTPRelMI && !IsPCREL &&
83 if (
MI.getOpcode() == PPC::ADJCALLSTACKDOWN)
85 else if (
MI.getOpcode() == PPC::ADJCALLSTACKUP)
96 Register GPR3 = Is64Bit ? PPC::X3 : PPC::R3;
97 Register GPR4 = Is64Bit ? PPC::X4 : PPC::R4;
98 if (!IsPCREL && !IsTLSTPRelMI)
99 InReg =
MI.getOperand(1).getReg();
103 switch (
MI.getOpcode()) {
106 case PPC::ADDItlsgdLADDR:
107 Opc1 = PPC::ADDItlsgdL;
108 Opc2 = PPC::GETtlsADDR;
110 case PPC::ADDItlsldLADDR:
111 Opc1 = PPC::ADDItlsldL;
112 Opc2 = PPC::GETtlsldADDR;
114 case PPC::ADDItlsgdLADDR32:
115 Opc1 = PPC::ADDItlsgdL32;
116 Opc2 = PPC::GETtlsADDR32;
118 case PPC::ADDItlsldLADDR32:
119 Opc1 = PPC::ADDItlsldL32;
120 Opc2 = PPC::GETtlsldADDR32;
125 Opc2 = PPC::GETtlsMOD32AIX;
130 Opc2 = PPC::GETtlsMOD64AIX;
135 Opc2 = PPC::GETtlsADDR64AIX;
140 Opc2 = PPC::GETtlsADDR32AIX;
142 case PPC::GETtlsTpointer32AIX:
146 Opc2 = PPC::GETtlsTpointer32AIX;
149 assert(IsPCREL &&
"Expecting General/Local Dynamic PCRel");
150 Opc1 = PPC::PADDI8pc;
151 Opc2 =
MI.getOperand(2).getTargetFlags() ==
153 ? PPC::GETtlsADDRPCREL
154 : PPC::GETtlsldADDRPCREL;
180 Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
181 : (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
182 if (!
RegInfo.use_empty(OutReg)) {
183 std::set<MachineInstr *>
Uses;
186 Uses.insert(MO.getParent());
192 if (
Uses.count(&*UseIter))
198 if (UseIter !=
MBB.
end()) {
201 std::set<MachineInstr *> LoadFromTocs;
203 if (MO.isReg() && MO.isUse()) {
205 if (
RegInfo.hasOneDef(MOReg)) {
207 RegInfo.getOneDef(MOReg)->getParent();
212 if (Temp == &
MI &&
RegInfo.hasOneDef(InReg))
213 Temp =
RegInfo.getOneDef(InReg)->getParent();
215 LoadFromTocs.insert(Temp);
218 LoadFromTocs.clear();
226 if (LoadFromTocs.size() == 2) {
235 if (LoadFromTocs.count(&*
I)) {
247 OffsetIter->moveBefore(&*UseIter);
257 }
else if (!IsTLSTPRelMI) {
277 assert(InReg != PPC::NoRegister &&
"Operand must be a register");
286 Call->addOperand(
MI.getOperand(2));
288 Call->addOperand(
MI.getOperand(3));
298 MI.removeFromParent();
308 return (
MI.getOpcode() == PPC::PADDI8pc) &&
309 (
MI.getOperand(2).getTargetFlags() ==
311 MI.getOperand(2).getTargetFlags() ==
318 bool Changed =
false;
336 "PowerPC TLS Dynamic Call Fixup",
false,
false)
342char PPCTLSDynamicCall::
ID = 0;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Rewrite Partial Register Uses
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
CodeModel::Model getCodeModel() const
Returns the code model.
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.
void initializePPCTLSDynamicCallPass(PassRegistry &)
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()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Dynamic
Denotes mode unknown at compile time.