[llvm-dev] Inserting instructions when encountered a specific label
Kaarthik Alagapan via llvm-dev
llvm-dev at lists.llvm.org
Wed Oct 23 11:37:08 PDT 2019
Hello,
I’m trying to insert an instruction if a specific label name/string is encountered and would appreciate some guidance on where I should start. Basically when parsing going through this .ll file:
; Function Attrs: noinline nounwind optnone uwtable
define i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i32, align 4
%7 = alloca i32, align 4
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
store i32 2, i32* %6, align 4
store i32 3, i32* %7, align 4
%8 = load i32, i32* %6, align 4
%9 = load i32, i32* %7, align 4
%10 = icmp slt i32 %8, %9
sbr i1 %10, label %true, label %false
true:
%true1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0))
br label %end
false:
%false1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0))
br label %end
end:
%end1 = load i32, i32* %3, align 4
ret i32 %end1
}
I want to insert a new instruction when I encounter the true, false, and end labels (inside their respective blocks). I tried to detect the label names using " I.printAsOperand(errs(), false);” when parsing the instructions in SelectionDAGBuilder but it was only visiting instructions in the first/main BB and outputted %2. Which pass or phase would be the best to see if the current block’s label matches “true”, “false”, or “end” and insert an instruction inside that block?
Thank you,
Kaarthik A.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191023/25dfe8d6/attachment.html>
More information about the llvm-dev
mailing list