2014-01-09 02:39:45 +00:00
|
|
|
//===--- IRPrintingPasses.cpp - Module and Function printing passes -------===//
|
2008-10-21 23:33:38 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-10-21 23:33:38 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2022-11-18 01:47:56 +00:00
|
|
|
// PrintModulePass and PrintFunctionPass implementations for the legacy pass
|
|
|
|
// manager.
|
2008-10-21 23:33:38 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-01-12 11:10:32 +00:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2020-07-25 15:52:05 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2020-12-03 10:59:10 -08:00
|
|
|
#include "llvm/IR/PrintPasses.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 13:15:01 -08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2008-10-21 23:33:38 +00:00
|
|
|
#include "llvm/Pass.h"
|
2010-01-05 01:30:18 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2008-10-22 03:25:22 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2020-07-25 15:52:05 +01:00
|
|
|
|
2008-10-21 23:33:38 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)
During the transition from debug intrinsics to debug records, we used
several different command line options to customise handling: the
printing of debug records to bitcode and textual could be independent of
how the debug-info was represented inside a module, whether the
autoupgrader ran could be customised. This was all valuable during
development, but now that totally removing debug intrinsics is coming
up, this patch removes those options in favour of a single flag
(experimental-debuginfo-iterators), which enables autoupgrade, in-memory
debug records, and debug record printing to bitcode and textual IR.
We need to do this ahead of removing the
experimental-debuginfo-iterators flag, to reduce the amount of
test-juggling that happens at that time.
There are quite a number of weird test behaviours related to this --
some of which I simply delete in this commit. Things like
print-non-instruction-debug-info.ll , the test suite now checks for
debug records in all tests, and we don't want to check we can print as
intrinsics. Or the update_test_checks tests -- these are duplicated with
write-experimental-debuginfo=false to ensure file writing for intrinsics
is correct, but that's something we're imminently going to delete.
A short survey of curious test changes:
* free-intrinsics.ll: we don't need to test that debug-info is a zero
cost intrinsic, because we won't be using intrinsics in the future.
* undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory
mode while we sorted something out; it works now either way.
* salvage-cast-debug-info.ll: was testing intrinsics-in-memory get
salvaged, isn't necessary now
* localize-constexpr-debuginfo.ll: was producing "dead metadata"
intrinsics for optimised-out variable values, dbg-records takes the
(correct) representation of poison/undef as an operand. Looks like we
didn't update this in the past to avoid spurious test differences.
* Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing
that debug-info affected codegen, and we deferred updating the tests
until now. This is just one of those silent gnochange issues that get
fixed by RemoveDIs.
Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc,
that checks we can autoupgrade debug intrinsics that are in bitcode into
the new debug records.
2025-04-01 14:27:11 +01:00
|
|
|
extern cl::opt<bool> UseNewDbgInfoFormat;
|
2024-02-27 11:13:46 +00:00
|
|
|
|
2008-10-21 23:33:38 +00:00
|
|
|
namespace {
|
|
|
|
|
2014-01-12 12:15:39 +00:00
|
|
|
class PrintModulePassWrapper : public ModulePass {
|
2022-11-18 01:47:56 +00:00
|
|
|
raw_ostream &OS;
|
|
|
|
std::string Banner;
|
|
|
|
bool ShouldPreserveUseListOrder;
|
2014-01-12 11:16:01 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
2022-11-18 01:47:56 +00:00
|
|
|
PrintModulePassWrapper() : ModulePass(ID), OS(dbgs()) {}
|
2015-04-15 02:38:06 +00:00
|
|
|
PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner,
|
|
|
|
bool ShouldPreserveUseListOrder)
|
2022-11-18 01:47:56 +00:00
|
|
|
: ModulePass(ID), OS(OS), Banner(Banner),
|
|
|
|
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
|
2014-01-12 11:16:01 +00:00
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
bool runOnModule(Module &M) override {
|
[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)
During the transition from debug intrinsics to debug records, we used
several different command line options to customise handling: the
printing of debug records to bitcode and textual could be independent of
how the debug-info was represented inside a module, whether the
autoupgrader ran could be customised. This was all valuable during
development, but now that totally removing debug intrinsics is coming
up, this patch removes those options in favour of a single flag
(experimental-debuginfo-iterators), which enables autoupgrade, in-memory
debug records, and debug record printing to bitcode and textual IR.
We need to do this ahead of removing the
experimental-debuginfo-iterators flag, to reduce the amount of
test-juggling that happens at that time.
There are quite a number of weird test behaviours related to this --
some of which I simply delete in this commit. Things like
print-non-instruction-debug-info.ll , the test suite now checks for
debug records in all tests, and we don't want to check we can print as
intrinsics. Or the update_test_checks tests -- these are duplicated with
write-experimental-debuginfo=false to ensure file writing for intrinsics
is correct, but that's something we're imminently going to delete.
A short survey of curious test changes:
* free-intrinsics.ll: we don't need to test that debug-info is a zero
cost intrinsic, because we won't be using intrinsics in the future.
* undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory
mode while we sorted something out; it works now either way.
* salvage-cast-debug-info.ll: was testing intrinsics-in-memory get
salvaged, isn't necessary now
* localize-constexpr-debuginfo.ll: was producing "dead metadata"
intrinsics for optimised-out variable values, dbg-records takes the
(correct) representation of poison/undef as an operand. Looks like we
didn't update this in the past to avoid spurious test differences.
* Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing
that debug-info affected codegen, and we deferred updating the tests
until now. This is just one of those silent gnochange issues that get
fixed by RemoveDIs.
Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc,
that checks we can autoupgrade debug intrinsics that are in bitcode into
the new debug records.
2025-04-01 14:27:11 +01:00
|
|
|
ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat);
|
2024-02-27 11:13:46 +00:00
|
|
|
// Remove intrinsic declarations when printing in the new format.
|
|
|
|
// TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to
|
|
|
|
// update test output.
|
[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)
During the transition from debug intrinsics to debug records, we used
several different command line options to customise handling: the
printing of debug records to bitcode and textual could be independent of
how the debug-info was represented inside a module, whether the
autoupgrader ran could be customised. This was all valuable during
development, but now that totally removing debug intrinsics is coming
up, this patch removes those options in favour of a single flag
(experimental-debuginfo-iterators), which enables autoupgrade, in-memory
debug records, and debug record printing to bitcode and textual IR.
We need to do this ahead of removing the
experimental-debuginfo-iterators flag, to reduce the amount of
test-juggling that happens at that time.
There are quite a number of weird test behaviours related to this --
some of which I simply delete in this commit. Things like
print-non-instruction-debug-info.ll , the test suite now checks for
debug records in all tests, and we don't want to check we can print as
intrinsics. Or the update_test_checks tests -- these are duplicated with
write-experimental-debuginfo=false to ensure file writing for intrinsics
is correct, but that's something we're imminently going to delete.
A short survey of curious test changes:
* free-intrinsics.ll: we don't need to test that debug-info is a zero
cost intrinsic, because we won't be using intrinsics in the future.
* undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory
mode while we sorted something out; it works now either way.
* salvage-cast-debug-info.ll: was testing intrinsics-in-memory get
salvaged, isn't necessary now
* localize-constexpr-debuginfo.ll: was producing "dead metadata"
intrinsics for optimised-out variable values, dbg-records takes the
(correct) representation of poison/undef as an operand. Looks like we
didn't update this in the past to avoid spurious test differences.
* Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing
that debug-info affected codegen, and we deferred updating the tests
until now. This is just one of those silent gnochange issues that get
fixed by RemoveDIs.
Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc,
that checks we can autoupgrade debug intrinsics that are in bitcode into
the new debug records.
2025-04-01 14:27:11 +01:00
|
|
|
if (UseNewDbgInfoFormat)
|
2024-02-27 11:13:46 +00:00
|
|
|
M.removeDebugIntrinsicDeclarations();
|
2023-11-09 16:00:21 +00:00
|
|
|
|
2022-11-18 01:47:56 +00:00
|
|
|
if (llvm::isFunctionInPrintList("*")) {
|
|
|
|
if (!Banner.empty())
|
|
|
|
OS << Banner << "\n";
|
|
|
|
M.print(OS, nullptr, ShouldPreserveUseListOrder);
|
|
|
|
} else {
|
|
|
|
bool BannerPrinted = false;
|
|
|
|
for (const auto &F : M.functions()) {
|
|
|
|
if (llvm::isFunctionInPrintList(F.getName())) {
|
|
|
|
if (!BannerPrinted && !Banner.empty()) {
|
|
|
|
OS << Banner << "\n";
|
|
|
|
BannerPrinted = true;
|
|
|
|
}
|
|
|
|
F.print(OS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-09 16:00:21 +00:00
|
|
|
|
2014-01-12 11:16:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2014-01-12 11:16:01 +00:00
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2017-03-10 07:09:20 +00:00
|
|
|
|
2017-08-25 12:38:53 +00:00
|
|
|
StringRef getPassName() const override { return "Print Module IR"; }
|
2014-01-12 11:16:01 +00:00
|
|
|
};
|
|
|
|
|
2014-01-12 12:15:39 +00:00
|
|
|
class PrintFunctionPassWrapper : public FunctionPass {
|
2022-11-18 01:47:56 +00:00
|
|
|
raw_ostream &OS;
|
|
|
|
std::string Banner;
|
2014-01-12 11:16:01 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
2022-11-18 01:47:56 +00:00
|
|
|
PrintFunctionPassWrapper() : FunctionPass(ID), OS(dbgs()) {}
|
2014-01-12 12:15:39 +00:00
|
|
|
PrintFunctionPassWrapper(raw_ostream &OS, const std::string &Banner)
|
2022-11-18 01:47:56 +00:00
|
|
|
: FunctionPass(ID), OS(OS), Banner(Banner) {}
|
2014-01-12 11:16:01 +00:00
|
|
|
|
|
|
|
// This pass just prints a banner followed by the function as it's processed.
|
2014-03-05 06:35:38 +00:00
|
|
|
bool runOnFunction(Function &F) override {
|
[DebugInfo][RemoveDIs] Remove debug-intrinsic printing cmdline options (#131855)
During the transition from debug intrinsics to debug records, we used
several different command line options to customise handling: the
printing of debug records to bitcode and textual could be independent of
how the debug-info was represented inside a module, whether the
autoupgrader ran could be customised. This was all valuable during
development, but now that totally removing debug intrinsics is coming
up, this patch removes those options in favour of a single flag
(experimental-debuginfo-iterators), which enables autoupgrade, in-memory
debug records, and debug record printing to bitcode and textual IR.
We need to do this ahead of removing the
experimental-debuginfo-iterators flag, to reduce the amount of
test-juggling that happens at that time.
There are quite a number of weird test behaviours related to this --
some of which I simply delete in this commit. Things like
print-non-instruction-debug-info.ll , the test suite now checks for
debug records in all tests, and we don't want to check we can print as
intrinsics. Or the update_test_checks tests -- these are duplicated with
write-experimental-debuginfo=false to ensure file writing for intrinsics
is correct, but that's something we're imminently going to delete.
A short survey of curious test changes:
* free-intrinsics.ll: we don't need to test that debug-info is a zero
cost intrinsic, because we won't be using intrinsics in the future.
* undef-dbg-val.ll: apparently we pinned this to non-RemoveDIs in-memory
mode while we sorted something out; it works now either way.
* salvage-cast-debug-info.ll: was testing intrinsics-in-memory get
salvaged, isn't necessary now
* localize-constexpr-debuginfo.ll: was producing "dead metadata"
intrinsics for optimised-out variable values, dbg-records takes the
(correct) representation of poison/undef as an operand. Looks like we
didn't update this in the past to avoid spurious test differences.
* Transforms/Scalarizer/dbginfo.ll: this test was explicitly testing
that debug-info affected codegen, and we deferred updating the tests
until now. This is just one of those silent gnochange issues that get
fixed by RemoveDIs.
Finally: I've added a bitcode test, dbg-intrinsics-autoupgrade.ll.bc,
that checks we can autoupgrade debug intrinsics that are in bitcode into
the new debug records.
2025-04-01 14:27:11 +01:00
|
|
|
ScopedDbgInfoFormatSetter FormatSetter(F, UseNewDbgInfoFormat);
|
2023-11-09 16:00:21 +00:00
|
|
|
|
2022-11-18 01:47:56 +00:00
|
|
|
if (isFunctionInPrintList(F.getName())) {
|
|
|
|
if (forcePrintModuleIR())
|
|
|
|
OS << Banner << " (function: " << F.getName() << ")\n"
|
|
|
|
<< *F.getParent();
|
|
|
|
else
|
|
|
|
OS << Banner << '\n' << static_cast<Value &>(F);
|
|
|
|
}
|
2023-11-09 16:00:21 +00:00
|
|
|
|
2014-01-12 11:16:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2014-01-12 11:16:01 +00:00
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2017-03-10 07:09:20 +00:00
|
|
|
|
2017-08-25 12:38:53 +00:00
|
|
|
StringRef getPassName() const override { return "Print Function IR"; }
|
2014-01-12 11:16:01 +00:00
|
|
|
};
|
|
|
|
|
2022-11-18 01:47:56 +00:00
|
|
|
} // namespace
|
2008-10-21 23:33:38 +00:00
|
|
|
|
2014-01-12 12:15:39 +00:00
|
|
|
char PrintModulePassWrapper::ID = 0;
|
|
|
|
INITIALIZE_PASS(PrintModulePassWrapper, "print-module",
|
2018-07-11 23:30:25 +00:00
|
|
|
"Print module to stderr", false, true)
|
2014-01-12 12:15:39 +00:00
|
|
|
char PrintFunctionPassWrapper::ID = 0;
|
|
|
|
INITIALIZE_PASS(PrintFunctionPassWrapper, "print-function",
|
2018-07-11 23:30:25 +00:00
|
|
|
"Print function to stderr", false, true)
|
2008-10-21 23:33:38 +00:00
|
|
|
|
2014-01-12 11:30:46 +00:00
|
|
|
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS,
|
2015-04-15 02:38:06 +00:00
|
|
|
const std::string &Banner,
|
|
|
|
bool ShouldPreserveUseListOrder) {
|
|
|
|
return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder);
|
2008-10-21 23:33:38 +00:00
|
|
|
}
|
|
|
|
|
2014-01-12 11:30:46 +00:00
|
|
|
FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
|
|
|
|
const std::string &Banner) {
|
2014-01-12 12:15:39 +00:00
|
|
|
return new PrintFunctionPassWrapper(OS, Banner);
|
2008-10-21 23:33:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 00:29:27 +00:00
|
|
|
bool llvm::isIRPrintingPass(Pass *P) {
|
2022-11-18 01:47:56 +00:00
|
|
|
const char *PID = (const char *)P->getPassID();
|
2018-05-15 00:29:27 +00:00
|
|
|
|
2019-10-30 11:19:06 -07:00
|
|
|
return (PID == &PrintModulePassWrapper::ID) ||
|
|
|
|
(PID == &PrintFunctionPassWrapper::ID);
|
2018-05-15 00:29:27 +00:00
|
|
|
}
|