Path: blob/main/contrib/llvm-project/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
35267 views
//===-- SPIRVSubtarget.h - SPIR-V Subtarget Information --------*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file declares the SPIR-V specific subclass of TargetSubtargetInfo.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H13#define LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H1415#include "SPIRVCallLowering.h"16#include "SPIRVFrameLowering.h"17#include "SPIRVISelLowering.h"18#include "SPIRVInlineAsmLowering.h"19#include "SPIRVInstrInfo.h"20#include "llvm/ADT/SmallSet.h"21#include "llvm/CodeGen/GlobalISel/CallLowering.h"22#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"23#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"24#include "llvm/CodeGen/SelectionDAGTargetInfo.h"25#include "llvm/CodeGen/TargetSubtargetInfo.h"26#include "llvm/IR/DataLayout.h"27#include "llvm/Target/TargetMachine.h"28#include "llvm/TargetParser/Triple.h"2930#define GET_SUBTARGETINFO_HEADER31#include "SPIRVGenSubtargetInfo.inc"3233namespace llvm {34class StringRef;35class SPIRVTargetMachine;3637class SPIRVSubtarget : public SPIRVGenSubtargetInfo {38private:39const unsigned PointerSize;40VersionTuple SPIRVVersion;41VersionTuple OpenCLVersion;4243SmallSet<SPIRV::Extension::Extension, 4> AvailableExtensions;44SmallSet<SPIRV::InstructionSet::InstructionSet, 4> AvailableExtInstSets;45std::unique_ptr<SPIRVGlobalRegistry> GR;4647SPIRVInstrInfo InstrInfo;48SPIRVFrameLowering FrameLowering;49SPIRVTargetLowering TLInfo;50Triple TargetTriple;5152// GlobalISel related APIs.53std::unique_ptr<CallLowering> CallLoweringInfo;54std::unique_ptr<RegisterBankInfo> RegBankInfo;55std::unique_ptr<LegalizerInfo> Legalizer;56std::unique_ptr<InstructionSelector> InstSelector;57std::unique_ptr<InlineAsmLowering> InlineAsmInfo;5859// TODO: Initialise the available extensions, extended instruction sets60// based on the environment settings.61void initAvailableExtensions();62void initAvailableExtInstSets();6364public:65// This constructor initializes the data members to match that66// of the specified triple.67SPIRVSubtarget(const Triple &TT, const std::string &CPU,68const std::string &FS, const SPIRVTargetMachine &TM);69SPIRVSubtarget &initSubtargetDependencies(StringRef CPU, StringRef FS);7071// Parses features string setting specified subtarget options.72// The definition of this function is auto generated by tblgen.73void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);74unsigned getPointerSize() const { return PointerSize; }75unsigned getBound() const { return GR->getBound(); }76bool canDirectlyComparePointers() const;77// TODO: this environment is not implemented in Triple, we need to decide78// how to standardize its support. For now, let's assume SPIR-V with physical79// addressing is OpenCL, and Logical addressing is Vulkan.80bool isOpenCLEnv() const {81return TargetTriple.getArch() == Triple::spirv32 ||82TargetTriple.getArch() == Triple::spirv64;83}84bool isVulkanEnv() const { return TargetTriple.getArch() == Triple::spirv; }85const std::string &getTargetTripleAsStr() const { return TargetTriple.str(); }86VersionTuple getSPIRVVersion() const { return SPIRVVersion; };87bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const;88bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const;89// TODO: implement command line args or other ways to determine this.90bool hasOpenCLFullProfile() const { return true; }91bool hasOpenCLImageSupport() const { return true; }92const SmallSet<SPIRV::Extension::Extension, 4> &93getAllAvailableExtensions() const {94return AvailableExtensions;95}96bool canUseExtension(SPIRV::Extension::Extension E) const;97bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const;9899SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }100101const CallLowering *getCallLowering() const override {102return CallLoweringInfo.get();103}104const RegisterBankInfo *getRegBankInfo() const override {105return RegBankInfo.get();106}107const LegalizerInfo *getLegalizerInfo() const override {108return Legalizer.get();109}110InstructionSelector *getInstructionSelector() const override {111return InstSelector.get();112}113const InlineAsmLowering *getInlineAsmLowering() const override {114return InlineAsmInfo.get();115}116const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }117const SPIRVFrameLowering *getFrameLowering() const override {118return &FrameLowering;119}120const SPIRVTargetLowering *getTargetLowering() const override {121return &TLInfo;122}123const SPIRVRegisterInfo *getRegisterInfo() const override {124return &InstrInfo.getRegisterInfo();125}126127static bool classof(const TargetSubtargetInfo *ST) {128return ST->getTargetTriple().isSPIRV();129}130};131} // namespace llvm132133#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H134135136