diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-04-14 21:41:27 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-06-22 18:20:56 +0000 |
commit | bdd1243df58e60e85101c09001d9812a789b6bc4 (patch) | |
tree | a1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp | |
parent | 781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff) | |
parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp b/contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp new file mode 100644 index 000000000000..59f730d8a495 --- /dev/null +++ b/contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp @@ -0,0 +1,56 @@ +//===- HLSLResource.cpp - HLSL Resource helper objects --------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +/// +/// \file This file contains helper objects for working with HLSL Resources. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/Frontend/HLSL/HLSLResource.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/Module.h" + +using namespace llvm; +using namespace llvm::hlsl; + +GlobalVariable *FrontendResource::getGlobalVariable() { + return cast<GlobalVariable>( + cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue()); +} + +StringRef FrontendResource::getSourceType() { + return cast<MDString>(Entry->getOperand(1))->getString(); +} + +uint32_t FrontendResource::FrontendResource::getResourceKind() { + return cast<ConstantInt>( + cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue()) + ->getLimitedValue(); +} +uint32_t FrontendResource::getResourceIndex() { + return cast<ConstantInt>( + cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue()) + ->getLimitedValue(); +} +uint32_t FrontendResource::getSpace() { + return cast<ConstantInt>( + cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue()) + ->getLimitedValue(); +} + +FrontendResource::FrontendResource(GlobalVariable *GV, StringRef TypeStr, + ResourceKind RK, uint32_t ResIndex, + uint32_t Space) { + auto &Ctx = GV->getContext(); + IRBuilder<> B(Ctx); + Entry = MDNode::get( + Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TypeStr), + ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))), + ConstantAsMetadata::get(B.getInt32(ResIndex)), + ConstantAsMetadata::get(B.getInt32(Space))}); +} |