15a5ac124SDimitry Andric //===---------- PPCTLSDynamicCall.cpp - TLS Dynamic Call Fixup ------------===//
25a5ac124SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a5ac124SDimitry Andric //
75a5ac124SDimitry Andric //===----------------------------------------------------------------------===//
85a5ac124SDimitry Andric //
95a5ac124SDimitry Andric // This pass expands ADDItls{ld,gd}LADDR[32] machine instructions into
105a5ac124SDimitry Andric // separate ADDItls[gd]L[32] and GETtlsADDR[32] instructions, both of
115a5ac124SDimitry Andric // which define GPR3. A copy is added from GPR3 to the target virtual
125a5ac124SDimitry Andric // register of the original instruction. The GETtlsADDR[32] is really
135a5ac124SDimitry Andric // a call instruction, so its target register is constrained to be GPR3.
145a5ac124SDimitry Andric // This is not true of ADDItls[gd]L[32], but there is a legacy linker
155a5ac124SDimitry Andric // optimization bug that requires the target register of the addi of
165a5ac124SDimitry Andric // a local- or general-dynamic TLS access sequence to be GPR3.
175a5ac124SDimitry Andric //
185a5ac124SDimitry Andric // This is done in a late pass so that TLS variable accesses can be
195a5ac124SDimitry Andric // fully commoned by MachineCSE.
205a5ac124SDimitry Andric //
215a5ac124SDimitry Andric //===----------------------------------------------------------------------===//
225a5ac124SDimitry Andric
235a5ac124SDimitry Andric #include "PPC.h"
245a5ac124SDimitry Andric #include "PPCInstrBuilder.h"
257ab83427SDimitry Andric #include "PPCInstrInfo.h"
265a5ac124SDimitry Andric #include "PPCTargetMachine.h"
27044eb2f6SDimitry Andric #include "llvm/CodeGen/LiveIntervals.h"
28ac9a064cSDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
295a5ac124SDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h"
305a5ac124SDimitry Andric #include "llvm/CodeGen/MachineInstrBuilder.h"
31706b4fc4SDimitry Andric #include "llvm/InitializePasses.h"
325a5ac124SDimitry Andric #include "llvm/Support/Debug.h"
335a5ac124SDimitry Andric #include "llvm/Support/raw_ostream.h"
345a5ac124SDimitry Andric
355a5ac124SDimitry Andric using namespace llvm;
365a5ac124SDimitry Andric
375a5ac124SDimitry Andric #define DEBUG_TYPE "ppc-tls-dynamic-call"
385a5ac124SDimitry Andric
395a5ac124SDimitry Andric namespace {
405a5ac124SDimitry Andric struct PPCTLSDynamicCall : public MachineFunctionPass {
415a5ac124SDimitry Andric static char ID;
PPCTLSDynamicCall__anon99ebc6810111::PPCTLSDynamicCall425a5ac124SDimitry Andric PPCTLSDynamicCall() : MachineFunctionPass(ID) {
435a5ac124SDimitry Andric initializePPCTLSDynamicCallPass(*PassRegistry::getPassRegistry());
445a5ac124SDimitry Andric }
455a5ac124SDimitry Andric
465a5ac124SDimitry Andric const PPCInstrInfo *TII;
475a5ac124SDimitry Andric
485a5ac124SDimitry Andric protected:
processBlock__anon99ebc6810111::PPCTLSDynamicCall495a5ac124SDimitry Andric bool processBlock(MachineBasicBlock &MBB) {
505a5ac124SDimitry Andric bool Changed = false;
519df3605dSDimitry Andric bool NeedFence = true;
52ac9a064cSDimitry Andric const PPCSubtarget &Subtarget =
53ac9a064cSDimitry Andric MBB.getParent()->getSubtarget<PPCSubtarget>();
54ac9a064cSDimitry Andric bool Is64Bit = Subtarget.isPPC64();
55ac9a064cSDimitry Andric bool IsAIX = Subtarget.isAIXABI();
56ac9a064cSDimitry Andric bool IsLargeModel =
57ac9a064cSDimitry Andric Subtarget.getTargetMachine().getCodeModel() == CodeModel::Large;
58b60736ecSDimitry Andric bool IsPCREL = false;
59ac9a064cSDimitry Andric MachineFunction *MF = MBB.getParent();
60ac9a064cSDimitry Andric MachineRegisterInfo &RegInfo = MF->getRegInfo();
615a5ac124SDimitry Andric
625a5ac124SDimitry Andric for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end();
635a5ac124SDimitry Andric I != IE;) {
64b915e9e0SDimitry Andric MachineInstr &MI = *I;
65b60736ecSDimitry Andric IsPCREL = isPCREL(MI);
667fa27ce4SDimitry Andric // There are a number of slight differences in code generation
677fa27ce4SDimitry Andric // when we call .__get_tpointer (32-bit AIX TLS).
687fa27ce4SDimitry Andric bool IsTLSTPRelMI = MI.getOpcode() == PPC::GETtlsTpointer32AIX;
69ac9a064cSDimitry Andric bool IsTLSLDAIXMI = (MI.getOpcode() == PPC::TLSLDAIX8 ||
70ac9a064cSDimitry Andric MI.getOpcode() == PPC::TLSLDAIX);
715a5ac124SDimitry Andric
72b915e9e0SDimitry Andric if (MI.getOpcode() != PPC::ADDItlsgdLADDR &&
73b915e9e0SDimitry Andric MI.getOpcode() != PPC::ADDItlsldLADDR &&
74b915e9e0SDimitry Andric MI.getOpcode() != PPC::ADDItlsgdLADDR32 &&
75344a3780SDimitry Andric MI.getOpcode() != PPC::ADDItlsldLADDR32 &&
76344a3780SDimitry Andric MI.getOpcode() != PPC::TLSGDAIX &&
77ac9a064cSDimitry Andric MI.getOpcode() != PPC::TLSGDAIX8 && !IsTLSTPRelMI && !IsPCREL &&
78ac9a064cSDimitry Andric !IsTLSLDAIXMI) {
799df3605dSDimitry Andric // Although we create ADJCALLSTACKDOWN and ADJCALLSTACKUP
809df3605dSDimitry Andric // as scheduling fences, we skip creating fences if we already
819df3605dSDimitry Andric // have existing ADJCALLSTACKDOWN/UP to avoid nesting,
829df3605dSDimitry Andric // which causes verification error with -verify-machineinstrs.
839df3605dSDimitry Andric if (MI.getOpcode() == PPC::ADJCALLSTACKDOWN)
849df3605dSDimitry Andric NeedFence = false;
859df3605dSDimitry Andric else if (MI.getOpcode() == PPC::ADJCALLSTACKUP)
869df3605dSDimitry Andric NeedFence = true;
879df3605dSDimitry Andric
885a5ac124SDimitry Andric ++I;
895a5ac124SDimitry Andric continue;
905a5ac124SDimitry Andric }
915a5ac124SDimitry Andric
92eb11fae6SDimitry Andric LLVM_DEBUG(dbgs() << "TLS Dynamic Call Fixup:\n " << MI);
935a5ac124SDimitry Andric
941d5ae102SDimitry Andric Register OutReg = MI.getOperand(0).getReg();
95b60736ecSDimitry Andric Register InReg = PPC::NoRegister;
96cfca06d7SDimitry Andric Register GPR3 = Is64Bit ? PPC::X3 : PPC::R3;
97344a3780SDimitry Andric Register GPR4 = Is64Bit ? PPC::X4 : PPC::R4;
987fa27ce4SDimitry Andric if (!IsPCREL && !IsTLSTPRelMI)
99b60736ecSDimitry Andric InReg = MI.getOperand(1).getReg();
100b60736ecSDimitry Andric DebugLoc DL = MI.getDebugLoc();
1015a5ac124SDimitry Andric
102b60736ecSDimitry Andric unsigned Opc1, Opc2;
103b915e9e0SDimitry Andric switch (MI.getOpcode()) {
1045a5ac124SDimitry Andric default:
1055a5ac124SDimitry Andric llvm_unreachable("Opcode inconsistency error");
1065a5ac124SDimitry Andric case PPC::ADDItlsgdLADDR:
1075a5ac124SDimitry Andric Opc1 = PPC::ADDItlsgdL;
1085a5ac124SDimitry Andric Opc2 = PPC::GETtlsADDR;
1095a5ac124SDimitry Andric break;
1105a5ac124SDimitry Andric case PPC::ADDItlsldLADDR:
1115a5ac124SDimitry Andric Opc1 = PPC::ADDItlsldL;
1125a5ac124SDimitry Andric Opc2 = PPC::GETtlsldADDR;
1135a5ac124SDimitry Andric break;
1145a5ac124SDimitry Andric case PPC::ADDItlsgdLADDR32:
1155a5ac124SDimitry Andric Opc1 = PPC::ADDItlsgdL32;
1165a5ac124SDimitry Andric Opc2 = PPC::GETtlsADDR32;
1175a5ac124SDimitry Andric break;
1185a5ac124SDimitry Andric case PPC::ADDItlsldLADDR32:
1195a5ac124SDimitry Andric Opc1 = PPC::ADDItlsldL32;
1205a5ac124SDimitry Andric Opc2 = PPC::GETtlsldADDR32;
1215a5ac124SDimitry Andric break;
122ac9a064cSDimitry Andric case PPC::TLSLDAIX:
123ac9a064cSDimitry Andric // TLSLDAIX is expanded to one copy and GET_TLS_MOD, so we only set
124ac9a064cSDimitry Andric // Opc2 here.
125ac9a064cSDimitry Andric Opc2 = PPC::GETtlsMOD32AIX;
126ac9a064cSDimitry Andric break;
127ac9a064cSDimitry Andric case PPC::TLSLDAIX8:
128ac9a064cSDimitry Andric // TLSLDAIX8 is expanded to one copy and GET_TLS_MOD, so we only set
129ac9a064cSDimitry Andric // Opc2 here.
130ac9a064cSDimitry Andric Opc2 = PPC::GETtlsMOD64AIX;
131ac9a064cSDimitry Andric break;
132344a3780SDimitry Andric case PPC::TLSGDAIX8:
133344a3780SDimitry Andric // TLSGDAIX8 is expanded to two copies and GET_TLS_ADDR, so we only
134344a3780SDimitry Andric // set Opc2 here.
135344a3780SDimitry Andric Opc2 = PPC::GETtlsADDR64AIX;
136344a3780SDimitry Andric break;
137344a3780SDimitry Andric case PPC::TLSGDAIX:
138344a3780SDimitry Andric // TLSGDAIX is expanded to two copies and GET_TLS_ADDR, so we only
139344a3780SDimitry Andric // set Opc2 here.
140344a3780SDimitry Andric Opc2 = PPC::GETtlsADDR32AIX;
141344a3780SDimitry Andric break;
1427fa27ce4SDimitry Andric case PPC::GETtlsTpointer32AIX:
1437fa27ce4SDimitry Andric // GETtlsTpointer32AIX is expanded to a call to GET_TPOINTER on AIX
1447fa27ce4SDimitry Andric // 32-bit mode within PPCAsmPrinter. This instruction does not need
1457fa27ce4SDimitry Andric // to change, so Opc2 is set to the same instruction opcode.
1467fa27ce4SDimitry Andric Opc2 = PPC::GETtlsTpointer32AIX;
1477fa27ce4SDimitry Andric break;
148b60736ecSDimitry Andric case PPC::PADDI8pc:
149b60736ecSDimitry Andric assert(IsPCREL && "Expecting General/Local Dynamic PCRel");
150b60736ecSDimitry Andric Opc1 = PPC::PADDI8pc;
151b60736ecSDimitry Andric Opc2 = MI.getOperand(2).getTargetFlags() ==
152b60736ecSDimitry Andric PPCII::MO_GOT_TLSGD_PCREL_FLAG
153b60736ecSDimitry Andric ? PPC::GETtlsADDRPCREL
154b60736ecSDimitry Andric : PPC::GETtlsldADDRPCREL;
1555a5ac124SDimitry Andric }
1565a5ac124SDimitry Andric
1579df3605dSDimitry Andric // We create ADJCALLSTACKUP and ADJCALLSTACKDOWN around _tls_get_addr
158eb11fae6SDimitry Andric // as scheduling fence to avoid it is scheduled before
1599df3605dSDimitry Andric // mflr in the prologue and the address in LR is clobbered (PR25839).
1609df3605dSDimitry Andric // We don't really need to save data to the stack - the clobbered
161050e163aSDimitry Andric // registers are already saved when the SDNode (e.g. PPCaddiTlsgdLAddr)
162050e163aSDimitry Andric // gets translated to the pseudo instruction (e.g. ADDItlsgdLADDR).
163ac9a064cSDimitry Andric if (NeedFence) {
164ac9a064cSDimitry Andric MBB.getParent()->getFrameInfo().setAdjustsStack(true);
1656b3f41edSDimitry Andric BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKDOWN)).addImm(0)
1666b3f41edSDimitry Andric .addImm(0);
167ac9a064cSDimitry Andric }
168050e163aSDimitry Andric
169344a3780SDimitry Andric if (IsAIX) {
170ac9a064cSDimitry Andric if (IsTLSLDAIXMI) {
171ac9a064cSDimitry Andric // The relative order between the node that loads the variable
172ac9a064cSDimitry Andric // offset from the TOC, and the .__tls_get_mod node is being tuned
173ac9a064cSDimitry Andric // here. It is better to put the variable offset TOC load after the
174ac9a064cSDimitry Andric // call, since this node can use clobbers r4/r5.
175ac9a064cSDimitry Andric // Search for the pattern of the two nodes that load from the TOC
176ac9a064cSDimitry Andric // (either for the variable offset or for the module handle), and
177ac9a064cSDimitry Andric // then move the variable offset TOC load right before the node that
178ac9a064cSDimitry Andric // uses the OutReg of the .__tls_get_mod node.
179ac9a064cSDimitry Andric unsigned LDTocOp =
180ac9a064cSDimitry Andric Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
181ac9a064cSDimitry Andric : (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
182ac9a064cSDimitry Andric if (!RegInfo.use_empty(OutReg)) {
183ac9a064cSDimitry Andric std::set<MachineInstr *> Uses;
184ac9a064cSDimitry Andric // Collect all instructions that use the OutReg.
185ac9a064cSDimitry Andric for (MachineOperand &MO : RegInfo.use_operands(OutReg))
186ac9a064cSDimitry Andric Uses.insert(MO.getParent());
187ac9a064cSDimitry Andric // Find the first user (e.g.: lwax/stfdx) of the OutReg within the
188ac9a064cSDimitry Andric // current BB.
189ac9a064cSDimitry Andric MachineBasicBlock::iterator UseIter = MBB.begin();
190ac9a064cSDimitry Andric for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
191ac9a064cSDimitry Andric ++UseIter)
192ac9a064cSDimitry Andric if (Uses.count(&*UseIter))
193ac9a064cSDimitry Andric break;
194ac9a064cSDimitry Andric
195ac9a064cSDimitry Andric // Additional handling is required when UserIter (the first user
196ac9a064cSDimitry Andric // of OutReg) is pointing to a valid node that loads from the TOC.
197ac9a064cSDimitry Andric // Check the pattern and do the movement if the pattern matches.
198ac9a064cSDimitry Andric if (UseIter != MBB.end()) {
199ac9a064cSDimitry Andric // Collect all associated nodes that load from the TOC. Use
200ac9a064cSDimitry Andric // hasOneDef() to guard against unexpected scenarios.
201ac9a064cSDimitry Andric std::set<MachineInstr *> LoadFromTocs;
202ac9a064cSDimitry Andric for (MachineOperand &MO : UseIter->operands())
203ac9a064cSDimitry Andric if (MO.isReg() && MO.isUse()) {
204ac9a064cSDimitry Andric Register MOReg = MO.getReg();
205ac9a064cSDimitry Andric if (RegInfo.hasOneDef(MOReg)) {
206ac9a064cSDimitry Andric MachineInstr *Temp =
207ac9a064cSDimitry Andric RegInfo.getOneDef(MOReg)->getParent();
208ac9a064cSDimitry Andric // For the current TLSLDAIX node, get the corresponding
209ac9a064cSDimitry Andric // node that loads from the TOC for the InReg. Otherwise,
210ac9a064cSDimitry Andric // Temp probably pointed to the variable offset TOC load
211ac9a064cSDimitry Andric // we would like to move.
212ac9a064cSDimitry Andric if (Temp == &MI && RegInfo.hasOneDef(InReg))
213ac9a064cSDimitry Andric Temp = RegInfo.getOneDef(InReg)->getParent();
214ac9a064cSDimitry Andric if (Temp->getOpcode() == LDTocOp)
215ac9a064cSDimitry Andric LoadFromTocs.insert(Temp);
216ac9a064cSDimitry Andric } else {
217ac9a064cSDimitry Andric // FIXME: analyze this scenario if there is one.
218ac9a064cSDimitry Andric LoadFromTocs.clear();
219ac9a064cSDimitry Andric break;
220ac9a064cSDimitry Andric }
221ac9a064cSDimitry Andric }
222ac9a064cSDimitry Andric
223ac9a064cSDimitry Andric // Check the two nodes that loaded from the TOC: one should be
224ac9a064cSDimitry Andric // "_$TLSML", and the other will be moved before the node that
225ac9a064cSDimitry Andric // uses the OutReg of the .__tls_get_mod node.
226ac9a064cSDimitry Andric if (LoadFromTocs.size() == 2) {
227ac9a064cSDimitry Andric MachineBasicBlock::iterator TLSMLIter = MBB.end();
228ac9a064cSDimitry Andric MachineBasicBlock::iterator OffsetIter = MBB.end();
229ac9a064cSDimitry Andric // Make sure the two nodes that loaded from the TOC are within
230ac9a064cSDimitry Andric // the current BB, and that one of them is from the "_$TLSML"
231ac9a064cSDimitry Andric // pseudo symbol, while the other is from the variable.
232ac9a064cSDimitry Andric for (MachineBasicBlock::iterator I = MBB.begin(),
233ac9a064cSDimitry Andric IE = MBB.end();
234ac9a064cSDimitry Andric I != IE; ++I)
235ac9a064cSDimitry Andric if (LoadFromTocs.count(&*I)) {
236ac9a064cSDimitry Andric MachineOperand MO = I->getOperand(1);
237ac9a064cSDimitry Andric if (MO.isGlobal() && MO.getGlobal()->hasName() &&
238ac9a064cSDimitry Andric MO.getGlobal()->getName() == "_$TLSML")
239ac9a064cSDimitry Andric TLSMLIter = I;
240ac9a064cSDimitry Andric else
241ac9a064cSDimitry Andric OffsetIter = I;
242ac9a064cSDimitry Andric }
243ac9a064cSDimitry Andric // Perform the movement when the desired scenario has been
244ac9a064cSDimitry Andric // identified, which should be when both of the iterators are
245ac9a064cSDimitry Andric // valid.
246ac9a064cSDimitry Andric if (TLSMLIter != MBB.end() && OffsetIter != MBB.end())
247ac9a064cSDimitry Andric OffsetIter->moveBefore(&*UseIter);
248ac9a064cSDimitry Andric }
249ac9a064cSDimitry Andric }
250ac9a064cSDimitry Andric }
251ac9a064cSDimitry Andric // The module-handle is copied into r3. The copy is followed by
252ac9a064cSDimitry Andric // GETtlsMOD32AIX/GETtlsMOD64AIX.
253ac9a064cSDimitry Andric BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), GPR3)
254ac9a064cSDimitry Andric .addReg(InReg);
255ac9a064cSDimitry Andric // The call to .__tls_get_mod.
256ac9a064cSDimitry Andric BuildMI(MBB, I, DL, TII->get(Opc2), GPR3).addReg(GPR3);
257ac9a064cSDimitry Andric } else if (!IsTLSTPRelMI) {
258ac9a064cSDimitry Andric // The variable offset and region handle (for TLSGD) are copied in
259ac9a064cSDimitry Andric // r4 and r3. The copies are followed by
260ac9a064cSDimitry Andric // GETtlsADDR32AIX/GETtlsADDR64AIX.
261344a3780SDimitry Andric BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), GPR4)
262344a3780SDimitry Andric .addReg(MI.getOperand(1).getReg());
263344a3780SDimitry Andric BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), GPR3)
264344a3780SDimitry Andric .addReg(MI.getOperand(2).getReg());
265344a3780SDimitry Andric BuildMI(MBB, I, DL, TII->get(Opc2), GPR3).addReg(GPR3).addReg(GPR4);
2667fa27ce4SDimitry Andric } else
2677fa27ce4SDimitry Andric // The opcode of GETtlsTpointer32AIX does not change, because later
2687fa27ce4SDimitry Andric // this instruction will be expanded into a call to .__get_tpointer,
2697fa27ce4SDimitry Andric // which will return the thread pointer into r3.
2707fa27ce4SDimitry Andric BuildMI(MBB, I, DL, TII->get(Opc2), GPR3);
271344a3780SDimitry Andric } else {
272b60736ecSDimitry Andric MachineInstr *Addi;
273b60736ecSDimitry Andric if (IsPCREL) {
274b60736ecSDimitry Andric Addi = BuildMI(MBB, I, DL, TII->get(Opc1), GPR3).addImm(0);
275b60736ecSDimitry Andric } else {
2765a5ac124SDimitry Andric // Expand into two ops built prior to the existing instruction.
277b60736ecSDimitry Andric assert(InReg != PPC::NoRegister && "Operand must be a register");
278b60736ecSDimitry Andric Addi = BuildMI(MBB, I, DL, TII->get(Opc1), GPR3).addReg(InReg);
279b60736ecSDimitry Andric }
280b60736ecSDimitry Andric
281b915e9e0SDimitry Andric Addi->addOperand(MI.getOperand(2));
2825a5ac124SDimitry Andric
283344a3780SDimitry Andric MachineInstr *Call =
284344a3780SDimitry Andric (BuildMI(MBB, I, DL, TII->get(Opc2), GPR3).addReg(GPR3));
285b60736ecSDimitry Andric if (IsPCREL)
286b60736ecSDimitry Andric Call->addOperand(MI.getOperand(2));
287b60736ecSDimitry Andric else
288b915e9e0SDimitry Andric Call->addOperand(MI.getOperand(3));
289344a3780SDimitry Andric }
2909df3605dSDimitry Andric if (NeedFence)
291050e163aSDimitry Andric BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKUP)).addImm(0).addImm(0);
292050e163aSDimitry Andric
2935a5ac124SDimitry Andric BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), OutReg)
2945a5ac124SDimitry Andric .addReg(GPR3);
2955a5ac124SDimitry Andric
2965a5ac124SDimitry Andric // Move past the original instruction and remove it.
2975a5ac124SDimitry Andric ++I;
298b915e9e0SDimitry Andric MI.removeFromParent();
2995a5ac124SDimitry Andric
3005a5ac124SDimitry Andric Changed = true;
3015a5ac124SDimitry Andric }
3025a5ac124SDimitry Andric
3035a5ac124SDimitry Andric return Changed;
3045a5ac124SDimitry Andric }
3055a5ac124SDimitry Andric
3065a5ac124SDimitry Andric public:
isPCREL__anon99ebc6810111::PPCTLSDynamicCall307b60736ecSDimitry Andric bool isPCREL(const MachineInstr &MI) {
308b60736ecSDimitry Andric return (MI.getOpcode() == PPC::PADDI8pc) &&
309b60736ecSDimitry Andric (MI.getOperand(2).getTargetFlags() ==
310b60736ecSDimitry Andric PPCII::MO_GOT_TLSGD_PCREL_FLAG ||
311b60736ecSDimitry Andric MI.getOperand(2).getTargetFlags() ==
312b60736ecSDimitry Andric PPCII::MO_GOT_TLSLD_PCREL_FLAG);
313b60736ecSDimitry Andric }
314b60736ecSDimitry Andric
runOnMachineFunction__anon99ebc6810111::PPCTLSDynamicCall3155a5ac124SDimitry Andric bool runOnMachineFunction(MachineFunction &MF) override {
3165a5ac124SDimitry Andric TII = MF.getSubtarget<PPCSubtarget>().getInstrInfo();
3175a5ac124SDimitry Andric
3185a5ac124SDimitry Andric bool Changed = false;
3195a5ac124SDimitry Andric
320c0981da4SDimitry Andric for (MachineBasicBlock &B : llvm::make_early_inc_range(MF))
3215a5ac124SDimitry Andric if (processBlock(B))
3225a5ac124SDimitry Andric Changed = true;
3235a5ac124SDimitry Andric
3245a5ac124SDimitry Andric return Changed;
3255a5ac124SDimitry Andric }
3265a5ac124SDimitry Andric
getAnalysisUsage__anon99ebc6810111::PPCTLSDynamicCall3275a5ac124SDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override {
328ac9a064cSDimitry Andric AU.addRequired<LiveIntervalsWrapperPass>();
329ac9a064cSDimitry Andric AU.addRequired<SlotIndexesWrapperPass>();
3305a5ac124SDimitry Andric MachineFunctionPass::getAnalysisUsage(AU);
3315a5ac124SDimitry Andric }
3325a5ac124SDimitry Andric };
3331a82d4c0SDimitry Andric }
3345a5ac124SDimitry Andric
3355a5ac124SDimitry Andric INITIALIZE_PASS_BEGIN(PPCTLSDynamicCall, DEBUG_TYPE,
3365a5ac124SDimitry Andric "PowerPC TLS Dynamic Call Fixup", false, false)
337ac9a064cSDimitry Andric INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
338ac9a064cSDimitry Andric INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass)
3395a5ac124SDimitry Andric INITIALIZE_PASS_END(PPCTLSDynamicCall, DEBUG_TYPE,
3405a5ac124SDimitry Andric "PowerPC TLS Dynamic Call Fixup", false, false)
3415a5ac124SDimitry Andric
3425a5ac124SDimitry Andric char PPCTLSDynamicCall::ID = 0;
3435a5ac124SDimitry Andric FunctionPass*
createPPCTLSDynamicCallPass()3445a5ac124SDimitry Andric llvm::createPPCTLSDynamicCallPass() { return new PPCTLSDynamicCall(); }
345