LLVM  15.0.0git
SPIRVSubtarget.cpp
Go to the documentation of this file.
1 //===-- SPIRVSubtarget.cpp - 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 implements the SPIR-V specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "SPIRVSubtarget.h"
14 #include "SPIRV.h"
15 #include "SPIRVGlobalRegistry.h"
16 #include "SPIRVLegalizerInfo.h"
17 #include "SPIRVRegisterBankInfo.h"
18 #include "SPIRVTargetMachine.h"
19 #include "llvm/MC/TargetRegistry.h"
20 #include "llvm/Support/Host.h"
21 
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "spirv-subtarget"
25 
26 #define GET_SUBTARGETINFO_TARGET_DESC
27 #define GET_SUBTARGETINFO_CTOR
28 #include "SPIRVGenSubtargetInfo.inc"
29 
30 // Compare version numbers, but allow 0 to mean unspecified.
31 static bool isAtLeastVer(uint32_t Target, uint32_t VerToCompareTo) {
32  return Target == 0 || Target >= VerToCompareTo;
33 }
34 
35 static unsigned computePointerSize(const Triple &TT) {
36  const auto Arch = TT.getArch();
37  // TODO: unify this with pointers legalization.
38  assert(TT.isSPIRV());
39  return Arch == Triple::spirv32 ? 32 : 64;
40 }
41 
42 SPIRVSubtarget::SPIRVSubtarget(const Triple &TT, const std::string &CPU,
43  const std::string &FS,
44  const SPIRVTargetMachine &TM)
45  : SPIRVGenSubtargetInfo(TT, CPU, /*TuneCPU=*/CPU, FS),
46  PointerSize(computePointerSize(TT)), SPIRVVersion(0), InstrInfo(),
47  FrameLowering(initSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) {
48  GR = std::make_unique<SPIRVGlobalRegistry>(PointerSize);
49  CallLoweringInfo =
50  std::make_unique<SPIRVCallLowering>(TLInfo, *this, GR.get());
51  Legalizer = std::make_unique<SPIRVLegalizerInfo>(*this);
52  RegBankInfo = std::make_unique<SPIRVRegisterBankInfo>();
53  InstSelector.reset(
54  createSPIRVInstructionSelector(TM, *this, *RegBankInfo.get()));
55 }
56 
58  StringRef FS) {
59  ParseSubtargetFeatures(CPU, /*TuneCPU=*/CPU, FS);
60  if (SPIRVVersion == 0)
61  SPIRVVersion = 14;
62  return *this;
63 }
64 
65 // If the SPIR-V version is >= 1.4 we can call OpPtrEqual and OpPtrNotEqual.
67  return isAtLeastVer(SPIRVVersion, 14);
68 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
SPIRVLegalizerInfo.h
llvm::SPIRVSubtarget::canDirectlyComparePointers
bool canDirectlyComparePointers() const
Definition: SPIRVSubtarget.cpp:66
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
Host.h
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:57
llvm::SPIRVSubtarget
Definition: SPIRVSubtarget.h:36
SPIRVSubtarget.h
llvm::Triple::spirv32
@ spirv32
Definition: Triple.h:98
SPIRVGenSubtargetInfo
llvm::Legalizer
Definition: Legalizer.h:36
llvm::SPIRVSubtarget::ParseSubtargetFeatures
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
computePointerSize
static unsigned computePointerSize(const Triple &TT)
Definition: SPIRVSubtarget.cpp:35
SPIRVTargetMachine.h
SPIRVGlobalRegistry.h
llvm::SPIRVSubtarget::SPIRVSubtarget
SPIRVSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const SPIRVTargetMachine &TM)
Definition: SPIRVSubtarget.cpp:42
SPIRV.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::X86AS::FS
@ FS
Definition: X86.h:192
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
uint32_t
llvm::SPIRVTargetMachine
Definition: SPIRVTargetMachine.h:20
SPIRVRegisterBankInfo.h
llvm::createSPIRVInstructionSelector
InstructionSelector * createSPIRVInstructionSelector(const SPIRVTargetMachine &TM, const SPIRVSubtarget &Subtarget, const RegisterBankInfo &RBI)
Definition: SPIRVInstructionSelector.cpp:1263
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
TargetRegistry.h
isAtLeastVer
static bool isAtLeastVer(uint32_t Target, uint32_t VerToCompareTo)
Definition: SPIRVSubtarget.cpp:31