IR: Expose ModuleSlotTracker in Value::print()

Allow callers of `Value::print()` and `Metadata::print()` to pass in a
`ModuleSlotTracker`.  This allows them to pay only once for calculating
module-level slots (such as Metadata).

This is related to PR23865, where there was a huge cost for
`MachineFunction::print()`.  Although I don't have a *particular* user
in mind for this new code, I have hit big slowdowns before when running
`opt -debug`, and I think this will be useful.  Going forward, if
someone hits a big slowdown with `print()` statements, they can create a
`ModuleSlotTracker` and send it through.  Similarly, adding support to
`Value::dump()` and `Metadata::dump()` should be trivial.

I added unit tests to be sure the `print()` functions actually behave
the same way with and without the slot tracker.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240867 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-06-27 00:38:26 +00:00
parent e92934e078
commit 2a5fda92b4
5 changed files with 118 additions and 10 deletions

View File

@@ -16,6 +16,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
@@ -356,6 +357,10 @@ TEST_F(MDNodeTest, PrintFromFunction) {
EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M));
EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M));
ModuleSlotTracker MST(&M);
EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, MST));
EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, MST));
}
TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
@@ -384,6 +389,14 @@ TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false));
EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true));
EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true));
ModuleSlotTracker MST(&M);
EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS, MST));
EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS, MST));
EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false, MST));
EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false, MST));
EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true, MST));
EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true, MST));
}
#undef EXPECT_PRINTER_EQ