I'm trying to have meaningful names for the basic blocks in LLVM IR. That is, instead of the name 6
for this loop header, I would like it to be something like: loop.header.6
. I'm pretty sure previous llvm/opt
versions had this option, but I can't seem to find it in llvm-13
. The actual source code for this is probably irrelevant, but given below for completeness
$ sed -n "18,23p" main.ll
6: ; preds = %27, %1
%7 = load i32, i32* %4, align 4
%8 = load i32, i32* %3, align 4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %30
Source code + compilation flags:
$ cat ~/main.cpp
#include <stdio.h>
bool isPrime(int p) {
for (int i=2;i<p;i++)
for (int j=2;j<p;j++)
if (i*j == p)
return 0;
return 1; }
int main(int argc, char **argv) {
printf("%d\n", isPrime(7));
}
$ ./clang -O0 -c -emit-llvm ~/main.cpp -o main.bc
$ ./llvm-dis ./main.bc -o main.ll
The value names are only added by a frontend (clang
) if it is compiled in debug mode / with assertions enabled.
Note that the names might become misleading after optimizations, etc.