Skip to content

Compiler Implementation

Brandon Holt edited this page Apr 15, 2013 · 10 revisions

Implementation possibilities

Built-in annotate attribute

In Doug Gregor's Extending Clang presentation, he talks about two different ways to do attributes.

Your annotation is just a string argument passed to annotate:

    int foo __attribute__((annotate("grappa_global")));

Build your own

It seems fairly supported to hack a new attribute into Clang. This is a bit more work, but more robust since I think it should allow you to restrict what kinds of things it can be put on (i.e. only declarations of pointers).

  • Problem with this approach is you do have to make changes to Clang source code, but hopefully in a limited number of places.
  • Clang does allow new attributes to be added, but it doesn't do anything to make sure these annotations are preserved all the way to IR generation
  • So, will use the changes to Clang Adrian had to add for EnerC.

Status of Clang/LLVM Extensions

  • Working with Adrian to refactor things so we can share most of the annotation code he's written
  • Ported the EnerC stuff from LLVM-2.9 to LLVM-3.2 (and its associated version of Clang), which is now in a private GitHub repo.
  • Mostly working "global" qualifier using the qual() attribute, with simple "type checking" implemented.
  • Current Limitations
    • can't differentiate function overloading based on attributes (not a big deal)
    • can't differentiate between putting global on the type or the pointer (or one of a couple levels of pointer). Yet to see if this will be a problem
      • For instance: int global * x === global int * x.

Instructions for running

Clang type checker

# (from cmake directory)
bin/Debug/clang -Xclang -load -Xclang lib/Debug/libGrappaTypeChecker.dylib -Xclang -add-plugin -Xclang grappa-type-checker -I ../../tools/clang/enerc/checkers/grappa ../../tools/clang/enerc/test/grappa/basic.cpp

Clone this wiki locally