1 year ago

#175338

test-img

tommasopeduzzi

Dynamically sized arrays in LLVM-IR by allocating new memory if the size became bigger

I’ve been thinking on how I could implement arrays can be implemented, without the size of the array being known at compile-time. An idea was to check if the size of the object trying to be allocated is bigger than the chunk of memory that has been allocated for that variable every time when an assignment to a variable happens. If so a new allocation happens with the size of the object trying to be allocated and the old chunk is freed. However I cannot know the size of the object that is being assigned at compile-time, so I’d have to check this at run-time. Another problem I have is that I'd have to change the pointer to the AllocaInst, but that wouldn't work because of the SSA form of IR.

Is this even a good way to achieve dynamically sized arrays, or should I do something else, like making a new data structure? If I'm on the right path, how can implement this?Any help is greatly appreciated! Tom

llvm

llvm-c++-api

0 Answers

Your Answer

Accepted video resources