llvm.org GIT mirror llvm / 8e98e02
Reapply "[GlobalISel] Remove the GISelAccessor API." This reverts commit r310425, thus reapplying r310335 with a fix for link issue of the AArch64 unittests on Linux bots when BUILD_SHARED_LIBS is ON. Original commit message: [GlobalISel] Remove the GISelAccessor API. Its sole purpose was to avoid spreading around ifdefs related to building global-isel. Since r309990, GlobalISel is not optional anymore, thus, we can get rid of this mechanism all together. NFC. ---- The fix for the link issue consists in adding the GlobalISel library in the list of dependencies for the AArch64 unittests. This dependency comes from the use of AArch64Subtarget that needs to know how to destruct the GISel related APIs when being detroyed. Thanks to Bill Seurer and Ahmed Bougacha for helping me reproducing and understand the problem. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310969 91177308-0d34-0410-b5e6-96231b3b80d8 Quentin Colombet 3 years ago
11 changed file(s) with 77 addition(s) and 242 deletion(s). Raw diff Collapse all Expand all
632632
633633 * ``TargetPassConfig`` --- create the passes constituting the pipeline,
634634 including additional passes not included in the :ref:`pipeline`.
635 * ``GISelAccessor`` --- setup the various subtarget-provided classes, with a
636 graceful fallback to no-op when GlobalISel isn't enabled.
+0
-39
include/llvm/CodeGen/GlobalISel/GISelAccessor.h less more
None //===-- GISelAccessor.h - GISel Accessor ------------------------*- C++ -*-===//
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 file declares the API to access the various APIs related
10 /// to GlobalISel.
11 //
12 //===----------------------------------------------------------------------===/
13
14 #ifndef LLVM_CODEGEN_GLOBALISEL_GISELACCESSOR_H
15 #define LLVM_CODEGEN_GLOBALISEL_GISELACCESSOR_H
16
17 namespace llvm {
18 class CallLowering;
19 class InstructionSelector;
20 class LegalizerInfo;
21 class RegisterBankInfo;
22
23 /// The goal of this helper class is to gather the accessor to all
24 /// the APIs related to GlobalISel.
25 /// It should be derived to feature an actual accessor to the GISel APIs.
26 /// The reason why this is not simply done into the subtarget is to avoid
27 /// spreading ifdefs around.
28 struct GISelAccessor {
29 virtual ~GISelAccessor() {}
30 virtual const CallLowering *getCallLowering() const { return nullptr;}
31 virtual const InstructionSelector *getInstructionSelector() const {
32 return nullptr;
33 }
34 virtual const LegalizerInfo *getLegalizerInfo() const { return nullptr; }
35 virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr;}
36 };
37 } // End namespace llvm;
38 #endif
2020 #include "AArch64CallLowering.h"
2121 #include "AArch64LegalizerInfo.h"
2222 #include "AArch64RegisterBankInfo.h"
23 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
2423 #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
2524 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
2625 #include "llvm/CodeGen/GlobalISel/Legalizer.h"
140139 }
141140 }
142141
143 namespace {
144
145 struct AArch64GISelActualAccessor : public GISelAccessor {
146 std::unique_ptr CallLoweringInfo;
147 std::unique_ptr InstSelector;
148 std::unique_ptr Legalizer;
149 std::unique_ptr RegBankInfo;
150
151 const CallLowering *getCallLowering() const override {
152 return CallLoweringInfo.get();
153 }
154
155 const InstructionSelector *getInstructionSelector() const override {
156 return InstSelector.get();
157 }
158
159 const LegalizerInfo *getLegalizerInfo() const override {
160 return Legalizer.get();
161 }
162
163 const RegisterBankInfo *getRegBankInfo() const override {
164 return RegBankInfo.get();
165 }
166 };
167
168 } // end anonymous namespace
169
170142 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
171143 const std::string &FS,
172144 const TargetMachine &TM, bool LittleEndian)
173145 : AArch64GenSubtargetInfo(TT, CPU, FS),
174 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()),
175 IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(),
146 ReserveX18(TT.isOSDarwin() || TT.isOSWindows()), IsLittle(LittleEndian),
147 TargetTriple(TT), FrameLowering(),
176148 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(),
177 TLInfo(TM, *this), GISel() {
178 AArch64GISelActualAccessor *AArch64GISel = new AArch64GISelActualAccessor();
179 AArch64GISel->CallLoweringInfo.reset(
180 new AArch64CallLowering(*getTargetLowering()));
181 AArch64GISel->Legalizer.reset(new AArch64LegalizerInfo());
149 TLInfo(TM, *this) {
150 CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering()));
151 Legalizer.reset(new AArch64LegalizerInfo());
182152
183153 auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo());
184154
185155 // FIXME: At this point, we can't rely on Subtarget having RBI.
186156 // It's awkward to mix passing RBI and the Subtarget; should we pass
187157 // TII/TRI as well?
188 AArch64GISel->InstSelector.reset(createAArch64InstructionSelector(
158 InstSelector.reset(createAArch64InstructionSelector(
189159 *static_cast(&TM), *this, *RBI));
190160
191 AArch64GISel->RegBankInfo.reset(RBI);
192 setGISelAccessor(*AArch64GISel);
161 RegBankInfo.reset(RBI);
193162 }
194163
195164 const CallLowering *AArch64Subtarget::getCallLowering() const {
196 assert(GISel && "Access to GlobalISel APIs not set");
197 return GISel->getCallLowering();
165 return CallLoweringInfo.get();
198166 }
199167
200168 const InstructionSelector *AArch64Subtarget::getInstructionSelector() const {
201 assert(GISel && "Access to GlobalISel APIs not set");
202 return GISel->getInstructionSelector();
169 return InstSelector.get();
203170 }
204171
205172 const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const {
206 assert(GISel && "Access to GlobalISel APIs not set");
207 return GISel->getLegalizerInfo();
173 return Legalizer.get();
208174 }
209175
210176 const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
211 assert(GISel && "Access to GlobalISel APIs not set");
212 return GISel->getRegBankInfo();
177 return RegBankInfo.get();
213178 }
214179
215180 /// Find the target operand flags that describe how a global value should be
1818 #include "AArch64InstrInfo.h"
1919 #include "AArch64RegisterInfo.h"
2020 #include "AArch64SelectionDAGInfo.h"
21 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
21 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
22 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
23 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
24 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
2225 #include "llvm/IR/DataLayout.h"
2326 #include "llvm/Target/TargetSubtargetInfo.h"
2427 #include
126129 AArch64InstrInfo InstrInfo;
127130 AArch64SelectionDAGInfo TSInfo;
128131 AArch64TargetLowering TLInfo;
129 /// Gather the accessor points to GlobalISel-related APIs.
130 /// This is used to avoid ifndefs spreading around while GISel is
131 /// an optional library.
132 std::unique_ptr GISel;
132
133 /// GlobalISel related APIs.
134 std::unique_ptr CallLoweringInfo;
135 std::unique_ptr InstSelector;
136 std::unique_ptr Legalizer;
137 std::unique_ptr RegBankInfo;
133138
134139 private:
135140 /// initializeSubtargetDependencies - Initializes using CPUString and the
147152 AArch64Subtarget(const Triple &TT, const std::string &CPU,
148153 const std::string &FS, const TargetMachine &TM,
149154 bool LittleEndian);
150
151 /// This object will take onwership of \p GISelAccessor.
152 void setGISelAccessor(GISelAccessor &GISel) {
153 this->GISel.reset(&GISel);
154 }
155155
156156 const AArch64SelectionDAGInfo *getSelectionDAGInfo() const override {
157157 return &TSInfo;
8888
8989 return *this;
9090 }
91
92 namespace {
93
94 struct SIGISelActualAccessor : public GISelAccessor {
95 std::unique_ptr CallLoweringInfo;
96 std::unique_ptr InstSelector;
97 std::unique_ptr Legalizer;
98 std::unique_ptr RegBankInfo;
99 const AMDGPUCallLowering *getCallLowering() const override {
100 return CallLoweringInfo.get();
101 }
102 const InstructionSelector *getInstructionSelector() const override {
103 return InstSelector.get();
104 }
105 const LegalizerInfo *getLegalizerInfo() const override {
106 return Legalizer.get();
107 }
108 const RegisterBankInfo *getRegBankInfo() const override {
109 return RegBankInfo.get();
110 }
111 };
112
113 } // end anonymous namespace
11491
11592 AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
11693 const TargetMachine &TM)
364341 : AMDGPUSubtarget(TT, GPU, FS, TM), InstrInfo(*this),
365342 FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0),
366343 TLInfo(TM, *this) {
367 SIGISelActualAccessor *GISel = new SIGISelActualAccessor();
368 GISel->CallLoweringInfo.reset(new AMDGPUCallLowering(*getTargetLowering()));
369 GISel->Legalizer.reset(new AMDGPULegalizerInfo());
370
371 GISel->RegBankInfo.reset(new AMDGPURegisterBankInfo(*getRegisterInfo()));
372 GISel->InstSelector.reset(new AMDGPUInstructionSelector(
373 *this, *static_cast(GISel->RegBankInfo.get())));
374 setGISelAccessor(*GISel);
344 CallLoweringInfo.reset(new AMDGPUCallLowering(*getTargetLowering()));
345 Legalizer.reset(new AMDGPULegalizerInfo());
346
347 RegBankInfo.reset(new AMDGPURegisterBankInfo(*getRegisterInfo()));
348 InstSelector.reset(new AMDGPUInstructionSelector(
349 *this, *static_cast(RegBankInfo.get())));
375350 }
376351
377352 void SISubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
1515 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
1616
1717 #include "AMDGPU.h"
18 #include "AMDGPUCallLowering.h"
1819 #include "R600FrameLowering.h"
1920 #include "R600ISelLowering.h"
2021 #include "R600InstrInfo.h"
2425 #include "SIMachineFunctionInfo.h"
2526 #include "Utils/AMDGPUBaseInfo.h"
2627 #include "llvm/ADT/Triple.h"
27 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
28 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
29 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
30 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
2831 #include "llvm/CodeGen/MachineFunction.h"
2932 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
3033 #include "llvm/MC/MCInstrItineraries.h"
629632 SIInstrInfo InstrInfo;
630633 SIFrameLowering FrameLowering;
631634 SITargetLowering TLInfo;
632 std::unique_ptr GISel;
635
636 /// GlobalISel related APIs.
637 std::unique_ptr CallLoweringInfo;
638 std::unique_ptr InstSelector;
639 std::unique_ptr Legalizer;
640 std::unique_ptr RegBankInfo;
633641
634642 public:
635643 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
648656 }
649657
650658 const CallLowering *getCallLowering() const override {
651 assert(GISel && "Access to GlobalISel APIs not set");
652 return GISel->getCallLowering();
659 return CallLoweringInfo.get();
653660 }
654661
655662 const InstructionSelector *getInstructionSelector() const override {
656 assert(GISel && "Access to GlobalISel APIs not set");
657 return GISel->getInstructionSelector();
663 return InstSelector.get();
658664 }
659665
660666 const LegalizerInfo *getLegalizerInfo() const override {
661 assert(GISel && "Access to GlobalISel APIs not set");
662 return GISel->getLegalizerInfo();
667 return Legalizer.get();
663668 }
664669
665670 const RegisterBankInfo *getRegBankInfo() const override {
666 assert(GISel && "Access to GlobalISel APIs not set");
667 return GISel->getRegBankInfo();
671 return RegBankInfo.get();
668672 }
669673
670674 const SIRegisterInfo *getRegisterInfo() const override {
671675 return &InstrInfo.getRegisterInfo();
672 }
673
674 void setGISelAccessor(GISelAccessor &GISel) {
675 this->GISel.reset(&GISel);
676676 }
677677
678678 // XXX - Why is this here if it isn't in the default pass set?
2727 #include "llvm/ADT/StringRef.h"
2828 #include "llvm/ADT/Triple.h"
2929 #include "llvm/ADT/Twine.h"
30 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
3130 #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
3231 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
3332 #include "llvm/CodeGen/GlobalISel/Legalizer.h"
9695 return new ARMFrameLowering(STI);
9796 }
9897
99 namespace {
100
101 struct ARMGISelActualAccessor : public GISelAccessor {
102 std::unique_ptr CallLoweringInfo;
103 std::unique_ptr InstSelector;
104 std::unique_ptr Legalizer;
105 std::unique_ptr RegBankInfo;
106
107 const CallLowering *getCallLowering() const override {
108 return CallLoweringInfo.get();
109 }
110
111 const InstructionSelector *getInstructionSelector() const override {
112 return InstSelector.get();
113 }
114
115 const LegalizerInfo *getLegalizerInfo() const override {
116 return Legalizer.get();
117 }
118
119 const RegisterBankInfo *getRegBankInfo() const override {
120 return RegBankInfo.get();
121 }
122 };
123
124 } // end anonymous namespace
125
12698 ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU,
12799 const std::string &FS,
128100 const ARMBaseTargetMachine &TM, bool IsLittle)
138110 : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
139111 TLInfo(TM, *this) {
140112
141 ARMGISelActualAccessor *GISel = new ARMGISelActualAccessor();
142 GISel->CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering()));
143 GISel->Legalizer.reset(new ARMLegalizerInfo(*this));
113 CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering()));
114 Legalizer.reset(new ARMLegalizerInfo(*this));
144115
145116 auto *RBI = new ARMRegisterBankInfo(*getRegisterInfo());
146117
147118 // FIXME: At this point, we can't rely on Subtarget having RBI.
148119 // It's awkward to mix passing RBI and the Subtarget; should we pass
149120 // TII/TRI as well?
150 GISel->InstSelector.reset(createARMInstructionSelector(
121 InstSelector.reset(createARMInstructionSelector(
151122 *static_cast(&TM), *this, *RBI));
152123
153 GISel->RegBankInfo.reset(RBI);
154 setGISelAccessor(*GISel);
124 RegBankInfo.reset(RBI);
155125 }
156126
157127 const CallLowering *ARMSubtarget::getCallLowering() const {
158 assert(GISel && "Access to GlobalISel APIs not set");
159 return GISel->getCallLowering();
128 return CallLoweringInfo.get();
160129 }
161130
162131 const InstructionSelector *ARMSubtarget::getInstructionSelector() const {
163 assert(GISel && "Access to GlobalISel APIs not set");
164 return GISel->getInstructionSelector();
132 return InstSelector.get();
165133 }
166134
167135 const LegalizerInfo *ARMSubtarget::getLegalizerInfo() const {
168 assert(GISel && "Access to GlobalISel APIs not set");
169 return GISel->getLegalizerInfo();
136 return Legalizer.get();
170137 }
171138
172139 const RegisterBankInfo *ARMSubtarget::getRegBankInfo() const {
173 assert(GISel && "Access to GlobalISel APIs not set");
174 return GISel->getRegBankInfo();
140 return RegBankInfo.get();
175141 }
176142
177143 bool ARMSubtarget::isXRaySupported() const {
1919 #include "ARMISelLowering.h"
2020 #include "ARMSelectionDAGInfo.h"
2121 #include "llvm/ADT/Triple.h"
22 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
22 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
23 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
24 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
25 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
2326 #include "llvm/CodeGen/MachineFunction.h"
2427 #include "llvm/MC/MCInstrItineraries.h"
2528 #include "llvm/MC/MCSchedule.h"
423426 ARMSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
424427 const ARMBaseTargetMachine &TM, bool IsLittle);
425428
426 /// This object will take onwership of \p GISelAccessor.
427 void setGISelAccessor(GISelAccessor &GISel) { this->GISel.reset(&GISel); }
428
429429 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
430430 /// that still makes it profitable to inline the call.
431431 unsigned getMaxInlineSizeThreshold() const {
473473 std::unique_ptr InstrInfo;
474474 ARMTargetLowering TLInfo;
475475
476 /// Gather the accessor points to GlobalISel-related APIs.
477 /// This is used to avoid ifndefs spreading around while GISel is
478 /// an optional library.
479 std::unique_ptr GISel;
476 /// GlobalISel related APIs.
477 std::unique_ptr CallLoweringInfo;
478 std::unique_ptr InstSelector;
479 std::unique_ptr Legalizer;
480 std::unique_ptr RegBankInfo;
480481
481482 void initializeEnvironment();
482483 void initSubtargetFeatures(StringRef CPU, StringRef FS);
368368 return *this;
369369 }
370370
371 namespace {
372
373 struct X86GISelActualAccessor : public GISelAccessor {
374 std::unique_ptr CallLoweringInfo;
375 std::unique_ptr Legalizer;
376 std::unique_ptr RegBankInfo;
377 std::unique_ptr InstSelector;
378
379 const CallLowering *getCallLowering() const override {
380 return CallLoweringInfo.get();
381 }
382
383 const InstructionSelector *getInstructionSelector() const override {
384 return InstSelector.get();
385 }
386
387 const LegalizerInfo *getLegalizerInfo() const override {
388 return Legalizer.get();
389 }
390
391 const RegisterBankInfo *getRegBankInfo() const override {
392 return RegBankInfo.get();
393 }
394 };
395
396 } // end anonymous namespace
397
398371 X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
399372 const X86TargetMachine &TM,
400373 unsigned StackAlignOverride)
419392 setPICStyle(PICStyles::StubPIC);
420393 else if (isTargetELF())
421394 setPICStyle(PICStyles::GOT);
422 X86GISelActualAccessor *GISel = new X86GISelActualAccessor();
423
424 GISel->CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering()));
425 GISel->Legalizer.reset(new X86LegalizerInfo(*this, TM));
395
396 CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering()));
397 Legalizer.reset(new X86LegalizerInfo(*this, TM));
426398
427399 auto *RBI = new X86RegisterBankInfo(*getRegisterInfo());
428 GISel->RegBankInfo.reset(RBI);
429 GISel->InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI));
430 setGISelAccessor(*GISel);
400 RegBankInfo.reset(RBI);
401 InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI));
431402 }
432403
433404 const CallLowering *X86Subtarget::getCallLowering() const {
434 assert(GISel && "Access to GlobalISel APIs not set");
435 return GISel->getCallLowering();
405 return CallLoweringInfo.get();
436406 }
437407
438408 const InstructionSelector *X86Subtarget::getInstructionSelector() const {
439 assert(GISel && "Access to GlobalISel APIs not set");
440 return GISel->getInstructionSelector();
409 return InstSelector.get();
441410 }
442411
443412 const LegalizerInfo *X86Subtarget::getLegalizerInfo() const {
444 assert(GISel && "Access to GlobalISel APIs not set");
445 return GISel->getLegalizerInfo();
413 return Legalizer.get();
446414 }
447415
448416 const RegisterBankInfo *X86Subtarget::getRegBankInfo() const {
449 assert(GISel && "Access to GlobalISel APIs not set");
450 return GISel->getRegBankInfo();
417 return RegBankInfo.get();
451418 }
452419
453420 bool X86Subtarget::enableEarlyIfConversion() const {
1919 #include "X86SelectionDAGInfo.h"
2020 #include "llvm/ADT/StringRef.h"
2121 #include "llvm/ADT/Triple.h"
22 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
22 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
23 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
24 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
25 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
2326 #include "llvm/IR/CallingConv.h"
2427 #include "llvm/MC/MCInstrItineraries.h"
2528 #include "llvm/Target/TargetMachine.h"
313316 /// Instruction itineraries for scheduling
314317 InstrItineraryData InstrItins;
315318
316 /// Gather the accessor points to GlobalISel-related APIs.
317 /// This is used to avoid ifndefs spreading around while GISel is
318 /// an optional library.
319 std::unique_ptr GISel;
319 /// GlobalISel related APIs.
320 std::unique_ptr CallLoweringInfo;
321 std::unique_ptr Legalizer;
322 std::unique_ptr RegBankInfo;
323 std::unique_ptr InstSelector;
320324
321325 private:
322326 /// Override the stack alignment.
344348 ///
345349 X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
346350 const X86TargetMachine &TM, unsigned StackAlignOverride);
347
348 /// This object will take onwership of \p GISelAccessor.
349 void setGISelAccessor(GISelAccessor &GISel) { this->GISel.reset(&GISel); }
350351
351352 const X86TargetLowering *getTargetLowering() const override {
352353 return &TLInfo;
88 AArch64Info
99 CodeGen
1010 Core
11 GlobalISel
1112 MC
1213 MIRParser
1314 SelectionDAG