LLVM 24.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
18#include "llvm/IR/Function.h"
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
22#include "llvm/Support/Debug.h"
24#include <cstdint>
25
26namespace llvm {
27class Module;
29class DXILResourceMap;
30
31namespace dxil {
32
34
36#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
37 bool FlagName : 1;
38#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) bool FlagName : 1;
39#include "llvm/BinaryFormat/DXContainerConstants.def"
40
41#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
42 FlagName = false;
43#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) FlagName = false;
45#include "llvm/BinaryFormat/DXContainerConstants.def"
46 }
47
48 constexpr uint64_t getMask(int Bit) const {
49 return Bit != -1 ? 1ull << Bit : 0;
50 }
51
53 uint64_t ModuleFlags = 0;
54#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
55 ModuleFlags |= FlagName ? getMask(DxilModuleBit) : 0ull;
56#include "llvm/BinaryFormat/DXContainerConstants.def"
57 return ModuleFlags;
58 }
59
60 operator uint64_t() const {
61 uint64_t FlagValue = getModuleFlags();
62#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
63 FlagValue |= FlagName ? getMask(DxilModuleBit) : 0ull;
64#include "llvm/BinaryFormat/DXContainerConstants.def"
65 return FlagValue;
66 }
67
69 uint64_t FeatureFlags = 0;
70#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
71 FeatureFlags |= FlagName ? getMask(FeatureBit) : 0ull;
72#include "llvm/BinaryFormat/DXContainerConstants.def"
73 return FeatureFlags;
74 }
75
76 void merge(const ComputedShaderFlags CSF) {
77#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \
78 FlagName |= CSF.FlagName;
79#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) FlagName |= CSF.FlagName;
80#include "llvm/BinaryFormat/DXContainerConstants.def"
81 }
82
83 void print(raw_ostream &OS = dbgs()) const;
84 LLVM_DUMP_METHOD void dump() const { print(); }
85};
86
89 const DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI,
90 const ModuleSignatureInfo &Signatures);
91 const ComputedShaderFlags &getFunctionFlags(const Function *) const;
92 const ComputedShaderFlags &getCombinedFlags() const { return CombinedSFMask; }
93
94private:
95 // This boolean is inversely set by the LLVM module flag dx.resmayalias to
96 // determine whether or not the ResMayNotAlias DXIL module flag can be set
97 bool CanSetResMayNotAlias;
98
99 /// Map of Function-Shader Flag Mask pairs representing properties of each of
100 /// the functions in the module. Shader Flags of each function represent both
101 /// module-level and function-level flags
103 /// Combined Shader Flag Mask of all functions of the module
104 ComputedShaderFlags CombinedSFMask{};
105 ComputedShaderFlags gatherGlobalModuleFlags(const Module &M,
106 const DXILResourceMap &,
107 const ModuleMetadataInfo &);
108 void updateFunctionFlags(ComputedShaderFlags &, const Instruction &,
109 DXILResourceTypeMap &, const ModuleMetadataInfo &);
110};
111
112class ShaderFlagsAnalysis : public AnalysisInfoMixin<ShaderFlagsAnalysis> {
114 static AnalysisKey Key;
115
116public:
118
120
122};
123
124/// Printer pass for ShaderFlagsAnalysis results.
126 : public OptionalPassInfoMixin<ShaderFlagsAnalysisPrinterPass> {
127 raw_ostream &OS;
128
129public:
132};
133
134/// Wrapper pass for the legacy pass manager.
135///
136/// This is required because the passes that will depend on this are codegen
137/// passes which run through the legacy pass manager.
140
141public:
142 static char ID;
143
145
146 const ModuleShaderFlags &getShaderFlags() { return MSFI; }
147
148 bool runOnModule(Module &M) override;
149
150 void getAnalysisUsage(AnalysisUsage &AU) const override;
151};
152
153} // namespace dxil
154} // namespace llvm
155
156#endif // LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H
uint64_t uint64_t
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
This header defines various interfaces for pass management in LLVM.
Represent the analysis usage information of a pass.
ModulePass(char &pid)
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
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:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that can be skipped.
void merge(const ComputedShaderFlags CSF)
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.
void initialize(Module &, DXILResourceTypeMap &DRTM, const DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI, const ModuleSignatureInfo &Signatures)
Construct ModuleShaderFlags for module Module M.
const ComputedShaderFlags & getCombinedFlags() const