llvm-6502/include/llvm/IR
Duncan P. N. Exon Smith dad20b2ae2 IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532.  Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.

I have a follow-up patch prepared for `clang`.  If this breaks other
sub-projects, I apologize in advance :(.  Help me compile it on Darwin
I'll try to fix it.  FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.

This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.

Here's a quick guide for updating your code:

  - `Metadata` is the root of a class hierarchy with three main classes:
    `MDNode`, `MDString`, and `ValueAsMetadata`.  It is distinct from
    the `Value` class hierarchy.  It is typeless -- i.e., instances do
    *not* have a `Type`.

  - `MDNode`'s operands are all `Metadata *` (instead of `Value *`).

  - `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
    replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.

    If you're referring solely to resolved `MDNode`s -- post graph
    construction -- just use `MDNode*`.

  - `MDNode` (and the rest of `Metadata`) have only limited support for
    `replaceAllUsesWith()`.

    As long as an `MDNode` is pointing at a forward declaration -- the
    result of `MDNode::getTemporary()` -- it maintains a side map of its
    uses and can RAUW itself.  Once the forward declarations are fully
    resolved RAUW support is dropped on the ground.  This means that
    uniquing collisions on changing operands cause nodes to become
    "distinct".  (This already happened fairly commonly, whenever an
    operand went to null.)

    If you're constructing complex (non self-reference) `MDNode` cycles,
    you need to call `MDNode::resolveCycles()` on each node (or on a
    top-level node that somehow references all of the nodes).  Also,
    don't do that.  Metadata cycles (and the RAUW machinery needed to
    construct them) are expensive.

  - An `MDNode` can only refer to a `Constant` through a bridge called
    `ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).

    As a side effect, accessing an operand of an `MDNode` that is known
    to be, e.g., `ConstantInt`, takes three steps: first, cast from
    `Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
    third, cast down to `ConstantInt`.

    The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
    metadata schema owners transition away from using `Constant`s when
    the type isn't important (and they don't care about referring to
    `GlobalValue`s).

    In the meantime, I've added transitional API to the `mdconst`
    namespace that matches semantics with the old code, in order to
    avoid adding the error-prone three-step equivalent to every call
    site.  If your old code was:

        MDNode *N = foo();
        bar(isa             <ConstantInt>(N->getOperand(0)));
        baz(cast            <ConstantInt>(N->getOperand(1)));
        bak(cast_or_null    <ConstantInt>(N->getOperand(2)));
        bat(dyn_cast        <ConstantInt>(N->getOperand(3)));
        bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));

    you can trivially match its semantics with:

        MDNode *N = foo();
        bar(mdconst::hasa               <ConstantInt>(N->getOperand(0)));
        baz(mdconst::extract            <ConstantInt>(N->getOperand(1)));
        bak(mdconst::extract_or_null    <ConstantInt>(N->getOperand(2)));
        bat(mdconst::dyn_extract        <ConstantInt>(N->getOperand(3)));
        bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));

    and when you transition your metadata schema to `MDInt`:

        MDNode *N = foo();
        bar(isa             <MDInt>(N->getOperand(0)));
        baz(cast            <MDInt>(N->getOperand(1)));
        bak(cast_or_null    <MDInt>(N->getOperand(2)));
        bat(dyn_cast        <MDInt>(N->getOperand(3)));
        bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));

  - A `CallInst` -- specifically, intrinsic instructions -- can refer to
    metadata through a bridge called `MetadataAsValue`.  This is a
    subclass of `Value` where `getType()->isMetadataTy()`.

    `MetadataAsValue` is the *only* class that can legally refer to a
    `LocalAsMetadata`, which is a bridged form of non-`Constant` values
    like `Argument` and `Instruction`.  It can also refer to any other
    `Metadata` subclass.

(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223802 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 18:38:53 +00:00
..
Argument.h Provide convenient access to the zext/sext attributes of function arguments. NFC. 2014-08-05 05:43:41 +00:00
AssemblyAnnotationWriter.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
Attributes.h Revert accidentally committed r217107 2014-09-03 23:38:05 +00:00
AutoUpgrade.h Rename loop unrolling and loop vectorizer metadata to have a common prefix. 2014-06-25 15:41:00 +00:00
BasicBlock.h Move helper for getting a terminating musttail call to BasicBlock 2014-08-12 00:05:15 +00:00
CallingConv.h X86: Implement the vectorcall calling convention 2014-10-28 01:29:26 +00:00
CallSite.h Add a dereferenceable attribute 2014-07-18 15:51:28 +00:00
CFG.h Revert "[C++11] Add predecessors(BasicBlock *) / successors(BasicBlock *) iterator ranges." 2014-07-21 17:06:51 +00:00
CMakeLists.txt [CMake] intrinsics_gen: Use add_public_tablegen_target(). 2014-02-20 13:42:16 +00:00
Comdat.h IR: Add COMDATs to the IR 2014-06-27 18:19:56 +00:00
Constant.h InstCombine: sub nsw %x, C -> add nsw %x, -C if C isn't INT_MIN 2014-08-22 16:41:23 +00:00
ConstantFolder.h Add CreatePointerBitCastOrAddrSpaceCast to IRBuilder and co. 2014-07-14 17:24:35 +00:00
ConstantRange.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
Constants.h Rename END_WITH_NULL to LLVM_END_WITH_NULL and move to Compiler.h 2014-11-04 01:12:21 +00:00
DataLayout.h AArch64: treat [N x Ty] as a block during procedure calls. 2014-11-27 21:02:42 +00:00
DebugInfo.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
DebugLoc.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
DerivedTypes.h Add params() to FunctionType. NFC. 2014-11-21 19:03:35 +00:00
DiagnosticInfo.h Update the error handling of lib/Linker. 2014-10-25 04:06:10 +00:00
DiagnosticPrinter.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
DIBuilder.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Dominators.h Move operator[] to DomTreeNodeBase 2014-07-02 06:50:48 +00:00
Function.h Prologue support 2014-12-03 02:08:38 +00:00
GetElementPtrTypeIterator.h [C++11] More 'nullptr' conversion or in some cases just using a boolean check instead of comparing to nullptr. 2014-04-09 06:08:46 +00:00
GlobalAlias.h IR: Add COMDATs to the IR 2014-06-27 18:19:56 +00:00
GlobalObject.h Fix broken C++ mode comment 2014-11-05 01:36:22 +00:00
GlobalValue.h Modernize the error handling of the Materialize function. 2014-10-24 22:50:48 +00:00
GlobalVariable.h [pr19844] Add thread local mode to aliases. 2014-05-28 18:15:43 +00:00
GVMaterializer.h Ask the module for its the identified types. 2014-12-03 07:18:23 +00:00
InlineAsm.h Reapply r215966, r215965, r215964, r215963, r215960, r215959, r215958, and r215957 2014-08-19 16:39:58 +00:00
InstIterator.h [Modules] Move InstIterator out of the Support library, where it had no 2014-03-04 10:30:26 +00:00
InstrTypes.h Revert r220349 to re-instate r220277 with a fix for PR21330 -- quite 2014-11-25 08:20:27 +00:00
Instruction.def Add addrspacecast instruction. 2013-11-15 01:34:59 +00:00
Instruction.h Revert "IR: MDNode => Value" 2014-11-11 21:30:22 +00:00
Instructions.h Revert "Move function to obtain branch weights into the BranchInst class. NFC." 2014-12-09 17:32:12 +00:00
InstVisitor.h [Layering] Move InstVisitor.h into the IR library as it is pretty 2014-03-06 03:23:41 +00:00
IntrinsicInst.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Intrinsics.h Masked Load / Store Intrinsics - the CodeGen part. 2014-12-04 09:40:44 +00:00
Intrinsics.td InstrProf: An intrinsic and lowering for instrumentation based profiling 2014-12-08 18:02:35 +00:00
IntrinsicsAArch64.td Port memory barriers intrinsics to AArch64 2014-07-17 10:50:20 +00:00
IntrinsicsARM.td ARM: add @llvm.arm.space intrinsic for testing ConstantIslands. 2014-11-13 17:58:48 +00:00
IntrinsicsHexagon.td
IntrinsicsMips.td [mips][msa] Add DLSA instruction. 2014-02-10 12:05:17 +00:00
IntrinsicsNVVM.td [NVPTX] Make the alignment an explicit argument to ldu/ldg 2014-08-29 15:30:20 +00:00
IntrinsicsPowerPC.td [PowerPC] Add VSX builtins for vec_div 2014-11-14 12:10:40 +00:00
IntrinsicsR600.td R600/SI: Add missing parameter to div_fmas intrinsic 2014-10-21 22:20:55 +00:00
IntrinsicsX86.td [AVX512] Add 512b integer shift by variable intrinsics and patterns. 2014-11-25 20:41:51 +00:00
IntrinsicsXCore.td [XCore] Add intrinsic for CLRPT (clear port time) instruction. 2014-02-25 17:31:15 +00:00
IRBuilder.h Masked Load / Store Intrinsics - the CodeGen part. 2014-12-04 09:40:44 +00:00
IRPrintingPasses.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
LeakDetector.h [Modules] Move the LeakDetector header into the IR library where the 2014-03-04 12:46:06 +00:00
LegacyPassManager.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
LegacyPassManagers.h FunctionPassManager isn't used by the JIT anymore, it is used in 2014-09-10 10:48:06 +00:00
LegacyPassNameParser.h Do not register and de-register PassRegistrationListeners during 2014-06-12 00:16:36 +00:00
LLVMContext.h Introduce enum values for previously defined metadata types. (NFC) 2014-10-21 00:13:20 +00:00
Mangler.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
MDBuilder.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Metadata.def IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Metadata.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
MetadataTracking.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Module.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
NoFolder.h [Modules] Move the NoFolder into the IR library as it creates 2014-03-04 12:05:47 +00:00
OperandTraits.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
Operator.h InstCombine: Don't assume that m_ZExt matches an Instruction 2014-11-01 23:46:05 +00:00
PassManager.h Use range based for loops to avoid needing to re-mention SmallPtrSet size. 2014-08-24 23:23:06 +00:00
PatternMatch.h [CGP] Rewrite pattern match for splitBranchCondition to work with Values instead. 2014-12-09 17:50:10 +00:00
PredIteratorCache.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
Statepoint.h GCRelocateOperands: Try to appease msc17. 2014-12-03 02:40:24 +00:00
SymbolTableListTraits.h [C++11] More 'nullptr' conversion or in some cases just using a boolean check instead of comparing to nullptr. 2014-04-09 06:08:46 +00:00
TrackingMDRef.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Type.h Add and use Type::subtypes. NFC. 2014-11-24 20:44:36 +00:00
TypeBuilder.h #include <climits> instead of <limits.h> in C++ header file. 2013-06-13 23:49:09 +00:00
TypeFinder.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
Use.h Updated the link to the correct URL. 2014-04-29 13:21:05 +00:00
UseListOrder.h verify-uselistorder: Force -preserve-bc-use-list-order 2014-08-19 21:08:27 +00:00
User.h IR: Move NumOperands from User to Value, NFC 2014-10-15 20:39:05 +00:00
Value.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
ValueHandle.h IR: Cleanup comments for Value, User, and MDNode 2014-10-15 20:28:31 +00:00
ValueMap.h IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
ValueSymbolTable.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
Verifier.h verify-di: Implement DebugInfoVerifier 2014-04-15 16:27:38 +00:00