[LLVMdev] How to codegen an LLVM-IR that has dynamic arrays in it?

Paul Vario paul.paul.mit at gmail.com
Wed Feb 19 15:19:35 PST 2014


I see. Problem solved! Thank you all for the clarification.

Best,
Paul


On Tue, Feb 18, 2014 at 4:24 AM, Tim Northover <t.p.northover at gmail.com>wrote:

> Hi Paul,
>
> >                     Value *sz = Mod->getOrInsertGlobal("SIZE", Int32Ty);
> >                     Type *ArrayTy = ArrayType::get(FloatTy, sz)
> >                     AllocaInst *AI = CreateAlloca(ArrayTy, 0, "");
>
> You can't create dynamically varying types like that in LLVM, but an
> AllocaInst can have a parameter saying how many elements to allocate,
> so instead of trying to write:
>
>    %numElts = load i32* @SIZE
>    %val = alloca [@var x float] ; %val would have dynamic type
> [%numElts x float]*. Not good.
>
> You'd want:
>     %numElts = load i32* @SIZE
>     %val = alloca float, i32 %numElts ; %val now has type float*, but
> %numElts elements can be accessed.
>
> Roughly the same would happen if you took Owen up on using malloc
> (%val would have to have type "float*" rather than a static array
> type).
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140219/bc3fdb8a/attachment.html>


More information about the llvm-dev mailing list