1//===- DXILOpBuilder.h - Helper class for build DIXLOp functions ----------===//
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 class to help build DXIL op functions.
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_LIB_TARGET_DIRECTX_DXILOPBUILDER_H
13#define LLVM_LIB_TARGET_DIRECTX_DXILOPBUILDER_H
14
15#include "DXILConstants.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/IR/IRBuilder.h"
18#include "llvm/Support/DXILABI.h"
19#include "llvm/Support/Error.h"
20#include "llvm/TargetParser/Triple.h"
21
22namespace llvm {
23class Module;
24class IRBuilderBase;
25class CallInst;
26class Constant;
27class Value;
28class Type;
29class FunctionType;
30
31namespace dxil {
32
33class DXILOpBuilder {
34public:
35 DXILOpBuilder(Module &M);
36
37 IRBuilder<> &getIRB() { return IRB; }
38
39 /// Create a call instruction for the given DXIL op. The arguments
40 /// must be valid for an overload of the operation.
41 CallInst *createOp(dxil::OpCode Op, ArrayRef<Value *> Args,
42 const Twine &Name = "", Type *RetTy = nullptr);
43
44 /// Try to create a call instruction for the given DXIL op. Fails if the
45 /// overload is invalid.
46 Expected<CallInst *> tryCreateOp(dxil::OpCode Op, ArrayRef<Value *> Args,
47 const Twine &Name = "",
48 Type *RetTy = nullptr);
49
50 /// Get a `%dx.types.ResRet` type with the given element type.
51 StructType *getResRetType(Type *ElementTy);
52
53 /// Get a `%dx.types.CBufRet` type with the given element type.
54 StructType *getCBufRetType(Type *ElementTy);
55
56 /// Get the `%dx.types.Handle` type.
57 StructType *getHandleType();
58
59 /// Get a constant `%dx.types.ResBind` value.
60 Constant *getResBind(uint32_t LowerBound, uint32_t UpperBound,
61 uint32_t SpaceID, dxil::ResourceClass RC);
62 /// Get a constant `%dx.types.ResourceProperties` value.
63 Constant *getResProps(uint32_t Word0, uint32_t Word1);
64
65 /// Return the name of the given opcode.
66 static const char *getOpCodeName(dxil::OpCode DXILOp);
67
68private:
69 /// Gets a specific overload type of the function for the given DXIL op. If
70 /// the operation is not overloaded, \c OverloadType may be nullptr.
71 FunctionType *getOpFunctionType(dxil::OpCode OpCode,
72 Type *OverloadType = nullptr);
73
74 Module &M;
75 IRBuilder<> IRB;
76 VersionTuple DXILVersion;
77 Triple::EnvironmentType ShaderStage;
78};
79
80} // namespace dxil
81} // namespace llvm
82
83#endif
84