12#include "TargetInfo.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/IR/DerivedTypes.h"
16#include "llvm/IR/Type.h"
29 DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
30 : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
32 llvm::Type *getHLSLType(CodeGenModule &CGM,
const Type *
T,
33 const CGHLSLOffsetInfo &OffsetInfo)
const override;
35 llvm::Type *getHLSLPadding(CodeGenModule &CGM,
36 CharUnits NumBytes)
const override {
38 return llvm::TargetExtType::get(CGM.
getLLVMContext(),
"dx.Padding", {},
42 bool isHLSLPadding(llvm::Type *Ty)
const override {
43 if (
auto *TET = dyn_cast<llvm::TargetExtType>(Ty))
44 return TET->getName() ==
"dx.Padding";
49llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
52 auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
57 const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
58 switch (ResAttrs.ResourceClass) {
59 case llvm::dxil::ResourceClass::UAV:
60 case llvm::dxil::ResourceClass::SRV: {
62 QualType ContainedTy = ResType->getContainedType();
69 bool IsRawBuffer = ResAttrs.RawBuffer;
71 ResAttrs.ResourceDimension != llvm::dxil::ResourceDimension::Unknown;
72 assert((!IsRawBuffer || !IsTexture) &&
"A resource cannot be both a raw "
73 "buffer and a texture.");
74 bool IsMultiSampledTexture = IsTexture && ResAttrs.isMultiSampled();
75 llvm::StringRef
TypeName =
"dx.TypedBuffer";
78 else if (IsMultiSampledTexture)
87 unsigned SampleCount = 0;
88 if (
const Expr *SCE = ResAttrs.SampleCountExpr) {
89 std::optional<llvm::APSInt> Count =
91 if (Count && Count->isNonNegative())
92 SampleCount = Count->getZExtValue();
94 SmallVector<unsigned, 4> Ints = {
95 ResAttrs.ResourceClass ==
96 llvm::dxil::ResourceClass::UAV,
97 IsMultiSampledTexture ? SampleCount : ResAttrs.IsROV};
103 ->getUnqualifiedDesugaredType();
109 llvm::dxil::ResourceKind RK = llvm::dxil::ResourceKind::Invalid;
110 switch (ResAttrs.ResourceDimension) {
111 case llvm::dxil::ResourceDimension::Dim1D:
112 RK = llvm::dxil::ResourceKind::Texture1D;
114 case llvm::dxil::ResourceDimension::Dim2D:
115 if (ResAttrs.isMultiSampled())
116 RK = ResAttrs.IsArray ? llvm::dxil::ResourceKind::Texture2DMSArray
117 : llvm::dxil::ResourceKind::Texture2DMS;
119 RK = ResAttrs.IsArray ? llvm::dxil::ResourceKind::Texture2DArray
120 : llvm::dxil::ResourceKind::Texture2D;
122 case llvm::dxil::ResourceDimension::Dim3D:
123 RK = llvm::dxil::ResourceKind::Texture3D;
125 case llvm::dxil::ResourceDimension::Cube:
126 RK = llvm::dxil::ResourceKind::TextureCube;
129 llvm_unreachable(
"Unsupported resource dimension for texture.");
131 Ints.push_back(
static_cast<unsigned>(RK));
134 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
136 case llvm::dxil::ResourceClass::CBuffer: {
137 QualType ContainedTy = ResType->getContainedType();
141 llvm::StructType *BufferLayoutTy =
142 HLSLBufferLayoutBuilder(CGM).layOutStruct(
147 return llvm::TargetExtType::get(Ctx,
"dx.CBuffer", {BufferLayoutTy});
149 case llvm::dxil::ResourceClass::Sampler:
150 return llvm::TargetExtType::get(Ctx,
"dx.Sampler", {}, {0});
152 llvm_unreachable(
"Unknown llvm::dxil::ResourceClass enum");
157std::unique_ptr<TargetCodeGenInfo>
159 return std::make_unique<DirectXTargetCodeGenInfo>(CGM.
getTypes());
C Language Family Type Representation.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
This class organizes the cross-function state that is used while generating LLVM code.
CodeGenTypes & getTypes()
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
The base class of the type hierarchy.
bool isStructureType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isVectorType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
std::unique_ptr< TargetCodeGenInfo > createDirectXTargetCodeGenInfo(CodeGenModule &CGM)
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
@ Type
The name was classified as a type.
U cast(CodeGen::Address addr)