Path: blob/main/contrib/llvm-project/llvm/lib/Frontend/HLSL/HLSLResource.cpp
35266 views
//===- HLSLResource.cpp - HLSL Resource helper objects --------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file This file contains helper objects for working with HLSL Resources.9///10//===----------------------------------------------------------------------===//1112#include "llvm/Frontend/HLSL/HLSLResource.h"13#include "llvm/IR/IRBuilder.h"14#include "llvm/IR/Metadata.h"15#include "llvm/IR/Module.h"1617using namespace llvm;18using namespace llvm::hlsl;1920GlobalVariable *FrontendResource::getGlobalVariable() {21return cast<GlobalVariable>(22cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue());23}2425ResourceKind FrontendResource::getResourceKind() {26return static_cast<ResourceKind>(27cast<ConstantInt>(28cast<ConstantAsMetadata>(Entry->getOperand(1))->getValue())29->getLimitedValue());30}31ElementType FrontendResource::getElementType() {32return static_cast<ElementType>(33cast<ConstantInt>(34cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())35->getLimitedValue());36}37bool FrontendResource::getIsROV() {38return cast<ConstantInt>(39cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())40->getLimitedValue();41}42uint32_t FrontendResource::getResourceIndex() {43return cast<ConstantInt>(44cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())45->getLimitedValue();46}47uint32_t FrontendResource::getSpace() {48return cast<ConstantInt>(49cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue())50->getLimitedValue();51}5253FrontendResource::FrontendResource(MDNode *E) : Entry(E) {54assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");55}5657FrontendResource::FrontendResource(GlobalVariable *GV, ResourceKind RK,58ElementType ElTy, bool IsROV,59uint32_t ResIndex, uint32_t Space) {60auto &Ctx = GV->getContext();61IRBuilder<> B(Ctx);62Entry = MDNode::get(63Ctx, {ValueAsMetadata::get(GV),64ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),65ConstantAsMetadata::get(B.getInt32(static_cast<int>(ElTy))),66ConstantAsMetadata::get(B.getInt1(IsROV)),67ConstantAsMetadata::get(B.getInt32(ResIndex)),68ConstantAsMetadata::get(B.getInt32(Space))});69}707172