LLVM 19.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
27 bool ShouldPreserveUseListOrder,
28 bool EmitSummaryIndex)
29 : OS(OS), Banner(Banner),
30 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
31 EmitSummaryIndex(EmitSummaryIndex) {}
32
34 // RemoveDIs: there's no textual representation of the DPValue debug-info,
35 // convert to dbg.values before writing out.
36 bool ShouldConvert = M.IsNewDbgInfoFormat;
37 if (ShouldConvert)
38 M.convertFromNewDbgValues();
39
41 if (!Banner.empty())
42 OS << Banner << "\n";
43 M.print(OS, nullptr, ShouldPreserveUseListOrder);
44 } else {
45 bool BannerPrinted = false;
46 for (const auto &F : M.functions()) {
47 if (llvm::isFunctionInPrintList(F.getName())) {
48 if (!BannerPrinted && !Banner.empty()) {
49 OS << Banner << "\n";
50 BannerPrinted = true;
51 }
52 F.print(OS);
53 }
54 }
55 }
56
58 EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
59 : nullptr;
60 if (Index) {
61 if (Index->modulePaths().empty())
62 Index->addModule("");
63 Index->print(OS);
64 }
65
66 if (ShouldConvert)
67 M.convertToNewDbgValues();
68
70}
71
74 : OS(OS), Banner(Banner) {}
75
78 // RemoveDIs: there's no textual representation of the DPValue debug-info,
79 // convert to dbg.values before writing out.
80 bool ShouldConvert = F.IsNewDbgInfoFormat;
81 if (ShouldConvert)
82 F.convertFromNewDbgValues();
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
91 if (ShouldConvert)
92 F.convertToNewDbgValues();
93
95}
This file defines passes to print out IR in various granularities.
#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:348
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:500
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:109
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
PreservedAnalyses run(Function &F, AnalysisManager< Function > &)
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: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)