<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 3/5/15 12:17 AM, Yuxi Chen wrote:<br>
    </div>
    <blockquote
cite="mid:83E2887150EB424E8D7877B912AE1FF128AAF316@xm-mbx-07-prod.ad.uchicago.edu"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html;
        charset=iso-8859-1">
      <div>
        <div>
          <div id="divRpF832726"><br>
          </div>
          <div>
            <div>
              <div>Hi John,
                <div><br>
                </div>
                <div>Thanks for your reply. "While deleting" is not in
                  my code. </div>
                <div>I have carefully checked my pass code, and test.bc
                  which I will run for test, there is no global variable
                  named myFlag. It's a bit weird. This global variable
                  is added by myself in the pass. And the operation I do
                  is just to load the global variable and store it. I
                  really do not know the reason.<br>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    You should run grep on the LLVM source code to find which code is
    deleting the global variable (it is probably one of the LLVM
    optimization passes).  Once you find the code that is deleting the
    global variable, you can look at the code and determine why it is
    deleting the global variable.<br>
    <br>
    Once you know why the global variable is being deleted, you can
    figure out how to keep it from being deleted (perhaps the code using
    it is dead, or perhaps it has the wrong linkage type, etc, etc.).<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:83E2887150EB424E8D7877B912AE1FF128AAF316@xm-mbx-07-prod.ad.uchicago.edu"
      type="cite">
      <div>
        <div>
          <div>
            <div>
              <div>
                <div>
                  <br>
                  Module* JFIX::insertCounterMod(Module*
                  mod,Instruction* OptAplusOne,Value* pthreadPID){ 
                  //insert myPid[flag++] = pid,after Operation A<br>
                       <br>
                        //type definition, myPid[20]<br>
                      ArrayType* ArrayTy_3 =
                  ArrayType::get(IntegerType::get(mod->getContext(),
                  64), 20);<br>
                  <br>
                      ConstantInt* const_int32_20 =
                  ConstantInt::get(mod->getContext(), APInt(32,
                  StringRef("0"), 10)); //constant definition<br>
                      ConstantAggregateZero* const_array_23 =
                  ConstantAggregateZero::get(ArrayTy_3);<br>
                      ConstantInt* const_int32_24 =
                  ConstantInt::get(mod->getContext(), APInt(32,
                  StringRef("1"), 10));<br>
                      <br>
                      GlobalVariable* gvar_int32_myFlag =
                  getGlobalFromMap(mod->getModuleIdentifier(),"myFlag");<br>
                      GlobalVariable* gvar_array_myPid =
                  getGlobalFromMap(mod->getModuleIdentifier(),"myPid");<br>
                     
                  gvar_int32_myFlag->setInitializer(const_int32_20);
                  //Global Variable Definitions<br>
                     
                  gvar_array_myPid->setInitializer(const_array_23);<br>
                  <br>
                      gvar_int32_myFlag->dump();<br>
                      gvar_array_myPid->dump();<br>
                  <br>
                      LoadInst* int64_64 = new LoadInst(pthreadPID, "",
                  false, OptAplusOne);   //do myPid[flag++] = pthreadID<br>
                      int64_64->setAlignment(8);<br>
                      LoadInst* int32_65 = new
                  LoadInst(gvar_int32_myFlag, "", false, OptAplusOne);<br>
                      int32_65->setAlignment(4);<br>
                      BinaryOperator* int32_inc =
                  BinaryOperator::Create(Instruction::Add, int32_65,
                  const_int32_24, "inc", OptAplusOne);<br>
                      StoreInst* void_66 = new StoreInst(int32_inc,
                  gvar_int32_myFlag, false, OptAplusOne);<br>
                      void_66->setAlignment(4);<br>
                      CastInst* int64_idxprom = new SExtInst(int32_65,
                  IntegerType::get(mod->getContext(), 64), "idxprom",
                  OptAplusOne);<br>
                      std::vector<Value*> ptr_arrayidx_indices;<br>
                      ptr_arrayidx_indices.push_back(const_int32_20);<br>
                      ptr_arrayidx_indices.push_back(int64_idxprom);<br>
                      Instruction* ptr_arrayidx =
                  GetElementPtrInst::Create(gvar_array_myPid,
                  ptr_arrayidx_indices, "arrayidx", OptAplusOne);<br>
                      StoreInst* void_67 = new StoreInst(int64_64,
                  ptr_arrayidx, false, OptAplusOne);<br>
                      void_67->setAlignment(8);<br>
                      return mod;<br>
                  }<br>
                  <br>
                  Best,<br>
                  Yuxi<br>
                  <div>
                    <hr tabindex="-1">
                    <div id="divRpF726021"><b>From:</b> John Criswell
                      [<a class="moz-txt-link-abbreviated" href="mailto:jtcriswel@gmail.com">jtcriswel@gmail.com</a>]<br>
                      <b>Sent:</b> Wednesday, March 04, 2015 9:48 PM<br>
                      <b>To:</b> Yuxi Chen; <a class="moz-txt-link-abbreviated" href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
                      <b>Subject:</b> Re: [LLVMdev] global variable<br>
                      <br>
                    </div>
                    <div>
                      <div class="moz-cite-prefix">On 3/4/15 10:13 PM,
                        Yuxi Chen wrote:<br>
                      </div>
                      <blockquote type="cite">
                        <div>Hi all,<br>
                          <br>
                          I am newbie for llvm.  I just create a global
                          variable, there are some statements in my pass
                          like:<br>
                          <br>
                              LoadInst* int64_64 = new
                          LoadInst(pthreadPID, "", false, OptAplusOne);<br>
                              int64_64->setAlignment(8);<br>
                          <br>
                              int64_64->dump();<br>
                              LoadInst* int32_65 = new
                          LoadInst(gvar_int32_myFlag, "", false,
                          OptAplusOne);<br>
                              int32_65->setAlignment(4);<br>
                          <br>
                              int32_65->dump();<br>
                          <br>
                          But when I run my pass,  it generates an
                          error, I don't know why.<br>
                          <br>
                          @myFlag = global i32 0, align 4<br>
                          @myPid = common global [20 x i64]
                          zeroinitializer, align 16  //this is the
                          global,
                          <br>
                            %117 = load i64* %t, align 8<br>
                            %118 = load i32* @myFlag, align 4<br>
                          While deleting: i32* %myFlag<br>
                          Use still stuck around after Def is
                          destroyed:@myFlag = global i32 <null
                          operand!>, align 4<br>
                          <br>
                          I am sure I initialize the global variable
                          myFlag, I don't delete this global variable.<br>
                          <br>
                          Can anyone give some hints, or suggestions? <br>
                        </div>
                      </blockquote>
                      <br>
                      What code is printing the "While deleting:" text? 
                      Is it your code that prints that, or is it some
                      existing LLVM pass?<br>
                      <br>
                      It looks like something is trying to remove the
                      myFlag global variable, but I don't know what code
                      is trying to do that.  I suggest you find that
                      code and figure out why it's trying to remove a
                      global variable that you're still using.<br>
                      <br>
                      Regards,<br>
                      <br>
                      John Criswell<br>
                      <br>
                      <blockquote type="cite">
                        <div><br>
                          Yuxi<br>
                          <br>
                        </div>
                        <br>
                        <fieldset class="mimeAttachmentHeader"
                          target="_blank"></fieldset>
                        <br>
                        <pre>_______________________________________________
LLVM Developers mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
                      </blockquote>
                      <br>
                      <br>
                      <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </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>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>