/src/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- HLSLResource.cpp - HLSL Resource helper objects --------------------===// |
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 | | /// \file This file contains helper objects for working with HLSL Resources. |
10 | | /// |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "llvm/Frontend/HLSL/HLSLResource.h" |
14 | | #include "llvm/IR/IRBuilder.h" |
15 | | #include "llvm/IR/Metadata.h" |
16 | | #include "llvm/IR/Module.h" |
17 | | |
18 | | using namespace llvm; |
19 | | using namespace llvm::hlsl; |
20 | | |
21 | 0 | GlobalVariable *FrontendResource::getGlobalVariable() { |
22 | 0 | return cast<GlobalVariable>( |
23 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue()); |
24 | 0 | } |
25 | | |
26 | 0 | ResourceKind FrontendResource::getResourceKind() { |
27 | 0 | return static_cast<ResourceKind>( |
28 | 0 | cast<ConstantInt>( |
29 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(1))->getValue()) |
30 | 0 | ->getLimitedValue()); |
31 | 0 | } |
32 | 0 | ElementType FrontendResource::getElementType() { |
33 | 0 | return static_cast<ElementType>( |
34 | 0 | cast<ConstantInt>( |
35 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue()) |
36 | 0 | ->getLimitedValue()); |
37 | 0 | } |
38 | 0 | bool FrontendResource::getIsROV() { |
39 | 0 | return cast<ConstantInt>( |
40 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue()) |
41 | 0 | ->getLimitedValue(); |
42 | 0 | } |
43 | 0 | uint32_t FrontendResource::getResourceIndex() { |
44 | 0 | return cast<ConstantInt>( |
45 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue()) |
46 | 0 | ->getLimitedValue(); |
47 | 0 | } |
48 | 0 | uint32_t FrontendResource::getSpace() { |
49 | 0 | return cast<ConstantInt>( |
50 | 0 | cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue()) |
51 | 0 | ->getLimitedValue(); |
52 | 0 | } |
53 | | |
54 | | FrontendResource::FrontendResource(GlobalVariable *GV, ResourceKind RK, |
55 | | ElementType ElTy, bool IsROV, |
56 | 0 | uint32_t ResIndex, uint32_t Space) { |
57 | 0 | auto &Ctx = GV->getContext(); |
58 | 0 | IRBuilder<> B(Ctx); |
59 | 0 | Entry = MDNode::get( |
60 | 0 | Ctx, {ValueAsMetadata::get(GV), |
61 | 0 | ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))), |
62 | 0 | ConstantAsMetadata::get(B.getInt32(static_cast<int>(ElTy))), |
63 | 0 | ConstantAsMetadata::get(B.getInt1(IsROV)), |
64 | 0 | ConstantAsMetadata::get(B.getInt32(ResIndex)), |
65 | 0 | ConstantAsMetadata::get(B.getInt32(Space))}); |
66 | 0 | } |