Dear All, Is it legal to have an alloca in a basic block other than a function's entry block? -- John T.
On Aug 13, 2008, at 10:49 AM, John Criswell wrote:> Is it legal to have an alloca in a basic block other than a > function's entry block?How else could you generate code for: #include <stdlib.h> void *vp; size_t foo(int); void watch(void *); void* bar(int i) { if (i) vp = alloca(foo(i)); watch (vp); } ? The answer should be yes.
> Is it legal to have an alloca in a basic block other than a function's > entry block?It is legal, but mem2reg will not promote as far as I know. Ciao, Duncan.
This is the right answer for C's alloca. The question probably referred to LLVM IR's alloca, however. On Aug 13, 2008, at 11:07 AMPDT, Mike Stump wrote:> On Aug 13, 2008, at 10:49 AM, John Criswell wrote: >> Is it legal to have an alloca in a basic block other than a >> function's entry block? > > How else could you generate code for: > > #include <stdlib.h> > > void *vp; > size_t foo(int); > void watch(void *); > > void* bar(int i) { > if (i) > vp = alloca(foo(i)); > watch (vp); > } > > ? The answer should be yes. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Yes it is legal, but for performance reasons you want to avoid that. -Tanya On Wed, 13 Aug 2008, John Criswell wrote:> Dear All, > > Is it legal to have an alloca in a basic block other than a function's > entry block? > > -- John T. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
John Criswell wrote:> Dear All, > > Is it legal to have an alloca in a basic block other than a function's > entry block? >Thanks everyone for the answers. My original question was referring to the LLVM IR and not standard C. So, the consensus seems to be that it is legal, which makes sense since LLVM supports the C alloca function. FWIW, I'm not inserting allocas into code; rather I'm instrumenting them and found a test case where an alloca does not appear in an entry block (176.gcc from SPEC2000, if you're curious). I needed to know whether that was an error or whether my instrumentation needs to handle that properly. Thanks again. -- John T.> -- John T. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Thu, Aug 14, 2008 at 7:55 AM, John Criswell <criswell at uiuc.edu> wrote:> Thanks everyone for the answers. My original question was referring to > the LLVM IR and not standard C. > > So, the consensus seems to be that it is legal, which makes sense since > LLVM supports the C alloca function.Yeah, legal, but the performance sucks because it codegens into a call to the C library's alloca function. It's probably worth documenting in LangRef because the difference in the generated code is so striking. -Eli