forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DirectX] Add DirectXTargetCodeGenInfo (llvm#104856)
Adds target codegen info class for DirectX. For now it always translates `__hlsl_resource_t` handle to `target("dx.TypedBuffer", i32, 1, 0, 1)` (`RWBuffer<int>`). More work is needed to determine the actual target exp type and parameters based on the resource handle attributes. Part 1/2 of llvm#95952
- Loading branch information
Showing
6 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===- DirectX.cpp---------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "ABIInfoImpl.h" | ||
#include "TargetInfo.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
|
||
using namespace clang; | ||
using namespace clang::CodeGen; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Target codegen info implementation for DirectX. | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace { | ||
|
||
class DirectXTargetCodeGenInfo : public TargetCodeGenInfo { | ||
public: | ||
DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) | ||
: TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {} | ||
|
||
llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override; | ||
}; | ||
|
||
llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM, | ||
const Type *Ty) const { | ||
auto *BuiltinTy = dyn_cast<BuiltinType>(Ty); | ||
if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource) | ||
return nullptr; | ||
|
||
llvm::LLVMContext &Ctx = CGM.getLLVMContext(); | ||
// FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x float>, | ||
// 1, 0, 0) only for now (RWBuffer<float4>); more work us needed to determine | ||
// the target ext type and its parameters based on the handle type | ||
// attributes (not yet implemented) | ||
llvm::FixedVectorType *ElemType = | ||
llvm::FixedVectorType::get(llvm::Type::getFloatTy(Ctx), 4); | ||
unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0}; | ||
return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags); | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<TargetCodeGenInfo> | ||
CodeGen::createDirectXTargetCodeGenInfo(CodeGenModule &CGM) { | ||
return std::make_unique<DirectXTargetCodeGenInfo>(CGM.getTypes()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -O1 -o - %s | FileCheck %s | ||
|
||
void foo(__hlsl_resource_t res); | ||
|
||
// CHECK: define void @"?bar@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %[[PARAM:[a-zA-Z0-9]+]]) | ||
// CHECK: call void @"?foo@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %[[PARAM]]) | ||
void bar(__hlsl_resource_t a) { | ||
foo(a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters