Hi everybody, I want to read the name of the arguments of fucntion IR LLVM, I have the following function define: define void @vecadd(i32, float* nocapture readonly, float* nocapture readonly, float* nocapture) local_unnamed_addr #0 { As we see, the argument has no name, if we look at call function in main function we see the arguments name (a, b and c): call void @vecadd(i32 10, float* getelementptr inbounds ([10 x float], [10 x float]* @a, i64 0, i64 0), float* getelementptr inbounds ([10 x float], [10 x float]* @b, i64 0, i64 0), float* nonnull %3) The problem is, how can I get arguments name from the instruction inside define function because I just have the instructions in define function. Any idea please? Kinds regards Mohamed Messelka -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190729/9c22b18a/attachment.html>
Hi Mohamed, On Mon, Jul 29, 2019 at 1:09 PM mohamed messelka via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi everybody, > > I want to read the name of the arguments of fucntion IR LLVM, I have the following function define: > > define void @vecadd(i32, float* nocapture readonly, float* nocapture readonly, float* nocapture) local_unnamed_addr #0 {The arguments are unnamed, which means they will be implicitly named %0, %1, %2. Does that help? Thanks, Hans
Hi Mohamed, On Mon, 29 Jul 2019 at 12:09, mohamed messelka via llvm-dev <llvm-dev at lists.llvm.org> wrote:> As we see, the argument has no name, if we look at call function in main function we see the arguments name (a, b and c): > > call void @vecadd(i32 10, float* getelementptr inbounds ([10 x float], [10 x float]* @a, i64 0, i64 0), float* getelementptr inbounds ([10 x float], [10 x float]* @b, i64 0, i64 0), float* nonnull %3)Some kind of name, but not a good one for a couple of reasons: it'll vary between callsites, and may not even be referencable in @vecadd itself if it's a local name to the caller.> The problem is, how can I get arguments name from the instruction inside define function because I just have the instructions in define function.When names are omitted in LLVM, it starts assigning them automatically by counting up %0, %1, .... A function's (unnamed) arguments will always start at %0 so in that case it's pretty easy to calculate the proper value. In more complicated cases you'd use the class "ModuleSlotTracker" to compute it for you, but that's really not very efficient. But the chances are pretty good that you don't need the name anyway. It's only really useful for debug output, and not generally worth the hassle of computing manually even there. What are you really trying to do? Cheers. Tim.
(Adding llvm-dev back to reply list). On Mon, 29 Jul 2019 at 12:52, mohamed messelka <m14m at live.fr> wrote:> I want to generate DFG with names because later I need them, so how to get the names from call function :Normally any graph structure you build up would be constructed directly from the "Value *" pointers rather than by trying to cross-reference names of Values. You say you need them later, but what for?> call void @vecadd(i32 10, float* getelementptr inbounds ([10 x float], [10 x float]* @a, i64 0, i64 0), float* getelementptr inbounds ([10 x float], [10 x float]* @b, i64 0, i64 0), float* nonnull %3) > > any idea?Something like this would work: std::string CurName; unsigned ValueNo = 0; for (auto &Arg : F.args()) { CurName = Arg.getName(); if (CurName.empty()) CurName = std::to_string(ValueNo++); [... Use CurName ...] } But please think really hard about why you're trying to do this. Wanting to use names of LLVM instructions is a large red flag that there's something wrong. Cheers. Tim.
(Adding llvm-dev back again. Please use reply-all). On Mon, 29 Jul 2019 at 13:22, mohamed messelka <m14m at live.fr> wrote:> 1- I need them to read the correct values in fake memory to test some acceleration.That doesn't sound like a plausible use-case for the name of a Value.> 2- you code is good but the problem is: in define function has no names for argumentsThe arguments have no explicit names, but they're still implicitly called %0, %1, %2, ... Within the function that's what they'll be referred to as. For example: define i32 @foo(i32) { %val = add i32 %0, 1 ret i32 %val } will add 1 to its first argument and return it.> but for call fucntion has name for arguments as you see @a and @b: > > call void @vecadd(i32 10, float* getelementptr inbounds ([10 x float], [10 x float]* @a, i64 0, i64 0), float* getelementptr inbounds ([10 x float], [10 x float]* @b, i64 0, i64 0), float* nonnull %3)At that particular callsite, yes. But that won't be true in general, and (for example) %3 in that call is completely meaningless inside @vecadd. Cheers. Tim.
On Mon, Jul 29, 2019 at 4:39 AM Hans Wennborg via llvm-dev < llvm-dev at lists.llvm.org> wrote:> The arguments are unnamed, which means they will be implicitly named %0, > %1, %2. >OP's use case for the names aside, I think we should consider changing LLVM's IR printer to print unnamed arguments in function definitions as %0, %1, etc, like we do for instructions. We can skip the names for Function declarations since nothing can refer to them, but it's confusing to see %0 references with no definition. Unnamed BBs are another common source of confusion, but I'd leave that alone for now. Reid -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190729/af6342c8/attachment.html>