Shemer, Anat
2013-Feb-12 12:33 UTC
[LLVMdev] giving metadata a function parameter as an operand
Hi, Is it possible to give an instruction metadata that accepts function argument as operand? The 2 functions are in the same module so the metadata operand can be resolved. Here is how I imagine it should look like: define i32 @f(i32 %v) { %v0 = call i32 @f1 (i32 %v, metadata !0) ; this ok ret i32 %v0 } define i32 @f1 (i32 %v, metadata %md) { ; and this is ok too %t0 = add i32 %v, 1, !md !%md ; ^ here it says it expects an integer ret i32 %t0 } !0 = metadata !{i32 4} Thanks, Anat --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130212/f925385a/attachment.html>
Hal Finkel
2013-Feb-12 16:11 UTC
[LLVMdev] giving metadata a function parameter as an operand
----- Original Message -----> From: "Anat Shemer" <anat.shemer at intel.com> > To: llvmdev at cs.uiuc.edu > Sent: Tuesday, February 12, 2013 6:33:41 AM > Subject: [LLVMdev] giving metadata a function parameter as an operand > > > > Hi, > > Is it possible to give an instruction metadata that accepts function > argument as operand? The 2 functions are in the same module so the > metadata operand can be resolved. Here is how I imagine it should > look like: > > define i32 @f(i32 %v) { > %v0 = call i32 @f1 (i32 %v, metadata !0) ; this ok > ret i32 %v0 > } > > define i32 @f1 (i32 %v, metadata %md) { ; and this is ok too > %t0 = add i32 %v, 1, !md !%md > ; ^ here it says it expects an integer > ret i32 %t0 > } > > !0 = metadata !{i32 4}Can you explain your motivation for wanting this? -Hal> > Thanks, Anat > > > > --------------------------------------------------------------------- > Intel Israel (74) Limited > > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Eli Bendersky
2013-Feb-12 16:23 UTC
[LLVMdev] giving metadata a function parameter as an operand
On Tue, Feb 12, 2013 at 4:33 AM, Shemer, Anat <anat.shemer at intel.com> wrote:> Hi, > > Is it possible to give an instruction metadata that accepts function > argument as operand? The 2 functions are in the same module so the metadata > operand can be resolved. Here is how I imagine it should look like: > > define i32 @f(i32 %v) { > %v0 = call i32 @f1 (i32 %v, metadata !0) ; this ok > ret i32 %v0 > } > > define i32 @f1 (i32 %v, metadata %md) { ; and this is ok too > %t0 = add i32 %v, 1, !md !%md > ; ^ here it says it expects an integer > ret i32 %t0 > } > > !0 = metadata !{i32 4}>From a cursory look at LLParser.cpp, this is not supported, since onlyconstant (= known at compile time) metadata nodes can be attached to instructions. This makes sense, because metadata attached to instructions are a complile-time property that should be available to LLVM optimization passes and backends. What are the semantics of having this value only known at runtime? Perhaps there's a better way to achieve what you're trying to do. Eli
Shemer, Anat
2013-Feb-12 22:31 UTC
[LLVMdev] giving metadata a function parameter as an operand
Hi, Thanks for looking into this. The function f1 is inlined in the function f. Once this happens %md is a constant. I do this because I would like to inline f1 with different metadata values depending on the call site. There is a finite number of possible metadata values, practically 2 at the moment. One alternative that I currently have in mind is to duplicate the function f1, where the metadata is the only difference. Another alternative has the advantage of duplicating only the instruction that has the metadata attached but is more complex. (The idea is to transfer %md to f1 as i32 and duplicate the instruction with the metadata in f1 in separate basic blocks such that each copy has different metadata value. Additional control flow will check the value of %md and jump to the right block accordingly. This solution hopes that future passes will remove the redundant blocks once f1 is inlined and %md becomes a constant.) Both these options require code duplication with all the consequences of maintainability. And of course it's possible to write a pass that will handle this case. But first I look for an existing solution. Thanks, Anat -----Original Message----- From: Eli Bendersky [mailto:eliben at google.com] Sent: Tuesday, February 12, 2013 18:24 To: Shemer, Anat Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] giving metadata a function parameter as an operand On Tue, Feb 12, 2013 at 4:33 AM, Shemer, Anat <anat.shemer at intel.com> wrote:> Hi, > > Is it possible to give an instruction metadata that accepts function > argument as operand? The 2 functions are in the same module so the > metadata operand can be resolved. Here is how I imagine it should look like: > > define i32 @f(i32 %v) { > %v0 = call i32 @f1 (i32 %v, metadata !0) ; this ok > ret i32 %v0 > } > > define i32 @f1 (i32 %v, metadata %md) { ; and this is ok too > %t0 = add i32 %v, 1, !md !%md > ; ^ here it says it expects an integer > ret i32 %t0 > } > > !0 = metadata !{i32 4}>From a cursory look at LLParser.cpp, this is not supported, since only constant (= known at compile time) metadata nodes can be attached to instructions. This makes sense, because metadata attached to instructions are a complile-time property that should be available to LLVM optimization passes and backends. What are the semantics of having this value only known at runtime? Perhaps there's a better way to achieve what you're trying to do.Eli --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.