Patrick Martin
Patrick Martin

Reputation: 229

Extracting LLVM IR Identifiers

I have an instruction visitor implemented that inspects FCmpInst. In my IR, I have a couple lines generated from clang on a c++ file:

%2 = load float, float* %x, align 4
%3 = fcmp ogt float %2, 1.0000e+00

Calling getOperand(0) during the FCmpInst visit returns the load instruction above. Then, if I call getPointerOperand() on the load instruction, it points back to the alloca instruction that first sets aside %x. I do not want the pointer - instead, I want the identifier name "%x". How do we extract these names from the IR? I see that calling dump() on any instruction shows the identifier, but I have not found an API call that could pull out the identifier itself. Thanks!

Upvotes: 2

Views: 733

Answers (2)

Armand Behroozi
Armand Behroozi

Reputation: 1

I was trying to do the same thing. I needed to detect global identifiers.

isa<GlobalValue>(mem_address) did it for me.

Upvotes: 0

Ismail Badawi
Ismail Badawi

Reputation: 37227

You can use the getName method on Value.

Note that not every value is named -- in particular, you won't be able to retrieve names like %1, %2, etc. as those are generated on the fly while the IR is being written out.

Upvotes: 1

Related Questions