[PATCH] IR: Move the slot tracker out of AsmWriter into a separate public module.

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Jun 17 13:52:58 PDT 2015


> On 2015 Jun 17, at 13:20, Alex Lorenz <arphaman at gmail.com> wrote:
> 
> Hi dexonsmith, bob.wilson, bogner,
> 
> This patch moves the SlotTracker class out of AsmWriter.cpp into a separate module that's publicly accessible.
> 
> This patch would be useful for MIR Serialization, in particular it would enable the MIR parser to parse metadata machine operands. The metadata machine operands are serialized using the familiar '!' <slot> notation, and the MIR parser has to be able to map from slot numbers to the actual metadata nodes. The SlotTracker class would allow the MIRParser to create this mapping.

I can see that this would be useful for *writing* .mir files, but I
don't think you can safely use this for *reading* .mir files.

Metadata slots can be assigned arbitrarily in an LLVM IR file, such as:

    !named = !{!36, !72}
    !72 = !{!"string"}}
    !36 = !{!72, !{!{}}}

If you were to parse the module and then run the slot tracker, you'd get:

    !named = !{!1, !2}
    !1 = !{!2, !3}
    !2 = !{!"string"}
    !3 = !{!4}
    !4 = !{}

or something close to that.

You couldn't safely take an already-parsed Module, run the slot-tracker
on it, and then parse machine functions that referenced metadata.  But
it sounds like that's what you're suggesting?

Instead, I think you need to:

 1. Yes, surface the slot tracker (exactly this patch), but for completely
    different reasons:  so that you can write out correct metadata numbers
    for metadata references within machine functions, to match the metadata
    that you wrote out for the LLVM IR.
 2. Use (1) so that the same slots are used when writing LLVM IR portion of
    MIR as the machine functions.
 3. Find a way to surface `LLParser::NumberedMetadata` in a similar way
    (could be some way of copying them out?) when parsing the LLVM IR part
    of MIR.
 4. Use that slot mapping when you're reading machine functions.

Also, I'm not sure this just affects metadata.  What about llvm::Type?
llvm::GlobalValue?  (Maybe their numbered slots are more strictly organized
so they're okay, but I'm not sure.)

Does this make sense?

> 
> REPOSITORY
>  rL LLVM
> 
> http://reviews.llvm.org/D10517
> 
> Files:
>  include/llvm/IR/SlotTracker.h
>  lib/IR/AsmWriter.cpp
>  lib/IR/CMakeLists.txt
>  lib/IR/SlotTracker.cpp
> 
> EMAIL PREFERENCES
>  http://reviews.llvm.org/settings/panel/emailpreferences/
> <D10517.27862.patch>





More information about the llvm-commits mailing list