[LLVMdev] Helping the optimizer along (__assume)

Devang Patel dpatel at apple.com
Wed Oct 22 17:31:53 PDT 2008


On Oct 22, 2008, at 3:28 PM, Paul Biggar wrote:

> Hi,
>
> I'm interested in whether or not there is a way of providing
> source-level annotations to help LLVM with optimizations, similar to
> VisualC++'s __assume facility
> (http://msdn.microsoft.com/en-us/library/1b3fsfxw.aspx).

There is a way to provide source level annotations.

int * foo (int *x __attribute((annotate("I_say_not_null"))))
{
	return x;
}

llvm-gcc will produce following IR

@.str = internal constant [9 x i8] c"/tmp/a.c\00", section  
"llvm.metadata"	; <[9 x i8]*> [#uses=1]
@"\01LC" = internal constant [15 x i8] c"I_say_not_null\00"		; <[15 x  
i8]*> [#uses=1]

define i32* @foo(i32* %x) nounwind {
entry:
	%x_addr = alloca i32*		; <i32**> [#uses=1]
	%x_addr1 = bitcast i32** %x_addr to i8*		; <i8*> [#uses=1]
	call void @llvm.var.annotation(i8* %x_addr1, i8* getelementptr ([15 x  
i8]* @"\01LC", i32 0, i32 0), i8* getelementptr ([9 x i8]* @.str, i32  
0, i32 0), i32 1)
	ret i32* %x
}

However, this mechanism (or other alternative approaches suggested by  
others) has not been extended to communicate annotated information  
meaning to LLVM optimization passes.

-
Devang

>
>
> As part of our PHP compiler (phpcompiler.org), it would be great to be
> able to annotate our generated C code with, for example, (var !=
> NULL), or (var->type == STRING), and have that information passed
> around (esp interprocedurally at link-time) by the LLVM optimizers. It
> would also greatly simplify our code generation.
>
> I can provide a detailed example if what I'm asking is unclear...
>
>
> Thanks in advance,
> Paul
> phpcompiler.org
>
> -- 
> Paul Biggar
> paul.biggar at gmail.com
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-
Devang






More information about the llvm-dev mailing list