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 SPIRVTargetMachine; 34 35 class SPIRVSubtarget : public SPIRVGenSubtargetInfo { 36 private: 37 const unsigned PointerSize; 38 uint32_t SPIRVVersion; 39 uint32_t OpenCLVersion; 40 41 SmallSet<SPIRV::Extension::Extension, 4> AvailableExtensions; 42 SmallSet<SPIRV::InstructionSet::InstructionSet, 4> AvailableExtInstSets; 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); 65 SPIRVSubtarget &initSubtargetDependencies(StringRef CPU, StringRef FS); 66 67 // Parses features string setting specified subtarget options. 68 // The definition of this function is auto generated by tblgen. 69 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS); 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 } 96 InstructionSelector *getInstructionSelector() const override { 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 113