[cfe-users] How to get llvm Location of Used Variables

Bella V via cfe-users cfe-users at lists.llvm.org
Tue Feb 23 23:40:31 PST 2021


Hello LLVM Experts,
Please ignore the last email. I'm trying to get the location of used
variables inside the function pass.

For example:

*Symbol a = [4, 4, 6] linesSymbol b= [5, 5, 7] lines*

*C code:*
void bar() {
    int a = 10;   //line 2
    int b = 20;   //line 3
    a = a + 5;    //line 4
    b = b + 1;   //line 5
    a++;           //line 6
    b--;            //line 7
}

*LLVM IR:*
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  call void @llvm.dbg.declare(metadata i32* %a, metadata !10, metadata
!DIExpression()), !dbg !12
  store i32 10, i32* %a, align 4, !dbg !12
  call void @llvm.dbg.declare(metadata i32* %b, metadata !13, metadata
!DIExpression()), !dbg !14
  store i32 20, i32* %b, align 4, !dbg !14

  %0 = load i32, i32* *%a*, align 4, !dbg !15
  %add = add nsw i32 %0, 5, !dbg !16
  store i32 %add, i32* *%a*, align 4, !dbg !17
  %1 = load i32, i32* *%b*, align 4, !dbg !18
  %add1 = add nsw i32 %1, 1, !dbg !19
  store i32 %add1, i32* *%b*, align 4, !dbg !20
  %2 = load i32, i32* *%a*, align 4, !dbg !21
  %inc = add nsw i32 %2, 1, !dbg !21
  store i32 %inc, i32* *%a*, align 4, !dbg !21
  %3 = load i32, i32* *%b*, align 4, !dbg !22
  %dec = add nsw i32 %3, -1, !dbg !22
  store i32 %dec, i32* *%b*, align 4, !dbg !22
  ret void, !dbg !23
}
!10 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 2, type: !11)
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!12 = !DILocation(line: 2, column: 7, scope: !7)
!13 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 3, type: !11)
!14 = !DILocation(line: 3, column: 7, scope: !7)
!15 = !DILocation(line: 4, column: 7, scope: !7)
!16 = !DILocation(line: 4, column: 9, scope: !7)
!17 = !DILocation(line: 4, column: 5, scope: !7)
!18 = !DILocation(line: 5, column: 7, scope: !7)
!19 = !DILocation(line: 5, column: 9, scope: !7)
!20 = !DILocation(line: 5, column: 5, scope: !7)
!21 = !DILocation(line: 6, column: 4, scope: !7)
!22 = !DILocation(line: 7, column: 4, scope: !7)
!23 = !DILocation(line: 8, column: 2, scope: !7)


Thanks and Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20210223/cd3fd358/attachment.html>


More information about the cfe-users mailing list