IR: Make Metadata::print() reliable and useful
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 14 Mar 2015 20:19:36 +0000 (20:19 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 14 Mar 2015 20:19:36 +0000 (20:19 +0000)
commitd6d70e753dd6061d5796937b1e05fbe54f4692f8
treeda5e5b5de4f1d6aad38b138b36e6b5ce049e7a84
parent096b1da29d21cda6c8950e477010777019ed0e88
IR: Make Metadata::print() reliable and useful

Replumb the `AsmWriter` so that `Metadata::print()` is generally useful.
(Similarly change `Metadata::printAsOperand()`.)

- `SlotTracker` now has a mode where all metadata will be correctly
  numbered when initializing a `Module`.  Normally, `Metadata` only
  referenced from within `Function`s gets numbered when the `Function`
  is incorporated.
- `Metadata::print()` and `Metadata::printAsOperand()` (and
  `Metadata::dump()`) now take an optional `Module` argument.  When
  provided, `SlotTracker` is initialized with the new mode, and the
  numbering will be complete and consistent for all calls to `print()`.
- `Value::print()` uses the new `SlotTracker` mode when printing
  intrinsics with `MDNode` operands, `MetadataAsValue` operands, or the
  bodies of functions.  Thus, metadata numbering will be consistent
  between calls to `Metadata::print()` and `Value::print()`.
- `Metadata::print()` (and `Metadata::dump()`) now print the full
  definition of `MDNode`s:

    !5 = !{!6, !"abc", !7}

  This matches behaviour for `Value::print()`, which includes the name
  of instructions.
- Updated call sites in `Verifier` to call `print()` instead of
  `printAsOperand()`.

All this, so that `Verifier` can print out useful failure messages that
involve `Metadata` for PR22777.

Note that `Metadata::printAsOperand()` previously took an optional
`bool` and `Module` operand.  The former was cargo-culted from
`Value::printAsOperand()` and wasn't doing anything useful.  The latter
didn't give consistent results (without the new `SlotTracker` mode).

llvm-svn: 232275
llvm/include/llvm/IR/Metadata.h
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/Verifier.cpp
llvm/unittests/IR/MetadataTest.cpp