Dipanjan Das via llvm-dev
2017-Oct-10 08:59 UTC
[llvm-dev] Creating arbitrary data type in LLVM IR
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? 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? -- Thanks & Regards, Dipanjan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171010/418b5937/attachment.html>
David Chisnall via llvm-dev
2017-Oct-10 09:07 UTC
[llvm-dev] Creating arbitrary data type in LLVM IR
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