[llvm-dev] How to get variable annotations?

Nisal Menuka via llvm-dev llvm-dev at lists.llvm.org
Sun Oct 1 22:50:39 PDT 2017


Hi,
I want to identify an annotated variable in my function pass. How can
I do this? I was trying to follow this,
https://stackoverflow.com/questions/15114284/llvm-get-annotations, but
my generated IR do not have any global annotations as I can see.

******C code******
#include <stdio.h>
int main (){
int x __attribute__((annotate("my_var")))= 0;
int a,b;
x = x + 1;
a = 5;
b = 6;
x = x + a;

return x;
}

*****IR*****

; ModuleID = 'test.c'
source_filename = "test.c"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"

@.str = private unnamed_addr constant [7 x i8] c"my_var\00", section
"llvm.metadata"
@.str.1 = private unnamed_addr constant [7 x i8] c"test.c\00", section
"llvm.metadata"

; Function Attrs: noinline nounwind optnone
define i32 @main() #0 {
entry:
  %retval = alloca i32, align 4
  %x = alloca i32, align 4
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  store i32 0, i32* %retval, align 4
  %x1 = bitcast i32* %x to i8*
  call void @llvm.var.annotation(i8* %x1, i8* getelementptr inbounds
([7 x i8], [7 x i8]* @.$
  store i32 0, i32* %x, align 4
  %0 = load i32, i32* %x, align 4
  %add = add nsw i32 %0, 1
  store i32 %add, i32* %x, align 4
  store i32 5, i32* %a, align 4
  store i32 6, i32* %b, align 4
  %1 = load i32, i32* %x, align 4
  %2 = load i32, i32* %a, align 4
  %add2 = add nsw i32 %1, %2
  store i32 %add2, i32* %x, align 4
  %3 = load i32, i32* %x, align 4
  ret i32 %3
}

; Function Attrs: nounwind
declare void @llvm.var.annotation(i8*, i8*, i8*, i32) #1

attributes #0 = { noinline nounwind optnone
"correctly-rounded-divide-sqrt-fp-math"="false" $
attributes #1 = { nounwind }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}


Thanks,
Nisal


More information about the llvm-dev mailing list