title: Correct way to use PtrUseVisitor Class in LLVM
body: <p>So I found the <code>InstVisitor</code> class in LLVM, which was refreshing to traverse through the function and see instructions of my interest. A straightforward implementation that I was able to get it working is as follows:</p>
  <pre><code>class MyInstVisitor : public InstVisitor &lt;MyInstVisitor&gt; {
      public:
  
      void visitLoadInst(Instruction &amp;I) {
          errs() &lt;&lt; &quot;Load:\t&quot; &lt;&lt; I &lt;&lt; &quot;\n&quot;;
      }
  };
  </code></pre>
  <p>Afterward, the usage case is as follows:</p>
  <pre><code>void visitor(Function &amp;F) {
      MyInstVisitor MAV;
      MAV.visit(F);
      for (auto &amp;I : F) {
          errs() &lt;&lt; I &lt;&lt; &quot;\n&quot;; // this traverses a function through for loop
      }
  }
  </code></pre>
  <p>After looking around further, I found a child class of <code>InstVisitor</code>, a <code>PtrUseVisitor</code> (<a href="https://llvm.org/doxygen/classllvm_1_1PtrUseVisitor.html" rel="nofollow noreferrer">https://llvm.org/doxygen/classllvm_1_1PtrUseVisitor.html</a>) that I wanted to use (as I wish to visit all of the users of a pointer value after locating the <code>llvm::LoadInst</code>).</p>
  <p>However, I am stuck trying to find a way to use this correctly.</p>
  <p>I have tried a variety of things, to summarize:</p>
  <ol>
  <li><code>PtrUseVisitor</code> cannot be instantiated like <code>InstVisitor</code></li>
  <li>as the template looks like this: <code>llvm::PtrUseVisitor&lt;DerivedT&gt;</code> I have also tried doing something like <code>llvm::PtrUseVisitor&lt;Instruction&gt;::visitPtr()</code>, which is incorrect.</li>
  <li>I think I'm missing something regarding how to use the child class of inheritance, but examples I could find are related to elementary things (such as inheriting from class <code>Animal</code>, for instance)</li>
  </ol>
  <p>And many more... just a bit lost at the moment.</p>
  <p>My main goal is to use the following member function:
  <code>PtrUseVisitor::visitPtr()</code>. Can anyone help with providing me with an example of how to use this?</p>
  <p>I appreciate any help you can provide.</p>