<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 11/21/11 6:35 AM, Deu Arm wrote:
    <blockquote
cite="mid:CAAD26ec3BzNAp2KSmGdSa+Mptq97eyE4-ksQh4L8AEcUUuLaWw@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      Hi everybody,
      <div><br>
      </div>
      <div>I am writing an LLVM pass and I want to iterate over the
        whole module (including global variables), that's why I use
        ModulePass instead of FunctionPass. But I don't know how to do
        it. Using Module::iterator seams to iterate only over functions.
        But I need to iterate over all the Instructions in the module.
        How should I do such an iteration?</div>
    </blockquote>
    <br>
    To iterate over all the instructions, you need essentially need to
    do the following:<br>
    <br>
    for all Functions F in Module M)<br>
        for all Basic Blocks BB in Function F<br>
            for all Instructions I in Basic Block BB<br>
                do_something_with I<br>
    <br>
    That said, if you need to process certain instructions within the
    module, the best thing to do is to make your pass inherit from the
    InstVisitor<> class
    (<a class="moz-txt-link-freetext" href="http://llvm.org/doxygen/classllvm_1_1InstCombiner.html">http://llvm.org/doxygen/classllvm_1_1InstCombiner.html</a>).  You
    basically inherit from InstVisitor like so:<br>
    <br>
    class MyPass : public ModulePass, InstVisitor<MyPass> {<br>
        ...<br>
    }<br>
    <br>
    ... and then implement a visit method for each type of instruction
    that you want to handle.  In your runOnModule() method, call
    visit(M) to start iterating over every instruction in the Module. 
    The visit() method will call the appropriate visitXXX() method for
    each instruction.<br>
    <br>
    For an example, see the Load/Store Instrumentation pass from
    SAFECode:<br>
    <br>
<a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/safecode/trunk/lib/InsertPoolChecks/LoadStoreChecks.cpp?view=markup&pathrev=144620">http://llvm.org/viewvc/llvm-project/safecode/trunk/lib/InsertPoolChecks/LoadStoreChecks.cpp?view=markup&pathrev=144620</a><br>
<a class="moz-txt-link-freetext" href="http://llvm.org/viewvc/llvm-project/safecode/trunk/include/safecode/LoadStoreChecks.h?view=markup&pathrev=144620">http://llvm.org/viewvc/llvm-project/safecode/trunk/include/safecode/LoadStoreChecks.h?view=markup&pathrev=144620</a><br>
    <br>
    <blockquote
cite="mid:CAAD26ec3BzNAp2KSmGdSa+Mptq97eyE4-ksQh4L8AEcUUuLaWw@mail.gmail.com"
      type="cite">
      <div>Also, I would like to find all the "string" variables and do
        some changes to them. But LLVM's IR language does not have such
        a type. Tell me, please, what should I use.</div>
    </blockquote>
    <br>
    Strings are usually encoded as GlobalVariable's.  To find them, use
    the global_begin() and global_end() iterators to iterate over all
    GlobalVariables in the program.  Strings are pointer to arrays of
    type i8.<br>
    <br>
    -- John T.<br>
    <br>
    <blockquote
cite="mid:CAAD26ec3BzNAp2KSmGdSa+Mptq97eyE4-ksQh4L8AEcUUuLaWw@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      <div>Sincerely, </div>
      <div>Shuhmacher</div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>