LLVM Type Int32Ty Problems & LLVMContextImpl.h Problems

Hello! I’m newer to LLVM development . I’m trying to use AllocaInst class to construct an instruction , I wrote like this:

AllocaInst *alloc = new AllocaInst(llvm::Int32Ty, 0, “indexLoc”,i);

but it return the error:

error: use of undeclared identifier ‘llvm::Int32Ty’
AllocaInst *alloc = new AllocaInst(Int32Ty, 0, “indexLoc”,i);

I found that the Int32Ty is defined in the LLVMContextImpl.h , but I can not find it in the llvm include directory.

I installed llvm in “/usr/local/llvm” but there is no “LLVMContextImpl.h” in /usr/local/llvm/include/llvm/IR (LLVMContext.h exists)

Does this mean that the llvm is not installed correctly? What should I do to fix it? Thank you~

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of Jin Huang
Subject: [LLVMdev] LLVM Type Int32Ty Problems & LLVMContextImpl.h Problems

AllocaInst \*alloc = new AllocaInst\(llvm::Int32Ty, 0, "indexLoc",i\);

I think you should be using llvm::Type::getInt32Ty(Context), not llvm::Int32Ty, which is for internal LLVM usage.

Also, using llvm::IRBuilder<> is a whole lot easier and safer than trying to create instruction objects directly.

- Chuck

llvm::Type::getInt32Ty(Context) really works ,and I found a lot of useful functions to create instructions in llvm::IRBuilder<>.

Thank you! Chuck