1 //===-- SPIRVSubtarget.h - SPIR-V Subtarget Information --------*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the SPIR-V specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
14 #define LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
15 
16 #include "SPIRVCallLowering.h"
17 #include "SPIRVFrameLowering.h"
18 #include "SPIRVISelLowering.h"
19 #include "SPIRVInstrInfo.h"
20 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
21 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
22 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
23 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
24 #include "llvm/CodeGen/TargetSubtargetInfo.h"
25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/Target/TargetMachine.h"
27 
28 #define GET_SUBTARGETINFO_HEADER
29 #include "SPIRVGenSubtargetInfo.inc"
30 
31 namespace llvm {
32 class StringRef;
33 class SPIRVGlobalRegistry;
34 class SPIRVTargetMachine;
35 
36 class SPIRVSubtarget : public SPIRVGenSubtargetInfo {
37 private:
38   const unsigned PointerSize;
39   uint32_t SPIRVVersion;
40 
41   std::unique_ptr<SPIRVGlobalRegistry> GR;
42 
43   SPIRVInstrInfo InstrInfo;
44   SPIRVFrameLowering FrameLowering;
45   SPIRVTargetLowering TLInfo;
46 
47   // GlobalISel related APIs.
48   std::unique_ptr<CallLowering> CallLoweringInfo;
49   std::unique_ptr<RegisterBankInfo> RegBankInfo;
50   std::unique_ptr<LegalizerInfo> Legalizer;
51   std::unique_ptr<InstructionSelector> InstSelector;
52 
53 public:
54   // This constructor initializes the data members to match that
55   // of the specified triple.
56   SPIRVSubtarget(const Triple &TT, const std::string &CPU,
57                  const std::string &FS, const SPIRVTargetMachine &TM);
58   SPIRVSubtarget &initSubtargetDependencies(StringRef CPU, StringRef FS);
59 
60   // Parses features string setting specified subtarget options.
61   // The definition of this function is auto generated by tblgen.
62   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
63   unsigned getPointerSize() const { return PointerSize; }
64   bool canDirectlyComparePointers() const;
65   uint32_t getSPIRVVersion() const { return SPIRVVersion; };
66   SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }
67 
68   const CallLowering *getCallLowering() const override {
69     return CallLoweringInfo.get();
70   }
71   const RegisterBankInfo *getRegBankInfo() const override {
72     return RegBankInfo.get();
73   }
74   const LegalizerInfo *getLegalizerInfo() const override {
75     return Legalizer.get();
76   }
77   InstructionSelector *getInstructionSelector() const override {
78     return InstSelector.get();
79   }
80   const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
81   const SPIRVFrameLowering *getFrameLowering() const override {
82     return &FrameLowering;
83   }
84   const SPIRVTargetLowering *getTargetLowering() const override {
85     return &TLInfo;
86   }
87   const SPIRVRegisterInfo *getRegisterInfo() const override {
88     return &InstrInfo.getRegisterInfo();
89   }
90 };
91 } // namespace llvm
92 
93 #endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
94