2
votes

I have been trying to extract pointer type using cpp API in llvm IR to use as metadata for the instruction. I have found various ways to get the pointer type of the instruction operands (e.g. getPointerElementType()) but the results are always in hex format (0x....) which is not useful because it doesn't tell whether the pointer is int or float etc. I am mainly working with load instruction. My question is how to get the pointer type in Ascii (e.g. as float or i32)?

P.s. I am very new to llvm, so forgive me if i asked something very basic.

1

1 Answers

0
votes

I have found the answer to this here, Is any way to get llvm deference pointer value's raw type(i.e. pointer type)

A couple of missing bits though:

  1. Remember to include Instructions.h for LoadInst to be recognized as below:

    #include "llvm/IR/Instructions.h"

  2. The accepted answer can be optimized for Load instruction (instead of function call) by passing the pointer to instruction:

    LoadInst* LI = dyn_cast(O0)

O0 should be pointer to load instruction in question.

Hope it helps.