LLVM 22.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#include <memory>
26
27namespace llvm {
28class Module;
29class GlobalVariable;
30class DXILResourceTypeMap;
31class DXILResourceMap;
32
33namespace dxil {
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 ComputedShaderFlags &getFunctionFlags(const Function *) const;
91 const ComputedShaderFlags &getCombinedFlags() const { return CombinedSFMask; }
92
93private:
94 // This boolean is inversely set by the LLVM module flag dx.resmayalias to
95 // determine whether or not the ResMayNotAlias DXIL module flag can be set
96 bool CanSetResMayNotAlias;
97
98 /// Map of Function-Shader Flag Mask pairs representing properties of each of
99 /// the functions in the module. Shader Flags of each function represent both
100 /// module-level and function-level flags
102 /// Combined Shader Flag Mask of all functions of the module
103 ComputedShaderFlags CombinedSFMask{};
104 ComputedShaderFlags gatherGlobalModuleFlags(const Module &M,
105 const DXILResourceMap &,
106 const ModuleMetadataInfo &);
107 void updateFunctionFlags(ComputedShaderFlags &, const Instruction &,
108 DXILResourceTypeMap &, const ModuleMetadataInfo &);
109};
110
111class ShaderFlagsAnalysis : public AnalysisInfoMixin<ShaderFlagsAnalysis> {
113 static AnalysisKey Key;
114
115public:
117
119
121};
122
123/// Printer pass for ShaderFlagsAnalysis results.
125 : public PassInfoMixin<ShaderFlagsAnalysisPrinter> {
126 raw_ostream &OS;
127
128public:
131};
132
133/// Wrapper pass for the legacy pass manager.
134///
135/// This is required because the passes that will depend on this are codegen
136/// passes which run through the legacy pass manager.
139
140public:
141 static char ID;
142
144
145 const ModuleShaderFlags &getShaderFlags() { return MSFI; }
146
147 bool runOnModule(Module &M) override;
148
149 void getAnalysisUsage(AnalysisUsage &AU) const override;
150};
151
152} // namespace dxil
153} // namespace llvm
154
155#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:638
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:255
Represent the analysis usage information of a pass.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
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:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:29
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:70
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)
Construct ModuleShaderFlags for module Module M.
const ComputedShaderFlags & getCombinedFlags() const