[LLVMdev] question about LLVMContext

Owen Anderson resistor at mac.com
Mon Aug 24 09:55:55 PDT 2009


On Aug 24, 2009, at 8:09 AM, Samir Sapra wrote:

> Hi devs:
>
> I'm trying to do something quite simple, but it seems I need to  
> provide an
> LLVMContext& to do it. I'm not sure what the 'proper' LLVMContext  
> would be
> in my situation.
>
> I'm writing an analysis that is a FunctionPass. At some point in the  
> pass,
> I am given a Value * representing an N-bit integer. My goal is to  
> contruct
> two ConstantInt instances, for comparison purposes -- one  
> representing 0
> and another representing 2^N (the latter of course needs a wider  
> integer
> type).
>
> I'm trying to use ConstantInt::get (LLVMContext &Context, const  
> APInt &V)
> which returns static ConstantInt *. (Other APIs exist but ultimately I
> think I'll still need an LLVMContext).
>
> For the 2^N case, what LLVMContext should I provide? Do you need more
> details from me?

For any optimization and/or analysis pass, you want all of your  
Value*'s and Type*'s to be
of the same context.  You can call the getContext() method on any  
Value or Type accesible
to your analysis and pass it in.

--Owen



More information about the llvm-dev mailing list