question about LLVMContext

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

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?

Notes --
In most uses of ConstantInt::get (), the LLVMContext to use seems obvious.
E.g. to get the ConstantInt representing 0, I call getType() on the N-bit
integer Value * that I'm trying to compare with. Once I have the Type *, I
can either call getContext on it, or directly call something like
ConstantInt::get (const Type *Ty, uint64_t V, bool isSigned=false).

In the LLVM repository, there is an optimization where you find function
calls that will return a ConstantInt, and replace them with the
ConstantInt being returned. There you use the context of the return type
of the function.

The Function & provided to FunctionPass::runOnFunction also has a
getContext() member that is useful in some situations. Is my situation one
of them?

Thanks in advance,

Samir Sapra
Student & LLVM Fan

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.