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;
42  std::unique_ptr<SPIRVGlobalRegistry> GR;
43 
44  SPIRVInstrInfo InstrInfo;
45  SPIRVFrameLowering FrameLowering;
46  SPIRVTargetLowering TLInfo;
47 
48  // GlobalISel related APIs.
49  std::unique_ptr<CallLowering> CallLoweringInfo;
50  std::unique_ptr<RegisterBankInfo> RegBankInfo;
51  std::unique_ptr<LegalizerInfo> Legalizer;
52  std::unique_ptr<InstructionSelector> InstSelector;
53 
54  // TODO: Initialise the available extensions based on
55  // the environment settings.
56  void initAvailableExtensions();
57 
58 public:
59  // This constructor initializes the data members to match that
60  // of the specified triple.
61  SPIRVSubtarget(const Triple &TT, const std::string &CPU,
62  const std::string &FS, const SPIRVTargetMachine &TM);
64 
65  // Parses features string setting specified subtarget options.
66  // The definition of this function is auto generated by tblgen.
68  unsigned getPointerSize() const { return PointerSize; }
69  bool canDirectlyComparePointers() const;
70  // TODO: this environment is not implemented in Triple, we need to decide
71  // how to standartize its support. For now, let's assume that we always
72  // operate with OpenCL.
73  bool isOpenCLEnv() const { return true; }
74  uint32_t getSPIRVVersion() const { return SPIRVVersion; };
75  bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const;
76  bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const;
77  // TODO: implement command line args or other ways to determine this.
78  bool hasOpenCLFullProfile() const { return true; }
79  bool hasOpenCLImageSupport() const { return true; }
80  bool canUseExtension(SPIRV::Extension::Extension E) const;
81 
82  SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }
83 
84  const CallLowering *getCallLowering() const override {
85  return CallLoweringInfo.get();
86  }
87  const RegisterBankInfo *getRegBankInfo() const override {
88  return RegBankInfo.get();
89  }
90  const LegalizerInfo *getLegalizerInfo() const override {
91  return Legalizer.get();
92  }
94  return InstSelector.get();
95  }
96  const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
97  const SPIRVFrameLowering *getFrameLowering() const override {
98  return &FrameLowering;
99  }
100  const SPIRVTargetLowering *getTargetLowering() const override {
101  return &TLInfo;
102  }
103  const SPIRVRegisterInfo *getRegisterInfo() const override {
104  return &InstrInfo.getRegisterInfo();
105  }
106 };
107 } // namespace llvm
108 
109 #endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
llvm::SPIRVSubtarget::getLegalizerInfo
const LegalizerInfo * getLegalizerInfo() const override
Definition: SPIRVSubtarget.h:90
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SPIRVSubtarget::canDirectlyComparePointers
bool canDirectlyComparePointers() const
Definition: SPIRVSubtarget.cpp:81
SPIRVCallLowering.h
CallLowering.h
llvm::SPIRVFrameLowering
Definition: SPIRVFrameLowering.h:26
llvm::SPIRVSubtarget::getInstructionSelector
InstructionSelector * getInstructionSelector() const override
Definition: SPIRVSubtarget.h:93
llvm::SPIRVSubtarget::isOpenCLEnv
bool isOpenCLEnv() const
Definition: SPIRVSubtarget.h:73
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:58
llvm::SPIRVSubtarget
Definition: SPIRVSubtarget.h:35
llvm::SmallSet< SPIRV::Extension::Extension, 4 >
llvm::SPIRVSubtarget::getCallLowering
const CallLowering * getCallLowering() const override
Definition: SPIRVSubtarget.h:84
LegalizerInfo.h
SPIRVGenSubtargetInfo
llvm::SPIRVInstrInfo::getRegisterInfo
const SPIRVRegisterInfo & getRegisterInfo() const
Definition: SPIRVInstrInfo.h:30
TargetMachine.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SPIRVSubtarget::getInstrInfo
const SPIRVInstrInfo * getInstrInfo() const override
Definition: SPIRVSubtarget.h:96
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:74
SPIRVFrameLowering.h
llvm::SPIRVSubtarget::getRegBankInfo
const RegisterBankInfo * getRegBankInfo() const override
Definition: SPIRVSubtarget.h:87
llvm::SPIRVSubtarget::hasOpenCLImageSupport
bool hasOpenCLImageSupport() const
Definition: SPIRVSubtarget.h:79
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:68
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:68
llvm::X86AS::FS
@ FS
Definition: X86.h:196
llvm::SPIRVTargetLowering
Definition: SPIRVISelLowering.h:22
llvm::SPIRVGlobalRegistry
Definition: SPIRVGlobalRegistry.h:27
llvm::SPIRVSubtarget::isAtLeastOpenCLVer
bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const
Definition: SPIRVSubtarget.cpp:76
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:97
llvm::SPIRVTargetMachine
Definition: SPIRVTargetMachine.h:20
SelectionDAGTargetInfo.h
llvm::SPIRVSubtarget::getSPIRVGlobalRegistry
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
Definition: SPIRVSubtarget.h:82
llvm::LegalizerInfo
Definition: LegalizerInfo.h:1180
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::SPIRVSubtarget::hasOpenCLFullProfile
bool hasOpenCLFullProfile() const
Definition: SPIRVSubtarget.h:78
llvm::SPIRVSubtarget::getTargetLowering
const SPIRVTargetLowering * getTargetLowering() const override
Definition: SPIRVSubtarget.h:100
llvm::CallLowering
Definition: CallLowering.h:44
llvm::SPIRVSubtarget::isAtLeastSPIRVVer
bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const
Definition: SPIRVSubtarget.cpp:72
llvm::SPIRVSubtarget::getRegisterInfo
const SPIRVRegisterInfo * getRegisterInfo() const override
Definition: SPIRVSubtarget.h:103