[llvm-dev] Creating arbitrary data type in LLVM IR
David Chisnall via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 10 02:07:38 PDT 2017
On 10 Oct 2017, at 09:59, Dipanjan Das via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> LLVM Type class offers pointers to known data types, e.g. Type::getInt8PtrTy(), Type::getDoublePtryTy() etc. What if I need to get a type representing a pointer to some arbitrary structure? How do I create such pointer in IR?
Once you have an llvm::Type, call its getPointerTo() method. The argument is the address space of the pointer - most of the time the default 0 will be correct.
> The problem is not necessarily only with the pointer. If I need to create a function in IR that accepts STL Map as an argument, how do I declare the signature of such a function as well?
Getting an llvm::Type for a std::map is a *lot* harder, because the exact type depends on your C++ standard library implementation and on the type of the template parameters. Your best bet is going to be to embed some of the clang libraries and have them parse <map> for you and emit the specialisation that you need.
David
More information about the llvm-dev
mailing list