LLVM 19.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 static_cast<ResourceKind>(
28 cast<ConstantInt>(
29 cast<ConstantAsMetadata>(Entry->getOperand(1))->getValue())
30 ->getLimitedValue());
31}
33 return static_cast<ElementType>(
34 cast<ConstantInt>(
35 cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())
36 ->getLimitedValue());
37}
39 return cast<ConstantInt>(
40 cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
41 ->getLimitedValue();
42}
44 return cast<ConstantInt>(
45 cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
46 ->getLimitedValue();
47}
49 return cast<ConstantInt>(
50 cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue())
51 ->getLimitedValue();
52}
53
55 ElementType ElTy, bool IsROV,
56 uint32_t ResIndex, uint32_t Space) {
57 auto &Ctx = GV->getContext();
58 IRBuilder<> B(Ctx);
59 Entry = MDNode::get(
60 Ctx, {ValueAsMetadata::get(GV),
61 ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),
62 ConstantAsMetadata::get(B.getInt32(static_cast<int>(ElTy))),
63 ConstantAsMetadata::get(B.getInt1(IsROV)),
64 ConstantAsMetadata::get(B.getInt32(ResIndex)),
65 ConstantAsMetadata::get(B.getInt32(Space))});
66}
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:528
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2644
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1541
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:495
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