[LLVMdev] RFC: [Proposal] Module-Level Attributes

Bill Wendling wendling at apple.com
Thu Oct 28 17:46:16 PDT 2010


                     Module-Level Attributes


Overview
--------

LLVM currently lacks the ability to specify an attribute on a module as a
whole. This isn't typically a problem as most optimizations and code
transformations rely upon more finer-grained information, such as function
attributes. However, some transformations, in particular LTO, may need to know
information about the module. As a side-benefit, it could be used to reduce the
number of global variables which are currently used only to convey information
to the back-end, linker, et al.

Proposal
--------

Syntax:

   ml-attr ::= 'module' 'attr' NAME ('[' NAME (',' NAME)* ']')?

where the optional list of NAMEs in the square brackets represents sub-attributes
of the main attribute.

Semantics:

Module-level attributes are looked at only by those parts of the compiler which
care about them. Deleting a module attribute may effect code generation. Each module-
level attribute will have its own documented semantics for how it may be used.

Example:

The Objective-C imageinfo section isn't merged correctly for the following.

t.mm:
#import <Foundation/Foundation.h>

NSAutoreleasePool *foo();

int main() {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSAutoreleasePool *pond = foo();
  return 0;
}

f.mm:
#import <Foundation/Foundation.h>

NSAutoreleasePool *foo() {
  return [[NSAutoreleasePool alloc] init];
}

$ llvm-g++ -fobjc-gc t.mm -c -flto
$ llvm-g++ -fno-objc-gc f.mm -c -flto
$ llvm-g++ t.o f.o -flto -framework Foundation
ld: warning: section __DATA/__objc_imageinfo__DATA has unexpectedly large size 16 in /tmp/lto.o
$

In this example, LTO is concatenating the imageinfo sections instead of
performing a proper merge.

Here are the LLVM global variables that contain the imageinfo information.

-fno-objc-gc:
@OBJC_IMAGE_INFO = private constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"

-fobjc-gc-only:
@OBJC_IMAGE_INFO = private constant [2 x i32] [i32 0, i32 22], section "__DATA, __objc_imageinfo, regular, no_dead_strip"

With module-level attributes, these global variables wouldn't exist. Instead,
they would be replaced by something like this:

-fno-objc-gc:
module attr ImageInfo [CorrectedSynthesize]

-fobjc-gc-only:
module attr ImageInfo [CorrectedSynthesize, GCOnly]

LTO would see that the module attributes are incompatible and will reject trying
to link the two modules.

Comments?

-bw

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101028/7a8ff71e/attachment.html>


More information about the llvm-dev mailing list