LLVM 19.0.0git
DXILShaderFlags.cpp
Go to the documentation of this file.
1//===- DXILShaderFlags.cpp - 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#include "DXILShaderFlags.h"
15#include "DirectX.h"
16#include "llvm/IR/Instruction.h"
17#include "llvm/IR/Module.h"
19
20using namespace llvm;
21using namespace llvm::dxil;
22
23static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I) {
24 Type *Ty = I.getType();
25 if (Ty->isDoubleTy()) {
26 Flags.Doubles = true;
27 switch (I.getOpcode()) {
28 case Instruction::FDiv:
29 case Instruction::UIToFP:
30 case Instruction::SIToFP:
31 case Instruction::FPToUI:
32 case Instruction::FPToSI:
33 Flags.DX11_1_DoubleExtensions = true;
34 break;
35 }
36 }
37}
38
41 for (const auto &F : M)
42 for (const auto &BB : F)
43 for (const auto &I : BB)
44 updateFlags(Flags, I);
45 return Flags;
46}
47
49 uint64_t FlagVal = (uint64_t) * this;
50 OS << formatv("; Shader Flags Value: {0:x8}\n;\n", FlagVal);
51 if (FlagVal == 0)
52 return;
53 OS << "; Note: shader requires additional functionality:\n";
54#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
55 if (FlagName) \
56 (OS << ";").indent(7) << Str << "\n";
57#include "llvm/BinaryFormat/DXContainerConstants.def"
58 OS << "; Note: extra DXIL module flags:\n";
59#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
60 if (FlagName) \
61 (OS << ";").indent(7) << Str << "\n";
62#include "llvm/BinaryFormat/DXContainerConstants.def"
63 OS << ";\n";
64}
65
66AnalysisKey ShaderFlagsAnalysis::Key;
67
71}
72
76 Flags.print(OS);
78}
79
81
82INITIALIZE_PASS(ShaderFlagsAnalysisWrapper, "dx-shader-flag-analysis",
83 "DXIL Shader Flag Analysis", true, true)
static void updateFlags(ComputedShaderFlags &Flags, const Instruction &I)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:473
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:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Wrapper pass for the legacy pass manager.
ComputedShaderFlags 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
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
static ComputedShaderFlags computeFlags(Module &M)
void print(raw_ostream &OS=dbgs()) const