blob: dd2b0b60bc19bf7b075df0c3c4da495e8364f72b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
//===- 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());
}
ResourceKind FrontendResource::getResourceKind() {
return static_cast<ResourceKind>(
cast<ConstantInt>(
cast<ConstantAsMetadata>(Entry->getOperand(1))->getValue())
->getLimitedValue());
}
ElementType FrontendResource::getElementType() {
return static_cast<ElementType>(
cast<ConstantInt>(
cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())
->getLimitedValue());
}
bool FrontendResource::getIsROV() {
return cast<ConstantInt>(
cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
->getLimitedValue();
}
uint32_t FrontendResource::getResourceIndex() {
return cast<ConstantInt>(
cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
->getLimitedValue();
}
uint32_t FrontendResource::getSpace() {
return cast<ConstantInt>(
cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue())
->getLimitedValue();
}
FrontendResource::FrontendResource(MDNode *E) : Entry(E) {
assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");
}
FrontendResource::FrontendResource(GlobalVariable *GV, ResourceKind RK,
ElementType ElTy, bool IsROV,
uint32_t ResIndex, uint32_t Space) {
auto &Ctx = GV->getContext();
IRBuilder<> B(Ctx);
Entry = MDNode::get(
Ctx, {ValueAsMetadata::get(GV),
ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),
ConstantAsMetadata::get(B.getInt32(static_cast<int>(ElTy))),
ConstantAsMetadata::get(B.getInt1(IsROV)),
ConstantAsMetadata::get(B.getInt32(ResIndex)),
ConstantAsMetadata::get(B.getInt32(Space))});
}
|