[LLVMdev] Is sizeof(pointer) known in LLVM IR?

Daniel Liew daniel.liew at imperial.ac.uk
Fri Dec 20 15:23:32 PST 2013


On 20 December 2013 22:44, Philip Reames <listmail at philipreames.com> wrote:
> Looking through the IR documentation, I have been unable to establish if
> the size of a pointer value is knowable to an LLVM optimization pass.
> For an IR->IR optimization pass, is the pass allowed to assume anything
> about the size of a pointer value?  Or is making such an assumption
> explicitly disallowed?

If you look at some LLVM assembly (e.g. emitted by clang -emit-llvm -S
your_program.c) you'll see "target datalayout..." at the top. The
information on the size of the pointer and its alignment are there.
AFAIK this information is present in all LLVM modules and so is
present very early on.

Take a look at [1] and pay special attention to the bit starting
"p[n]:<size>:<abi>:<pref>"

The LLVM C++ API for llvm::Module seems to have what you want [2] so I
see no reason why you could not have access to this in one of your
passes.

[1] http://llvm.org/docs/LangRef.html#data-layout
[2] http://llvm.org/docs/doxygen/html/classllvm_1_1Module.html#a3f499ddbebdc1456836d7b00a735df26

Hope that helps,

Cheers,
Dan Liew.



More information about the llvm-dev mailing list