LLVM 20.0.0git
DXILMetadataAnalysis.cpp
Go to the documentation of this file.
1//=- DXILMetadataAnalysis.cpp - Representation of Module metadata -*- C++ -*=//
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
10#include "llvm/ADT/APInt.h"
11#include "llvm/IR/Constants.h"
13#include "llvm/IR/Metadata.h"
14#include "llvm/IR/Module.h"
16
17#define DEBUG_TYPE "dxil-metadata-analysis"
18
19using namespace llvm;
20using namespace dxil;
21
24 Triple TT(Triple(M.getTargetTriple()));
25 MMDAI.DXILVersion = TT.getDXILVersion();
26 MMDAI.ShaderModelVersion = TT.getOSVersion();
27 MMDAI.ShaderStage = TT.getEnvironment();
28 NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
29 if (ValidatorVerNode) {
30 auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
31 auto *MajorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(0));
32 auto *MinorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(1));
33 MMDAI.ValidatorVersion =
34 VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
35 }
36 return MMDAI;
37}
38
40 OS << "Shader Model Version : " << ShaderModelVersion.getAsString() << "\n";
41 OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
42 OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
43 << "\n";
44 OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
45}
46
47//===----------------------------------------------------------------------===//
48// DXILMetadataAnalysis and DXILMetadataAnalysisPrinterPass
49
50// Provide an explicit template instantiation for the static ID.
51AnalysisKey DXILMetadataAnalysis::Key;
52
55 return collectMetadataInfo(M);
56}
57
61
62 Data.print(OS);
64}
65
66//===----------------------------------------------------------------------===//
67// DXILMetadataAnalysisWrapperPass
68
70 : ModulePass(ID) {
73}
74
76
78 AnalysisUsage &AU) const {
79 AU.setPreservesAll();
80}
81
83 MetadataInfo.reset(new ModuleMetadataInfo(collectMetadataInfo(M)));
84 return false;
85}
86
87void DXILMetadataAnalysisWrapperPass::releaseMemory() { MetadataInfo.reset(); }
88
90 const Module *) const {
91 if (!MetadataInfo) {
92 OS << "No module metadata info has been built!\n";
93 return;
94 }
95 MetadataInfo->print(dbgs());
96}
97
98#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
101#endif
102
103INITIALIZE_PASS(DXILMetadataAnalysisWrapperPass, "dxil-metadata-analysis",
104 "DXIL Module Metadata analysis", false, true)
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:533
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static ModuleMetadataInfo collectMetadataInfo(Module &M)
This file contains the declarations for metadata subclasses.
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:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
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...
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
dxil::ModuleMetadataInfo run(Module &M, ModuleAnalysisManager &AM)
Gather module metadata info for the module M.
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 tuple of MDNodes.
Definition: Metadata.h:1730
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1388
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static StringRef getEnvironmentTypeName(EnvironmentType Kind)
Get the canonical name for the Kind environment.
Definition: Triple.cpp:305
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
std::string getAsString() const
Retrieve a string representation of the version number.
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
void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &)
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
Triple::EnvironmentType ShaderStage
void print(raw_ostream &OS) const