LLVM 18.0.0git
HLSLResource.cpp
Go to the documentation of this file.
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
14#include "llvm/IR/IRBuilder.h"
15#include "llvm/IR/Metadata.h"
16#include "llvm/IR/Module.h"
17
18using namespace llvm;
19using namespace llvm::hlsl;
20
22 return cast<GlobalVariable>(
23 cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue());
24}
25
27 return cast<MDString>(Entry->getOperand(1))->getString();
28}
29
30uint32_t FrontendResource::FrontendResource::getResourceKind() {
31 return cast<ConstantInt>(
32 cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())
33 ->getLimitedValue();
34}
36 return cast<ConstantInt>(
37 cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
38 ->getLimitedValue();
39}
41 return cast<ConstantInt>(
42 cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
43 ->getLimitedValue();
44}
45
47 ResourceKind RK, uint32_t ResIndex,
48 uint32_t Space) {
49 auto &Ctx = GV->getContext();
50 IRBuilder<> B(Ctx);
51 Entry = MDNode::get(
52 Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TypeStr),
53 ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),
54 ConstantAsMetadata::get(B.getInt32(ResIndex)),
55 ConstantAsMetadata::get(B.getInt32(Space))});
56}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:506
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2639
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1391
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1504
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:564
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:459
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1074
GlobalVariable * getGlobalVariable()
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18