[cfe-dev] [llvm-dev] [PATCH/DRAFT] Embed metadata into object file

Christian Dietrich via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 6 03:35:17 PDT 2016


Mehdi Amini <mehdi.amini at apple.com> writes:

> Yes, I meant conceptually it is the same as debug info, so it makes
> sense to solve it the same way (i.e. metadata + backend support for
> codegen).

Ah ok, I thought you were suggesting to use the debugging
infrastructure.

Ok, then there are several directions this effort could go:

- The current patch is usable for others in its current form.
  (Transporting only strings)
- A more elaborated and diverse metadata storage format is useful. When
  thinking about that, something like:

  !llvm.extra_sections = {!0, !1, !2}
  !0 = !StringSection(section=!"clang.strings", data=!"My Analysis Backend")
  !1 = !MetadataSection(section=!"clang.metadata", data=!4)
  !2 = !JSONSection(section=!"clang.json", data=!4)

  !4 = !{!"fooo", i32 123, i8 255, !5}
  !5 = !{!"Barfoo"}


  In this fictive example,
    - clang.strings would be a metadata string section, and the most
      flexible possibility.
    - clang.metadata would contain a materialized bitcode stream which
      contains only metadata referenced by !4
    - clang.json would contain a json string, derived from !4

  Would this would only be the LLVM side. How would the path from
  AST->IR look like. For !StringSection, I already drafted a
  possibility.
  
  For !MetadataSection, and JSONSection, it would be necessary to attach
  more complex structures to the AST. I currently don't know how we
  could attach these structures.  An attribute with a Metadata * just
  feels bad, since it mixes LLVM and clang types.

- The third possibility is: This is all bullshit and is not needed for LLVM.

> The FrontendAction is totally separated from the LLVM-pass, but I
> don’t see why your plugin can’t contain both.
>
> To load an LLVM pass into the pipeline, see what Polly is doing for
> instance: http://polly.llvm.org/example_load_Polly_into_clang.html

After looking in the code, I realized that it is possible to register
passes by llvm::RegisterStandardPasses, which in executed on plugin
load. I was not aware of this possibility. Thank you very much :-)
Perhaps it would be nice to have an clang plugin example that contains
as well an FrontentAction, and a associated LLVM pass to demonstrate
this possibility?

chris
-- 
Christian Dietrich, M.Sc. (Wissenschaftlicher Mitarbeiter)
Lehrstuhl für Informatik 4 (Verteilte Systeme und Betriebssysteme)
Friedrich-Alexander-Universität Erlangen-Nürnberg
Martensstr. 1
91058 Erlangen

Tel:    (09131) 85-27280
Fax:    (09131) 85-28732
eMail:  christian.dietrich at fau.de
WWW:    http://www4.cs.fau.de/~dietrich



More information about the cfe-dev mailing list