<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
Hello,</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
I've written a Module Pass to iterate over the CallGraph using the CallGraph Pass. Here is the code for <span style="margin: 0px; background-color: rgb(255, 255, 255); display: inline !important">getAnalysisUsage and runOnModule methods:</span></div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<br>
</div>
<blockquote style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); margin: 0px 0px 0px 40px; border: none">
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px"><i> void getAnalysisUsage(AnalysisUsage &AU) const {</i></span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> AU.addRequired<CallGraph>();</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> AU.addPreserved<CallGraph>();</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> }</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i><br>
</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> bool runOnModule(Module &M) override {</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i>CallGraph &cg = getAnalysis<CallGraph>();</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> CallGraphNode *cgm = cg[M.getFunction("main")];</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> </i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> for (CallGraphNode::iterator ti = cgm->begin(); ti != cgm->end(); ++ti)</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> {</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> CallGraphNode * cgn = ti->second;</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> if(cgn==NULL)</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> continue;</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> errs()<<cgn->getFunction()<<"\n";</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> errs()<<cgn->getFunction()->getName()<<"\n";</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> }</i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> return false; </i></div>
</div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<div style="margin: 0px"><i> }</i></div>
</div>
</blockquote>
</blockquote>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px"> </span><br>
</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px"><br>
</span></div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px">I'm using llvm3.4.2 to compile and run the pass. I get the following error while iterating through callee nodes of main function:</span></div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px"><br>
</span></div>
<blockquote style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 15px; background-color: rgb(255, 255, 255); margin: 0px 0px 0px 40px; border: none">
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px"><span style="margin: 0px">0 opt 0x00000000011d2302 llvm::sys::PrintStackTrace(_IO_FILE*) + 34</span></span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">1 opt 0x00000000011d1eb4</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">2 libpthread.so.0 0x00007f88d72d3330</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">3 libcgwalk.so 0x00007f88d64d6596</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">4 opt 0x00000000010ddb45 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 709</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">5 opt 0x0000000000552724 main + 2452</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">6 libc.so.6 0x00007f88d66fbf45 __libc_start_main + 245</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">7 opt 0x000000000056d865</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">Stack dump:</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">0. Program arguments: opt -load build/proj/libcgwalk.so -cgwalk </div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">1. Running pass 'Cgwalk' on module '<stdin>'.</div>
</span></div>
</blockquote>
<blockquote style="margin: 0px 0px 0px 40px; border: none">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0)">
<span style="margin: 0px">
<div style="margin: 0px">Segmentation fault (core dumped)</div>
<div style="margin: 0px"><br>
</div>
</span></div>
</blockquote>
</blockquote>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px"><span style="margin: 0px"></span><br>
</span></div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)">
<span style="margin: 0px"><span style="margin: 0px; background-color: rgb(255, 255, 255); display: inline !important">I'm running the pass on bitcode of a simple C program where main calls 2 other functions.</span></span></div>
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<div style="font-family:Tahoma; font-size:13px">
<div style=""><font face="Times New Roman" size="2" style=""><span style="font-family:"Times New Roman",Times,serif; font-size:12pt">Thanks,
</span></font><span style="font-family:"Times New Roman",Times,serif; font-size:12pt"></span>
<div style=""><font face="Times New Roman" size="2" style=""><span style="font-family:"Times New Roman",Times,serif; font-size:12pt">Chaitra</span></font></div>
</div>
</div>
</div>
</div>
</body>
</html>