[llvm-commits] [PATCH] Allow converting ConstantExprs to Instructions

James Molloy James.Molloy at arm.com
Fri Nov 16 10:17:02 PST 2012


Hi,

ConstantExprs are extremely opaque in LLVM, and it's very difficult to
transform them in any way.

A use case I'm thinking of is from a design constraint coming from SPIR:

https://groups.google.com/d/msg/llvm-dev/71tgtvash74/a94eadJIqB0J

Basically we want to change an operand of a constant expression from a
Constant to a Value, which requires unwrapping the expression which is
impossible with the current API.

The attached patch implements a simple extra API function to retrieve an
Instruction* equivalent for a ConstantExpr. With this addition, dealing
with the constraints imposed by SPIR is actually possible without
horrible hackery...

The test is nasty, I admit. I had to find a way to stop the constant
folder folding away what I was trying to test, which means the test
can't just use trivial i32 operands (it uses a GlobalValue bitcasted to
an i32/i64 to fool the optimiser).

What do you think?

Cheers,

James
-------------- next part --------------
A non-text attachment was scrubbed...
Name: constantexprs.patch
Type: text/x-patch
Size: 9459 bytes
Desc: constantexprs.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121116/69462018/attachment.bin>


More information about the llvm-commits mailing list