36 UserDefineType = 1 << 9,
57 case OverloadKind::HALF:
59 case OverloadKind::FLOAT:
61 case OverloadKind::DOUBLE:
63 case OverloadKind::I1:
65 case OverloadKind::I8:
67 case OverloadKind::I16:
69 case OverloadKind::I32:
71 case OverloadKind::I64:
73 case OverloadKind::VOID:
74 case OverloadKind::UNDEFINED:
76 case OverloadKind::ObjectType:
77 case OverloadKind::UserDefineType:
85 return OverloadKind::VOID;
90 return OverloadKind::VOID;
92 return OverloadKind::HALF;
94 return OverloadKind::FLOAT;
96 return OverloadKind::DOUBLE;
102 return OverloadKind::I1;
104 return OverloadKind::I8;
106 return OverloadKind::I16;
108 return OverloadKind::I32;
110 return OverloadKind::I64;
113 return OverloadKind::VOID;
117 return OverloadKind::UserDefineType;
125 return OverloadKind::UNDEFINED;
130 if (Kind < OverloadKind::UserDefineType) {
132 }
else if (Kind == OverloadKind::UserDefineType) {
134 return ST->getStructName().str();
135 }
else if (Kind == OverloadKind::ObjectType) {
137 return ST->getStructName().str();
162#define DXIL_OP_OPERATION_TABLE
163#include "DXILOperation.inc"
164#undef DXIL_OP_OPERATION_TABLE
168 if (Kind == OverloadKind::VOID) {
178 if (Kind == OverloadKind::VOID)
179 return TypeName.str();
181 assert(Kind < OverloadKind::UserDefineType &&
"invalid overload kind");
199 Type *FieldTypes[5] = {ElementTy, ElementTy, ElementTy, ElementTy,
218 {ElementTy, ElementTy, ElementTy, ElementTy,
219 ElementTy, ElementTy, ElementTy, ElementTy},
224 TypeName, {ElementTy, ElementTy, ElementTy, ElementTy}, Ctx);
267 {Int32Ty, Int32Ty, Int32Ty, Int32Ty}, Context);
275 {Int32Ty, Int32Ty, Int32Ty, Int32Ty}, Context);
288 case OpParamType::VoidTy:
290 case OpParamType::HalfTy:
292 case OpParamType::FloatTy:
294 case OpParamType::DoubleTy:
296 case OpParamType::Int1Ty:
298 case OpParamType::Int8Ty:
300 case OpParamType::Int16Ty:
302 case OpParamType::Int32Ty:
304 case OpParamType::Int64Ty:
306 case OpParamType::OverloadTy:
308 case OpParamType::ResRetHalfTy:
310 case OpParamType::ResRetFloatTy:
312 case OpParamType::ResRetDoubleTy:
314 case OpParamType::ResRetInt16Ty:
316 case OpParamType::ResRetInt32Ty:
318 case OpParamType::ResRetInt64Ty:
320 case OpParamType::CBufRetHalfTy:
322 case OpParamType::CBufRetFloatTy:
324 case OpParamType::CBufRetDoubleTy:
326 case OpParamType::CBufRetInt16Ty:
328 case OpParamType::CBufRetInt32Ty:
330 case OpParamType::CBufRetInt64Ty:
332 case OpParamType::HandleTy:
334 case OpParamType::ResBindTy:
336 case OpParamType::ResPropsTy:
338 case OpParamType::SplitDoubleTy:
340 case OpParamType::BinaryWithCarryTy:
342 case OpParamType::DimensionsTy:
344 case OpParamType::Fouri32s:
346 case OpParamType::TwoI32Ty:
357 return ShaderKind::pixel;
359 return ShaderKind::vertex;
361 return ShaderKind::geometry;
363 return ShaderKind::hull;
365 return ShaderKind::domain;
367 return ShaderKind::compute;
369 return ShaderKind::library;
371 return ShaderKind::raygeneration;
373 return ShaderKind::intersection;
375 return ShaderKind::anyhit;
377 return ShaderKind::closesthit;
379 return ShaderKind::miss;
381 return ShaderKind::callable;
383 return ShaderKind::mesh;
385 return ShaderKind::amplification;
390 "Shader Kind Not Found - Invalid DXIL Environment Specified");
412#define DXIL_OP_FUNCTION_TYPE(OpCode, RetType, ...) \
414 return FunctionType::get( \
415 getTypeFromOpParamType(RetType, Context, OverloadTy), \
416 getArgTypesFromOpParamTypes({__VA_ARGS__}, Context, OverloadTy), \
418#include "DXILOperation.inc"
429 size_t Index = PropList.
size() - 1;
430 for (
auto Iter = PropList.
rbegin(); Iter != PropList.
rend();
432 const T &Prop = *Iter;
433 if (
VersionTuple(Prop.DXILVersion.Major, Prop.DXILVersion.Minor) <=
447 return (OpCodePack << 32) | (VersionMajor << 16) | VersionMinor;
455#define DXIL_VERSION(MAJOR, MINOR) {MAJOR, MINOR},
456#include "DXILOperation.inc"
460 for (
auto Version : Versions) {
461 if (DXILVersion <
VersionTuple(Version.Major, Version.Minor))
467#define DXIL_OP_ATTRIBUTES(OpCode, VersionMajor, VersionMinor, ...) \
468 case computeSwitchEnum(OpCode, VersionMajor, VersionMinor): { \
469 auto Other = dxil::Attributes{__VA_ARGS__}; \
470 Attributes |= Other; \
473#include "DXILOperation.inc"
485 AttrBuilder FnAttrs(Ctx);
487 if (Attributes.ReadNone)
489 if (Attributes.ReadOnly)
491 if (Attributes.NoReturn)
492 FnAttrs.addAttribute(Attribute::NoReturn);
493 if (Attributes.NoDuplicate)
494 FnAttrs.addAttribute(Attribute::NoDuplicate);
495 FnAttrs.addAttribute(Attribute::NoUnwind);
497 return AttributeList::get(Ctx, AttributeList::FunctionIndex, FnAttrs);
508 const Triple &TT = M.getTargetTriple();
509 DXILVersion = TT.getDXILVersion();
510 ShaderStage = TT.getEnvironment();
514 Twine(DXILVersion.getAsString()) +
515 ": Unknown Compilation Target Shader Stage specified ");
521 Twine(
"Cannot create ") + getOpCodeName(
OpCode) +
" operation: " +
Msg,
531 Type *OverloadTy =
nullptr;
539 if (
static_cast<unsigned>(ArgIndex) >= Args.size())
541 OverloadTy = Args[ArgIndex]->getType();
547 std::optional<size_t> OlIndexOrErr =
549 if (!OlIndexOrErr.has_value())
551 DXILVersion.getAsString());
559 if ((ValidTyMask != OverloadKind::UNDEFINED) &&
560 (ValidTyMask & (
uint16_t)Kind) == 0)
565 std::optional<size_t> StIndexOrErr =
567 if (!StIndexOrErr.has_value())
569 DXILVersion.getAsString());
571 uint16_t ValidShaderKindMask = Prop->
Stages[*StIndexOrErr].ValidStages;
574 if (ValidShaderKindMask == ShaderKind::removed)
582 if (!(ValidShaderKindMask & ModuleStagekind))
585 AttributeList DXILFnAttrs =
589 M.getOrInsertFunction(DXILFnName, DXILOpFT, DXILFnAttrs);
594 OpArgs.
append(Args.begin(), Args.end());
597 CallInst *CI = IRB.CreateCall(DXILFn, OpArgs, Name);
605 if (
Error E = Result.takeError())
611 return ::getResRetType(ElementTy);
615 return ::getCBufRetType(ElementTy);
619 return ::getHandleType(IRB.getContext());
628 {ConstantInt::get(Int32Ty, LowerBound),
629 ConstantInt::get(Int32Ty, UpperBound),
630 ConstantInt::get(Int32Ty, SpaceID),
631 ConstantInt::get(Int8Ty, llvm::to_underlying(RC))});
638 {ConstantInt::get(Int32Ty, Word0), ConstantInt::get(Int32Ty, Word1)});
642 return ::getOpCodeName(DXILOp);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static StructType * getResRetType(Type *ElementTy)
static StructType * getFouri32sType(LLVMContext &Context)
static ShaderKind getShaderKindEnum(Triple::EnvironmentType EnvType)
static Type * getTypeFromOpParamType(OpParamType Kind, LLVMContext &Ctx, Type *OverloadTy)
static std::optional< size_t > getPropIndex(ArrayRef< T > PropList, const VersionTuple DXILVer)
Get index of the property from PropList valid for the most recent DXIL version not greater than DXILV...
static SmallVector< Type * > getArgTypesFromOpParamTypes(ArrayRef< dxil::OpParamType > Types, LLVMContext &Context, Type *OverloadTy)
static StructType * getTwoI32Type(LLVMContext &Context)
static const char * getOverloadTypeName(OverloadKind Kind)
static StructType * getCBufRetType(Type *ElementTy)
static StructType * getSplitDoubleType(LLVMContext &Context)
static OverloadKind getOverloadKind(Type *Ty)
static constexpr uint64_t computeSwitchEnum(dxil::OpCode OpCode, uint16_t VersionMajor, uint16_t VersionMinor)
static StructType * getBinaryWithCarryType(LLVMContext &Context)
static StructType * getOrCreateStructType(StringRef Name, ArrayRef< Type * > EltTys, LLVMContext &Ctx)
static StructType * getDimensionsType(LLVMContext &Context)
static StructType * getHandleType(LLVMContext &Ctx)
static AttributeList getDXILFnAttributeList(LLVMContext &Ctx, dxil::OpCode OpCode, VersionTuple DXILVersion)
Get the attributes to apply to the function for the DXIL operation with the given OpCode and DXIL ver...
static dxil::Attributes getDXILAttributes(dxil::OpCode OpCode, VersionTuple DXILVersion)
Get the set of attributes for a given DXIL OpCode and the DXIL version.
static std::string constructOverloadName(OverloadKind Kind, Type *Ty, const OpCodeProperty &Prop)
static FunctionType * getDXILOpFunctionType(dxil::OpCode OpCode, LLVMContext &Context, Type *OverloadTy)
Construct DXIL function type.
constexpr StringLiteral DXILOpNamePrefix
static std::string constructOverloadTypeName(OverloadKind Kind, StringRef TypeName)
static StructType * getResPropsType(LLVMContext &Context)
static StructType * getResBindType(LLVMContext &Context)
Module.h This file contains the declarations for the Module class.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
Represent a constant reference to an array (0 or more elements consecutively in memory),...
reverse_iterator rend() const
size_t size() const
Get the array size.
reverse_iterator rbegin() const
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
Class to represent integer types.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
This is an important class for using LLVM in a threaded context.
static MemoryEffectsBase readOnly()
static MemoryEffectsBase none()
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Represent a constant reference to a string, i.e.
Class to represent struct types.
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
TypeID
Definitions of all of the base types for the Type system.
@ HalfTyID
16-bit floating point type
@ VoidTyID
type with no size
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ DoubleTyID
64-bit floating point type
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Represents a version number in the form major[.minor[.subminor[.build]]].
StructType * getResRetType(Type *ElementTy)
Get a dx.types.ResRet type with the given element type.
Expected< CallInst * > tryCreateOp(dxil::OpCode Op, ArrayRef< Value * > Args, const Twine &Name="", Type *RetTy=nullptr)
Try to create a call instruction for the given DXIL op.
CallInst * createOp(dxil::OpCode Op, ArrayRef< Value * > Args, const Twine &Name="", Type *RetTy=nullptr)
Create a call instruction for the given DXIL op.
Constant * getResBind(uint32_t LowerBound, uint32_t UpperBound, uint32_t SpaceID, dxil::ResourceClass RC)
Get a constant dx.types.ResBind value.
static const char * getOpCodeName(dxil::OpCode DXILOp)
Return the name of the given opcode.
Constant * getResProps(uint32_t Word0, uint32_t Word1)
Get a constant dx.types.ResourceProperties value.
StructType * getHandleType()
Get the dx.types.Handle type.
StructType * getCBufRetType(Type *ElementTy)
Get a dx.types.CBufRet type with the given element type.
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Error makeOpError(dxil::OpCode OpCode, Twine Msg)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_GET_TYPE_NAME_CONSTEXPR StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
llvm::SmallVector< OpOverload > Overloads
dxil::OpCodeClass OpCodeClass
unsigned OpCodeNameOffset
unsigned OpCodeClassNameOffset
llvm::SmallVector< OpStage > Stages