new annotations in IR?

With recent work a plugin can now Annotate a VarDecl at the AST level, how can this be used in a Pass at the IR level? What classes are responsible for their manipulation? I assumed it would be part of Value, or something common like it, but I do not see any mentions of Annotation or Attribute.

Thank you

Hi Mark,

I don’t know anything about Clang’s annotations or attributes, but from what you describe it sounds like you want to attach metadata to Values?

Try searching for “metadata” instead, that should get you more results J

Cheers,

James

Close, metadata has already been attached to Clang’s VarDecls. I do not know what this would be in LLVM, my first guess just just Value(since its kind of a goto object for everything I need).

AFAIK, there is no specific code to manipulate annotations. You could
write an analysis pass to process & use them though, that shouldn't
require a lot of work.

How can they processed? I cant seem to find any solid information about how they exist in IR form from a Passes perspective. I see things like @llvm.var.annotation in dumps but no relevant sounding methods to get at these.

Thank you

The llvm.var.annotation and llvm.annotation intrinsics are documented here:
http://llvm.org/docs/LangRef.html#int_var_annotation

I couldn't find any documentation for the llvm.ptr.annotation.*
intrinsics in the language reference, but they follow the same model as
llvm.var.annotation except the first argument is a pointer to the field struct.

The llvm.global.annotation array does't seem to be documented either, but from
clang sources:

  /// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the
  /// annotation information for a given GlobalValue. The annotation struct is
  /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
  /// GlobalValue being annotated. The second field is the constant string
  /// created from the AnnotateAttr's annotation. The third field is a constant
  /// string containing the name of the translation unit. The fourth field is
  /// the line number in the file of the annotated value declaration.

So, you would process those annotations like you would process regular IR
instructions & globals. For e.g., for the intrinsics, you can iterate over all
their uses, and for the global annotation array, iterator over all the operands
of the initializer. Intrinsics processing can be done like this for e.g.:

   Function *F = Mod->getFunction("lvm.var.annotation");
   // Assuming lvm.var.annotation was indeed used in the module
   for (Value::use_iterator u = F->use_begin(), ...) {
      // Do something with u.

Feel free to submit patches for the language reference :wink:

Hope this helps,
Julien