llvm.org GIT mirror llvm / 22f5417
Use shouldAssumeDSOLocal on AArch64. This reduces code duplication and now AArch64 also handles PIE. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270844 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
5 changed file(s) with 69 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/ADT/ArrayRef.h"
1717 #include "llvm/ADT/DenseMap.h"
1818 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Triple.h"
1920 #include "llvm/CodeGen/ISDOpcodes.h"
2021 #include "llvm/IR/CallSite.h"
2122 #include "llvm/IR/InlineAsm.h"
2223 #include "llvm/IR/Instructions.h"
24 #include "llvm/Support/CodeGen.h"
2325
2426 namespace llvm {
2527 class GlobalValue;
117119 // or we are in LTO.
118120 bool canBeOmittedFromSymbolTable(const GlobalValue *GV);
119121
122 bool shouldAssumeDSOLocal(Reloc::Model RM, const Triple &TT, const Module &M,
123 const GlobalValue *GV);
124
120125 DenseMap
121126 getFuncletMembership(const MachineFunction &MF);
122127
649649 return !GS.IsCompared;
650650 }
651651
652 // FIXME: make this a proper option
653 static bool CanUseCopyRelocWithPIE = false;
654
655 bool llvm::shouldAssumeDSOLocal(Reloc::Model RM, const Triple &TT,
656 const Module &M, const GlobalValue *GV) {
657 // DLLImport explicitly marks the GV as external.
658 if (GV && GV->hasDLLImportStorageClass())
659 return false;
660
661 // Every other GV is local on COFF
662 if (TT.isOSBinFormatCOFF())
663 return true;
664
665 if (RM == Reloc::Static)
666 return true;
667
668 if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
669 return true;
670
671 if (TT.isOSBinFormatELF()) {
672 assert(RM != Reloc::DynamicNoPIC);
673 // Some linkers can use copy relocations with pie executables.
674 if (M.getPIELevel() != PIELevel::Default) {
675 if (CanUseCopyRelocWithPIE)
676 return true;
677
678 // If the symbol is defined, it cannot be preempted.
679 if (GV && !GV->isDeclarationForLinker())
680 return true;
681 return false;
682 }
683
684 // ELF supports preemption of other symbols.
685 return false;
686 }
687
688 assert(TT.isOSBinFormatMachO());
689 if (GV && GV->isStrongDefinitionForLinker())
690 return true;
691
692 return false;
693 }
694
652695 static void collectFuncletMembers(
653696 DenseMap &FuncletMembership, int Funclet,
654697 const MachineBasicBlock *MBB) {
1313 #include "AArch64Subtarget.h"
1414 #include "AArch64InstrInfo.h"
1515 #include "AArch64PBQPRegAlloc.h"
16 #include "llvm/CodeGen/Analysis.h"
1617 #include "llvm/CodeGen/MachineScheduler.h"
1718 #include "llvm/IR/GlobalValue.h"
1819 #include "llvm/Support/TargetRegistry.h"
7273 unsigned char
7374 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
7475 const TargetMachine &TM) const {
75 bool isDef = GV->isStrongDefinitionForLinker();
76
7776 // MachO large model always goes via a GOT, simply to get a single 8-byte
7877 // absolute relocation on all global addresses.
7978 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
79 return AArch64II::MO_GOT;
80
81 Reloc::Model RM = TM.getRelocationModel();
82 if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV))
8083 return AArch64II::MO_GOT;
8184
8285 // The small code mode's direct accesses use ADRP, which cannot necessarily
8386 // produce the value 0 (if the code is above 4GB).
8487 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) {
8588 // In PIC mode use the GOT, but in absolute mode use a constant pool load.
86 if (TM.getRelocationModel() == Reloc::Static)
89 if (RM == Reloc::Static)
8790 return AArch64II::MO_CONSTPOOL;
8891 else
8992 return AArch64II::MO_GOT;
90 }
91
92 // If symbol visibility is hidden, the extra load is not needed if
93 // the symbol is definitely defined in the current translation unit.
94
95 // The handling of non-hidden symbols in PIC mode is rather target-dependent:
96 // + On MachO, if the symbol is defined in this module the GOT can be
97 // skipped.
98 // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
99 // defined could end up in unexpected places. Use a GOT.
100 if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
101 if (isTargetMachO())
102 return isDef ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
103 else
104 // No need to go through the GOT for local symbols on ELF.
105 return GV->hasLocalLinkage() ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT;
10693 }
10794
10895 return AArch64II::MO_NO_FLAG;
1313 #include "X86Subtarget.h"
1414 #include "X86InstrInfo.h"
1515 #include "X86TargetMachine.h"
16 #include "llvm/CodeGen/Analysis.h"
1617 #include "llvm/IR/Attributes.h"
1718 #include "llvm/IR/Function.h"
1819 #include "llvm/IR/GlobalValue.h"
4748 /// we should reference it in a non-pcrel context.
4849 unsigned char X86Subtarget::classifyBlockAddressReference() const {
4950 return classifyLocalReference(nullptr);
50 }
51
52 // FIXME: make this a proper option
53 static bool CanUseCopyRelocWithPIE = false;
54
55 static bool shouldAssumeDSOLocal(Reloc::Model RM, const Triple &TT,
56 const Module &M, const GlobalValue *GV) {
57 // DLLImport explicitly marks the GV as external.
58 if (GV && GV->hasDLLImportStorageClass())
59 return false;
60
61 // Every other GV is local on COFF
62 if (TT.isOSBinFormatCOFF())
63 return true;
64
65 if (RM == Reloc::Static)
66 return true;
67
68 if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
69 return true;
70
71 if (TT.isOSBinFormatELF()) {
72 assert(RM != Reloc::DynamicNoPIC);
73 // Some linkers can use copy relocations with pie executables.
74 if (M.getPIELevel() != PIELevel::Default) {
75 if (CanUseCopyRelocWithPIE)
76 return true;
77
78 // If the symbol is defined, it cannot be preempted.
79 if (GV && !GV->isDeclarationForLinker())
80 return true;
81 return false;
82 }
83
84 // ELF supports preemption of other symbols.
85 return false;
86 }
87
88 assert(TT.isOSBinFormatMachO());
89 if (GV && GV->isStrongDefinitionForLinker())
90 return true;
91
92 return false;
9351 }
9452
9553 /// Classify a global variable reference for the current subtarget according to
0 ; RUN: llc -mtriple aarch64-pc-linux -relocation-model=pic < %s | FileCheck %s
1
2 @g1 = global i32 42
3
4 define i32* @get_g1() {
5 ; CHECK: get_g1:
6 ; CHECK: adrp x0, g1
7 ; CHECK-NEXT: add x0, x0, :lo12:g1
8 ret i32* @g1
9 }
10
11 !llvm.module.flags = !{!0}
12
13 !0 = !{i32 1, !"PIE Level", i32 2}