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)
commitf9f505e626678b90b02e1392b6b88f24dfec7b15
treed2edcfb898d9af1c39dee89b8e2ea04545fcccbd
parentf508adde2efbc454a53daddb718085a975c98ad8
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).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232275 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/Metadata.h
lib/IR/AsmWriter.cpp
lib/IR/Verifier.cpp
unittests/IR/MetadataTest.cpp