From 479baf477a52685339f4146a47248da6d2bba202 Mon Sep 17 00:00:00 2001 From: HEIR Team Date: Tue, 18 Feb 2025 10:28:21 -0800 Subject: [PATCH] Integrate LLVM at llvm/llvm-project@9d24f9437944 Updates LLVM usage to match [9d24f9437944](https://github.com/llvm/llvm-project/commit/9d24f9437944) PiperOrigin-RevId: 728265165 --- bazel/import_llvm.bzl | 2 +- lib/Pipelines/PipelineRegistration.cpp | 12 ++-- patches/llvm.patch | 77 +++++++------------------- tools/heir-opt.cpp | 2 +- 4 files changed, 28 insertions(+), 65 deletions(-) diff --git a/bazel/import_llvm.bzl b/bazel/import_llvm.bzl index 43316f69e..a1b80e991 100644 --- a/bazel/import_llvm.bzl +++ b/bazel/import_llvm.bzl @@ -7,7 +7,7 @@ load( def import_llvm(name): """Imports LLVM.""" - LLVM_COMMIT = "34cf04b59b8d94c8eeb9929ec2cd3d63631af86f" + LLVM_COMMIT = "9d24f943794420e512512eb9329341355e9289f8" new_git_repository( name = name, diff --git a/lib/Pipelines/PipelineRegistration.cpp b/lib/Pipelines/PipelineRegistration.cpp index ded8517d6..aa2910499 100644 --- a/lib/Pipelines/PipelineRegistration.cpp +++ b/lib/Pipelines/PipelineRegistration.cpp @@ -39,8 +39,8 @@ namespace mlir::heir { void tosaToLinalg(OpPassManager &manager) { manager.addNestedPass(createTosaToLinalgNamed()); manager.addNestedPass(createTosaToLinalg()); - manager.addNestedPass(createTosaToArith(true, false)); - manager.addNestedPass(createTosaToTensor()); + manager.addNestedPass(createTosaToArithPass({true, false})); + manager.addNestedPass(createTosaToTensorPass()); manager.addPass(bufferization::createEmptyTensorToAllocTensorPass()); manager.addNestedPass(createLinalgDetensorizePass()); manager.addPass(createConvertTensorToLinalgPass()); @@ -60,7 +60,7 @@ void oneShotBufferize(OpPassManager &manager) { manager.addPass(bufferization::createBufferDeallocationSimplificationPass()); manager.addPass(bufferization::createLowerDeallocationsPass()); manager.addPass(createCSEPass()); - manager.addPass(mlir::createBufferizationToMemRefPass()); + manager.addPass(mlir::createConvertBufferizationToMemRefPass()); manager.addPass(createCanonicalizerPass()); } @@ -114,7 +114,7 @@ void polynomialToLLVMPipelineBuilder(OpPassManager &manager) { // But lowering to loops also re-introduces affine.apply, so re-lower that manager.addNestedPass(createConvertLinalgToLoopsPass()); manager.addPass(createLowerAffinePass()); - manager.addPass(createBufferizationToMemRefPass()); + manager.addPass(createConvertBufferizationToMemRefPass()); // Cleanup manager.addPass(createCanonicalizerPass()); @@ -124,7 +124,7 @@ void polynomialToLLVMPipelineBuilder(OpPassManager &manager) { // ToLLVM manager.addPass(arith::createArithExpandOpsPass()); - manager.addPass(createConvertSCFToCFPass()); + manager.addPass(createSCFToControlFlowPass()); manager.addNestedPass(memref::createExpandStridedMetadataPass()); manager.addPass(createConvertToLLVMPass()); @@ -161,7 +161,7 @@ void basicMLIRToLLVMPipelineBuilder(OpPassManager &manager) { // ToLLVM manager.addPass(arith::createArithExpandOpsPass()); - manager.addPass(createConvertSCFToCFPass()); + manager.addPass(createSCFToControlFlowPass()); manager.addNestedPass(memref::createExpandStridedMetadataPass()); manager.addPass(createConvertToLLVMPass()); diff --git a/patches/llvm.patch b/patches/llvm.patch index 3447d7fa5..63bd1d16d 100644 --- a/patches/llvm.patch +++ b/patches/llvm.patch @@ -1,61 +1,24 @@ Auto generated patch. Do not edit or delete it, even if empty. -diff -ruN --strip-trailing-cr a/libcxx/src/iostream.cpp b/libcxx/src/iostream.cpp ---- a/libcxx/src/iostream.cpp -+++ b/libcxx/src/iostream.cpp -@@ -18,8 +18,8 @@ +diff -ruN --strip-trailing-cr a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl +--- a/utils/bazel/llvm-project-overlay/llvm/config.bzl ++++ b/utils/bazel/llvm-project-overlay/llvm/config.bzl +@@ -47,6 +47,7 @@ - template - union stream_data { -- stream_data() {} -- ~stream_data() {} -+ constexpr stream_data() {} -+ constexpr ~stream_data() {} - struct { - // The stream has to be the first element, since that's referenced by the stream declarations in - StreamT stream; -@@ -38,13 +38,19 @@ - #define CHAR_MANGLING_wchar_t "_W" - #define CHAR_MANGLING(CharT) CHAR_MANGLING_##CharT + linux_defines = posix_defines + [ + "_GNU_SOURCE", ++ "HAVE_GETAUXVAL=1", + "HAVE_MALLINFO=1", + "HAVE_SBRK=1", + "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1", +diff -ruN --strip-trailing-cr a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h +--- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h ++++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h +@@ -296,7 +296,7 @@ -+#ifdef _LIBCPP_COMPILER_CLANG_BASED -+# define STRING_DATA_CONSTINIT constinit -+#else -+# define STRING_DATA_CONSTINIT -+#endif -+ - #ifdef _LIBCPP_ABI_MICROSOFT - # define STREAM(StreamT, BufferT, CharT, var) \ -- stream_data, BufferT> var __asm__( \ -+ STRING_DATA_CONSTINIT stream_data, BufferT> var __asm__( \ - "?" #var "@" ABI_NAMESPACE_STR "@std@@3V?$" #StreamT \ - "@" CHAR_MANGLING(CharT) "U?$char_traits@" CHAR_MANGLING(CharT) "@" ABI_NAMESPACE_STR "@std@@@12@A") - #else --# define STREAM(StreamT, BufferT, CharT, var) stream_data, BufferT> var -+# define STREAM(StreamT, BufferT, CharT, var) STRING_DATA_CONSTINIT stream_data, BufferT> var - #endif + /* HAVE_PROC_PID_RUSAGE defined in Bazel */ - // These definitions and the declarations in technically cause ODR violations, since they have different -diff -ruN --strip-trailing-cr a/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp ---- a/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp -+++ b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp -@@ -0,0 +1,20 @@ -+//===----------------------------------------------------------------------===// -+// -+// Part of the LLVM Project, 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 -+// -+//===----------------------------------------------------------------------===// -+ -+#include -+ -+// FIXME: Remove after issue https://github.com/llvm/llvm-project/issues/127348 resolved. -+extern "C" const char* __asan_default_options() { return "check_initialization_order=true:strict_init_order=true"; } -+ -+// Test that ios used from globals constructors doesn't trigger Asan initialization-order-fiasco. -+ -+struct Global { -+ Global() { std::cout << "Hello!"; } -+} global; -+ -+int main(int, char**) { return 0; } +-#define HAVE_GETAUXVAL 1 ++/* HAVE_GETAUXVAL defined in Bazel */ + + /* Directly provide definitions here behind platform preprocessor definitions. + * The preprocessor conditions are sufficient to handle all of the configuration diff --git a/tools/heir-opt.cpp b/tools/heir-opt.cpp index 980181b08..206200dce 100644 --- a/tools/heir-opt.cpp +++ b/tools/heir-opt.cpp @@ -229,7 +229,7 @@ int main(int argc, char **argv) { registerPass( []() -> std::unique_ptr { return createConvertFuncToLLVMPass(); }); registerPass( - []() -> std::unique_ptr { return createConvertSCFToCFPass(); }); + []() -> std::unique_ptr { return createSCFToControlFlowPass(); }); registerPass([]() -> std::unique_ptr { return createFinalizeMemRefToLLVMConversionPass(); });