<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'>Hi all,<br><br>I have been trying to build a loop nesting analysis which works interprocedurally. In order <br>to find the functions called inside a given loop, I am traversing the Instructions into the<br>BasicBlock's that conform a Loop, and applying the code that CallGraph construction uses:<br><br>------ extract from CallGraph.cpp : 144<br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    // Look for calls by this function.</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">      for (BasicBlock::iterator II = BB->begin(), IE = BB->end();</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">           II != IE; ++II) {</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">        CallSite CS(cast<Value>(II));</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">        if (CS && !isa<DbgInfoIntrinsic>(II)) {</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">          const Function *Callee = CS.getCalledFunction();</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">          if (Callee)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">            Node->addCalledFunction(CS, getOrInsertFunction(Callee));</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">          else</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">            Node->addCalledFunction(CS, CallsExternalNode);</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">        }</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">      }</span><br>------ <br><br>While analyzing the IS NAS Parallel Benchmark I find the following BasicBlock:<br><br><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">; <label>:24                                      ; preds = %20</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">  %25 = call double (...)* bitcast (double (double*, double*)* @randlc to double (...)*)(double* %t1, double* %t1)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">  store double %25, double* %t2, align 8</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">  br label %26</span><br><br>As can be seen, the first Instruction after the label contains a call to randlc(). However, this gets counted by CallGraph as an external node, since<br>@randlc has been bitcasted and CS.getCalledFunction() fails to return a non-null value. As a result, the CallGraph for the caller does not contain<br>randlc(), but a call to an external node instead.<br><br><br>Furthermore, this behavior stems from the following definition of the function randlc() :<br><br>-----<br><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">double randlc( X, A ) /* Instead of randlc( double * X, double * A ) */</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">double * X;</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">double * A;</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">{</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> ...</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">}</span><br>-----<br><br>If defined with the types included in the header line, the generated call code does not include a bitcast of the function signature<br>(although both versions of the code define randlc() using <span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">define double @randlc(double* %X, double* %A) nounwind</span> ).<br><br><br>Summarizing, I have two questions: 1) is the CallGraph analysis "working as intended" here?; and 2) what would be the correct approach<br>to modifying the proposed analysis in order to detect that randlc() is being called in that CallInst ?<br><br><br>Best regards,<br>Gabriel<br></div></body></html>