<div dir="ltr">
<p class=""><span class="">Hi all,</span></p><p class="">I'm compiling linux kernel with clang. I want to generate IR with no optimization. However, kernel can only be compile with -O2 instead of -O0.</p><p class="">Here is the source code snippet: </p><p class=""><span class="">struct</span><span class=""> zone *next_zone(</span><span class="">struct</span><span class=""> zone *zone)</span></p><p class=""><span class=""> </span><span class="">{ </span>pg_data_t *<b>pgdat</b> = zone->zone_pgdat;</p><p class="">}</p><p class="">I want to know there is an assignment from "zone" to "pgdat". I'm trying to iterate "store" instructions in IR. </p><p class=""><span class="">When I compile with -O2, I have the following IR:</span></p><p class=""><span class="">define %struct.zone* @next_zone(%struct.zone* readonly %zone) #0 !dbg !</span><span class="">214</span><span class=""> {</span></p>
<p class=""><span class=""> </span><span class="">call</span><span class=""> void @llvm.dbg.</span><span class="">value</span><span class="">(metadata %struct.zone* %zone, i64 </span><span class="">0</span><span class="">, metadata !</span><span class="">218</span><span class="">, metadata !</span><span class="">305</span><span class="">), !dbg !</span><span class="">326</span></p>
<p class=""><span class=""> </span><span class="">%1 = getelementptr inbounds %struct.zone, %struct.zone* %zone, i64 </span><span class="">0</span><span class="">, i32 </span><span class="">5</span><span class="">, !dbg !</span><span class="">327</span></p>
<p class=""><span class=""> </span><span class="">%2 = load %struct.pglist_data*, %struct.pglist_data** %1, align </span><span class="">8</span><span class="">, !dbg !</span><span class="">327</span></p>
<p class=""><span class=""> </span><span class="">call</span><span class=""> void @llvm.dbg.</span><span class="">value</span><span class="">(metadata %struct.pglist_data* %2, i64 </span><span class="">0</span><span class="">, metadata !</span><span class="">219</span><span class="">, metadata !</span><span class="">305</span><span class="">), !dbg !</span><span class="">328 }</span></p><p class=""><b>Store instruction has been optimized, and no variable name in IR.</b></p><p class=""><span class="">When I comile with -O0, I have the following IR:</span></p><p class=""><span class="">define %struct.zone* @</span><span class="">next_zone</span><span class="">(%struct.zone* %zone) #0 !dbg !</span><span class="">211</span><span class=""> {</span></p><p class=""><span class=""> %1 = alloca %struct.zone*, align </span><span class="">8</span></p><p class=""><span class=""> %pgdat = alloca %struct.pglist_data*, align </span><span class="">8</span></p><p class=""><span class="">
</span></p><p class=""><span class=""> store %struct.zone* %zone, %struct.zone** %1, align </span><span class="">8</span></p><p class=""><span class=""><b> </b>call</span><span class=""> void @llvm.dbg.declare(metadata %struct.zone** %1, metadata !</span><span class="">297</span><span class="">, metadata !</span><span class="">265</span><span class="">), !dbg !</span><span class="">298</span></p><p class=""><span class="">
</span></p><p class=""><span class=""> call</span><span class=""> void @llvm.dbg.declare(metadata %struct.pglist_data** %pgdat, metadata !</span><span class="">299</span><span class="">, metadata !</span><span class="">265</span><span class="">), !dbg !</span><span class="">302</span></p><p class=""><span class=""> </span><span class="">%2 = load %struct.zone*, %struct.zone** %1, align </span><span class="">8</span><span class="">, !dbg !</span><span class="">303</span></p>
<p class=""><span class=""> %3 = getelementptr inbounds %struct.zone, %struct.zone* %2, i32 </span><span class="">0</span><span class="">, i32 </span><span class="">5</span><span class="">, !dbg !</span><span class="">304</span></p><p class=""><span class=""> %4 = load %struct.pglist_data*, %struct.pglist_data** %3, align </span><span class="">8</span><span class="">, !dbg !</span><span class="">304</span></p><p class=""><span class="">
</span></p><p class=""><span class=""> <b>store %struct.pglist_data* %4, %struct.pglist_data** %</b></span><b><span class="">pgdat</span><span class="">, align </span><span class="">8</span><span class="">, !dbg !</span><span class="">302</span></b></p><div>There is store instruction. I know there is an assignment. From this store, I backward traverse until I find variable.</div><div>For example, I go through %4->%3->%2->%1->struct.zone. I have variable name pgdat in IR as well.</div><div><br></div><div>Since kernel can only be compiled with -O2, IR has been optimized a lot.</div><div>Is there any way I can know the variable name and there is an assignment from "zone" to "pgdat"?</div><div><br></div><div>Thank you!</div>-- <br><div class="gmail_signature"><div dir="ltr">Regards,<div>Kai</div></div></div>
</div>