clang 20.0.0git
DirectX.cpp
Go to the documentation of this file.
1//===- DirectX.cpp---------------------------------------------------------===//
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#include "ABIInfoImpl.h"
10#include "TargetInfo.h"
11#include "llvm/IR/DerivedTypes.h"
12
13using namespace clang;
14using namespace clang::CodeGen;
15
16//===----------------------------------------------------------------------===//
17// Target codegen info implementation for DirectX.
18//===----------------------------------------------------------------------===//
19
20namespace {
21
22class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
23public:
24 DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
25 : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
26
27 llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
28};
29
30llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
31 const Type *Ty) const {
32 auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
33 if (!ResType)
34 return nullptr;
35
36 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
37 const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
38 switch (ResAttrs.ResourceClass) {
39 case llvm::dxil::ResourceClass::UAV:
40 case llvm::dxil::ResourceClass::SRV: {
41 // TypedBuffer and RawBuffer both need element type
42 QualType ContainedTy = ResType->getContainedType();
43 if (ContainedTy.isNull())
44 return nullptr;
45
46 // convert element type
47 llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
48
49 llvm::StringRef TypeName =
50 ResAttrs.RawBuffer ? "dx.RawBuffer" : "dx.TypedBuffer";
51 SmallVector<unsigned, 3> Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
52 llvm::dxil::ResourceClass::UAV,
53 /*IsROV*/ ResAttrs.IsROV};
54 if (!ResAttrs.RawBuffer)
55 Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
56
57 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
58 }
59 case llvm::dxil::ResourceClass::CBuffer:
60 llvm_unreachable("dx.CBuffer handles are not implemented yet");
61 break;
62 case llvm::dxil::ResourceClass::Sampler:
63 llvm_unreachable("dx.Sampler handles are not implemented yet");
64 break;
65 }
66 llvm_unreachable("Unknown llvm::dxil::ResourceClass enum");
67}
68
69} // namespace
70
71std::unique_ptr<TargetCodeGenInfo>
73 return std::make_unique<DirectXTargetCodeGenInfo>(CGM.getTypes());
74}
This class organizes the cross-function state that is used while generating LLVM code.
llvm::LLVMContext & getLLVMContext()
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
DefaultABIInfo - The default implementation for ABI specific details.
Definition: ABIInfoImpl.h:21
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:47
virtual llvm::Type * getHLSLType(CodeGenModule &CGM, const Type *T) const
Return an LLVM type that corresponds to a HLSL type.
Definition: TargetInfo.h:442
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
The base class of the type hierarchy.
Definition: Type.h:1828
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition: Type.cpp:2180
std::unique_ptr< TargetCodeGenInfo > createDirectXTargetCodeGenInfo(CodeGenModule &CGM)
Definition: DirectX.cpp:72
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
llvm::dxil::ResourceClass ResourceClass
Definition: Type.h:6255