LLVM 20.0.0git
DXILShaderFlags.h
Go to the documentation of this file.
1//===- DXILShaderFlags.h - DXIL Shader Flags 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 and APIs for working with DXIL
10/// Shader Flags.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
15#define LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
16
17#include "llvm/IR/Function.h"
18#include "llvm/IR/PassManager.h"
19#include "llvm/Pass.h"
21#include "llvm/Support/Debug.h"
23#include <cstdint>
24#include <memory>
25
26namespace llvm {
27class Module;
28class GlobalVariable;
29class DXILResourceTypeMap;
30
31namespace dxil {
32
34#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
35 bool FlagName : 1;
36#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) bool FlagName : 1;
37#include "llvm/BinaryFormat/DXContainerConstants.def"
38
39#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
40 FlagName = false;
41#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) FlagName = false;
43#include "llvm/BinaryFormat/DXContainerConstants.def"
44 }
45
46 constexpr uint64_t getMask(int Bit) const {
47 return Bit != -1 ? 1ull << Bit : 0;
48 }
49
51 uint64_t ModuleFlags = 0;
52#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
53 ModuleFlags |= FlagName ? getMask(DxilModuleBit) : 0ull;
54#include "llvm/BinaryFormat/DXContainerConstants.def"
55 return ModuleFlags;
56 }
57
58 operator uint64_t() const {
59 uint64_t FlagValue = getModuleFlags();
60#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
61 FlagValue |= FlagName ? getMask(DxilModuleBit) : 0ull;
62#include "llvm/BinaryFormat/DXContainerConstants.def"
63 return FlagValue;
64 }
65
67 uint64_t FeatureFlags = 0;
68#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
69 FeatureFlags |= FlagName ? getMask(FeatureBit) : 0ull;
70#include "llvm/BinaryFormat/DXContainerConstants.def"
71 return FeatureFlags;
72 }
73
74 void merge(const uint64_t IVal) {
75#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
76 FlagName |= (IVal & getMask(DxilModuleBit));
77#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
78 FlagName |= (IVal & getMask(DxilModuleBit));
79#include "llvm/BinaryFormat/DXContainerConstants.def"
80 return;
81 }
82
83 void print(raw_ostream &OS = dbgs()) const;
84 LLVM_DUMP_METHOD void dump() const { print(); }
85};
86
88 void initialize(const Module &, DXILResourceTypeMap &DRTM);
89 const ComputedShaderFlags &getFunctionFlags(const Function *) const;
90 const ComputedShaderFlags &getCombinedFlags() const { return CombinedSFMask; }
91
92private:
93 /// Vector of sorted Function-Shader Flag mask pairs representing properties
94 /// of each of the functions in the module. Shader Flags of each function
95 /// represent both module-level and function-level flags
97 /// Combined Shader Flag Mask of all functions of the module
98 ComputedShaderFlags CombinedSFMask{};
99};
100
101class ShaderFlagsAnalysis : public AnalysisInfoMixin<ShaderFlagsAnalysis> {
103 static AnalysisKey Key;
104
105public:
107
109
111};
112
113/// Printer pass for ShaderFlagsAnalysis results.
115 : public PassInfoMixin<ShaderFlagsAnalysisPrinter> {
116 raw_ostream &OS;
117
118public:
121};
122
123/// Wrapper pass for the legacy pass manager.
124///
125/// This is required because the passes that will depend on this are codegen
126/// passes which run through the legacy pass manager.
129
130public:
131 static char ID;
132
134
135 const ModuleShaderFlags &getShaderFlags() { return MSFI; }
136
137 bool runOnModule(Module &M) override;
138
139 void getAnalysisUsage(AnalysisUsage &AU) const override;
140};
141
142} // namespace dxil
143} // namespace llvm
144
145#endif // LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Represent the analysis usage information of a pass.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
Printer pass for ShaderFlagsAnalysis results.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Wrapper pass for the legacy pass manager.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const ModuleShaderFlags & getShaderFlags()
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
ModuleShaderFlags run(Module &M, ModuleAnalysisManager &AM)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69
void merge(const uint64_t IVal)
constexpr uint64_t getMask(int Bit) const
LLVM_DUMP_METHOD void dump() const
void print(raw_ostream &OS=dbgs()) const
const ComputedShaderFlags & getFunctionFlags(const Function *) const
Return the shader flags mask of the specified function Func.
const ComputedShaderFlags & getCombinedFlags() const
void initialize(const Module &, DXILResourceTypeMap &DRTM)