Accessing the name of the temporary variable in Instruction

I have developed a pass to instrument LLVM bit code files with calls to a custom instrumentation library. For one of the instrumentation calls, I need to pass the name of the temporary variable used in LLVM bit code.

For example, if I see LLVM assembly code as shown below,

%13 = icmp eq i64 %11, 0, !dbg !14

After the instrumentation pass, it needs to look like the following

%13 = icmp eq i64 %11, 0, !dbg !14
call void @instrumentation_function(i8* getelementptr inbounds ([5 x i8]* @.str6, i64 0, i64 0))

where str6 is a private constant declared as follows
@.str6 = private constant [4 x i8] c"%13\00"

Note that the private constant that I am passing to the instrumentation_function is the name of the target temporary variable for the icmp instruction. I cannot find a way to get the name of the temporary variable used by the Instruction. In this case, I cannot find a way to get to %13 (or the number 13) from the Value/Instruction object holding this instruction. getName() does not return anything as %13 is not a variable declared in the program. Is there a way to get to this temporary variable name?

Thanks
Sreekumar

I have developed a pass to instrument LLVM bit code files with calls to a custom instrumentation library. For one of the instrumentation calls, I need to pass the name of the temporary variable used in LLVM bit code.

For example, if I see LLVM assembly code as shown below,

%13 = icmp eq i64 %11, 0, !dbg !14

After the instrumentation pass, it needs to look like the following

%13 = icmp eq i64 %11, 0, !dbg !14
call void @instrumentation_function(i8* getelementptr inbounds ([5 x i8]* @.str6, i64 0, i64 0))

where str6 is a private constant declared as follows
@.str6 = private constant [4 x i8] c"%13\00"

Note that the private constant that I am passing to the instrumentation_function is the name of the target temporary variable for the icmp instruction. I cannot find a way to get the name of the temporary variable used by the Instruction. In this case, I cannot find a way to get to %13 (or the number 13) from the Value/Instruction object holding this instruction. getName() does not return anything as %13 is not a variable declared in the program. Is there a way to get to this temporary variable name?

The problem occurs because the value doesn't actually have a name; the LLVM disassembler is just printing %13 because the value has no name.

You can run the -instnamer pass right before your analysis/transform pass. It will give each instruction a real name.

-- John T.

The problem occurs because the value doesn't actually have a name; the
LLVM disassembler is just printing %13 because the value has no name.

You can run the -instnamer pass right before your analysis/transform
pass. It will give each instruction a real name.

-- John T.

The -instnamer pass was the one that I wanted to solve the problem. Thanks for the information John.

Sreekumar