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?
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.
(Adding llvm-dev back again. Please use reply-all).
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 arguments
The 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:
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.
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.