Skip to content

Commit

Permalink
Require LLVM 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed May 30, 2015
1 parent 474c6e0 commit 549715d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 108 deletions.
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,11 @@ then
LLVM_VERSION=$($LLVM_CONFIG --version)

case $LLVM_VERSION in
(3.[5-6]*)
(3.6*)
msg "found ok version of LLVM: $LLVM_VERSION"
;;
(*)
err "bad LLVM version: $LLVM_VERSION, need >=3.5"
err "bad LLVM version: $LLVM_VERSION, need 3.6*"
;;
esac
fi
Expand Down
18 changes: 6 additions & 12 deletions src/rustllvm/ExecutionEngineWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,12 @@ extern "C" LLVMExecutionEngineRef LLVMBuildExecutionEngine(
options.JITEmitDebugInfo = true;
options.NoFramePointerElim = true;

ExecutionEngine *ee =
#if LLVM_VERSION_MINOR >= 6
EngineBuilder(std::unique_ptr<Module>(unwrap(mod)))
.setMCJITMemoryManager(std::unique_ptr<RustJITMemoryManager>(unwrap(mref)))
#else
EngineBuilder(unwrap(mod))
.setMCJITMemoryManager(unwrap(mref))
#endif
.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str)
.setTargetOptions(options)
.create();
ExecutionEngine *ee = EngineBuilder(std::unique_ptr<Module>(unwrap(mod)))
.setMCJITMemoryManager(std::unique_ptr<RustJITMemoryManager>(unwrap(mref)))
.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str)
.setTargetOptions(options)
.create();

if (!ee)
LLVMRustSetLastError(error_str.c_str());
Expand Down
12 changes: 0 additions & 12 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
LLVMPassManagerRef PMR,
LLVMModuleRef M) {
PassManagerBase *PM = unwrap(PMR);
#if LLVM_VERSION_MINOR >= 6
PM->add(new DataLayoutPass());
#else
PM->add(new DataLayoutPass(unwrap(M)));
#endif
unwrap(TM)->addAnalysisPasses(*PM);
}

Expand Down Expand Up @@ -192,14 +188,10 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
PassManager *PM = unwrap<PassManager>(PMR);

std::string ErrorInfo;
#if LLVM_VERSION_MINOR >= 6
std::error_code EC;
raw_fd_ostream OS(path, EC, sys::fs::F_None);
if (EC)
ErrorInfo = EC.message();
#else
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
#endif
if (ErrorInfo != "") {
LLVMRustSetLastError(ErrorInfo.c_str());
return false;
Expand All @@ -218,14 +210,10 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
PassManager *PM = unwrap<PassManager>(PMR);
std::string ErrorInfo;

#if LLVM_VERSION_MINOR >= 6
std::error_code EC;
raw_fd_ostream OS(path, EC, sys::fs::F_None);
if (EC)
ErrorInfo = EC.message();
#else
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
#endif

formatted_raw_ostream FOS(OS);

Expand Down
83 changes: 1 addition & 82 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty,

typedef DIBuilder* DIBuilderRef;

#if LLVM_VERSION_MINOR >= 6
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;

namespace llvm {
Expand All @@ -224,9 +223,6 @@ inline Metadata **unwrap(LLVMMetadataRef *Vals) {
return reinterpret_cast<Metadata**>(Vals);
}
}
#else
typedef LLVMValueRef LLVMMetadataRef;
#endif

template<typename DIT>
DIT unwrapDI(LLVMMetadataRef ref) {
Expand Down Expand Up @@ -288,11 +284,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(
LLVMMetadataRef ParameterTypes) {
return wrap(Builder->createSubroutineType(
unwrapDI<DIFile>(File),
#if LLVM_VERSION_MINOR >= 6
unwrapDI<DITypeArray>(ParameterTypes)));
#else
unwrapDI<DIArray>(ParameterTypes)));
#endif
}

extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
Expand Down Expand Up @@ -398,11 +390,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
unsigned Col) {
return wrap(Builder->createLexicalBlock(
unwrapDI<DIDescriptor>(Scope),
unwrapDI<DIFile>(File), Line, Col
#if LLVM_VERSION_MINOR == 5
, 0
#endif
));
unwrapDI<DIFile>(File), Line, Col));
}

extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
Expand All @@ -416,11 +404,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
bool isLocalToUnit,
LLVMValueRef Val,
LLVMMetadataRef Decl = NULL) {
#if LLVM_VERSION_MINOR >= 6
return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
#else
return wrap(Builder->createStaticVariable(unwrapDI<DIDescriptor>(Context),
#endif
Name,
LinkageName,
unwrapDI<DIFile>(File),
Expand All @@ -444,25 +428,6 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
int64_t* AddrOps,
unsigned AddrOpsCount,
unsigned ArgNo) {
#if LLVM_VERSION_MINOR == 5
if (AddrOpsCount > 0) {
SmallVector<llvm::Value *, 16> addr_ops;
llvm::Type *Int64Ty = Type::getInt64Ty(unwrap<MDNode>(Scope)->getContext());
for (unsigned i = 0; i < AddrOpsCount; ++i)
addr_ops.push_back(ConstantInt::get(Int64Ty, AddrOps[i]));

return wrap(Builder->createComplexVariable(
Tag,
unwrapDI<DIDescriptor>(Scope),
Name,
unwrapDI<DIFile>(File),
LineNo,
unwrapDI<DIType>(Ty),
addr_ops,
ArgNo
));
}
#endif
return wrap(Builder->createLocalVariable(Tag,
unwrapDI<DIDescriptor>(Scope), Name,
unwrapDI<DIFile>(File),
Expand Down Expand Up @@ -504,11 +469,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(
LLVMMetadataRef* Ptr,
unsigned Count) {
return wrap(Builder->getOrCreateArray(
#if LLVM_VERSION_MINOR >= 6
ArrayRef<Metadata*>(unwrap(Ptr), Count)));
#else
ArrayRef<Value*>(reinterpret_cast<Value**>(Ptr), Count)));
#endif
}

extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
Expand All @@ -518,21 +479,17 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
int64_t* AddrOps,
unsigned AddrOpsCount,
LLVMBasicBlockRef InsertAtEnd) {
#if LLVM_VERSION_MINOR >= 6
DIExpression Expr;
if (AddrOpsCount == 0) {
Expr = Builder->createExpression();
} else {
llvm::ArrayRef<int64_t> addr_ops(AddrOps, AddrOpsCount);
Expr = Builder->createExpression(addr_ops);
}
#endif
return wrap(Builder->insertDeclare(
unwrap(Val),
unwrapDI<DIVariable>(VarInfo),
#if LLVM_VERSION_MINOR >= 6
Expr,
#endif
unwrap(InsertAtEnd)));
}

Expand All @@ -543,21 +500,17 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
int64_t* AddrOps,
unsigned AddrOpsCount,
LLVMValueRef InsertBefore) {
#if LLVM_VERSION_MINOR >= 6
DIExpression Expr;
if (AddrOpsCount == 0) {
Expr = Builder->createExpression();
} else {
llvm::ArrayRef<int64_t> addr_ops(AddrOps, AddrOpsCount);
Expr = Builder->createExpression(addr_ops);
}
#endif
return wrap(Builder->insertDeclare(
unwrap(Val),
unwrapDI<DIVariable>(VarInfo),
#if LLVM_VERSION_MINOR >= 6
Expr,
#endif
unwrap<Instruction>(InsertBefore)));
}

Expand Down Expand Up @@ -665,12 +618,8 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
LLVMMetadataRef CompositeType,
LLVMMetadataRef TypeArray)
{
#if LLVM_VERSION_MINOR >= 6
DICompositeType tmp = unwrapDI<DICompositeType>(CompositeType);
Builder->replaceArrays(tmp, unwrapDI<DIArray>(TypeArray));
#else
unwrapDI<DICompositeType>(CompositeType).setTypeArray(unwrapDI<DIArray>(TypeArray));
#endif
}

extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
Expand All @@ -687,11 +636,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
unwrapDI<MDNode*>(Scope),
unwrapDI<MDNode*>(InlinedAt));

#if LLVM_VERSION_MINOR >= 6
return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode(context)));
#else
return wrap(debug_loc.getAsMDNode(context));
#endif
}

extern "C" void LLVMWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
Expand All @@ -711,30 +656,18 @@ extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
extern "C" bool
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
Module *Dst = unwrap(dst);
#if LLVM_VERSION_MINOR >= 6
std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
#else
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(buf, Dst->getContext());
#endif
if (!Src) {
LLVMRustSetLastError(Src.getError().message().c_str());
#if LLVM_VERSION_MINOR == 5
delete buf;
#endif
return false;
}

std::string Err;

#if LLVM_VERSION_MINOR >= 6
raw_string_ostream Stream(Err);
DiagnosticPrinterRawOStream DP(Stream);
if (Linker::LinkModules(Dst, *Src, [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
#else
if (Linker::LinkModules(Dst, *Src, Linker::DestroySource, &Err)) {
#endif
LLVMRustSetLastError(Err.c_str());
return false;
}
Expand All @@ -751,7 +684,6 @@ LLVMRustOpenArchive(char *path) {
return nullptr;
}

#if LLVM_VERSION_MINOR >= 6
ErrorOr<std::unique_ptr<Archive>> archive_or =
Archive::create(buf_or.get()->getMemBufferRef());

Expand All @@ -762,25 +694,12 @@ LLVMRustOpenArchive(char *path) {

OwningBinary<Archive> *ret = new OwningBinary<Archive>(
std::move(archive_or.get()), std::move(buf_or.get()));
#else
std::error_code err;
Archive *ret = new Archive(std::move(buf_or.get()), err);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return nullptr;
}
#endif

return ret;
}

#if LLVM_VERSION_MINOR >= 6
typedef OwningBinary<Archive> RustArchive;
#define GET_ARCHIVE(a) ((a)->getBinary())
#else
typedef Archive RustArchive;
#define GET_ARCHIVE(a) (a)
#endif

extern "C" void
LLVMRustDestroyArchive(RustArchive *ar) {
Expand Down

0 comments on commit 549715d

Please sign in to comment.