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 return MMDAI;
29}
30
32 OS << "Shader Model Version : " << ShaderModelVersion.getAsString() << "\n";
33 OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
34 OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
35 << "\n";
36}
37
38//===----------------------------------------------------------------------===//
39// DXILMetadataAnalysis and DXILMetadataAnalysisPrinterPass
40
41// Provide an explicit template instantiation for the static ID.
42AnalysisKey DXILMetadataAnalysis::Key;
43
46 return collectMetadataInfo(M);
47}
48
52
53 Data.print(OS);
55}
56
57//===----------------------------------------------------------------------===//
58// DXILMetadataAnalysisWrapperPass
59
61 : ModulePass(ID) {
64}
65
67
69 AnalysisUsage &AU) const {
70 AU.setPreservesAll();
71}
72
74 MetadataInfo.reset(new ModuleMetadataInfo(collectMetadataInfo(M)));
75 return false;
76}
77
78void DXILMetadataAnalysisWrapperPass::releaseMemory() { MetadataInfo.reset(); }
79
81 const Module *) const {
82 if (!MetadataInfo) {
83 OS << "No module metadata info has been built!\n";
84 return;
85 }
86 MetadataInfo->print(dbgs());
87}
88
89#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
92#endif
93
94INITIALIZE_PASS(DXILMetadataAnalysisWrapperPass, "dxil-metadata-analysis",
95 "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:537
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
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
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