llvm.org GIT mirror llvm / 9168f71
Revert "r227976 - [PowerPC] Yet another approach to __tls_get_addr" and related fixups Unfortunately, even with the workaround of disabling the linker TLS optimizations in Clang restored (which has already been done), this still breaks self-hosting on my P7 machine (-O3 -DNDEBUG -mcpu=native). Bill is currently working on an alternate implementation to address the TLS issue in a way that also fully elides the linker bug (which, unfortunately, this approach did not fully), so I'm reverting this now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228460 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 5 years ago
15 changed file(s) with 117 addition(s) and 292 deletion(s). Raw diff Collapse all Expand all
3131 PPCTargetObjectFile.cpp
3232 PPCTargetTransformInfo.cpp
3333 PPCSelectionDAGInfo.cpp
34 PPCTLSDynamicCall.cpp
3534 PPCVSXCopy.cpp
3635 PPCVSXFMAMutate.cpp
3736 )
3939 FunctionPass *createPPCVSXFMAMutatePass();
4040 FunctionPass *createPPCBranchSelectionPass();
4141 FunctionPass *createPPCISelDag(PPCTargetMachine &TM);
42 FunctionPass *createPPCTLSDynamicCallPass();
4342 void LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
4443 AsmPrinter &AP, bool isDarwin);
4544
9089 MO_TOC_LO = 7 << 4,
9190
9291 // Symbol for VK_PPC_TLS fixup attached to an ADD instruction
93 MO_TLS = 8 << 4
92 MO_TLS = 8 << 4,
93
94 // Symbols for VK_PPC_TLSGD and VK_PPC_TLSLD in __tls_get_addr
95 // call sequences.
96 MO_TLSLD = 9 << 4,
97 MO_TLSGD = 10 << 4
9498 };
9599 } // end namespace PPCII
96100
100100 const MachineInstr &MI);
101101 void LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
102102 const MachineInstr &MI);
103 void EmitTlsCall(const MachineInstr *MI, MCSymbolRefExpr::VariantKind VK);
104103 };
105104
106105 /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
404403 EmitToStreamer(OutStreamer, MCInstBuilder(PPC::NOP));
405404 }
406405
407 /// EmitTlsCall -- Given a GETtls[ld]ADDR[32] instruction, print a
408 /// call to __tls_get_addr to the current output stream.
409 void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
410 MCSymbolRefExpr::VariantKind VK) {
411 StringRef Name = "__tls_get_addr";
412 MCSymbol *TlsGetAddr = OutContext.GetOrCreateSymbol(Name);
413 MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
414
415 assert(MI->getOperand(0).isReg() &&
416 ((Subtarget.isPPC64() && MI->getOperand(0).getReg() == PPC::X3) ||
417 (!Subtarget.isPPC64() && MI->getOperand(0).getReg() == PPC::R3)) &&
418 "GETtls[ld]ADDR[32] must define GPR3");
419 assert(MI->getOperand(1).isReg() &&
420 ((Subtarget.isPPC64() && MI->getOperand(1).getReg() == PPC::X3) ||
421 (!Subtarget.isPPC64() && MI->getOperand(1).getReg() == PPC::R3)) &&
422 "GETtls[ld]ADDR[32] must read GPR3");
423
424 if (!Subtarget.isPPC64() && !Subtarget.isDarwin() &&
425 TM.getRelocationModel() == Reloc::PIC_)
426 Kind = MCSymbolRefExpr::VK_PLT;
427 const MCSymbolRefExpr *TlsRef =
428 MCSymbolRefExpr::Create(TlsGetAddr, Kind, OutContext);
429 const MachineOperand &MO = MI->getOperand(2);
430 const GlobalValue *GValue = MO.getGlobal();
431 MCSymbol *MOSymbol = getSymbol(GValue);
432 const MCExpr *SymVar = MCSymbolRefExpr::Create(MOSymbol, VK, OutContext);
433 EmitToStreamer(OutStreamer,
434 MCInstBuilder(Subtarget.isPPC64() ?
435 PPC::BL8_NOP_TLS : PPC::BL_TLS)
436 .addExpr(TlsRef)
437 .addExpr(SymVar));
438 }
439
440406 /// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
441407 /// the current output stream.
442408 ///
840806 .addExpr(SymGotTlsGD));
841807 return;
842808 }
843 case PPC::GETtlsADDR:
844 // Transform: %X3 = GETtlsADDR %X3,
845 // Into: BL8_NOP_TLS __tls_get_addr(sym@tlsgd)
846 case PPC::GETtlsADDR32: {
847 // Transform: %R3 = GETtlsADDR32 %R3,
848 // Into: BL_TLS __tls_get_addr(sym@tlsgd)@PLT
849 EmitTlsCall(MI, MCSymbolRefExpr::VK_PPC_TLSGD);
850 return;
851 }
852809 case PPC::ADDIStlsldHA: {
853810 // Transform: %Xd = ADDIStlsldHA %X2,
854811 // Into: %Xd = ADDIS8 %X2, sym@got@tlsld@ha
884841 .addReg(MI->getOperand(0).getReg())
885842 .addReg(MI->getOperand(1).getReg())
886843 .addExpr(SymGotTlsLD));
887 return;
888 }
889 case PPC::GETtlsldADDR:
890 // Transform: %X3 = GETtlsldADDR %X3,
891 // Into: BL8_NOP_TLS __tls_get_addr(sym@tlsld)
892 case PPC::GETtlsldADDR32: {
893 // Transform: %R3 = GETtlsldADDR32 %R3,
894 // Into: BL_TLS __tls_get_addr(sym@tlsld)@PLT
895 EmitTlsCall(MI, MCSymbolRefExpr::VK_PPC_TLSLD);
896844 return;
897845 }
898846 case PPC::ADDISdtprelHA:
354354 return FuncInfo->hasNonRISpills();
355355 }
356356
357 /// MustSaveLR - Return true if this function requires that we save the LR
358 /// register onto the stack in the prolog and restore it in the epilog of the
359 /// function.
360 static bool MustSaveLR(const MachineFunction &MF, unsigned LR) {
361 const PPCFunctionInfo *MFI = MF.getInfo();
362
363 // We need a save/restore of LR if there is any def of LR (which is
364 // defined by calls, including the PIC setup sequence), or if there is
365 // some use of the LR stack slot (e.g. for builtin_return_address).
366 // (LR comes in 32 and 64 bit versions.)
367 MachineRegisterInfo::def_iterator RI = MF.getRegInfo().def_begin(LR);
368 return RI !=MF.getRegInfo().def_end() || MFI->isLRStoreRequired();
369 }
370
371357 /// determineFrameLayout - Determine the size of the frame and maximum call
372358 /// frame size.
373359 unsigned PPCFrameLowering::determineFrameLayout(MachineFunction &MF,
394380 // stackless code if all local vars are reg-allocated.
395381 bool DisableRedZone = MF.getFunction()->getAttributes().
396382 hasAttribute(AttributeSet::FunctionIndex, Attribute::NoRedZone);
397 unsigned LR = RegInfo->getRARegister();
398383 if (!DisableRedZone &&
399384 (Subtarget.isPPC64() || // 32-bit SVR4, no stack-
400385 !Subtarget.isSVR4ABI() || // allocated locals.
402387 FrameSize <= 224 && // Fits in red zone.
403388 !MFI->hasVarSizedObjects() && // No dynamic alloca.
404389 !MFI->adjustsStack() && // No calls.
405 !MustSaveLR(MF, LR) &&
406390 !RegInfo->hasBasePointer(MF)) { // No special alignment.
407391 // No need for frame
408392 if (UpdateMF)
11231107 }
11241108 }
11251109
1110 /// MustSaveLR - Return true if this function requires that we save the LR
1111 /// register onto the stack in the prolog and restore it in the epilog of the
1112 /// function.
1113 static bool MustSaveLR(const MachineFunction &MF, unsigned LR) {
1114 const PPCFunctionInfo *MFI = MF.getInfo();
1115
1116 // We need a save/restore of LR if there is any def of LR (which is
1117 // defined by calls, including the PIC setup sequence), or if there is
1118 // some use of the LR stack slot (e.g. for builtin_return_address).
1119 // (LR comes in 32 and 64 bit versions.)
1120 MachineRegisterInfo::def_iterator RI = MF.getRegInfo().def_begin(LR);
1121 return RI !=MF.getRegInfo().def_end() || MFI->isLRStoreRequired();
1122 }
1123
11261124 void
11271125 PPCFrameLowering::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
11281126 RegScavenger *) const {
805805 case PPCISD::SHL: return "PPCISD::SHL";
806806 case PPCISD::CALL: return "PPCISD::CALL";
807807 case PPCISD::CALL_NOP: return "PPCISD::CALL_NOP";
808 case PPCISD::CALL_TLS: return "PPCISD::CALL_TLS";
809 case PPCISD::CALL_NOP_TLS: return "PPCISD::CALL_NOP_TLS";
808810 case PPCISD::MTCTR: return "PPCISD::MTCTR";
809811 case PPCISD::BCTRL: return "PPCISD::BCTRL";
810812 case PPCISD::BCTRL_LOAD_TOC: return "PPCISD::BCTRL_LOAD_TOC";
838840 case PPCISD::ADD_TLS: return "PPCISD::ADD_TLS";
839841 case PPCISD::ADDIS_TLSGD_HA: return "PPCISD::ADDIS_TLSGD_HA";
840842 case PPCISD::ADDI_TLSGD_L: return "PPCISD::ADDI_TLSGD_L";
841 case PPCISD::GET_TLS_ADDR: return "PPCISD::GET_TLS_ADDR";
842843 case PPCISD::ADDIS_TLSLD_HA: return "PPCISD::ADDIS_TLSLD_HA";
843844 case PPCISD::ADDI_TLSLD_L: return "PPCISD::ADDI_TLSLD_L";
844 case PPCISD::GET_TLSLD_ADDR: return "PPCISD::GET_TLSLD_ADDR";
845845 case PPCISD::ADDIS_DTPREL_HA: return "PPCISD::ADDIS_DTPREL_HA";
846846 case PPCISD::ADDI_DTPREL_L: return "PPCISD::ADDI_DTPREL_L";
847847 case PPCISD::VADD_SPLAT: return "PPCISD::VADD_SPLAT";
17001700 return LowerLabelRef(TgtBAHi, TgtBALo, isPIC, DAG);
17011701 }
17021702
1703 // Generate a call to __tls_get_addr for the given GOT entry Op.
1704 std::pair
1705 PPCTargetLowering::lowerTLSCall(SDValue Op, SDLoc dl,
1706 SelectionDAG &DAG) const {
1707
1708 Type *IntPtrTy = getDataLayout()->getIntPtrType(*DAG.getContext());
1709 TargetLowering::ArgListTy Args;
1710 TargetLowering::ArgListEntry Entry;
1711 Entry.Node = Op;
1712 Entry.Ty = IntPtrTy;
1713 Args.push_back(Entry);
1714
1715 TargetLowering::CallLoweringInfo CLI(DAG);
1716 CLI.setDebugLoc(dl).setChain(DAG.getEntryNode())
1717 .setCallee(CallingConv::C, IntPtrTy,
1718 DAG.getTargetExternalSymbol("__tls_get_addr", getPointerTy()),
1719 std::move(Args), 0);
1720
1721 return LowerCallTo(CLI);
1722 }
1723
17031724 SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op,
17041725 SelectionDAG &DAG) const {
17051726
17461767 }
17471768
17481769 if (Model == TLSModel::GeneralDynamic) {
1749 SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, 0);
1770 SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0,
1771 PPCII::MO_TLSGD);
17501772 SDValue GOTPtr;
17511773 if (is64bit) {
17521774 setUsesTOCBasePtr(DAG);
17591781 else
17601782 GOTPtr = DAG.getNode(PPCISD::PPC32_PICGOT, dl, PtrVT);
17611783 }
1762 SDValue GOTEntry = DAG.getNode(PPCISD::ADDI_TLSGD_L, dl,
1763 PtrVT, GOTPtr, TGA);
1764 return DAG.getNode(PPCISD::GET_TLS_ADDR, dl, PtrVT, GOTEntry, TGA);
1784 SDValue GOTEntry = DAG.getNode(PPCISD::ADDI_TLSGD_L, dl, PtrVT,
1785 GOTPtr, TGA);
1786 std::pair CallResult = lowerTLSCall(GOTEntry, dl, DAG);
1787 return CallResult.first;
17651788 }
17661789
17671790 if (Model == TLSModel::LocalDynamic) {
1768 SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, 0);
1791 SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0,
1792 PPCII::MO_TLSLD);
17691793 SDValue GOTPtr;
17701794 if (is64bit) {
17711795 setUsesTOCBasePtr(DAG);
17801804 }
17811805 SDValue GOTEntry = DAG.getNode(PPCISD::ADDI_TLSLD_L, dl, PtrVT,
17821806 GOTPtr, TGA);
1783 SDValue TLSAddr = DAG.getNode(PPCISD::GET_TLSLD_ADDR, dl,
1784 PtrVT, GOTEntry, TGA);
1785 SDValue DtvOffsetHi = DAG.getNode(PPCISD::ADDIS_DTPREL_HA, dl,
1786 PtrVT, TLSAddr, TGA);
1807 std::pair CallResult = lowerTLSCall(GOTEntry, dl, DAG);
1808 SDValue TLSAddr = CallResult.first;
1809 SDValue Chain = CallResult.second;
1810 SDValue DtvOffsetHi = DAG.getNode(PPCISD::ADDIS_DTPREL_HA, dl, PtrVT,
1811 Chain, TLSAddr, TGA);
17871812 return DAG.getNode(PPCISD::ADDI_DTPREL_L, dl, PtrVT, DtvOffsetHi, TGA);
17881813 }
17891814
38073832 if (Callee.getNode()) {
38083833 Ops.push_back(Chain);
38093834 Ops.push_back(Callee);
3835
3836 // If this is a call to __tls_get_addr, find the symbol whose address
3837 // is to be taken and add it to the list. This will be used to
3838 // generate __tls_get_addr(@tlsgd) or __tls_get_addr(@tlsld).
3839 // We find the symbol by walking the chain to the CopyFromReg, walking
3840 // back from the CopyFromReg to the ADDI_TLSGD_L or ADDI_TLSLD_L, and
3841 // pulling the symbol from that node.
3842 if (ExternalSymbolSDNode *S = dyn_cast(Callee))
3843 if (!strcmp(S->getSymbol(), "__tls_get_addr")) {
3844 assert(!needIndirectCall && "Indirect call to __tls_get_addr???");
3845 SDNode *AddI = Chain.getNode()->getOperand(2).getNode();
3846 SDValue TGTAddr = AddI->getOperand(1);
3847 assert(TGTAddr.getNode()->getOpcode() == ISD::TargetGlobalTLSAddress &&
3848 "Didn't find target global TLS address where we expected one");
3849 Ops.push_back(TGTAddr);
3850 CallOpc = PPCISD::CALL_TLS;
3851 }
38103852 }
38113853 // If this is a tail call add stack pointer delta.
38123854 if (isTailCall)
39694011 Ops.insert(std::next(Ops.begin()), AddTOC);
39704012 } else if ((CallOpc == PPCISD::CALL) &&
39714013 (!isLocalCall(Callee) ||
3972 DAG.getTarget().getRelocationModel() == Reloc::PIC_))
4014 DAG.getTarget().getRelocationModel() == Reloc::PIC_)) {
39734015 // Otherwise insert NOP for non-local calls.
39744016 CallOpc = PPCISD::CALL_NOP;
4017 } else if (CallOpc == PPCISD::CALL_TLS)
4018 // For 64-bit SVR4, TLS calls are always non-local.
4019 CallOpc = PPCISD::CALL_NOP_TLS;
39754020 }
39764021
39774022 Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops);
100100 /// SVR4 calls.
101101 CALL, CALL_NOP,
102102
103 /// CALL_TLS and CALL_NOP_TLS - Versions of CALL and CALL_NOP used
104 /// to access TLS variables.
105 CALL_TLS, CALL_NOP_TLS,
106
103107 /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
104108 /// MTCTR instruction.
105109 MTCTR,
223227 /// sym\@got\@tlsgd\@l.
224228 ADDI_TLSGD_L,
225229
226 /// G8RC = GET_TLS_ADDR %X3, Symbol - For the general-dynamic TLS
227 /// model, produces a call to __tls_get_addr(sym\@tlsgd).
228 GET_TLS_ADDR,
229
230230 /// G8RC = ADDIS_TLSLD_HA %X2, Symbol - For the local-dynamic TLS
231231 /// model, produces an ADDIS8 instruction that adds the GOT base
232232 /// register to sym\@got\@tlsld\@ha.
237237 /// sym\@got\@tlsld\@l.
238238 ADDI_TLSLD_L,
239239
240 /// G8RC = GET_TLSLD_ADDR %X3, Symbol - For the local-dynamic TLS
241 /// model, produces a call to __tls_get_addr(sym\@tlsld).
242 GET_TLSLD_ADDR,
243
244 /// G8RC = ADDIS_DTPREL_HA %X3, Symbol - For the local-dynamic TLS
245 /// model, produces an ADDIS8 instruction that adds X3 to
246 /// sym\@dtprel\@ha.
240 /// G8RC = ADDIS_DTPREL_HA %X3, Symbol, Chain - For the
241 /// local-dynamic TLS model, produces an ADDIS8 instruction
242 /// that adds X3 to sym\@dtprel\@ha. The Chain operand is needed
243 /// to tie this in place following a copy to %X3 from the result
244 /// of a GET_TLSLD_ADDR.
247245 ADDIS_DTPREL_HA,
248246
249247 /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
636634 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
637635 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
638636 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
637 std::pair lowerTLSCall(SDValue Op, SDLoc dl,
638 SelectionDAG &DAG) const;
639639 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
640640 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
641641 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
200200 (BL8 texternalsym:$dst)>;
201201 def : Pat<(PPCcall_nop (i64 texternalsym:$dst)),
202202 (BL8_NOP texternalsym:$dst)>;
203
204 def : Pat<(PPCcall_nop_tls texternalsym:$func, tglobaltlsaddr:$sym),
205 (BL8_NOP_TLS texternalsym:$func, tglobaltlsaddr:$sym)>;
203206
204207 // Atomic operations
205208 let usesCustomInserter = 1 in {
900903 [(set i64:$rD,
901904 (PPCaddiTlsgdL i64:$reg, tglobaltlsaddr:$disp))]>,
902905 isPPC64;
903 let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1, Defs = [LR8] in
904 def GETtlsADDR : Pseudo<(outs g8rc:$rD), (ins g8rc:$reg, tlsgd:$sym),
905 "#GETtlsADDR",
906 [(set i64:$rD,
907 (PPCgetTlsAddr i64:$reg, tglobaltlsaddr:$sym))]>,
908 isPPC64;
909906 def ADDIStlsldHA: Pseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
910907 "#ADDIStlsldHA",
911908 [(set i64:$rD,
916913 [(set i64:$rD,
917914 (PPCaddiTlsldL i64:$reg, tglobaltlsaddr:$disp))]>,
918915 isPPC64;
919 let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1, Defs = [LR8] in
920 def GETtlsldADDR : Pseudo<(outs g8rc:$rD), (ins g8rc:$reg, tlsgd:$sym),
921 "#GETtlsldADDR",
922 [(set i64:$rD,
923 (PPCgetTlsldAddr i64:$reg, tglobaltlsaddr:$sym))]>,
924 isPPC64;
925916 def ADDISdtprelHA: Pseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16imm64:$disp),
926917 "#ADDISdtprelHA",
927918 [(set i64:$rD,
109109 def PPCaddTls : SDNode<"PPCISD::ADD_TLS", SDTIntBinOp, []>;
110110 def PPCaddisTlsgdHA : SDNode<"PPCISD::ADDIS_TLSGD_HA", SDTIntBinOp>;
111111 def PPCaddiTlsgdL : SDNode<"PPCISD::ADDI_TLSGD_L", SDTIntBinOp>;
112 def PPCgetTlsAddr : SDNode<"PPCISD::GET_TLS_ADDR", SDTIntBinOp>;
113112 def PPCaddisTlsldHA : SDNode<"PPCISD::ADDIS_TLSLD_HA", SDTIntBinOp>;
114113 def PPCaddiTlsldL : SDNode<"PPCISD::ADDI_TLSLD_L", SDTIntBinOp>;
115 def PPCgetTlsldAddr : SDNode<"PPCISD::GET_TLSLD_ADDR", SDTIntBinOp>;
116 def PPCaddisDtprelHA : SDNode<"PPCISD::ADDIS_DTPREL_HA", SDTIntBinOp>;
114 def PPCaddisDtprelHA : SDNode<"PPCISD::ADDIS_DTPREL_HA", SDTIntBinOp,
115 [SDNPHasChain]>;
117116 def PPCaddiDtprelL : SDNode<"PPCISD::ADDI_DTPREL_L", SDTIntBinOp>;
118117
119118 def PPCvperm : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
136135 def PPCcall : SDNode<"PPCISD::CALL", SDT_PPCCall,
137136 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
138137 SDNPVariadic]>;
138 def PPCcall_tls : SDNode<"PPCISD::CALL_TLS", SDT_PPCCall,
139 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
140 SDNPVariadic]>;
139141 def PPCcall_nop : SDNode<"PPCISD::CALL_NOP", SDT_PPCCall,
140142 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
141143 SDNPVariadic]>;
144 def PPCcall_nop_tls : SDNode<"PPCISD::CALL_NOP_TLS", SDT_PPCCall,
145 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
146 SDNPVariadic]>;
142147 def PPCmtctr : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
143148 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
144149 def PPCbctrl : SDNode<"PPCISD::BCTRL", SDTNone,
24532458 def : Pat<(PPCcall (i32 texternalsym:$dst)),
24542459 (BL texternalsym:$dst)>;
24552460
2461 def : Pat<(PPCcall_tls texternalsym:$func, tglobaltlsaddr:$sym),
2462 (BL_TLS texternalsym:$func, tglobaltlsaddr:$sym)>;
2463
24562464 def : Pat<(PPCtc_return (i32 tglobaladdr:$dst), imm:$imm),
24572465 (TCRETURNdi tglobaladdr:$dst, imm:$imm)>;
24582466
25072515 "#ADDItlsgdL32",
25082516 [(set i32:$rD,
25092517 (PPCaddiTlsgdL i32:$reg, tglobaltlsaddr:$disp))]>;
2510 let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1, Defs = [LR] in
2511 def GETtlsADDR32 : Pseudo<(outs gprc:$rD), (ins gprc:$reg, tlsgd32:$sym),
2512 "GETtlsADDR32",
2513 [(set i32:$rD,
2514 (PPCgetTlsAddr i32:$reg, tglobaltlsaddr:$sym))]>;
25152518 def ADDItlsldL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
25162519 "#ADDItlsldL32",
25172520 [(set i32:$rD,
25182521 (PPCaddiTlsldL i32:$reg, tglobaltlsaddr:$disp))]>;
2519 let hasExtraSrcRegAllocReq = 1, hasExtraDefRegAllocReq = 1, Defs = [LR] in
2520 def GETtlsldADDR32 : Pseudo<(outs gprc:$rD), (ins gprc:$reg, tlsgd32:$sym),
2521 "GETtlsldADDR32",
2522 [(set i32:$rD,
2523 (PPCgetTlsldAddr i32:$reg,
2524 tglobaltlsaddr:$sym))]>;
25252522 def ADDIdtprelL32 : Pseudo<(outs gprc:$rD), (ins gprc_nor0:$reg, s16imm:$disp),
25262523 "#ADDIdtprelL32",
25272524 [(set i32:$rD,
136136 case PPCII::MO_TLS:
137137 RefKind = MCSymbolRefExpr::VK_PPC_TLS;
138138 break;
139 case PPCII::MO_TLSGD:
140 RefKind = MCSymbolRefExpr::VK_PPC_TLSGD;
141 break;
142 case PPCII::MO_TLSLD:
143 RefKind = MCSymbolRefExpr::VK_PPC_TLSLD;
144 break;
139145 }
140146
141147 if (MO.getTargetFlags() == PPCII::MO_PLT_OR_STUB && !isDarwin)
+0
-113
lib/Target/PowerPC/PPCTLSDynamicCall.cpp less more
None //===---------- PPCTLSDynamicCall.cpp - TLS Dynamic Call Fixup ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass fixes up GETtls[ld]ADDR[32] machine instructions so that
10 // they read and write GPR3. These are really call instructions, so
11 // must use the calling convention registers. This is done in a late
12 // pass so that TLS variable accesses can be fully commoned.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "PPCInstrInfo.h"
17 #include "PPC.h"
18 #include "PPCInstrBuilder.h"
19 #include "PPCTargetMachine.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/raw_ostream.h"
24
25 using namespace llvm;
26
27 #define DEBUG_TYPE "ppc-tls-dynamic-call"
28
29 namespace llvm {
30 void initializePPCTLSDynamicCallPass(PassRegistry&);
31 }
32
33 namespace {
34 // PPCTLSDynamicCall pass - Add copies to and from GPR3 around
35 // GETtls[ld]ADDR[32] machine instructions. These instructions
36 // are actually call instructions, so the register choice is
37 // constrained. We delay introducing these copies as late as
38 // possible so that TLS variable accesses can be fully commoned.
39 struct PPCTLSDynamicCall : public MachineFunctionPass {
40 static char ID;
41 PPCTLSDynamicCall() : MachineFunctionPass(ID) {
42 initializePPCTLSDynamicCallPass(*PassRegistry::getPassRegistry());
43 }
44
45 const PPCTargetMachine *TM;
46 const PPCInstrInfo *TII;
47
48 protected:
49 bool processBlock(MachineBasicBlock &MBB) {
50 bool Changed = false;
51 bool Is64Bit = TM->getSubtargetImpl()->isPPC64();
52
53 for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end();
54 I != IE; ++I) {
55 MachineInstr *MI = I;
56
57 if (MI->getOpcode() != PPC::GETtlsADDR &&
58 MI->getOpcode() != PPC::GETtlsldADDR &&
59 MI->getOpcode() != PPC::GETtlsADDR32 &&
60 MI->getOpcode() != PPC::GETtlsldADDR32)
61 continue;
62
63 DEBUG(dbgs() << "TLS Dynamic Call Fixup:\n " << *MI;);
64
65 unsigned OutReg = MI->getOperand(0).getReg();
66 unsigned InReg = MI->getOperand(1).getReg();
67 DebugLoc DL = MI->getDebugLoc();
68 unsigned GPR3 = Is64Bit ? PPC::X3 : PPC::R3;
69
70 BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), GPR3)
71 .addReg(InReg);
72 MI->getOperand(0).setReg(GPR3);
73 MI->getOperand(1).setReg(GPR3);
74 BuildMI(MBB, ++I, DL, TII->get(TargetOpcode::COPY), OutReg)
75 .addReg(GPR3);
76
77 Changed = true;
78 }
79
80 return Changed;
81 }
82
83 public:
84 bool runOnMachineFunction(MachineFunction &MF) override {
85 TM = static_cast(&MF.getTarget());
86 TII = TM->getSubtargetImpl()->getInstrInfo();
87
88 bool Changed = false;
89
90 for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
91 MachineBasicBlock &B = *I++;
92 if (processBlock(B))
93 Changed = true;
94 }
95
96 return Changed;
97 }
98
99 void getAnalysisUsage(AnalysisUsage &AU) const override {
100 MachineFunctionPass::getAnalysisUsage(AU);
101 }
102 };
103 }
104
105 INITIALIZE_PASS_BEGIN(PPCTLSDynamicCall, DEBUG_TYPE,
106 "PowerPC TLS Dynamic Call Fixup", false, false)
107 INITIALIZE_PASS_END(PPCTLSDynamicCall, DEBUG_TYPE,
108 "PowerPC TLS Dynamic Call Fixup", false, false)
109
110 char PPCTLSDynamicCall::ID = 0;
111 FunctionPass*
112 llvm::createPPCTLSDynamicCallPass() { return new PPCTLSDynamicCall(); }
265265 initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry());
266266 insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID,
267267 &PPCVSXFMAMutateID);
268 addPass(createPPCTLSDynamicCallPass());
269268 }
270269
271270 void PPCPassConfig::addPreSched2() {
1111 ; CHECK-LABEL: @test1
1212 ; CHECK: mflr 0
1313 ; CHECK: std 0, 16(1)
14 ; CHECK-DAG: ld 3, 64(1)
14 ; FIXME: These next two lines don't both need to load the same value.
15 ; CHECK-DAG: ld 3, 16(1)
1516 ; CHECK-DAG: ld 0, 16(1)
1617 ; CHECK: mtlr 0
1718 ; CHECK: blr
+0
-52
test/CodeGen/PowerPC/tls-cse.ll less more
None ; RUN: llc -march=ppc64 -mcpu=pwr7 -O2 -relocation-model=pic < %s | FileCheck %s
1 ; RUN: llc -march=ppc64 -mcpu=pwr7 -O2 -relocation-model=pic < %s | grep "__tls_get_addr" | count 1
2
3 ; This test was derived from LLVM's own
4 ; PrettyStackTraceEntry::~PrettyStackTraceEntry(). It demonstrates an
5 ; opportunity for CSE of calls to __tls_get_addr().
6
7 target datalayout = "e-m:e-i64:64-n32:64"
8 target triple = "powerpc64le-unknown-linux-gnu"
9
10 %"class.llvm::PrettyStackTraceEntry" = type { i32 (...)**, %"class.llvm::PrettyStackTraceEntry"* }
11
12 @_ZTVN4llvm21PrettyStackTraceEntryE = unnamed_addr constant [5 x i8*] [i8* null, i8* null, i8* bitcast (void (%"class.llvm::PrettyStackTraceEntry"*)* @_ZN4llvm21PrettyStackTraceEntryD2Ev to i8*), i8* bitcast (void (%"class.llvm::PrettyStackTraceEntry"*)* @_ZN4llvm21PrettyStackTraceEntryD0Ev to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*)], align 8
13 @_ZL20PrettyStackTraceHead = internal thread_local unnamed_addr global %"class.llvm::PrettyStackTraceEntry"* null, align 8
14 @.str = private unnamed_addr constant [87 x i8] c"PrettyStackTraceHead == this && \22Pretty stack trace entry destruction is out of order\22\00", align 1
15 @.str1 = private unnamed_addr constant [64 x i8] c"/home/wschmidt/llvm/llvm-test2/lib/Support/PrettyStackTrace.cpp\00", align 1
16 @__PRETTY_FUNCTION__._ZN4llvm21PrettyStackTraceEntryD2Ev = private unnamed_addr constant [62 x i8] c"virtual llvm::PrettyStackTraceEntry::~PrettyStackTraceEntry()\00", align 1
17
18 declare void @_ZN4llvm21PrettyStackTraceEntryD2Ev(%"class.llvm::PrettyStackTraceEntry"* %this) unnamed_addr
19 declare void @__cxa_pure_virtual()
20 declare void @__assert_fail(i8*, i8*, i32 zeroext, i8*)
21 declare void @_ZdlPv(i8*)
22
23 define void @_ZN4llvm21PrettyStackTraceEntryD0Ev(%"class.llvm::PrettyStackTraceEntry"* %this) unnamed_addr align 2 {
24 entry:
25 %0 = getelementptr inbounds %"class.llvm::PrettyStackTraceEntry"* %this, i64 0, i32 0
26 store i32 (...)** bitcast (i8** getelementptr inbounds ([5 x i8*]* @_ZTVN4llvm21PrettyStackTraceEntryE, i64 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
27 %1 = load %"class.llvm::PrettyStackTraceEntry"** @_ZL20PrettyStackTraceHead, align 8
28 %cmp.i = icmp eq %"class.llvm::PrettyStackTraceEntry"* %1, %this
29 br i1 %cmp.i, label %_ZN4llvm21PrettyStackTraceEntryD2Ev.exit, label %cond.false.i
30
31 cond.false.i: ; preds = %entry
32 tail call void @__assert_fail(i8* getelementptr inbounds ([87 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8]* @.str1, i64 0, i64 0), i32 zeroext 119, i8* getelementptr inbounds ([62 x i8]* @__PRETTY_FUNCTION__._ZN4llvm21PrettyStackTraceEntryD2Ev, i64 0, i64 0))
33 unreachable
34
35 _ZN4llvm21PrettyStackTraceEntryD2Ev.exit: ; preds = %entry
36 %NextEntry.i.i = getelementptr inbounds %"class.llvm::PrettyStackTraceEntry"* %this, i64 0, i32 1
37 %2 = bitcast %"class.llvm::PrettyStackTraceEntry"** %NextEntry.i.i to i64*
38 %3 = load i64* %2, align 8
39 store i64 %3, i64* bitcast (%"class.llvm::PrettyStackTraceEntry"** @_ZL20PrettyStackTraceHead to i64*), align 8
40 %4 = bitcast %"class.llvm::PrettyStackTraceEntry"* %this to i8*
41 tail call void @_ZdlPv(i8* %4)
42 ret void
43 }
44
45 ; CHECK-LABEL: _ZN4llvm21PrettyStackTraceEntryD0Ev:
46 ; CHECK: addis [[REG1:[0-9]+]], 2, _ZL20PrettyStackTraceHead@got@tlsld@ha
47 ; CHECK: addi 3, [[REG1]], _ZL20PrettyStackTraceHead@got@tlsld@l
48 ; CHECK: bl __tls_get_addr(_ZL20PrettyStackTraceHead@tlsld)
49 ; CHECK: addis 3, 3, _ZL20PrettyStackTraceHead@dtprel@ha
50 ; CHECK: ld {{[0-9]+}}, _ZL20PrettyStackTraceHead@dtprel@l(3)
51 ; CHECK: std {{[0-9]+}}, _ZL20PrettyStackTraceHead@dtprel@l(3)
0 ; RUN: llc -march=ppc64 -mcpu=pwr7 -O0 -relocation-model=pic < %s | FileCheck -check-prefix=OPT0 %s
11 ; RUN: llc -march=ppc64 -mcpu=pwr7 -O1 -relocation-model=pic < %s | FileCheck -check-prefix=OPT1 %s
2 ; R;U;N: llc -march=ppc32 -O0 -relocation-model=pic < %s | FileCheck -check-prefix=OPT0-32 %s
3 ; R;U;N: llc -march=ppc32 -O1 -relocation-model=pic < %s | FileCheck -check-prefix=OPT1-32 %s
2 ; RUN: llc -march=ppc32 -O0 -relocation-model=pic < %s | FileCheck -check-prefix=OPT0-32 %s
3 ; RUN: llc -march=ppc32 -O1 -relocation-model=pic < %s | FileCheck -check-prefix=OPT1-32 %s
44
55 target triple = "powerpc64-unknown-linux-gnu"
66 ; Test correct assembly code generation for thread-local storage using
6464 ; OPT1: bl __tls_get_addr(a2@tlsgd)
6565 ; OPT1-NEXT: nop
6666 ; OPT1-32-LABEL: main2
67 ; OPT1-32: addi {{[0-9]+}}, {{[0-9]+}}, a2@got@tlsgd
67 ; OPT1-32: addi 3, {{[0-9]+}}, a2@got@tlsgd
6868 ; OPT1-32: bl __tls_get_addr(a2@tlsgd)@PLT
1818 }
1919
2020 ; CHECK-LABEL: call_once:
21 ; CHECK: addi 3, {{[0-9]+}}, __once_callable@got@tlsgd@l
21 ; CHECK: addis 3, 2, __once_callable@got@tlsgd@ha
22 ; CHECK: addi 3, 3, __once_callable@got@tlsgd@l
2223 ; CHECK: bl __tls_get_addr(__once_callable@tlsgd)
2324 ; CHECK-NEXT: nop
2425 ; CHECK: std {{[0-9]+}}, 0(3)
25 ; CHECK: addi 3, {{[0-9]+}}, __once_call@got@tlsgd@l
26 ; CHECK: addis 3, 2, __once_call@got@tlsgd@ha
27 ; CHECK: addi 3, 3, __once_call@got@tlsgd@l
2628 ; CHECK: bl __tls_get_addr(__once_call@tlsgd)
2729 ; CHECK-NEXT: nop
2830 ; CHECK: std {{[0-9]+}}, 0(3)