title: How to get all Global Variables referenced by instruction in LLVM?
body: <p>In the example bellow, I am trying to extract all the global variables referenced by each instruction, but I keep missing some of them.</p>
  
  <pre><code>... // inside a BB
  for (Instruction * I : BB) {
    for (Use &amp;U : I-&gt;operands()) {
      if(GlobalVariable * GV = dyn_cast&lt;GlobalVariable &gt;(U)){
        // Do something with GV
        GV-&gt;dump();
      }
    }
  }
  </code></pre>
  
  <p>But when I am targeting getting the global values of:</p>
  
  <pre><code>@end = global i8 0, align 1
  @.str = private unnamed_addr constant [4 x i8] c"YES\00", align 1
  @.str.2 = private unnamed_addr constant [3 x i8] c"NO\00", align 1
  
  define void @TempF() {
  entry:
    %tmp8 = load i8, i8* @end, align 1
    %tmp9 = trunc i8 %tmp8 to i1
    %tmp10 = select i1 %tmp9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)
    ret void
  }
  </code></pre>
  
  <p>When running my pass on this IR, only <code>@end = global i8 0, align 1</code> gets printed. But not ...</p>
  
  <pre><code>@.str = private unnamed_addr constant [4 x i8] c"YES\00", align 1
  @.str.2 = private unnamed_addr constant [3 x i8] c"NO\00", align 1
  </code></pre>
  
  <p>I understand that <code>@.str</code> is not part of the operands as <code>@end</code> is. <code>@.str</code> is something reference by one of the operands.</p>
  
  <p>What modifications do I have to implement to be able to get the global variables inside the operands?</p>