Fixes to build with LLVM top-of-tree

This commit is contained in:
Matt Pharr
2011-07-26 10:57:49 +01:00
parent e230d2c9ca
commit 922dbdec06
2 changed files with 43 additions and 1 deletions

18
ctx.cpp
View File

@@ -765,8 +765,14 @@ FunctionEmitContext::EmitMalloc(LLVM_TYPE_CONST llvm::Type *ty, int align) {
LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(ty, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[1] = { LLVMInt32(1) };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&index[0], &index[1]);
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, arrayRef,
"offset_ptr", bblock);
#else
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1],
"offset_ptr", bblock);
#endif
AddDebugPos(poffset);
llvm::Value *sizeOf = PtrToIntInst(poffset, LLVMTypes::Int64Type, "offset_int");
@@ -798,8 +804,13 @@ lGetStringAsValue(llvm::BasicBlock *bblock, const char *s) {
llvm::GlobalValue::InternalLinkage,
sConstant, s);
llvm::Value *indices[2] = { LLVMInt32(0), LLVMInt32(0) };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[2]);
return llvm::GetElementPtrInst::Create(sPtr, arrayRef, "sptr", bblock);
#else
return llvm::GetElementPtrInst::Create(sPtr, &indices[0], &indices[2],
"sptr", bblock);
#endif
}
@@ -1289,9 +1300,16 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0
// The easy case: both the base pointer and the indices are
// uniform, so just emit the regular LLVM GEP instruction
llvm::Value *indices[2] = { index0, index1 };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[2]);
llvm::Instruction *inst =
llvm::GetElementPtrInst::Create(basePtr, arrayRef,
name ? name : "gep", bblock);
#else
llvm::Instruction *inst =
llvm::GetElementPtrInst::Create(basePtr, &indices[0], &indices[2],
name ? name : "gep", bblock);
#endif
AddDebugPos(inst);
return inst;
}

26
opt.cpp
View File

@@ -798,8 +798,14 @@ lSizeOf(LLVM_TYPE_CONST llvm::Type *type, llvm::Instruction *insertBefore) {
LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(type, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[1] = { LLVMInt32(1) };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&index[0], &index[1]);
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, arrayRef,
"offset_ptr", insertBefore);
#else
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1],
"offset_ptr", insertBefore);
#endif
lCopyMetadata(poffset, insertBefore);
llvm::Instruction *inst = new llvm::PtrToIntInst(poffset, LLVMTypes::Int64Type,
"offset_int", insertBefore);
@@ -822,8 +828,14 @@ lStructOffset(LLVM_TYPE_CONST llvm::Type *type, uint64_t member,
LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(type, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[2] = { LLVMInt32(0), LLVMInt32((int32_t)member) };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&index[0], &index[2]);
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, arrayRef,
"member_ptr", insertBefore);
#else
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[2],
"member_ptr", insertBefore);
#endif
lCopyMetadata(poffset, insertBefore);
llvm::Instruction *inst = new llvm::PtrToIntInst(poffset, LLVMTypes::Int64Type,
"member_int", insertBefore);
@@ -2122,9 +2134,15 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
new llvm::BitCastInst(base, LLVMTypes::VoidPointerType,
"base2i8", callInst);
lCopyMetadata(basei8, callInst);
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[1]);
llvm::Value *ptr =
llvm::GetElementPtrInst::Create(basei8, arrayRef, "ptr", callInst);
#else
llvm::Value *ptr =
llvm::GetElementPtrInst::Create(basei8, &indices[0], &indices[1],
"ptr", callInst);
#endif
lCopyMetadata(ptr, callInst);
if (gatherInfo != NULL) {
@@ -2182,13 +2200,19 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
// and 64 bit gather/scatters, respectively.)
// Get the base pointer using the first guy's offset.
llvm::Value *indices[2] = { offsetElements[0] };
llvm::Value *indices[1] = { offsetElements[0] };
llvm::Value *basei8 =
new llvm::BitCastInst(base, LLVMTypes::VoidPointerType, "base2i8", callInst);
lCopyMetadata(basei8, callInst);
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> arrayRef(&indices[0], &indices[1]);
llvm::Value *ptr =
llvm::GetElementPtrInst::Create(basei8, arrayRef, "ptr", callInst);
#else
llvm::Value *ptr =
llvm::GetElementPtrInst::Create(basei8, &indices[0], &indices[1],
"ptr", callInst);
#endif
lCopyMetadata(ptr, callInst);
if (gatherInfo != NULL) {