about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-01-30 00:25:44 +0000
committerbors <bors@rust-lang.org>2016-01-30 00:25:44 +0000
commit303892ee156e5c31222b10786e661abb24dcf241 (patch)
tree7e0f55d91bd180b8bc8ac8d700e99035da555fbf /src/rustllvm/RustWrapper.cpp
parent074f49a350f22b6f33890cd105b2ebe2c790ee3c (diff)
parent58f1b9c7fc93961fee8c94b6bdcbd5abfe84d5e0 (diff)
downloadrust-303892ee156e5c31222b10786e661abb24dcf241.tar.gz
rust-303892ee156e5c31222b10786e661abb24dcf241.zip
Auto merge of #30448 - alexcrichton:llvmup, r=nikomatsakis
These commits perform a few high-level changes with the goal of enabling i686 MSVC unwinding:

* LLVM is upgraded to pick up the new exception handling instructions and intrinsics for MSVC. This puts us somewhere along the 3.8 branch, but we should still be compatible with LLVM 3.7 for non-MSVC targets.
* All unwinding for MSVC targets (both 32 and 64-bit) are implemented in terms of this new LLVM support. I would like to also extend this to Windows GNU targets to drop the runtime dependencies we have on MinGW, but I'd like to land this first.
* Some tests were fixed up for i686 MSVC here and there where necessary. The full test suite should be passing now for that target.

In terms of landing this I plan to have this go through first, then verify that i686 MSVC works, then I'll enable `make check` on the bots for that target instead of just `make` as-is today.

Closes #25869
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
-rw-r--r--src/rustllvm/RustWrapper.cpp196
1 files changed, 195 insertions, 1 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index 5a9c096e5f5..0c18051dac7 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -348,6 +348,19 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
     LLVMValueRef Fn,
     LLVMMetadataRef TParam,
     LLVMMetadataRef Decl) {
+#if LLVM_VERSION_MINOR >= 8
+    DITemplateParameterArray TParams =
+        DITemplateParameterArray(unwrap<MDTuple>(TParam));
+    DISubprogram *Sub = Builder->createFunction(
+        unwrapDI<DIScope>(Scope), Name, LinkageName,
+        unwrapDI<DIFile>(File), LineNo,
+        unwrapDI<DISubroutineType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
+        Flags, isOptimized,
+        TParams,
+        unwrapDIptr<DISubprogram>(Decl));
+    unwrap<Function>(Fn)->setSubprogram(Sub);
+    return wrap(Sub);
+#else
     return wrap(Builder->createFunction(
         unwrapDI<DIScope>(Scope), Name, LinkageName,
         unwrapDI<DIFile>(File), LineNo,
@@ -356,6 +369,7 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
         unwrap<Function>(Fn),
         unwrapDIptr<MDNode>(TParam),
         unwrapDIptr<MDNode>(Decl)));
+#endif
 }
 
 extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType(
@@ -830,7 +844,9 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
 #if LLVM_VERSION_MINOR >= 6
     raw_string_ostream Stream(Err);
     DiagnosticPrinterRawOStream DP(Stream);
-#if LLVM_VERSION_MINOR >= 7
+#if LLVM_VERSION_MINOR >= 8
+    if (Linker::linkModules(*Dst, std::move(Src.get()))) {
+#elif LLVM_VERSION_MINOR >= 7
     if (Linker::LinkModules(Dst, Src->get(), [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
 #else
     if (Linker::LinkModules(Dst, *Src, [&](const DiagnosticInfo &DI) { DI.print(DP); })) {
@@ -971,3 +987,181 @@ LLVMRustBuildLandingPad(LLVMBuilderRef Builder,
                         LLVMValueRef F) {
     return LLVMBuildLandingPad(Builder, Ty, PersFn, NumClauses, Name);
 }
+
+extern "C" LLVMValueRef
+LLVMRustBuildCleanupPad(LLVMBuilderRef Builder,
+                        LLVMValueRef ParentPad,
+                        unsigned ArgCnt,
+                        LLVMValueRef *LLArgs,
+                        const char *Name) {
+#if LLVM_VERSION_MINOR >= 8
+    Value **Args = unwrap(LLArgs);
+    if (ParentPad == NULL) {
+        Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
+        ParentPad = wrap(Constant::getNullValue(Ty));
+    }
+    return wrap(unwrap(Builder)->CreateCleanupPad(unwrap(ParentPad),
+                                                  ArrayRef<Value*>(Args, ArgCnt),
+                                                  Name));
+#else
+    return NULL;
+#endif
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
+                        LLVMValueRef CleanupPad,
+                        LLVMBasicBlockRef UnwindBB) {
+#if LLVM_VERSION_MINOR >= 8
+    CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
+    return wrap(unwrap(Builder)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
+#else
+    return NULL;
+#endif
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCatchPad(LLVMBuilderRef Builder,
+                      LLVMValueRef ParentPad,
+                      unsigned ArgCnt,
+                      LLVMValueRef *LLArgs,
+                      const char *Name) {
+#if LLVM_VERSION_MINOR >= 8
+    Value **Args = unwrap(LLArgs);
+    return wrap(unwrap(Builder)->CreateCatchPad(unwrap(ParentPad),
+                                                ArrayRef<Value*>(Args, ArgCnt),
+                                                Name));
+#else
+    return NULL;
+#endif
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCatchRet(LLVMBuilderRef Builder,
+                      LLVMValueRef Pad,
+                      LLVMBasicBlockRef BB) {
+#if LLVM_VERSION_MINOR >= 8
+    return wrap(unwrap(Builder)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
+                                                unwrap(BB)));
+#else
+    return NULL;
+#endif
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCatchSwitch(LLVMBuilderRef Builder,
+                         LLVMValueRef ParentPad,
+                         LLVMBasicBlockRef BB,
+                         unsigned NumHandlers,
+                         const char *Name) {
+#if LLVM_VERSION_MINOR >= 8
+    if (ParentPad == NULL) {
+        Type *Ty = Type::getTokenTy(unwrap(Builder)->getContext());
+        ParentPad = wrap(Constant::getNullValue(Ty));
+    }
+    return wrap(unwrap(Builder)->CreateCatchSwitch(unwrap(ParentPad),
+                                                   unwrap(BB),
+                                                   NumHandlers,
+                                                   Name));
+#else
+    return NULL;
+#endif
+}
+
+extern "C" void
+LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
+                   LLVMBasicBlockRef Handler) {
+#if LLVM_VERSION_MINOR >= 8
+    Value *CatchSwitch = unwrap(CatchSwitchRef);
+    cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
+#endif
+}
+
+extern "C" void
+LLVMRustSetPersonalityFn(LLVMBuilderRef B,
+                         LLVMValueRef Personality) {
+#if LLVM_VERSION_MINOR >= 8
+    unwrap(B)->GetInsertBlock()
+             ->getParent()
+             ->setPersonalityFn(cast<Function>(unwrap(Personality)));
+#endif
+}
+
+#if LLVM_VERSION_MINOR >= 8
+extern "C" OperandBundleDef*
+LLVMRustBuildOperandBundleDef(const char *Name,
+                              LLVMValueRef *Inputs,
+                              unsigned NumInputs) {
+  return new OperandBundleDef(Name, makeArrayRef(unwrap(Inputs), NumInputs));
+}
+
+extern "C" void
+LLVMRustFreeOperandBundleDef(OperandBundleDef* Bundle) {
+  delete Bundle;
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCall(LLVMBuilderRef B,
+                    LLVMValueRef Fn,
+                    LLVMValueRef *Args,
+                    unsigned NumArgs,
+                    OperandBundleDef *Bundle,
+                    const char *Name) {
+    unsigned len = Bundle ? 1 : 0;
+    ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
+    return wrap(unwrap(B)->CreateCall(unwrap(Fn),
+                                      makeArrayRef(unwrap(Args), NumArgs),
+                                      Bundles,
+                                      Name));
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildInvoke(LLVMBuilderRef B,
+                    LLVMValueRef Fn,
+                    LLVMValueRef *Args,
+                    unsigned NumArgs,
+                    LLVMBasicBlockRef Then,
+                    LLVMBasicBlockRef Catch,
+                    OperandBundleDef *Bundle,
+                    const char *Name) {
+    unsigned len = Bundle ? 1 : 0;
+    ArrayRef<OperandBundleDef> Bundles = makeArrayRef(Bundle, len);
+    return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
+                                        makeArrayRef(unwrap(Args), NumArgs),
+                                        Bundles,
+                                        Name));
+}
+#else
+extern "C" void*
+LLVMRustBuildOperandBundleDef(const char *Name,
+                              LLVMValueRef *Inputs,
+                              unsigned NumInputs) {
+  return NULL;
+}
+
+extern "C" void
+LLVMRustFreeOperandBundleDef(void* Bundle) {
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildCall(LLVMBuilderRef B,
+                    LLVMValueRef Fn,
+                    LLVMValueRef *Args,
+                    unsigned NumArgs,
+                    void *Bundle,
+                    const char *Name) {
+    return LLVMBuildCall(B, Fn, Args, NumArgs, Name);
+}
+
+extern "C" LLVMValueRef
+LLVMRustBuildInvoke(LLVMBuilderRef B,
+                    LLVMValueRef Fn,
+                    LLVMValueRef *Args,
+                    unsigned NumArgs,
+                    LLVMBasicBlockRef Then,
+                    LLVMBasicBlockRef Catch,
+                    void *Bundle,
+                    const char *Name) {
+    return LLVMBuildInvoke(B, Fn, Args, NumArgs, Then, Catch, Name);
+}
+#endif