<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body bgcolor="#FFFFFF" fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<div id="divIP1" flocal="0" class="itmPrt cnvLayer2" sitmid="RgAAAACSsdLudus9RbliqEbmwh6BBwCD4ohxUOtCTo14d7kSrh/xAAAAR8MSAACD4ohxUOtCTo14d7kSrh/xAAAoqj76AAAJ" sck="g+KIcVDrQk6NeHe5Eq4f8QAAKKrzEw==" st="IPM.Note" fexp="1" sfid="LgAAAACSsdLudus9RbliqEbmwh6BAQCD4ohxUOtCTo14d7kSrh/xAAAAR8MSAAAB" iimgflt="4" fdraft="0" fphsh="0" fjnk="0" fmr="0" frr="0" iinternetmid="-1719011860" fsup="1" folk="0" farchive="0" freadrcp="0" spid="RgAAAACSsdLudus9RbliqEbmwh6BBwCD4ohxUOtCTo14d7kSrh/xAAAAR8MQAACD4ohxUOtCTo14d7kSrh/xAAAoqiKHAAAJ" fr="1" style="z-index: 2; position: relative; margin: 0px 10px 10px 0px; font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 13px;">
<div id="divExp" class="divExp" style="position: relative; width: auto; margin: 0px 0px 0px 4px; padding-left: 10px; z-index: 0;">
<div id="divBdy" class="bdyItmPrt" _fallwcm="1" style="font-size: medium; word-wrap: break-word; width: auto; overflow: hidden; position: relative; top: -5px; padding: 0px 15px 15px 0px; clear: both;">
<div dir="ltr"><font face="Tahoma" size="2" color="black"><span dir="ltr" style="font-size: 10pt;"><font face="Times New Roman" size="2"><span style="font-size: 16px;"><font face="Tahoma" size="2"><span style="font-size: 10pt;">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>
<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>
<div><br>
</div>
</span></font></span></font></span></font></div>
</div>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF767999" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> John Criswell [jtcriswel@gmail.com]<br>
<b>Sent:</b> Wednesday, March 04, 2015 9:48 PM<br>
<b>To:</b> Yuxi Chen; llvmdev@cs.uiuc.edu<br>
<b>Subject:</b> Re: [LLVMdev] global variable<br>
</font><br>
</div>
<div></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 class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a 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 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>
</body>
</html>