LLVM 20.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"
20#include "llvm/Support/Debug.h"
22
23using namespace llvm;
24
26
29 bool ShouldPreserveUseListOrder,
30 bool EmitSummaryIndex)
31 : OS(OS), Banner(Banner),
32 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
33 EmitSummaryIndex(EmitSummaryIndex) {}
34
36 // RemoveDIs: Regardless of the format we've processed this module in, use
37 // `WriteNewDbgInfoFormat` to determine which format we use to write it.
39 // Remove intrinsic declarations when printing in the new format.
40 // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to
41 // update test output.
43 M.removeDebugIntrinsicDeclarations();
44
46 if (!Banner.empty())
47 OS << Banner << "\n";
48 M.print(OS, nullptr, ShouldPreserveUseListOrder);
49 } else {
50 bool BannerPrinted = false;
51 for (const auto &F : M.functions()) {
52 if (llvm::isFunctionInPrintList(F.getName())) {
53 if (!BannerPrinted && !Banner.empty()) {
54 OS << Banner << "\n";
55 BannerPrinted = true;
56 }
57 F.print(OS);
58 }
59 }
60 }
61
63 EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
64 : nullptr;
65 if (Index) {
66 if (Index->modulePaths().empty())
67 Index->addModule("");
68 Index->print(OS);
69 }
70
72}
73
76 : OS(OS), Banner(Banner) {}
77
80 // RemoveDIs: Regardless of the format we've processed this function in, use
81 // `WriteNewDbgInfoFormat` to determine which format we use to write it.
83
84 if (isFunctionInPrintList(F.getName())) {
86 OS << Banner << " (function: " << F.getName() << ")\n" << *F.getParent();
87 else
88 OS << Banner << '\n' << static_cast<Value &>(F);
89 }
90
92}
cl::opt< bool > WriteNewDbgInfoFormat
This file defines passes to print out IR in various granularities.
cl::opt< bool > WriteNewDbgInfoFormat
#define F(x, y, z)
Definition: MD5.cpp:55
This is the interface to build a ModuleSummaryIndex for a module.
Module.h This file contains the declarations for the Module class.
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
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:65
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
PreservedAnalyses run(Function &F, AnalysisManager< Function > &)
PreservedAnalyses run(Module &M, AnalysisManager< Module > &)
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
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
bool forcePrintModuleIR()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
bool isFunctionInPrintList(StringRef FunctionName)