diff --git a/ctx.cpp b/ctx.cpp index 55aef7a9..bb7be50e 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -1582,7 +1582,12 @@ lGetStringAsValue(llvm::BasicBlock *bblock, const char *s) { sConstant, var_name.c_str()); llvm::Value *indices[2] = { LLVMInt32(0), LLVMInt32(0) }; llvm::ArrayRef arrayRef(&indices[0], &indices[2]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) return llvm::GetElementPtrInst::Create(sPtr, arrayRef, "sptr", bblock); +#else // LLVM 3.7++ + return llvm::GetElementPtrInst::Create(PTYPE(sPtr), + sPtr, arrayRef, "sptr", bblock); +#endif } @@ -2346,9 +2351,16 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, // uniform, so just emit the regular LLVM GEP instruction llvm::Value *ind[1] = { index }; llvm::ArrayRef arrayRef(&ind[0], &ind[1]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) llvm::Instruction *inst = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "gep", bblock); +#else // LLVM 3.7++ + llvm::Instruction *inst = + llvm::GetElementPtrInst::Create(PTYPE(basePtr), + basePtr, arrayRef, + name ? name : "gep", bblock); +#endif AddDebugPos(inst); return inst; } @@ -2406,9 +2418,16 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0 // uniform, so just emit the regular LLVM GEP instruction llvm::Value *indices[2] = { index0, index1 }; llvm::ArrayRef arrayRef(&indices[0], &indices[2]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) llvm::Instruction *inst = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "gep", bblock); +#else // LLVM 3.7++ + llvm::Instruction *inst = + llvm::GetElementPtrInst::Create(PTYPE(basePtr), + basePtr, arrayRef, + name ? name : "gep", bblock); +#endif AddDebugPos(inst); return inst; } @@ -2500,9 +2519,15 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, // If the pointer is uniform, we can use the regular LLVM GEP. llvm::Value *offsets[2] = { LLVMInt32(0), LLVMInt32(elementNum) }; llvm::ArrayRef arrayRef(&offsets[0], &offsets[2]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) resultPtr = llvm::GetElementPtrInst::Create(basePtr, arrayRef, name ? name : "struct_offset", bblock); +#else // LLVM 3.7++ + resultPtr = + llvm::GetElementPtrInst::Create(PTYPE(basePtr), basePtr, arrayRef, + name ? name : "struct_offset", bblock); +#endif } else { // Otherwise do the math to find the offset and add it to the given diff --git a/ispc.cpp b/ispc.cpp index 4a88df77..8741c8c7 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -1191,10 +1191,16 @@ Target::SizeOf(llvm::Type *type, llvm::PointerType *ptrType = llvm::PointerType::get(type, 0); llvm::Value *voidPtr = llvm::ConstantPointerNull::get(ptrType); llvm::ArrayRef arrayRef(&index[0], &index[1]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) llvm::Instruction *gep = llvm::GetElementPtrInst::Create(voidPtr, arrayRef, "sizeof_gep", insertAtEnd); - +#else // LLVM 3.7++ + llvm::Instruction *gep = + llvm::GetElementPtrInst::Create(PTYPE(voidPtr), voidPtr, + arrayRef, "sizeof_gep", + insertAtEnd); +#endif if (m_is32Bit || g->opt.force32BitAddressing) return new llvm::PtrToIntInst(gep, LLVMTypes::Int32Type, "sizeof_int", insertAtEnd); @@ -1223,10 +1229,16 @@ Target::StructOffset(llvm::Type *type, int element, llvm::PointerType *ptrType = llvm::PointerType::get(type, 0); llvm::Value *voidPtr = llvm::ConstantPointerNull::get(ptrType); llvm::ArrayRef arrayRef(&indices[0], &indices[2]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) llvm::Instruction *gep = llvm::GetElementPtrInst::Create(voidPtr, arrayRef, "offset_gep", insertAtEnd); - +#else // LLVM 3.7++ + llvm::Instruction *gep = + llvm::GetElementPtrInst::Create(PTYPE(voidPtr), voidPtr, + arrayRef, "offset_gep", + insertAtEnd); +#endif if (m_is32Bit || g->opt.force32BitAddressing) return new llvm::PtrToIntInst(gep, LLVMTypes::Int32Type, "offset_int", insertAtEnd); diff --git a/llvmutil.h b/llvmutil.h index cb4cd27e..289d0240 100644 --- a/llvmutil.h +++ b/llvmutil.h @@ -50,6 +50,8 @@ #include #endif +#define PTYPE(p) (llvm::cast((p)->getType()->getScalarType())->getElementType()) + namespace llvm { class PHINode; class InsertElementInst; diff --git a/opt.cpp b/opt.cpp index 23f2f00f..ac9d2e2b 100644 --- a/opt.cpp +++ b/opt.cpp @@ -330,8 +330,13 @@ lGEPInst(llvm::Value *ptr, llvm::Value *offset, const char *name, llvm::Instruction *insertBefore) { llvm::Value *index[1] = { offset }; llvm::ArrayRef arrayRef(&index[0], &index[1]); +#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4) || defined(LLVM_3_5) || defined(LLVM_3_6) return llvm::GetElementPtrInst::Create(ptr, arrayRef, name, insertBefore); +#else // LLVM 3.7++ + return llvm::GetElementPtrInst::Create(PTYPE(ptr), ptr, arrayRef, + name, insertBefore); +#endif }