<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Hi Alberto,<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">On 2/11/20 6:40 PM, Alberto Barbaro
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CA+W2qAjcE_SxThJxuMn-cPAKfGhdwt=nOyqpN4cEcHrE7b+vyg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">Hi Roland,
        <div dir="auto">Yes you are right, that's the proper class name.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Atm the goal for me is just to print all the
          instructions that are executed In the LLVM IR firm if
          possible.</div>
      </div>
    </blockquote>
    <br>
    The LLVMBitcodeInstructionVisitor is used just for parsing the
    bitcode. For runtime instrumentation, there is the Truffle
    instrumentation framework that might be better suited for what
    you're trying to do:<br>
<a class="moz-txt-link-freetext" href="https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/">https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/</a><br>
    <br>
    We already have a few instruments that you might find useful, either
    for using directly, or for building on top of them.<br>
    <br>
    You can already get a trace of all executed bitcode instructions:<br>
    <blockquote type="cite">$ llvm-dis hello.bc<br>
      $ lli --experimental-options --llvm.llDebug --llvm.traceIR
      hello.bc<br>
      [lli] &gt;&gt; Entering function @main at hello.ll:9:1 with
      arguments:[StackPointer 0x7f62b3fff010 (Bounds: 0x7f62aefff010 -
      0x7f62b3fff010), 1, 0x55ad10a8ba48, 0x55ad10a8ba58]<br>
      [lli] &gt;&gt; hello.ll:10:1 -&gt;   %1 = alloca i32, align 4<br>
      [lli] &gt;&gt; hello.ll:11:1 -&gt;   store i32 0, i32* %1, align 4<br>
      [lli] &gt;&gt; hello.ll:12:1 -&gt;   %2 = call i32 (i8*, ...)
      @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str,
      i32 0, i32 0)), !dbg !13<br>
      Hello, World!<br>
      [lli] &gt;&gt; hello.ll:13:1 -&gt;   ret i32 0, !dbg !14<br>
      [lli] &gt;&gt; Leaving @main<br>
    </blockquote>
    <br>
    The code for that is mainly in the classes LLVMTracerInstrument and
    LLVMTraceNodeFactory. That might be an easier entry point for what
    you're trying to do.<br>
    <br>
    <br>
    <br>
    We also have a code coverage tool:<br>
    <a class="moz-txt-link-freetext" href="https://www.graalvm.org/docs/reference-manual/tools/#code-coverage">https://www.graalvm.org/docs/reference-manual/tools/#code-coverage</a><br>
<a class="moz-txt-link-freetext" href="https://github.com/oracle/graal/tree/master/tools/src/com.oracle.truffle.tools.coverage/src/com/oracle/truffle/tools/coverage">https://github.com/oracle/graal/tree/master/tools/src/com.oracle.truffle.tools.coverage/src/com/oracle/truffle/tools/coverage</a><br>
    <br>
    If you run it with regular "lli --coverage ...", you'll get C code
    covarage, but you can combine that with the "--llvm.llDebug" option
    to get bitcode coverage, too (see below for example output).<br>
    <br>
    <br>
    I hope this helps,<br>
    Roland<br>
    <br>
    <br>
    <br>
    <blockquote type="cite">$ lli --coverage --coverage.Output=detailed
      --experimental-options --llvm.llDebug hello.bc<br>
      Hello, World!<br>
------------------------------------------------------------------------------------------<br>
      Code coverage per line of code and what percent of each element
      was covered during execution (per source)<br>
        + indicates the line is covered during execution<br>
        - indicates the line is not covered during execution<br>
        p indicates the line is part of a statement that was
      incidentally covered during execution<br>
          e.g. a not-taken branch of a covered if statement<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       /home/roland/test/hello/hello.ll                     |    
      100.00% |  100.00% |  100.00%<br>
      <br>
        ; ModuleID = 'hello.bc'<br>
        source_filename = "hello.c"<br>
        target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
        target triple = "x86_64-pc-linux-gnu"<br>
      <br>
        @.str = private unnamed_addr constant [15 x i8] c"Hello,
      World!\0A\00", align 1<br>
      <br>
        ; Function Attrs: noinline nounwind optnone sspstrong uwtable<br>
        define dso_local i32 @main() #0 !dbg !9 {<br>
      +   %1 = alloca i32, align 4<br>
      +   store i32 0, i32* %1, align 4<br>
      +   %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds
      ([15 x i8], [15 x i8]* @.str, i32 0, i32 0)), !dbg !13<br>
      +   ret i32 0, !dbg !14<br>
        }<br>
      <br>
        declare i32 @printf(i8*, ...) #1<br>
      <br>
        attributes #0 = { noinline nounwind optnone sspstrong uwtable
      "correctly-rounded-divide-sqrt-fp-math"="false"
      "disable-tail-calls"="false" "less-precise-fpmad"="false"
      "min-legal-vector-width"="0" "no-frame-pointer-elim"="true"
      "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
      "no-jump-tables"="false" "no-nans-fp-math"="false"
      "no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
      "stack-protector-buffer-size"="8" "target-cpu"="x86-64"
      "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
      "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
        attributes #1 = {
      "correctly-rounded-divide-sqrt-fp-math"="false"
      "disable-tail-calls"="false" "less-precise-fpmad"="false"
      "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
      "no-infs-fp-math"="false" "no-nans-fp-math"="false"
      "no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
      "stack-protector-buffer-size"="8" "target-cpu"="x86-64"
      "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
      "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
      <br>
        !llvm.dbg.cu = !{!0}<br>
        !llvm.module.flags = !{!3, !4, !5, !6, !7}<br>
        !llvm.ident = !{!8}<br>
      <br>
        !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1,
      producer: "clang version 8.0.1 (tags/RELEASE_801/final)",
      isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug,
      enums: !2, nameTableKind: None)<br>
        !1 = !DIFile(filename: "hello.c", directory:
      "/home/roland/test/hello")<br>
        !2 = !{}<br>
        !3 = !{i32 2, !"Dwarf Version", i32 4}<br>
        !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
        !5 = !{i32 1, !"wchar_size", i32 4}<br>
        !6 = !{i32 7, !"PIC Level", i32 2}<br>
        !7 = !{i32 7, !"PIE Level", i32 2}<br>
        !8 = !{!"clang version 8.0.1 (tags/RELEASE_801/final)"}<br>
        !9 = distinct !DISubprogram(name: "main", scope: !1, file: !1,
      line: 3, type: !10, scopeLine: 3, spFlags: DISPFlagDefinition,
      unit: !0, retainedNodes: !2)<br>
        !10 = !DISubroutineType(types: !11)<br>
        !11 = !{!12}<br>
        !12 = !DIBasicType(name: "int", size: 32, encoding:
      DW_ATE_signed)<br>
        !13 = !DILocation(line: 4, column: 5, scope: !9)<br>
        !14 = !DILocation(line: 5, column: 5, scope: !9)<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       com.oracle.truffle.llvm.libraries.bitcode/src/crt0.c |    
      100.00% |          |  100.00%<br>
      <br>
      NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       com.oracle.truffle.llvm.libraries.bitcode/src/exit.c |     
      87.50% |          |  100.00%<br>
      <br>
      NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
    </blockquote>
    <br>
    <blockquote type="cite">$ lli --coverage --coverage.Output=detailed
      hello.bc<br>
      Hello, World!<br>
------------------------------------------------------------------------------------------<br>
      Code coverage per line of code and what percent of each element
      was covered during execution (per source)<br>
        + indicates the line is covered during execution<br>
        - indicates the line is not covered during execution<br>
        p indicates the line is part of a statement that was
      incidentally covered during execution<br>
          e.g. a not-taken branch of a covered if statement<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       /home/roland/test/hello/hello.c                      |    
      100.00% |  100.00% |  100.00%<br>
      <br>
        #include &lt;stdio.h&gt;<br>
      <br>
        int main() {<br>
      +     printf("Hello, World!\n");<br>
      +     return 0;<br>
        }<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       com.oracle.truffle.llvm.libraries.bitcode/src/crt0.c |    
      100.00% |          |  100.00%<br>
      <br>
      NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
       Path                                                 | 
      Statements |    Lines |    Roots<br>
       com.oracle.truffle.llvm.libraries.bitcode/src/exit.c |     
      87.50% |          |  100.00%<br>
      <br>
      NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
    </blockquote>
    <br>
    <br>
    <blockquote type="cite"
cite="mid:CA+W2qAjcE_SxThJxuMn-cPAKfGhdwt=nOyqpN4cEcHrE7b+vyg@mail.gmail.com">
      <div dir="auto">
        <div dir="auto"><br>
        </div>
        <div dir="auto">If all goes well I'd like to work on a code
          coverage tool for the bitcode.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Thanks</div>
        <div dir="auto">Alberto</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Tue, Feb 11, 2020, 16:02
          Roland Schatz &lt;<a href="mailto:roland.schatz@oracle.com"
            moz-do-not-send="true">roland.schatz@oracle.com</a>&gt;
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div>
            <div>Hi Alberto!<br>
              <br>
              I assume you mean the LLVMBitcodeInstructionVisitor class,
              right? This class is part of the internal implementation
              of the LLVM runtime in GraalVM, and not meant to be
              extended or used outside of the LLVM runtime. This is not
              meant as API, we might change that class without notice,
              even in minor releases.<br>
              <br>
              What are you trying to achieve by subclassing it?<br>
              <br>
              - Roland<br>
              <br>
              On 2/11/20 4:31 PM, Alberto Barbaro wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="auto">Hi all,
                <div dir="auto">I've just started to use graalvm and
                  I've noticed that the LLVMBitcodeVisitor class is
                  market as final. I'd like to create my own visitor
                  extending it... So I was wondering if there is a
                  better approach rather then modifying a bit the source
                  code. How would you recommend to do it?</div>
                <div dir="auto"><br>
                </div>
                <div dir="auto">Thanks</div>
                <div dir="auto">Alberto</div>
              </div>
              <br>
              <fieldset></fieldset>
              <pre>_______________________________________________
GraalVM-Users mailing list
<a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" rel="noreferrer" moz-do-not-send="true">GraalVM-Users@oss.oracle.com</a>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" target="_blank" rel="noreferrer" moz-do-not-send="true">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></pre>
            </blockquote>
            <p><br>
            </p>
          </div>
          _______________________________________________<br>
          GraalVM-Users mailing list<br>
          <a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank"
            rel="noreferrer" moz-do-not-send="true">GraalVM-Users@oss.oracle.com</a><br>
          <a
            href="https://oss.oracle.com/mailman/listinfo/graalvm-users"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></blockquote>
      </div>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>