Skip to content

Commit

Permalink
Add llvm-project 17.0.3 (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-khabarov authored Nov 2, 2023
1 parent 22c3e02 commit 92a3b55
Show file tree
Hide file tree
Showing 18 changed files with 2,893 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/llvm-project/17.0.3/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
name = "llvm-project",
version = "17.0.3",
)

# Skylark depedndencies
bazel_dep(name = "bazel_skylib", version = "1.3.0")

# Library dependencies
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_cc", version = "0.0.9")
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 14:55:33 +0000
Subject: [PATCH] Add Bazel files to `.gitignore`

---
.gitignore | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/.gitignore b/.gitignore
index 20c4f52cd..6d630bf1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,3 +70,11 @@ pythonenv*
/clang/utils/analyzer/projects/*/RefScanBuildResults
# automodapi puts generated documentation files here.
/lldb/docs/python_api/
+
+#==============================================================================
+#
+# Bazel paths to ignore
+#==============================================================================
+.bazelrc
+.bazelversion
+/bazel-*
2,265 changes: 2,265 additions & 0 deletions modules/llvm-project/17.0.3/patches/0002-Add-LLVM-Bazel-overlay-files.patch

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions modules/llvm-project/17.0.3/patches/0003-Add-MODULE.bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 14:58:38 +0000
Subject: [PATCH] Add `MODULE.bazel`

---
MODULE.bazel | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 MODULE.bazel

diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 000000000..f945718c2
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,11 @@
+module(
+ name = "llvm-project",
+ version = "17.0.3",
+)
+
+# Skylark depedndencies
+bazel_dep(name = "bazel_skylib", version = "1.3.0")
+
+# Library dependencies
+bazel_dep(name = "platforms", version = "0.0.7")
+bazel_dep(name = "rules_cc", version = "0.0.9")
20 changes: 20 additions & 0 deletions modules/llvm-project/17.0.3/patches/0004-Add-BUILD.bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 15:05:58 +0000
Subject: [PATCH] Add `BUILD.bazel`

---
BUILD.bazel | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 BUILD.bazel

diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 000000000..05c507654
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,4 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 15:00:17 +0000
Subject: [PATCH] Add Bazel LLVM targets

The repository configuration step of the overlay generates the
`llvm/targets.bzl`. We can generate it ourselves by using the
`DEFAULT_TARGETS`:

```sh
tr '\n' ' ' < utils/bazel/configure.bzl |
grep -o 'DEFAULT_TARGETS *= *\[[^]]\+\]' |
sed \
-e 's|DEFAULT_TARGETS|llvm_targets|' \
-e 's|,\( *\)|,\n\1|g' \
-e 's|\[|[\n|' \
> llvm/targets.bzl
```
---
llvm/targets.bzl | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 llvm/targets.bzl

diff --git a/llvm/targets.bzl b/llvm/targets.bzl
new file mode 100644
index 000000000..7a31d801e
--- /dev/null
+++ b/llvm/targets.bzl
@@ -0,0 +1,21 @@
+llvm_targets = [
+ "AArch64",
+ "AMDGPU",
+ "ARM",
+ "AVR",
+ "BPF",
+ "Hexagon",
+ "Lanai",
+ "LoongArch",
+ "Mips",
+ "MSP430",
+ "NVPTX",
+ "PowerPC",
+ "RISCV",
+ "Sparc",
+ "SystemZ",
+ "VE",
+ "WebAssembly",
+ "X86",
+ "XCore",
+]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 15:01:20 +0000
Subject: [PATCH] Add LLVM version vars

The repository configuration step of the overlay generates the
`vars.bzl`. We have to add it manually.
---
vars.bzl | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 vars.bzl

diff --git a/vars.bzl b/vars.bzl
new file mode 100644
index 000000000..d744043d9
--- /dev/null
+++ b/vars.bzl
@@ -0,0 +1,5 @@
+LLVM_VERSION = "17.0.3"
+LLVM_VERSION_MAJOR = 17
+LLVM_VERSION_MINOR = 0
+LLVM_VERSION_PATCH = 3
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Thu, 19 Oct 2023 15:02:08 +0000
Subject: [PATCH] Guard against empty workspace root

The workspace root in `llvm/tblgen.bzl` is empty when running the build
from the root directory of the project. Default to `"."` to avoid
include errors resulting from this.
---
llvm/tblgen.bzl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tblgen.bzl b/llvm/tblgen.bzl
index d43390918..9486edf29 100644
--- a/llvm/tblgen.bzl
+++ b/llvm/tblgen.bzl
@@ -35,7 +35,7 @@ def gentbl(
tblgen_args: Extra arguments string to pass to the tblgen binary.
**kwargs: Keyword arguments to pass to subsidiary cc_library() rule.
"""
- llvm_project_execroot_path = Label("//llvm:tblgen.bzl").workspace_root
+ llvm_project_execroot_path = Label("//llvm:tblgen.bzl").workspace_root or "."

if td_file not in td_srcs:
td_srcs += [td_file]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Fri, 20 Oct 2023 10:57:18 +0000
Subject: [PATCH] Correct builtin headers prefix

`$${src#*clang/lib/Headers}` works when building from the
`llvm-project` root as well.
---
clang/BUILD.bazel | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/BUILD.bazel b/clang/BUILD.bazel
index 037719a51..ec87a37e2 100644
--- a/clang/BUILD.bazel
+++ b/clang/BUILD.bazel
@@ -1691,7 +1691,7 @@ genrule(
outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers],
cmd = """
for src in $(SRCS); do
- relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
+ relsrc=$${src#*clang/lib/Headers}
target=$(@D)/staging/include/$$relsrc
mkdir -p $$(dirname $$target)
cp $$src $$target
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Tue, 24 Oct 2023 11:48:21 +0000
Subject: [PATCH] Fix an operator overload for GCC 8.3

Rewrite an operator overload to be more explicit to make GCC 8.3 happy.
This is not needed for GCC 8.4+ and Clang.
---
llvm/include/llvm/ADT/STLExtras.h | 37 ++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 7edc58263..3195c007d 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1292,16 +1292,16 @@ public:
}

/// Compare this range with another.
- template <typename OtherT>
- friend bool operator==(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
- }
- template <typename OtherT>
- friend bool operator!=(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return !(lhs == rhs);
- }
+ template <typename DerivedT0, typename BaseT0, typename T0,
+ typename PointerT0, typename ReferenceT0,
+ typename OtherT>
+ friend bool operator==(const indexed_accessor_range_base<DerivedT0, BaseT0, T0, PointerT0, ReferenceT0> &lhs,
+ const OtherT &rhs);
+ template <typename DerivedT0, typename BaseT0, typename T0,
+ typename PointerT0, typename ReferenceT0,
+ typename OtherT>
+ friend bool operator!=(const indexed_accessor_range_base<DerivedT0, BaseT0, T0, PointerT0, ReferenceT0> &lhs,
+ const OtherT &rhs);

/// Return the size of this range.
size_t size() const { return count; }
@@ -1365,6 +1365,23 @@ protected:
/// The size from the owning range.
ptrdiff_t count;
};
+
+template <typename DerivedT, typename BaseT, typename T,
+ typename PointerT, typename ReferenceT,
+ typename OtherT>
+bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT, ReferenceT> &lhs,
+ const OtherT &rhs) {
+ return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template <typename DerivedT, typename BaseT, typename T,
+ typename PointerT, typename ReferenceT,
+ typename OtherT>
+bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT, ReferenceT> &lhs,
+ const OtherT &rhs) {
+ return !(lhs == rhs);
+}
+
} // end namespace detail

/// This class provides an implementation of a range of
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Tue, 24 Oct 2023 12:29:50 +0000
Subject: [PATCH] Use `TEST_TMPDIR` on Unix when it is set

Other directories (`TMPDIR`, `TMP`, `TEMP`, etc) might not be
available, so use Bazel's `TEST_TMPDIR` when it is set.
---
llvm/lib/Support/Unix/Path.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index e2aece49c..52ef00e4d 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -1427,7 +1427,7 @@ bool cache_directory(SmallVectorImpl<char> &result) {
static const char *getEnvTempDir() {
// Check whether the temporary directory is specified by an environment
// variable.
- const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
+ const char *EnvironmentVariables[] = {"TEST_TMPDIR", "TMPDIR", "TMP", "TEMP", "TEMPDIR"};
for (const char *Env : EnvironmentVariables) {
if (const char *Dir = std::getenv(Env))
return Dir;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alexander Khabarov <[email protected]>
Date: Tue, 24 Oct 2023 14:52:10 +0000
Subject: [PATCH] Use Windows assembly files for BLAKE3 on Windows

Use Windows assembly files instead of Unix ones when running on
Windows.
---
llvm/BUILD.bazel | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/llvm/BUILD.bazel b/llvm/BUILD.bazel
index a7e9398ea..ef5299138 100644
--- a/llvm/BUILD.bazel
+++ b/llvm/BUILD.bazel
@@ -220,6 +220,12 @@ cc_library(
"@platforms//cpu:aarch64": [
"lib/Support/BLAKE3/blake3_neon.c",
],
+ "@bazel_tools//src/conditions:windows_x64": [
+ "lib/Support/BLAKE3/blake3_avx2_x86-64_windows_msvc.asm",
+ "lib/Support/BLAKE3/blake3_avx512_x86-64_windows_msvc.asm",
+ "lib/Support/BLAKE3/blake3_sse2_x86-64_windows_msvc.asm",
+ "lib/Support/BLAKE3/blake3_sse41_x86-64_windows_msvc.asm",
+ ],
"@platforms//cpu:x86_64": [
"lib/Support/BLAKE3/blake3_avx2_x86-64_unix.S",
"lib/Support/BLAKE3/blake3_avx512_x86-64_unix.S",
Loading

0 comments on commit 92a3b55

Please sign in to comment.