[LLVMdev] Walking thru CallGraph bottom up

John Criswell jtcriswel at gmail.com
Wed Feb 25 08:01:24 PST 2015


On 2/25/15 10:51 AM, Simone Atzeni wrote:
> Thanks John.
>
> I guess I will use a ModulePass, so when I am implementing the “runOnModule” function,
> do I have to loop through all the functions, for each functions all the BasicBlocks and for each BasicBlock all the instructions

If you know the Instruction, you can get it's basic block using 
Instruction::getParent(), and then get its enclosing function using 
BasicBlock::getParent().

Once you know the enclosing function, you can use the CallGraph pass to 
find which functions call it, and then repeat the procedures for 
functions calling that function, etc.

> or given the Module I have to call the CallGraph directly?
> Is there an example out there? I can’t find anything.

It uses the DSA CallGraph pass, but 
http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/lib/InsertPoolChecks/CFIChecks.cpp?revision=189030&view=markup 
might provide a decent example.

Regards,

John Criswell

>
> Thanks.
> Simone
>
>> On Feb 24, 2015, at 13:29, John Criswell <jtcriswel at gmail.com> wrote:
>>
>> On 2/24/15 2:27 PM, Simone Atzeni wrote:
>>> Hi all,
>>>
>>> I would like to create a Pass that given an IR instruction walks starting from that instruction up to the main function
>>> to identify all the functions call that have been made to call that instruction.
>>>
>>> Is it possible? What kind of Pass should I create?
>> Yes, it is possible.  I think a ModulePass would be most appropriate, though a FunctionPass may be alright.
>>
>> To get the call graph, you can use LLVM's CallGraph analysis.  If you need to handle function pointers more accurately than LLVM's internal CallGraph analysis does, you can use DSA's CallGraph analysis (which has the same interface but may only work with LLVM 3.2 and earlier LLVM releases).
>>
>> -- John T.
>>
>>> Thanks
>>> Best,
>>> Simone
>>>
>>> Simone Atzeni
>>> simone.at at gmail.com
>>> +1 (801) 696-8373
>>>
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>> -- 
>> John Criswell
>> Assistant Professor
>> Department of Computer Science, University of Rochester
>> http://www.cs.rochester.edu/u/criswell
>>


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell





More information about the llvm-dev mailing list