[LLVMdev] Alloca with LLVMContext

Owen Anderson resistor at mac.com
Wed Jul 15 08:52:30 PDT 2009

On Jul 15, 2009, at 8:14 AM, John Criswell wrote:

> Dear All,
> Is there a reason why the AllocaInst constructor takes an LLVMContext
> argument?  Can't it just determine the context from either the basic
> block or instruction pointer argument?

BasicBlocks and Instructions don't necessarily have contexts, if  
they're not attached to a module.  You can also construct an  
AllocaInst without attaching it to a BasicBlock.

This problem was simpler for global values, where they're attached  
directly to a Module, which must have a context.  There I was able to  
split it into constructors that take mandatory contexts and ones that  
take mandatory modules.  With Instructions, it doesn't work so well,  
because even if I make the BasicBlock mandatory, there is not  
guarantee that it is attached to a Module.

This could be an argument for pushing the context member does into BBs  
and Instructions, but that has performance and memory use implications  
that I haven't considered yet.

> If the constructor can't infer it, would it be possible to make the
> context the last parameter and have it use a default LLVMContext (say,
> the one from getGlobalContext())?

Possibly.  I'll look at it when I get in.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090715/18ee4cd4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090715/18ee4cd4/attachment.bin>

More information about the llvm-dev mailing list