LLVM  16.0.0git
SPIRVSubtarget.h
Go to the documentation of this file.
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"
25 #include "llvm/IR/DataLayout.h"
27 
28 #define GET_SUBTARGETINFO_HEADER
29 #include "SPIRVGenSubtargetInfo.inc"
30 
31 namespace llvm {
32 class StringRef;
33 class SPIRVTargetMachine;
34 
36 private:
37  const unsigned PointerSize;
38  uint32_t SPIRVVersion;
39  uint32_t OpenCLVersion;
40 
41  SmallSet<SPIRV::Extension::Extension, 4> AvailableExtensions;
43  std::unique_ptr<SPIRVGlobalRegistry> GR;
44 
45  SPIRVInstrInfo InstrInfo;
46  SPIRVFrameLowering FrameLowering;
47  SPIRVTargetLowering TLInfo;
48 
49  // GlobalISel related APIs.
50  std::unique_ptr<CallLowering> CallLoweringInfo;
51  std::unique_ptr<RegisterBankInfo> RegBankInfo;
52  std::unique_ptr<LegalizerInfo> Legalizer;
53  std::unique_ptr<InstructionSelector> InstSelector;
54 
55  // TODO: Initialise the available extensions, extended instruction sets
56  // based on the environment settings.
57  void initAvailableExtensions();
58  void initAvailableExtInstSets();
59 
60 public:
61  // This constructor initializes the data members to match that
62  // of the specified triple.
63  SPIRVSubtarget(const Triple &TT, const std::string &CPU,
64  const std::string &FS, const SPIRVTargetMachine &TM);
66 
67  // Parses features string setting specified subtarget options.
68  // The definition of this function is auto generated by tblgen.
70  unsigned getPointerSize() const { return PointerSize; }
71  bool canDirectlyComparePointers() const;
72  // TODO: this environment is not implemented in Triple, we need to decide
73  // how to standartize its support. For now, let's assume that we always
74  // operate with OpenCL.
75  bool isOpenCLEnv() const { return true; }
76  uint32_t getSPIRVVersion() const { return SPIRVVersion; };
77  bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const;
78  bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const;
79  // TODO: implement command line args or other ways to determine this.
80  bool hasOpenCLFullProfile() const { return true; }
81  bool hasOpenCLImageSupport() const { return true; }
82  bool canUseExtension(SPIRV::Extension::Extension E) const;
83  bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const;
84 
85  SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }
86 
87  const CallLowering *getCallLowering() const override {
88  return CallLoweringInfo.get();
89  }
90  const RegisterBankInfo *getRegBankInfo() const override {
91  return RegBankInfo.get();
92  }
93  const LegalizerInfo *getLegalizerInfo() const override {
94  return Legalizer.get();
95  }
97  return InstSelector.get();
98  }
99  const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
100  const SPIRVFrameLowering *getFrameLowering() const override {
101  return &FrameLowering;
102  }
103  const SPIRVTargetLowering *getTargetLowering() const override {
104  return &TLInfo;
105  }
106  const SPIRVRegisterInfo *getRegisterInfo() const override {
107  return &InstrInfo.getRegisterInfo();
108  }
109 };
110 } // namespace llvm
111 
112 #endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
llvm::SPIRVSubtarget::getLegalizerInfo
const LegalizerInfo * getLegalizerInfo() const override
Definition: SPIRVSubtarget.h:93
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SPIRVSubtarget::canDirectlyComparePointers
bool canDirectlyComparePointers() const
Definition: SPIRVSubtarget.cpp:89
SPIRVCallLowering.h
CallLowering.h
llvm::SPIRVFrameLowering
Definition: SPIRVFrameLowering.h:26
llvm::SPIRVSubtarget::getInstructionSelector
InstructionSelector * getInstructionSelector() const override
Definition: SPIRVSubtarget.h:96
llvm::SPIRVSubtarget::isOpenCLEnv
bool isOpenCLEnv() const
Definition: SPIRVSubtarget.h:75
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::SPIRVSubtarget::initSubtargetDependencies
SPIRVSubtarget & initSubtargetDependencies(StringRef CPU, StringRef FS)
Definition: SPIRVSubtarget.cpp:61
llvm::SPIRVSubtarget
Definition: SPIRVSubtarget.h:35
llvm::SmallSet< SPIRV::Extension::Extension, 4 >
llvm::SPIRVSubtarget::getCallLowering
const CallLowering * getCallLowering() const override
Definition: SPIRVSubtarget.h:87
LegalizerInfo.h
SPIRVGenSubtargetInfo
InstrInfo
return InstrInfo
Definition: RISCVInsertVSETVLI.cpp:670
TargetMachine.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SPIRVSubtarget::getInstrInfo
const SPIRVInstrInfo * getInstrInfo() const override
Definition: SPIRVSubtarget.h:99
llvm::Legalizer
Definition: Legalizer.h:36
llvm::SPIRVSubtarget::ParseSubtargetFeatures
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
llvm::SPIRVSubtarget::getSPIRVVersion
uint32_t getSPIRVVersion() const
Definition: SPIRVSubtarget.h:76
SPIRVFrameLowering.h
llvm::SPIRVSubtarget::getRegBankInfo
const RegisterBankInfo * getRegBankInfo() const override
Definition: SPIRVSubtarget.h:90
llvm::SPIRVSubtarget::hasOpenCLImageSupport
bool hasOpenCLImageSupport() const
Definition: SPIRVSubtarget.h:81
llvm::SPIRVSubtarget::canUseExtInstSet
bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const
Definition: SPIRVSubtarget.cpp:75
InstructionSelector.h
SPIRVInstrInfo.h
llvm::SPIRVRegisterInfo
Definition: SPIRVRegisterInfo.h:23
llvm::RegisterBankInfo
Holds all the information related to register banks.
Definition: RegisterBankInfo.h:39
llvm::InstructionSelector
Provides the logic to select generic machine instructions.
Definition: InstructionSelector.h:428
llvm::SPIRVSubtarget::getPointerSize
unsigned getPointerSize() const
Definition: SPIRVSubtarget.h:70
llvm::SPIRVSubtarget::SPIRVSubtarget
SPIRVSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const SPIRVTargetMachine &TM)
Definition: SPIRVSubtarget.cpp:42
SPIRVISelLowering.h
llvm::SPIRVSubtarget::canUseExtension
bool canUseExtension(SPIRV::Extension::Extension E) const
Definition: SPIRVSubtarget.cpp:71
llvm::X86AS::FS
@ FS
Definition: X86.h:200
llvm::SPIRVTargetLowering
Definition: SPIRVISelLowering.h:22
llvm::SPIRVGlobalRegistry
Definition: SPIRVGlobalRegistry.h:27
llvm::SPIRVSubtarget::isAtLeastOpenCLVer
bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const
Definition: SPIRVSubtarget.cpp:84
llvm::SPIRVInstrInfo
Definition: SPIRVInstrInfo.h:24
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
uint32_t
TargetSubtargetInfo.h
llvm::SPIRVSubtarget::getFrameLowering
const SPIRVFrameLowering * getFrameLowering() const override
Definition: SPIRVSubtarget.h:100
llvm::SPIRVTargetMachine
Definition: SPIRVTargetMachine.h:21
SelectionDAGTargetInfo.h
llvm::SPIRVSubtarget::getSPIRVGlobalRegistry
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
Definition: SPIRVSubtarget.h:85
llvm::LegalizerInfo
Definition: LegalizerInfo.h:1182
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::SPIRVSubtarget::hasOpenCLFullProfile
bool hasOpenCLFullProfile() const
Definition: SPIRVSubtarget.h:80
llvm::SPIRVSubtarget::getTargetLowering
const SPIRVTargetLowering * getTargetLowering() const override
Definition: SPIRVSubtarget.h:103
llvm::CallLowering
Definition: CallLowering.h:44
llvm::SPIRVSubtarget::isAtLeastSPIRVVer
bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const
Definition: SPIRVSubtarget.cpp:80
llvm::SPIRVSubtarget::getRegisterInfo
const SPIRVRegisterInfo * getRegisterInfo() const override
Definition: SPIRVSubtarget.h:106