[llvm-dev] Removing constants from a constant array?

John Criswell via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 17 10:28:36 PST 2017


On 12/16/17 11:08 PM, Nicolai Davidsson via llvm-dev wrote:
> Hi,
>
> I’m currently writing a LLVM pass and would like to modify a constant array based on some basic analysis.
>
> Is there any way to simply remove entries (`llvm::Constant`) from an array (`llvm::ConstantArray`)? Replacing all uses with an undefined value doesn’t work as the array is terminated by an undefined value, subsequent elements thus are ignored at runtime. I’d rather avoid re-creating the entire array from scratch and replace the existing array with it but I’m afraid there’s not many other options.
>
> Is there any solution I’m not aware of yet?

In many cases, the only way to "change" a value using the LLVM C++ API 
is to create a new value and replace uses of the old value with the new 
value.  I haven't looked, but I would not be surprised if this is the 
only way to "modify" the number of elements in a ConstantArray.

I can see how removing a ConstantArray element or creating a new 
ConstantArray with fewer elements would be a bit of a pain: you would 
need to change the ConstantArray, all the GEPs for the constant array, 
and potentially handle code that casts the ConstantArray to another type.

What are you trying to achieve be "removing" an element from a 
ConstantArray?  Perhaps there is an easier way to do what you're trying 
to do.

Regards,

John Criswell

>
> Thanks,
> Nicolai
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell



More information about the llvm-dev mailing list