LLVM 24.0.0git
IRPrintingPasses.cpp
Go to the documentation of this file.
1//===--- IRPrintingPasses.cpp - Module and Function printing passes -------===//
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// PrintModulePass and PrintFunctionPass implementations.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/StringRef.h"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/Module.h"
18#include "llvm/IR/PrintPasses.h"
19#include "llvm/Pass.h"
21#include "llvm/Support/Debug.h"
23
24using namespace llvm;
25
27 : OS(dbgs()), ShouldPreserveUseListOrder(false), EmitSummaryIndex(false),
28 ShouldRenumberMetadata(false) {}
29PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
30 bool ShouldPreserveUseListOrder,
31 bool EmitSummaryIndex,
32 bool ShouldRenumberMetadata)
33 : OS(OS), Banner(Banner),
34 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
35 EmitSummaryIndex(EmitSummaryIndex),
36 ShouldRenumberMetadata(ShouldRenumberMetadata) {}
37
39 if (ShouldRenumberMetadata)
40 M.renumberMetadataForAssembly();
41
43 if (!Banner.empty())
44 OS << Banner << "\n";
45 M.print(OS, nullptr, ShouldPreserveUseListOrder);
46 } else {
47 bool BannerPrinted = false;
48 for (const auto &F : M.functions()) {
50 if (!BannerPrinted && !Banner.empty()) {
51 OS << Banner << "\n";
52 BannerPrinted = true;
53 }
54 F.print(OS);
55 }
56 }
57 }
58
59 ModuleSummaryIndex *Index =
60 EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
61 : nullptr;
62 if (Index) {
63 if (Index->modulePaths().empty())
64 Index->addModule("");
65 Index->print(OS);
66 }
67
69}
70
73 : OS(OS), Banner(Banner) {}
74
78 if (forcePrintModuleIR()) {
79 OS << Banner << " (function: " << F.getName() << ")\n";
80 F.getParent()->print(OS, nullptr);
81 } else
82 OS << Banner << '\n' << static_cast<Value &>(F);
83 }
84
86}
This file defines passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
This is the interface to build a ModuleSummaryIndex for a module.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Analysis pass to provide the ModuleSummaryIndex object.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
LLVM_ABI PreservedAnalyses run(Function &F, AnalysisManager< Function > &)
LLVM_ABI PreservedAnalyses run(Module &M, AnalysisManager< Module > &)
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.
LLVM_ABI bool forcePrintModuleIR()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI bool shouldPrintFunction(const Function &F)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool shouldPrintAllFunctions()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39