LLVM 19.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"
20#include "llvm/ADT/SmallSet.h"
26#include "llvm/IR/DataLayout.h"
29
30#define GET_SUBTARGETINFO_HEADER
31#include "SPIRVGenSubtargetInfo.inc"
32
33namespace llvm {
34class StringRef;
35class SPIRVTargetMachine;
36
38private:
39 const unsigned PointerSize;
40 uint32_t SPIRVVersion;
41 uint32_t OpenCLVersion;
42
45 std::unique_ptr<SPIRVGlobalRegistry> GR;
46
47 SPIRVInstrInfo InstrInfo;
48 SPIRVFrameLowering FrameLowering;
50 Triple TargetTriple;
51
52 // GlobalISel related APIs.
53 std::unique_ptr<CallLowering> CallLoweringInfo;
54 std::unique_ptr<RegisterBankInfo> RegBankInfo;
55 std::unique_ptr<LegalizerInfo> Legalizer;
56 std::unique_ptr<InstructionSelector> InstSelector;
57
58 // TODO: Initialise the available extensions, extended instruction sets
59 // based on the environment settings.
60 void initAvailableExtensions();
61 void initAvailableExtInstSets();
62
63public:
64 // This constructor initializes the data members to match that
65 // of the specified triple.
66 SPIRVSubtarget(const Triple &TT, const std::string &CPU,
67 const std::string &FS, const SPIRVTargetMachine &TM);
69
70 // Parses features string setting specified subtarget options.
71 // The definition of this function is auto generated by tblgen.
73 unsigned getPointerSize() const { return PointerSize; }
74 unsigned getBound() const { return GR->getBound(); }
75 bool canDirectlyComparePointers() const;
76 // TODO: this environment is not implemented in Triple, we need to decide
77 // how to standardize its support. For now, let's assume SPIR-V with physical
78 // addressing is OpenCL, and Logical addressing is Vulkan.
79 bool isOpenCLEnv() const {
80 return TargetTriple.getArch() == Triple::spirv32 ||
81 TargetTriple.getArch() == Triple::spirv64;
82 }
83 bool isVulkanEnv() const { return TargetTriple.getArch() == Triple::spirv; }
84 uint32_t getSPIRVVersion() const { return SPIRVVersion; };
85 bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const;
86 bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const;
87 // TODO: implement command line args or other ways to determine this.
88 bool hasOpenCLFullProfile() const { return true; }
89 bool hasOpenCLImageSupport() const { return true; }
92 return AvailableExtensions;
93 }
94 bool canUseExtension(SPIRV::Extension::Extension E) const;
95 bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const;
96
97 SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }
98
99 const CallLowering *getCallLowering() const override {
100 return CallLoweringInfo.get();
101 }
102 const RegisterBankInfo *getRegBankInfo() const override {
103 return RegBankInfo.get();
104 }
105 const LegalizerInfo *getLegalizerInfo() const override {
106 return Legalizer.get();
107 }
109 return InstSelector.get();
110 }
111 const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
112 const SPIRVFrameLowering *getFrameLowering() const override {
113 return &FrameLowering;
114 }
115 const SPIRVTargetLowering *getTargetLowering() const override {
116 return &TLInfo;
117 }
118 const SPIRVRegisterInfo *getRegisterInfo() const override {
119 return &InstrInfo.getRegisterInfo();
120 }
121
122 static bool classof(const TargetSubtargetInfo *ST) {
123 return ST->getTargetTriple().isSPIRV();
124 }
125};
126} // namespace llvm
127
128#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file describes how to lower LLVM calls to machine code calls.
Interface for Targets to specify which operations they can successfully select and how the others sho...
const char LLVMTargetMachineRef TM
This file defines the SmallSet class.
Holds all the information related to register banks.
const SPIRVRegisterInfo & getRegisterInfo() const
unsigned getPointerSize() const
bool hasOpenCLImageSupport() const
SPIRVSubtarget & initSubtargetDependencies(StringRef CPU, StringRef FS)
bool isAtLeastOpenCLVer(uint32_t VerToCompareTo) const
InstructionSelector * getInstructionSelector() const override
const LegalizerInfo * getLegalizerInfo() const override
bool canDirectlyComparePointers() const
const SPIRVInstrInfo * getInstrInfo() const override
const SmallSet< SPIRV::Extension::Extension, 4 > & getAllAvailableExtensions() const
static bool classof(const TargetSubtargetInfo *ST)
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
bool isAtLeastSPIRVVer(uint32_t VerToCompareTo) const
const SPIRVRegisterInfo * getRegisterInfo() const override
bool isOpenCLEnv() const
const SPIRVTargetLowering * getTargetLowering() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const
uint32_t getSPIRVVersion() const
const RegisterBankInfo * getRegBankInfo() const override
const CallLowering * getCallLowering() const override
unsigned getBound() const
bool hasOpenCLFullProfile() const
bool isVulkanEnv() const
bool canUseExtension(SPIRV::Extension::Extension E) const
const SPIRVFrameLowering * getFrameLowering() const override
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TargetSubtargetInfo - Generic base class for all target subtargets.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:361
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18