[llvm-dev] Modified LLVM IR

Sandeep Kumar Singh via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 9 01:34:23 PST 2016


Hi,

I want to edit LLVM generated IR file, like as given below,

Original LLVM IR file,
@.str2 = private unnamed_addr constant [17 x i8] c"\0AI am in
one_11\0A\00", align 1

; Function Attrs: nounwind
define i32 @one_1(i32 %ivar1, i32 %ivar2) #0 {
entry:
  %ivar1.addr = alloca i32, align 4
  %ivar2.addr = alloca i32, align 4
  %isum = alloca i32, align 4
  store i32 %ivar1, i32* %ivar1.addr, align 4
  store i32 %ivar2, i32* %ivar2.addr, align 4
  store i32 0, i32* %isum, align 4
  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([16 x
i8]* @.str, i32 0, i32 0)) #1
  %0 = load i32* %ivar1.addr, align 4
  %1 = load i32* %ivar2.addr, align 4
  %call1 = call i32 @one_11(i32 %0, i32 %1)
  store i32 %call1, i32* %isum, align 4
  %2 = load i32* %isum, align 4
  ret i32 %2
}

Modified LLVM IR file,
@.str2 = private unnamed_addr constant [17 x i8] c"\0AI am in
one_11\0A\00", align 1
@.str3 = private unnamed_addr constant [17 x i8] c"\0AI am in
one_12\0A\00", align 1

; Function Attrs: nounwind
define i32 @one_1(i32 %ivar1, i32 %ivar2) #0 {
entry:
  %ivar1.addr = alloca i32, align 4
  %ivar2.addr = alloca i32, align 4
  %isum = alloca i32, align 4
  store i32 %ivar1, i32* %ivar1.addr, align 4
  store i32 %ivar2, i32* %ivar2.addr, align 4
  store i32 0, i32* %isum, align 4
  %call1 = call i32 @one_12(i32 %0, i32 %1) <==
  store i32 %call1, i32* %isum, align       <==
  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([16 x
i8]* @.str, i32 0, i32 0)) #1
  %0 = load i32* %ivar1.addr, align 4
  %1 = load i32* %ivar2.addr, align 4
  %call2 = call i32 @one_11(i32 %0, i32 %1) <==
  store i32 %call2, i32* %isum, align 4     <==
  %2 = load i32* %isum, align 4
  ret i32 %2
}

With llc tool, I want to generate object file for modified llvm ir file and
it should call function
first "one_12"" and then function "one_11".

Can someone please tell me how I can do my above requirement.

Thanks in advance,
Deepika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160209/c6b38027/attachment.html>


More information about the llvm-dev mailing list