diff options
Diffstat (limited to 'patches/llvm_host')
9 files changed, 825 insertions, 0 deletions
diff --git a/patches/llvm_host/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch b/patches/llvm_host/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch new file mode 100644 index 00000000..c1dfc5bd --- /dev/null +++ b/patches/llvm_host/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch @@ -0,0 +1,112 @@ +From 1cec99f6d53d442d8a8c9d2ed9f4a58f8fdc6412 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Thu, 18 Feb 2016 08:30:07 +0100 +Subject: [PATCH 1/3] Add Musl, MuslEABI and Musl EABIHF triples + +--- + include/llvm/ADT/Triple.h | 11 +++++++++++ + lib/Support/Triple.cpp | 7 +++++++ + lib/Target/ARM/ARMSubtarget.h | 3 +++ + lib/Target/ARM/ARMTargetMachine.cpp | 2 ++ + 4 files changed, 23 insertions(+) + +diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h +index e01db0a..2fc4fc1 100644 +--- a/include/llvm/ADT/Triple.h ++++ b/include/llvm/ADT/Triple.h +@@ -174,6 +174,10 @@ public: + EABIHF, + Android, + ++ Musl, ++ MuslEABI, ++ MuslEABIHF, ++ + MSVC, + Itanium, + Cygnus, +@@ -544,6 +548,13 @@ public: + /// Tests whether the target is Android + bool isAndroid() const { return getEnvironment() == Triple::Android; } + ++ /// Tests whether the target is musl libc ++ bool isMusl() const { ++ return getEnvironment() == Triple::Musl || ++ getEnvironment() == Triple::MuslEABI || ++ getEnvironment() == Triple::MuslEABIHF; ++ } ++ + /// @} + /// @name Mutators + /// @{ +diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp +index 11afcf7..d90a06a 100644 +--- a/lib/Support/Triple.cpp ++++ b/lib/Support/Triple.cpp +@@ -199,6 +199,9 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) { + case CODE16: return "code16"; + case EABI: return "eabi"; + case EABIHF: return "eabihf"; ++ case Musl: return "musl"; ++ case MuslEABIHF: return "muslgnueabihf"; ++ case MuslEABI: return "muslgnueabi"; + case Android: return "android"; + case MSVC: return "msvc"; + case Itanium: return "itanium"; +@@ -454,6 +457,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { + .StartsWith("code16", Triple::CODE16) + .StartsWith("gnu", Triple::GNU) + .StartsWith("android", Triple::Android) ++ .StartsWith("muslgnueabihf", Triple::MuslEABIHF) ++ .StartsWith("muslgnueabi", Triple::MuslEABI) ++ .StartsWith("musl", Triple::Musl) + .StartsWith("msvc", Triple::MSVC) + .StartsWith("itanium", Triple::Itanium) + .StartsWith("cygnus", Triple::Cygnus) +@@ -1431,6 +1437,7 @@ StringRef Triple::getARMCPUForArch(StringRef MArch) const { + switch (getEnvironment()) { + case llvm::Triple::EABIHF: + case llvm::Triple::GNUEABIHF: ++ case llvm::Triple::MuslEABIHF: + return "arm1176jzf-s"; + default: + return "arm7tdmi"; +diff --git a/lib/Target/ARM/ARMSubtarget.h b/lib/Target/ARM/ARMSubtarget.h +index 4d54e57..7ed7ab7 100644 +--- a/lib/Target/ARM/ARMSubtarget.h ++++ b/lib/Target/ARM/ARMSubtarget.h +@@ -405,8 +405,10 @@ public: + bool isTargetEHABICompatible() const { + return (TargetTriple.getEnvironment() == Triple::EABI || + TargetTriple.getEnvironment() == Triple::GNUEABI || ++ TargetTriple.getEnvironment() == Triple::MuslEABI || + TargetTriple.getEnvironment() == Triple::EABIHF || + TargetTriple.getEnvironment() == Triple::GNUEABIHF || ++ TargetTriple.getEnvironment() == Triple::MuslEABIHF || + isTargetAndroid()) && + !isTargetDarwin() && !isTargetWindows(); + } +@@ -415,6 +417,7 @@ public: + // FIXME: this is invalid for WindowsCE + return TargetTriple.getEnvironment() == Triple::GNUEABIHF || + TargetTriple.getEnvironment() == Triple::EABIHF || ++ TargetTriple.getEnvironment() == Triple::MuslEABIHF || + isTargetWindows() || isAAPCS16_ABI(); + } + bool isTargetAndroid() const { return TargetTriple.isAndroid(); } +diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp +index fca1901..25f5cf9 100644 +--- a/lib/Target/ARM/ARMTargetMachine.cpp ++++ b/lib/Target/ARM/ARMTargetMachine.cpp +@@ -101,6 +101,8 @@ computeTargetABI(const Triple &TT, StringRef CPU, + case llvm::Triple::GNUEABIHF: + case llvm::Triple::EABIHF: + case llvm::Triple::EABI: ++ case llvm::Triple::MuslEABI: ++ case llvm::Triple::MuslEABIHF: + TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS; + break; + case llvm::Triple::GNU: +-- +2.7.3 + diff --git a/patches/llvm_host/llvm-0002-Fix-build-with-musl-libc.patch b/patches/llvm_host/llvm-0002-Fix-build-with-musl-libc.patch new file mode 100644 index 00000000..1a690808 --- /dev/null +++ b/patches/llvm_host/llvm-0002-Fix-build-with-musl-libc.patch @@ -0,0 +1,35 @@ +From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Thu, 18 Feb 2016 10:33:04 +0100 +Subject: [PATCH 2/3] Fix build with musl libc + +On musl libc the fopen64 and fopen are the same thing, but for +compatibility they have a `#define fopen64 fopen`. Same applies for +fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64. +--- + include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h +index 7becdf0..7f14427 100644 +--- a/include/llvm/Analysis/TargetLibraryInfo.h ++++ b/include/llvm/Analysis/TargetLibraryInfo.h +@@ -18,6 +18,15 @@ + #include "llvm/IR/Module.h" + #include "llvm/Pass.h" + ++#undef fopen64 ++#undef fseeko64 ++#undef fstat64 ++#undef fstatvfs64 ++#undef ftello64 ++#undef lstat64 ++#undef stat64 ++#undef tmpfile64 ++ + namespace llvm { + /// VecDesc - Describes a possible vectorization of a function. + /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized +-- +2.7.3 + diff --git a/patches/llvm_host/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch b/patches/llvm_host/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch new file mode 100644 index 00000000..d5d7f07b --- /dev/null +++ b/patches/llvm_host/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch @@ -0,0 +1,33 @@ +From d12ecb83d01dcb580dd94f4d57828f33d3eb4c35 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Thu, 18 Feb 2016 15:33:21 +0100 +Subject: [PATCH 3/3] Fix DynamicLibrary to build with musl libc + +stdin/out/err is part of the libc and not the kernel so we check for the +specific libc that does the unexpected instead of linux. + +This is needed for making it build with musl libc. +--- + lib/Support/DynamicLibrary.cpp | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp +index 9a7aeb5..0c1c8f8 100644 +--- a/lib/Support/DynamicLibrary.cpp ++++ b/lib/Support/DynamicLibrary.cpp +@@ -140,10 +140,10 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) { + #define EXPLICIT_SYMBOL(SYM) \ + if (!strcmp(symbolName, #SYM)) return &SYM + +-// On linux we have a weird situation. The stderr/out/in symbols are both ++// On GNU libc we have a weird situation. The stderr/out/in symbols are both + // macros and global variables because of standards requirements. So, we + // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first. +-#if defined(__linux__) and !defined(__ANDROID__) ++#if defined(__GLIBC__) + { + EXPLICIT_SYMBOL(stderr); + EXPLICIT_SYMBOL(stdout); +-- +2.7.3 + diff --git a/patches/llvm_host/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch b/patches/llvm_host/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch new file mode 100644 index 00000000..9945bf35 --- /dev/null +++ b/patches/llvm_host/llvm-0004-Fix-ScalarEvolutionExpander-step-scaling-bug.patch @@ -0,0 +1,99 @@ +From c8ce9e59a883f452bc538b5f16fb83649472dc3e Mon Sep 17 00:00:00 2001 +From: Keno Fischer <kfischer@college.harvard.edu> +Date: Wed, 13 Jul 2016 01:28:12 +0000 +Subject: [PATCH] Fix ScalarEvolutionExpander step scaling bug + +The expandAddRecExprLiterally function incorrectly transforms +`[Start + Step * X]` into `Step * [Start + X]` instead of the correct +transform of `[Step * X] + Start`. + +This caused https://github.com/JuliaLang/julia/issues/14704#issuecomment-174126219 +due to what appeared to be sufficiently complicated loop interactions. + +Patch by Jameson Nash (jameson@juliacomputing.com). + +Reviewers: sanjoy +Differential Revision: http://reviews.llvm.org/D16505 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275239 91177308-0d34-0410-b5e6-96231b3b80d8 + +Alpine maintainer notes: +This patch replaces deps/patches/llvm-3.7.1_3.patch from Julia. +--- + lib/Analysis/ScalarEvolutionExpander.cpp | 7 ++++ + .../ScalarEvolution/incorrect-offset-scaling.ll | 48 ++++++++++++++++++++++ + 2 files changed, 55 insertions(+) + create mode 100644 test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll + +diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp +index 7716435..77e4ec7 100644 +--- a/lib/Analysis/ScalarEvolutionExpander.cpp ++++ b/lib/Analysis/ScalarEvolutionExpander.cpp +@@ -1288,6 +1288,13 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) { + if (!SE.dominates(Step, L->getHeader())) { + PostLoopScale = Step; + Step = SE.getConstant(Normalized->getType(), 1); ++ if (!Start->isZero()) { ++ // The normalization below assumes that Start is constant zero, so if ++ // it isn't re-associate Start to PostLoopOffset. ++ assert(!PostLoopOffset && "Start not-null but PostLoopOffset set?"); ++ PostLoopOffset = Start; ++ Start = SE.getConstant(Normalized->getType(), 0); ++ } + Normalized = + cast<SCEVAddRecExpr>(SE.getAddRecExpr( + Start, Step, Normalized->getLoop(), +diff --git a/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll +new file mode 100644 +index 0000000..7ffb093 +--- /dev/null ++++ b/test/Analysis/ScalarEvolution/incorrect-offset-scaling.ll +@@ -0,0 +1,48 @@ ++; RUN: opt -S -loop-reduce < %s | FileCheck %s ++ ++target triple = "x86_64-unknown-unknown" ++target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" ++ ++define void @incorrect_offset_scaling(i64, i64*) { ++top: ++ br label %L ++ ++L: ; preds = %idxend.10, %idxend, %L2, %top ++ br i1 undef, label %L, label %L1 ++ ++L1: ; preds = %L1.preheader, %L2 ++ %r13 = phi i64 [ %r1, %L2 ], [ 1, %L ] ++; CHECK: %lsr.iv = phi i64 [ 0, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ] ++; CHECK-NOT: %lsr.iv = phi i64 [ -1, %L{{[^ ]+}} ], [ %lsr.iv.next, %L2 ] ++; CHECK: br ++ %r0 = add i64 %r13, -1 ++ br label %idxend.8 ++ ++L2: ; preds = %idxend.8 ++ %r1 = add i64 %r13, 1 ++ br i1 undef, label %L, label %L1 ++ ++if6: ; preds = %idxend.8 ++ %r2 = add i64 %0, -1 ++ %r3 = load i64, i64* %1, align 8 ++; CHECK-NOT: %r2 ++; CHECK: %r3 = load i64 ++ br label %ib ++ ++idxend.8: ; preds = %L1 ++ br i1 undef, label %if6, label %L2 ++ ++ib: ; preds = %if6 ++ %r4 = mul i64 %r3, %r0 ++ %r5 = add i64 %r2, %r4 ++ %r6 = icmp ult i64 %r5, undef ++; CHECK %2 = mul i64 %lsr.iv, %r3 ++; CHECK %3 = add i64 %1, -1 ++; CHECK %4 = add i64 %0, %r3 ++; CHECK %r6 ++ %r7 = getelementptr i64, i64* undef, i64 %r5 ++ store i64 1, i64* %r7, align 8 ++; CHECK %5 = mul i64 %lsr.iv, %r3 ++; CHECK %6 = add i64 %5, -1 ++ br label %L ++} diff --git a/patches/llvm_host/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch b/patches/llvm_host/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch new file mode 100644 index 00000000..7f891b66 --- /dev/null +++ b/patches/llvm_host/llvm-0005-optimize-store-of-bitcast-from-vector-to-aggregate.patch @@ -0,0 +1,181 @@ +From 1ca1fcaa5b4c75a65a202badfd5df8240a36ca0f Mon Sep 17 00:00:00 2001 +From: "Arch D. Robison" <arch.robison@intel.com> +Date: Mon, 25 Apr 2016 22:22:39 +0000 +Subject: [PATCH] Optimize store of "bitcast" from vector to aggregate. + +This patch is what was the "instcombine" portion of D14185, with an additional +test added (see julia_pseudovec in test/Transforms/InstCombine/insert-val-extract-elem.ll). +The patch causes instcombine to replace sequences of extractelement-insertvalue-store +that act essentially like a bitcast followed by a store. + +Differential review: http://reviews.llvm.org/D14260 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267482 91177308-0d34-0410-b5e6-96231b3b80d8 + +Alpine maintainer notes: + - Updated for llvm 3.8.1. + - This patch replaces llvm-D14260.patch from Julia. +--- + .../InstCombine/InstCombineLoadStoreAlloca.cpp | 60 ++++++++++++++++++ + .../InstCombine/insert-val-extract-elem.ll | 74 ++++++++++++++++++++++ + 2 files changed, 134 insertions(+) + create mode 100644 test/Transforms/InstCombine/insert-val-extract-elem.ll + +diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +index 96f0908..0ee6045 100644 +--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp ++++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +@@ -913,6 +913,61 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { + return nullptr; + } + ++/// \brief Look for extractelement/insertvalue sequence that acts like a bitcast. ++/// ++/// \returns underlying value that was "cast", or nullptr otherwise. ++/// ++/// For example, if we have: ++/// ++/// %E0 = extractelement <2 x double> %U, i32 0 ++/// %V0 = insertvalue [2 x double] undef, double %E0, 0 ++/// %E1 = extractelement <2 x double> %U, i32 1 ++/// %V1 = insertvalue [2 x double] %V0, double %E1, 1 ++/// ++/// and the layout of a <2 x double> is isomorphic to a [2 x double], ++/// then %V1 can be safely approximated by a conceptual "bitcast" of %U. ++/// Note that %U may contain non-undef values where %V1 has undef. ++static Value *likeBitCastFromVector(InstCombiner &IC, Value *V) { ++ Value *U = nullptr; ++ while (auto *IV = dyn_cast<InsertValueInst>(V)) { ++ auto *E = dyn_cast<ExtractElementInst>(IV->getInsertedValueOperand()); ++ if (!E) ++ return nullptr; ++ auto *W = E->getVectorOperand(); ++ if (!U) ++ U = W; ++ else if (U != W) ++ return nullptr; ++ auto *CI = dyn_cast<ConstantInt>(E->getIndexOperand()); ++ if (!CI || IV->getNumIndices() != 1 || CI->getZExtValue() != *IV->idx_begin()) ++ return nullptr; ++ V = IV->getAggregateOperand(); ++ } ++ if (!isa<UndefValue>(V) ||!U) ++ return nullptr; ++ ++ auto *UT = cast<VectorType>(U->getType()); ++ auto *VT = V->getType(); ++ // Check that types UT and VT are bitwise isomorphic. ++ const auto &DL = IC.getDataLayout(); ++ if (DL.getTypeStoreSizeInBits(UT) != DL.getTypeStoreSizeInBits(VT)) { ++ return nullptr; ++ } ++ if (auto *AT = dyn_cast<ArrayType>(VT)) { ++ if (AT->getNumElements() != UT->getNumElements()) ++ return nullptr; ++ } else { ++ auto *ST = cast<StructType>(VT); ++ if (ST->getNumElements() != UT->getNumElements()) ++ return nullptr; ++ for (const auto *EltT : ST->elements()) { ++ if (EltT != UT->getElementType()) ++ return nullptr; ++ } ++ } ++ return U; ++} ++ + /// \brief Combine stores to match the type of value being stored. + /// + /// The core idea here is that the memory does not have any intrinsic type and +@@ -924,6 +979,11 @@ + return true; + } + ++ if (Value *U = likeBitCastFromVector(IC, V)) { ++ combineStoreToNewValue(IC, SI, U); ++ return true; ++ } ++ + // FIXME: We should also canonicalize loads of vectors when their elements are + // cast to other types. + return false; +diff --git a/test/Transforms/InstCombine/insert-val-extract-elem.ll b/test/Transforms/InstCombine/insert-val-extract-elem.ll +new file mode 100644 +index 0000000..db7b403 +--- /dev/null ++++ b/test/Transforms/InstCombine/insert-val-extract-elem.ll +@@ -0,0 +1,74 @@ ++; RUN: opt -S -instcombine %s | FileCheck %s ++ ++; CHECK-LABEL: julia_2xdouble ++; CHECK-NOT: insertvalue ++; CHECK-NOT: extractelement ++; CHECK: store <2 x double> ++define void @julia_2xdouble([2 x double]* sret, <2 x double>*) { ++top: ++ %x = load <2 x double>, <2 x double>* %1 ++ %x0 = extractelement <2 x double> %x, i32 0 ++ %i0 = insertvalue [2 x double] undef, double %x0, 0 ++ %x1 = extractelement <2 x double> %x, i32 1 ++ %i1 = insertvalue [2 x double] %i0, double %x1, 1 ++ store [2 x double] %i1, [2 x double]* %0, align 4 ++ ret void ++} ++ ++; Test with two inserts to the same index ++; CHECK-LABEL: julia_2xi64 ++; CHECK-NOT: insertvalue ++; CHECK-NOT: extractelement ++; CHECK: store <2 x i64> ++define void @julia_2xi64([2 x i64]* sret, <2 x i64>*) { ++top: ++ %x = load <2 x i64>, <2 x i64>* %1 ++ %x0 = extractelement <2 x i64> %x, i32 1 ++ %i0 = insertvalue [2 x i64] undef, i64 %x0, 0 ++ %x1 = extractelement <2 x i64> %x, i32 1 ++ %i1 = insertvalue [2 x i64] %i0, i64 %x1, 1 ++ %x2 = extractelement <2 x i64> %x, i32 0 ++ %i2 = insertvalue [2 x i64] %i1, i64 %x2, 0 ++ store [2 x i64] %i2, [2 x i64]* %0, align 4 ++ ret void ++} ++ ++; CHECK-LABEL: julia_4xfloat ++; CHECK-NOT: insertvalue ++; CHECK-NOT: extractelement ++; CHECK: store <4 x float> ++define void @julia_4xfloat([4 x float]* sret, <4 x float>*) { ++top: ++ %x = load <4 x float>, <4 x float>* %1 ++ %x0 = extractelement <4 x float> %x, i32 0 ++ %i0 = insertvalue [4 x float] undef, float %x0, 0 ++ %x1 = extractelement <4 x float> %x, i32 1 ++ %i1 = insertvalue [4 x float] %i0, float %x1, 1 ++ %x2 = extractelement <4 x float> %x, i32 2 ++ %i2 = insertvalue [4 x float] %i1, float %x2, 2 ++ %x3 = extractelement <4 x float> %x, i32 3 ++ %i3 = insertvalue [4 x float] %i2, float %x3, 3 ++ store [4 x float] %i3, [4 x float]* %0, align 4 ++ ret void ++} ++ ++%pseudovec = type { float, float, float, float } ++ ++; CHECK-LABEL: julia_pseudovec ++; CHECK-NOT: insertvalue ++; CHECK-NOT: extractelement ++; CHECK: store <4 x float> ++define void @julia_pseudovec(%pseudovec* sret, <4 x float>*) { ++top: ++ %x = load <4 x float>, <4 x float>* %1 ++ %x0 = extractelement <4 x float> %x, i32 0 ++ %i0 = insertvalue %pseudovec undef, float %x0, 0 ++ %x1 = extractelement <4 x float> %x, i32 1 ++ %i1 = insertvalue %pseudovec %i0, float %x1, 1 ++ %x2 = extractelement <4 x float> %x, i32 2 ++ %i2 = insertvalue %pseudovec %i1, float %x2, 2 ++ %x3 = extractelement <4 x float> %x, i32 3 ++ %i3 = insertvalue %pseudovec %i2, float %x3, 3 ++ store %pseudovec %i3, %pseudovec* %0, align 4 ++ ret void ++} diff --git a/patches/llvm_host/llvm-0006-clone-every-functions-debug-info.patch b/patches/llvm_host/llvm-0006-clone-every-functions-debug-info.patch new file mode 100644 index 00000000..567ddcad --- /dev/null +++ b/patches/llvm_host/llvm-0006-clone-every-functions-debug-info.patch @@ -0,0 +1,129 @@ +From 11adcc4de0797c83e61ae0240927f0bafcf041a9 Mon Sep 17 00:00:00 2001 +From: Keno Fischer <kfischer@college.harvard.edu> +Date: Sat, 13 Feb 2016 02:04:29 +0000 +Subject: [PATCH] [Cloning] Clone every Function's Debug Info + +Summary: +Export the CloneDebugInfoMetadata utility, which clones all debug info +associated with a function into the first module. Also use this function +in CloneModule on each function we clone (the CloneFunction entrypoint +already does this). + +Without this, cloning a module will lead to DI quality regressions, +especially since r252219 reversed the Function <-> DISubprogram edge +(before we could get lucky and have this edge preserved if the +DISubprogram itself was, e.g. due to location metadata). + +This was verified to fix missing debug information in julia and +a unittest to verify the new behavior is included. + +Patch by Yichao Yu! Thanks! + +Reviewers: loladiro, pcc +Differential Revision: http://reviews.llvm.org/D17165 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260791 91177308-0d34-0410-b5e6-96231b3b80d8 + +Alpine maintainer notes: + - Corresponds to llvm-D17165-D18583.patch in Julia. +--- + include/llvm/Transforms/Utils/Cloning.h | 5 +++++ + lib/Transforms/Utils/CloneFunction.cpp | 4 ++-- + lib/Transforms/Utils/CloneModule.cpp | 1 + + unittests/Transforms/Utils/Cloning.cpp | 25 +++++++++++++++++++++++++ + 4 files changed, 33 insertions(+), 2 deletions(-) + +diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h +index 4f006f2..0bae2bd 100644 +--- a/include/llvm/Transforms/Utils/Cloning.h ++++ b/include/llvm/Transforms/Utils/Cloning.h +@@ -130,6 +130,11 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap, + bool ModuleLevelChanges, + ClonedCodeInfo *CodeInfo = nullptr); + ++/// Clone the module-level debug info associated with OldFunc. The cloned data ++/// will point to NewFunc instead. ++void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap); ++ + /// Clone OldFunc into NewFunc, transforming the old arguments into references + /// to VMap values. Note that if NewFunc already has basic blocks, the ones + /// cloned into it will be added to the end of the function. This function +diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp +index 6454afb..8b5692a 100644 +--- a/lib/Transforms/Utils/CloneFunction.cpp ++++ b/lib/Transforms/Utils/CloneFunction.cpp +@@ -187,8 +187,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs, + + // Clone the module-level debug info associated with OldFunc. The cloned data + // will point to NewFunc instead. +-static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap) { ++void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap) { + DebugInfoFinder Finder; + Finder.processModule(*OldFunc->getParent()); + +diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp +index 53de62a..b16a02a 100644 +--- a/lib/Transforms/Utils/CloneModule.cpp ++++ b/lib/Transforms/Utils/CloneModule.cpp +@@ -136,6 +136,7 @@ std::unique_ptr<Module> llvm::CloneModule( + VMap[&*J] = &*DestI++; + } + ++ CloneDebugInfoMetadata(F, &*I, VMap); + SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned. + CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); + } +diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp +index 25e322e..b761e4e 100644 +--- a/unittests/Transforms/Utils/Cloning.cpp ++++ b/unittests/Transforms/Utils/Cloning.cpp +@@ -423,6 +423,7 @@ class CloneModule : public ::testing::Test { + void SetupModule() { OldM = new Module("", C); } + + void CreateOldModule() { ++ DIBuilder DBuilder(*OldM); + IRBuilder<> IBuilder(C); + + auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); +@@ -431,9 +432,25 @@ class CloneModule : public ::testing::Test { + auto *F = + Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM); + F->setPersonalityFn(PersFn); ++ ++ // Create debug info ++ auto *File = DBuilder.createFile("filename.c", "/file/dir/"); ++ DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None); ++ DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes); ++ auto *CU = ++ DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c", ++ "/file/dir", "CloneModule", false, "", 0); ++ // Function DI ++ auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType, ++ true, true, 3, 0, false); ++ F->setSubprogram(Subprogram); ++ + auto *Entry = BasicBlock::Create(C, "", F); + IBuilder.SetInsertPoint(Entry); + IBuilder.CreateRetVoid(); ++ ++ // Finalize the debug info ++ DBuilder.finalize(); + } + + void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); } +@@ -447,4 +464,12 @@ TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); + } + ++TEST_F(CloneModule, Subprogram) { ++ Function *NewF = NewM->getFunction("f"); ++ DISubprogram *SP = NewF->getSubprogram(); ++ EXPECT_TRUE(SP != nullptr); ++ EXPECT_EQ(SP->getName(), "f"); ++ EXPECT_EQ(SP->getFile()->getFilename(), "filename.c"); ++ EXPECT_EQ(SP->getLine(), (unsigned)4); ++} + } diff --git a/patches/llvm_host/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch b/patches/llvm_host/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch new file mode 100644 index 00000000..0930c28e --- /dev/null +++ b/patches/llvm_host/llvm-0007-reduce-complexity-of-debug-info-clonning-and-fix-correctness.patch @@ -0,0 +1,102 @@ +From af289e04413504c3bdc252e08c3fe17bf7ea6dc8 Mon Sep 17 00:00:00 2001 +From: Peter Collingbourne <peter@pcc.me.uk> +Date: Wed, 30 Mar 2016 22:05:13 +0000 +Subject: [PATCH] Cloning: Reduce complexity of debug info cloning and fix + correctness issue. + +Commit r260791 contained an error in that it would introduce a cross-module +reference in the old module. It also introduced O(N^2) complexity in the +module cloner by requiring the entire module to be visited for each function. +Fix both of these problems by avoiding use of the CloneDebugInfoMetadata +function (which is only designed to do intra-module cloning) and cloning +function-attached metadata in the same way that we clone all other metadata. + +Differential Revision: http://reviews.llvm.org/D18583 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264935 91177308-0d34-0410-b5e6-96231b3b80d8 + +Alpine maintainer notes: + - Corresponds to llvm-D17165-D18583.patch in Julia. +--- + include/llvm/Transforms/Utils/Cloning.h | 5 ----- + lib/Transforms/Utils/CloneFunction.cpp | 13 +++++++++++-- + lib/Transforms/Utils/CloneModule.cpp | 1 - + unittests/Transforms/Utils/Cloning.cpp | 6 ++++++ + 4 files changed, 17 insertions(+), 8 deletions(-) + +diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h +index 0bae2bd..4f006f2 100644 +--- a/include/llvm/Transforms/Utils/Cloning.h ++++ b/include/llvm/Transforms/Utils/Cloning.h +@@ -130,11 +130,6 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap, + bool ModuleLevelChanges, + ClonedCodeInfo *CodeInfo = nullptr); + +-/// Clone the module-level debug info associated with OldFunc. The cloned data +-/// will point to NewFunc instead. +-void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap); +- + /// Clone OldFunc into NewFunc, transforming the old arguments into references + /// to VMap values. Note that if NewFunc already has basic blocks, the ones + /// cloned into it will be added to the end of the function. This function +diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp +index 05b0a17..8e1715a 100644 +--- a/lib/Transforms/Utils/CloneFunction.cpp ++++ b/lib/Transforms/Utils/CloneFunction.cpp +@@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, + .addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex, + OldAttrs.getFnAttributes())); + ++ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs; ++ OldFunc->getAllMetadata(MDs); ++ for (auto MD : MDs) ++ NewFunc->setMetadata( ++ MD.first, ++ MapMetadata(MD.second, VMap, ++ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges, ++ TypeMapper, Materializer)); ++ + // Loop over all of the basic blocks in the function, cloning them as + // appropriate. Note that we save BE this way in order to handle cloning of + // recursive functions into themselves. +@@ -187,8 +196,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs, + + // Clone the module-level debug info associated with OldFunc. The cloned data + // will point to NewFunc instead. +-void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap) { ++static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap) { + DebugInfoFinder Finder; + Finder.processModule(*OldFunc->getParent()); + +diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp +index 494e275..929f51b 100644 +--- a/lib/Transforms/Utils/CloneModule.cpp ++++ b/lib/Transforms/Utils/CloneModule.cpp +@@ -138,7 +138,6 @@ std::unique_ptr<Module> llvm::CloneModule( + VMap[&*J] = &*DestI++; + } + +- CloneDebugInfoMetadata(F, &*I, VMap); + SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned. + CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); + } +diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp +index b761e4e..f06a20f 100644 +--- a/unittests/Transforms/Utils/Cloning.cpp ++++ b/unittests/Transforms/Utils/Cloning.cpp +@@ -464,6 +464,12 @@ TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); + } + ++TEST_F(CloneModule, OldModuleUnchanged) { ++ DebugInfoFinder Finder; ++ Finder.processModule(*OldM); ++ EXPECT_EQ(1U, Finder.subprogram_count()); ++} ++ + TEST_F(CloneModule, Subprogram) { + Function *NewF = NewM->getFunction("f"); + DISubprogram *SP = NewF->getSubprogram(); diff --git a/patches/llvm_host/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch b/patches/llvm_host/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch new file mode 100644 index 00000000..b66584dc --- /dev/null +++ b/patches/llvm_host/llvm-0008-dont-widen-metadata-on-store-to-load-forwarding.patch @@ -0,0 +1,107 @@ +From 3c80c2658022201214241e9229ac35097cc476d2 Mon Sep 17 00:00:00 2001 +From: Eli Friedman <eli.friedman@gmail.com> +Date: Thu, 16 Jun 2016 02:33:42 +0000 +Subject: [PATCH] [InstCombine] Don't widen metadata on store-to-load + forwarding + +The original check for load CSE or store-to-load forwarding is wrong +when the forwarded stored value happened to be a load. + +Ref https://github.com/JuliaLang/julia/issues/16894 + +Differential Revision: http://reviews.llvm.org/D21271 + +Patch by Yichao Yu! + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272868 91177308-0d34-0410-b5e6-96231b3b80d8 + +Alpine maintainer notes: + - Updated for llvm 3.8.1. + - Corresponds to llvm-D21271-instcombine-tbaa-3.8.patch in Julia. +--- + include/llvm/Analysis/Loads.h | 3 ++- + lib/Analysis/Loads.cpp | 5 ++++- + .../InstCombine/InstCombineLoadStoreAlloca.cpp | 6 ++++-- + test/Transforms/InstCombine/tbaa-store-to-load.ll | 17 +++++++++++++++++ + 4 files changed, 27 insertions(+), 4 deletions(-) + create mode 100644 test/Transforms/InstCombine/tbaa-store-to-load.ll + +diff --git a/include/llvm/Analysis/Loads.h b/include/llvm/Analysis/Loads.h +index e5bd0c8..9d24b7b 100644 +--- a/include/llvm/Analysis/Loads.h ++++ b/include/llvm/Analysis/Loads.h +@@ -82,7 +82,8 @@ Value *FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, + BasicBlock::iterator &ScanFrom, + unsigned MaxInstsToScan = DefMaxInstsToScan, + AliasAnalysis *AA = nullptr, +- AAMDNodes *AATags = nullptr); ++ AAMDNodes *AATags = nullptr, ++ bool *IsLoadCSE = nullptr); + + } + +diff --git a/lib/Analysis/Loads.cpp b/lib/Analysis/Loads.cpp +index dce243c..7d3fd59 100644 +--- a/lib/Analysis/Loads.cpp ++++ b/lib/Analysis/Loads.cpp +@@ -322,7 +322,8 @@ llvm::DefMaxInstsToScan("available-load-scan-limit", cl::init(6), cl::Hidden, + Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, + BasicBlock::iterator &ScanFrom, + unsigned MaxInstsToScan, +- AliasAnalysis *AA, AAMDNodes *AATags) { ++ AliasAnalysis *AA, AAMDNodes *AATags, ++ bool *IsLoadCSE) { + if (MaxInstsToScan == 0) + MaxInstsToScan = ~0U; + +@@ -374,6 +375,8 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, + + if (AATags) + LI->getAAMetadata(*AATags); ++ if (IsLoadCSE) ++ *IsLoadCSE = true; + return LI; + } + +diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +index 6a5d5a6..d312983 100644 +--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp ++++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +@@ -800,10 +800,12 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { + // separated by a few arithmetic operations. + BasicBlock::iterator BBI(LI); + AAMDNodes AATags; ++ bool IsLoadCSE = false; + if (Value *AvailableVal = + FindAvailableLoadedValue(Op, LI.getParent(), BBI, +- DefMaxInstsToScan, AA, &AATags)) { +- if (LoadInst *NLI = dyn_cast<LoadInst>(AvailableVal)) { ++ DefMaxInstsToScan, AA, &AATags, &IsLoadCSE)) { ++ if (IsLoadCSE) { ++ LoadInst *NLI = cast<LoadInst>(AvailableVal); + unsigned KnownIDs[] = { + LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, + LLVMContext::MD_noalias, LLVMContext::MD_range, +diff --git a/test/Transforms/InstCombine/tbaa-store-to-load.ll b/test/Transforms/InstCombine/tbaa-store-to-load.ll +new file mode 100644 +index 0000000..707be73 +--- /dev/null ++++ b/test/Transforms/InstCombine/tbaa-store-to-load.ll +@@ -0,0 +1,17 @@ ++; RUN: opt -S -instcombine < %s 2>&1 | FileCheck %s ++ ++define i64 @f(i64* %p1, i64* %p2) { ++top: ++ ; check that the tbaa is preserved ++ ; CHECK-LABEL: @f( ++ ; CHECK: %v1 = load i64, i64* %p1, align 8, !tbaa !0 ++ ; CHECK: store i64 %v1, i64* %p2, align 8 ++ ; CHECK: ret i64 %v1 ++ %v1 = load i64, i64* %p1, align 8, !tbaa !0 ++ store i64 %v1, i64* %p2, align 8 ++ %v2 = load i64, i64* %p2, align 8 ++ ret i64 %v2 ++} ++ ++!0 = !{!1, !1, i64 0} ++!1 = !{!"load_tbaa"} diff --git a/patches/llvm_host/llvm-0009-nm-workaround.patch b/patches/llvm_host/llvm-0009-nm-workaround.patch new file mode 100644 index 00000000..5755e57f --- /dev/null +++ b/patches/llvm_host/llvm-0009-nm-workaround.patch @@ -0,0 +1,27 @@ +From https://llvm.org/bugs/show_bug.cgi?id=24115 + +diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp +index e7ee312..b9e4779 100644 +--- a/tools/llvm-nm/llvm-nm.cpp ++++ b/tools/llvm-nm/llvm-nm.cpp +@@ -486,7 +486,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName, + std::string ArchiveName, + std::string ArchitectureName) { + if (!NoSort) { +- std::function<bool(const NMSymbol &, const NMSymbol &)> Cmp; ++ bool (*Cmp)(const NMSymbol &, const NMSymbol &); + if (NumericSort) + Cmp = compareSymbolAddress; + else if (SizeSort) +@@ -495,8 +495,9 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName, + Cmp = compareSymbolName; + + if (ReverseSort) +- Cmp = [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); }; +- std::sort(SymbolList.begin(), SymbolList.end(), Cmp); ++ std::sort(SymbolList.begin(), SymbolList.end(), [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); }); ++ else ++ std::sort(SymbolList.begin(), SymbolList.end(), Cmp); + } + + if (!PrintFileName) { |