Path: blob/main/contrib/llvm-project/llvm/lib/Target/DirectX/DXILShaderFlags.h
35268 views
//===- DXILShaderFlags.h - DXIL Shader Flags 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 and APIs for working with DXIL9/// Shader Flags.10///11//===----------------------------------------------------------------------===//1213#ifndef LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H14#define LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H1516#include "llvm/IR/PassManager.h"17#include "llvm/Pass.h"18#include "llvm/Support/Compiler.h"19#include "llvm/Support/Debug.h"20#include "llvm/Support/raw_ostream.h"21#include <cstdint>2223namespace llvm {24class Module;25class GlobalVariable;2627namespace dxil {2829struct ComputedShaderFlags {30#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \31bool FlagName : 1;32#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) bool FlagName : 1;33#include "llvm/BinaryFormat/DXContainerConstants.def"3435#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \36FlagName = false;37#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) FlagName = false;38ComputedShaderFlags() {39#include "llvm/BinaryFormat/DXContainerConstants.def"40}4142constexpr uint64_t getMask(int Bit) const {43return Bit != -1 ? 1ull << Bit : 0;44}45operator uint64_t() const {46uint64_t FlagValue = 0;47#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \48FlagValue |= FlagName ? getMask(DxilModuleBit) : 0ull;49#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \50FlagValue |= FlagName ? getMask(DxilModuleBit) : 0ull;51#include "llvm/BinaryFormat/DXContainerConstants.def"52return FlagValue;53}54uint64_t getFeatureFlags() const {55uint64_t FeatureFlags = 0;56#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str) \57FeatureFlags |= FlagName ? getMask(FeatureBit) : 0ull;58#include "llvm/BinaryFormat/DXContainerConstants.def"59return FeatureFlags;60}6162static ComputedShaderFlags computeFlags(Module &M);63void print(raw_ostream &OS = dbgs()) const;64LLVM_DUMP_METHOD void dump() const { print(); }65};6667class ShaderFlagsAnalysis : public AnalysisInfoMixin<ShaderFlagsAnalysis> {68friend AnalysisInfoMixin<ShaderFlagsAnalysis>;69static AnalysisKey Key;7071public:72ShaderFlagsAnalysis() = default;7374using Result = ComputedShaderFlags;7576ComputedShaderFlags run(Module &M, ModuleAnalysisManager &AM);77};7879/// Printer pass for ShaderFlagsAnalysis results.80class ShaderFlagsAnalysisPrinter81: public PassInfoMixin<ShaderFlagsAnalysisPrinter> {82raw_ostream &OS;8384public:85explicit ShaderFlagsAnalysisPrinter(raw_ostream &OS) : OS(OS) {}86PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);87};8889/// Wrapper pass for the legacy pass manager.90///91/// This is required because the passes that will depend on this are codegen92/// passes which run through the legacy pass manager.93class ShaderFlagsAnalysisWrapper : public ModulePass {94ComputedShaderFlags Flags;9596public:97static char ID;9899ShaderFlagsAnalysisWrapper() : ModulePass(ID) {}100101const ComputedShaderFlags &getShaderFlags() { return Flags; }102103bool runOnModule(Module &M) override {104Flags = ComputedShaderFlags::computeFlags(M);105return false;106}107108void getAnalysisUsage(AnalysisUsage &AU) const override {109AU.setPreservesAll();110}111};112113} // namespace dxil114} // namespace llvm115116#endif // LLVM_TARGET_DIRECTX_DXILSHADERFLAGS_H117118119