LLVM  16.0.0git
DXILMetadata.cpp
Go to the documentation of this file.
1 //===- DXILMetadata.cpp - DXIL Metadata helper objects --------------------===//
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 /// \file This file contains helper objects for working with DXIL metadata.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #include "DXILMetadata.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/IR/IRBuilder.h"
16 #include "llvm/IR/Metadata.h"
17 #include "llvm/IR/Module.h"
19 
20 using namespace llvm;
21 using namespace llvm::dxil;
22 
24  : Entry(M.getOrInsertNamedMetadata("dx.valver")) {}
25 
27  auto &Ctx = Entry->getParent()->getContext();
28  IRBuilder<> B(Ctx);
29  Metadata *MDVals[2];
30 
31  MDVals[0] = ConstantAsMetadata::get(B.getInt32(ValidatorVer.getMajor()));
32  MDVals[1] =
33  ConstantAsMetadata::get(B.getInt32(ValidatorVer.getMinor().value_or(0)));
34 
35  if (isEmpty())
36  Entry->addOperand(MDNode::get(Ctx, MDVals));
37  else
38  Entry->setOperand(0, MDNode::get(Ctx, MDVals));
39 }
40 
41 bool ValidatorVersionMD::isEmpty() { return Entry->getNumOperands() == 0; }
42 
44  switch (Env) {
45  case Triple::Pixel:
46  return "ps";
47  case Triple::Vertex:
48  return "vs";
49  case Triple::Geometry:
50  return "gs";
51  case Triple::Hull:
52  return "hs";
53  case Triple::Domain:
54  return "ds";
55  case Triple::Compute:
56  return "cs";
57  case Triple::Library:
58  return "lib";
59  case Triple::Mesh:
60  return "ms";
62  return "as";
63  default:
64  break;
65  }
66  llvm_unreachable("Unsupported environment for DXIL generation.");
67  return "";
68 }
69 
71  NamedMDNode *Entry = M.getOrInsertNamedMetadata("dx.shaderModel");
72  Triple TT(M.getTargetTriple());
73  VersionTuple Ver = TT.getOSVersion();
74  LLVMContext &Ctx = M.getContext();
75  IRBuilder<> B(Ctx);
76 
77  Metadata *Vals[3];
78  Vals[0] = MDString::get(Ctx, getShortShaderStage(TT.getEnvironment()));
79  Vals[1] = ConstantAsMetadata::get(B.getInt32(Ver.getMajor()));
80  Vals[2] = ConstantAsMetadata::get(B.getInt32(Ver.getMinor().value_or(0)));
81  Entry->addOperand(MDNode::get(Ctx, Vals));
82 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1588
Metadata.h
llvm::NamedMDNode::getNumOperands
unsigned getNumOperands() const
Definition: Metadata.cpp:1212
llvm::Triple::Amplification
@ Amplification
Definition: Triple.h:274
llvm::Triple::EnvironmentType
EnvironmentType
Definition: Triple.h:227
VersionTuple.h
llvm::IRBuilder<>
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::NamedMDNode::setOperand
void setOperand(unsigned I, MDNode *New)
Definition: Metadata.cpp:1224
Module.h
llvm::dxil::ValidatorVersionMD::update
void update(VersionTuple ValidatorVer)
Definition: DXILMetadata.cpp:26
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:420
DXILMetadata.h
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1400
llvm::VersionTuple::getMajor
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:73
llvm::Triple::Vertex
@ Vertex
Definition: Triple.h:261
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1222
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Triple::Geometry
@ Geometry
Definition: Triple.h:262
llvm::VersionTuple
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:31
llvm::Triple::Hull
@ Hull
Definition: Triple.h:263
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Triple::Compute
@ Compute
Definition: Triple.h:265
llvm::dxil
Definition: DXILOperationCommon.h:23
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:498
IRBuilder.h
llvm::VersionTuple::getMinor
Optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:76
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::dxil::ValidatorVersionMD::ValidatorVersionMD
ValidatorVersionMD(Module &M)
Definition: DXILMetadata.cpp:23
Triple.h
llvm::Triple::Pixel
@ Pixel
Definition: Triple.h:260
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Triple::Mesh
@ Mesh
Definition: Triple.h:273
llvm::NamedMDNode::getParent
Module * getParent()
Get the module that holds this named metadata collection.
Definition: Metadata.h:1658
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
llvm::dxil::createShaderModelMD
void createShaderModelMD(Module &M)
Definition: DXILMetadata.cpp:70
getShortShaderStage
static StringRef getShortShaderStage(Triple::EnvironmentType Env)
Definition: DXILMetadata.cpp:43
llvm::Triple::Library
@ Library
Definition: Triple.h:266
llvm::dxil::ValidatorVersionMD::isEmpty
bool isEmpty()
Definition: DXILMetadata.cpp:41
llvm::Optional::value_or
constexpr T value_or(U &&alt) const &
Definition: Optional.h:291
llvm::Triple::Domain
@ Domain
Definition: Triple.h:264