aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGHLSLRuntime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.cpp')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5bc71a9..a708b3a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -23,6 +23,7 @@
#include "clang/AST/Type.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/LLVMContext.h"
@@ -42,8 +43,8 @@ using namespace llvm;
using llvm::hlsl::CBufferRowSizeInBytes;
static void initializeBufferFromBinding(CodeGenModule &CGM,
- llvm::GlobalVariable *GV, unsigned Slot,
- unsigned Space);
+ llvm::GlobalVariable *GV,
+ HLSLResourceBindingAttr *RBA);
namespace {
@@ -271,13 +272,10 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
emitBufferGlobalsAndMetadata(BufDecl, BufGV);
// Initialize cbuffer from binding (implicit or explicit)
- const HLSLResourceBindingAttr *RBA =
- BufDecl->getAttr<HLSLResourceBindingAttr>();
- // FIXME: handle implicit binding if no binding attribute is found
- // (llvm/llvm-project#110722)
- if (RBA && RBA->hasRegisterSlot())
- initializeBufferFromBinding(CGM, BufGV, RBA->getSlotNumber(),
- RBA->getSpaceNumber());
+ HLSLResourceBindingAttr *RBA = BufDecl->getAttr<HLSLResourceBindingAttr>();
+ assert(RBA &&
+ "cbuffer/tbuffer should always have resource binding attribute");
+ initializeBufferFromBinding(CGM, BufGV, RBA);
}
llvm::TargetExtType *
@@ -560,19 +558,29 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
}
static void initializeBufferFromBinding(CodeGenModule &CGM,
- llvm::GlobalVariable *GV, unsigned Slot,
- unsigned Space) {
+ llvm::GlobalVariable *GV,
+ HLSLResourceBindingAttr *RBA) {
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext());
- llvm::Value *Args[] = {
- llvm::ConstantInt::get(CGM.IntTy, Space), /* reg_space */
- llvm::ConstantInt::get(CGM.IntTy, Slot), /* lower_bound */
- llvm::ConstantInt::get(CGM.IntTy, 1), /* range_size */
- llvm::ConstantInt::get(CGM.IntTy, 0), /* index */
- llvm::ConstantInt::get(Int1Ty, false) /* non-uniform */
- };
- initializeBuffer(CGM, GV,
- CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic(),
- Args);
+ auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
+ auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
+ auto *RangeSize = llvm::ConstantInt::get(CGM.IntTy, 1);
+ auto *Space =
+ llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
+
+ if (RBA->hasRegisterSlot()) {
+ auto *RegSlot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
+ Intrinsic::ID Intr =
+ CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic();
+ initializeBuffer(CGM, GV, Intr,
+ {Space, RegSlot, RangeSize, Index, NonUniform});
+ } else {
+ auto *OrderID =
+ llvm::ConstantInt::get(CGM.IntTy, RBA->getImplicitBindingOrderID());
+ Intrinsic::ID Intr =
+ CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic();
+ initializeBuffer(CGM, GV, Intr,
+ {OrderID, Space, RangeSize, Index, NonUniform});
+ }
}
llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) {