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 llvm::StringRef
TypeName =
"dx.TypedBuffer";
80 SmallVector<unsigned, 4> Ints = { ResAttrs.ResourceClass ==
81 llvm::dxil::ResourceClass::UAV,
88 ->getUnqualifiedDesugaredType();
94 llvm::dxil::ResourceKind RK = llvm::dxil::ResourceKind::Invalid;
95 switch (ResAttrs.ResourceDimension) {
96 case llvm::dxil::ResourceDimension::Dim1D:
97 RK = llvm::dxil::ResourceKind::Texture1D;
99 case llvm::dxil::ResourceDimension::Dim2D:
100 RK = llvm::dxil::ResourceKind::Texture2D;
102 case llvm::dxil::ResourceDimension::Dim3D:
103 RK = llvm::dxil::ResourceKind::Texture3D;
105 case llvm::dxil::ResourceDimension::Cube:
106 RK = llvm::dxil::ResourceKind::TextureCube;
109 llvm_unreachable(
"Unsupported resource dimension for textur.");
111 Ints.push_back(
static_cast<unsigned>(RK));
114 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
116 case llvm::dxil::ResourceClass::CBuffer: {
117 QualType ContainedTy = ResType->getContainedType();
121 llvm::StructType *BufferLayoutTy =
122 HLSLBufferLayoutBuilder(CGM).layOutStruct(
127 return llvm::TargetExtType::get(Ctx,
"dx.CBuffer", {BufferLayoutTy});
129 case llvm::dxil::ResourceClass::Sampler:
130 return llvm::TargetExtType::get(Ctx,
"dx.Sampler", {}, {0});
132 llvm_unreachable(
"Unknown llvm::dxil::ResourceClass enum");
137std::unique_ptr<TargetCodeGenInfo>
139 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()
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)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Type
The name was classified as a type.
U cast(CodeGen::Address addr)