-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][LLVM] Remove llvm deps from the LLVM dialect
#150692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It's worth noting that while doing this cleanup I discovered vector to LLVM uses the LLVM context to compute alignments (even worse, it creates and then trashes the context for each alignment computation). That should be removed in the future. |
joker-eph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup!
|
Also, @joker-eph NVVM does have a hard dependency on its header to the NVPTX intrinsics. I only skim through that one, but at the least it looks like it could be moved to the source file and not the dialect header. |
|
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-mlir-llvm Author: Fabian Mora (fabianmcg) ChangesThis patch removes spurious includes of The only major dependencies still coming from LLVM are Finally, I also removed one constructor from Full diff: https://github.com/llvm/llvm-project/pull/150692.diff 11 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
index e355bb8f5ddae..f3bd5c090803d 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
@@ -32,11 +32,6 @@
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "mlir/Support/ThreadLocalCache.h"
#include "llvm/ADT/PointerEmbeddedInt.h"
-#include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/InstrTypes.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/Type.h"
namespace llvm {
class Type;
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index caba614bf2742..8c6f1eecdd759 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -555,8 +555,6 @@ def LLVM_AssumeOp
let builders = [
OpBuilder<(ins "Value":$cond)>,
- OpBuilder<(ins "Value":$cond,
- "ArrayRef<llvm::OperandBundleDefT<Value>>":$opBundles)>,
OpBuilder<(ins "Value":$cond, "llvm::StringRef":$tag, "ValueRange":$args)>,
OpBuilder<(ins "Value":$cond, "AssumeAlignTag":$tag, "Value":$ptr,
"Value":$align)>,
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
index c484072ffaa80..17ef8e44afd2d 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
@@ -19,6 +19,7 @@
#include "mlir/Target/LLVMIR/Import.h"
#include "mlir/Target/LLVMIR/LLVMImportInterface.h"
#include "mlir/Target/LLVMIR/TypeFromLLVM.h"
+#include "llvm/IR/Module.h"
namespace llvm {
class BasicBlock;
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 9cd491caa9421..4307bc6c502e7 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -29,7 +29,9 @@
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/Casting.h"
+
#include <optional>
using namespace mlir;
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index d987b72e98354..ff55f17315cfd 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -21,10 +21,7 @@ add_mlir_dialect_library(MLIRLLVMDialect
intrinsics_gen
LINK_COMPONENTS
- AsmParser
BinaryFormat
- BitReader
- BitWriter
Core
LINK_LIBS PUBLIC
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index d42ce96e3bb45..422039f81855a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -26,8 +26,7 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/TypeSwitch.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/Type.h"
+#include "llvm/IR/DataLayout.h"
#include "llvm/Support/Error.h"
#include <numeric>
@@ -4063,29 +4062,10 @@ void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
/*op_bundle_tags=*/ArrayAttr{});
}
-void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
- Value cond,
- ArrayRef<llvm::OperandBundleDefT<Value>> opBundles) {
- SmallVector<ValueRange> opBundleOperands;
- SmallVector<Attribute> opBundleTags;
- opBundleOperands.reserve(opBundles.size());
- opBundleTags.reserve(opBundles.size());
-
- for (const llvm::OperandBundleDefT<Value> &bundle : opBundles) {
- opBundleOperands.emplace_back(bundle.inputs());
- opBundleTags.push_back(
- StringAttr::get(builder.getContext(), bundle.getTag()));
- }
-
- auto opBundleTagsAttr = ArrayAttr::get(builder.getContext(), opBundleTags);
- return build(builder, state, cond, opBundleOperands, opBundleTagsAttr);
-}
-
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
Value cond, llvm::StringRef tag, ValueRange args) {
- llvm::OperandBundleDefT<Value> opBundle(
- tag.str(), SmallVector<Value>(args.begin(), args.end()));
- return build(builder, state, cond, opBundle);
+ return build(builder, state, cond, ArrayRef<ValueRange>(args),
+ builder.getStrArrayAttr(tag));
}
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index 6e29b129e8835..cffe310c468c4 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -30,15 +30,8 @@
#include "mlir/IR/Types.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/TypeSwitch.h"
-#include "llvm/AsmParser/Parser.h"
-#include "llvm/IR/Attributes.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/IntrinsicsNVPTX.h"
-#include "llvm/IR/Type.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <optional>
diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
index 1a9ccf56008b8..17371ecb79e7d 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
@@ -24,7 +24,6 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Operation.h"
#include "llvm/ADT/TypeSwitch.h"
-#include "llvm/IR/Type.h"
using namespace mlir;
using namespace ROCDL;
diff --git a/mlir/lib/Dialect/LLVMIR/IR/VCIXDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/VCIXDialect.cpp
index bd9d3528ceb74..1d4a0af4b045b 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/VCIXDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/VCIXDialect.cpp
@@ -20,11 +20,6 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Operation.h"
#include "llvm/ADT/TypeSwitch.h"
-#include "llvm/AsmParser/Parser.h"
-#include "llvm/IR/Attributes.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/Type.h"
-#include "llvm/Support/SourceMgr.h"
using namespace mlir;
using namespace vcix;
diff --git a/mlir/lib/Target/LLVM/CMakeLists.txt b/mlir/lib/Target/LLVM/CMakeLists.txt
index 7c6fc37c40a83..f6e44c60e65f6 100644
--- a/mlir/lib/Target/LLVM/CMakeLists.txt
+++ b/mlir/lib/Target/LLVM/CMakeLists.txt
@@ -8,6 +8,7 @@ add_mlir_library(MLIRTargetLLVM
intrinsics_gen
LINK_COMPONENTS
+ BitWriter
Core
IPO
IRReader
diff --git a/mlir/unittests/Target/LLVM/CMakeLists.txt b/mlir/unittests/Target/LLVM/CMakeLists.txt
index 15835b904c464..0daac1114677a 100644
--- a/mlir/unittests/Target/LLVM/CMakeLists.txt
+++ b/mlir/unittests/Target/LLVM/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS nativecodegen)
+set(LLVM_LINK_COMPONENTS nativecodegen BitReader)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
5c40e41 to
0cc2b22
Compare
This patch removes spurious includes of `llvm/IR` files, and unnecessary link components in the LLVM dialect. The only major dependencies still coming from LLVM are `llvm::DataLayout`, which is used by `verifyDataLayoutString` and some `dwarf` symbols in some attributes. Both of them should likely be removed in the future. Finally, I also removed one constructor from `LLVM::AssumeOp` that used [OperandBundleDefT](https://llvm.org/doxygen/classllvm_1_1OperandBundleDefT.html) without good reason and introduced a header unnecessarily.
This patch removes spurious includes of
llvm/IRfiles, and unnecessary link components in the LLVM dialect.The only major dependencies still coming from LLVM are
llvm::DataLayout, which is used byverifyDataLayoutStringand somedwarfsymbols in some attributes. Both of them should likely be removed in the future.Finally, I also removed one constructor from
LLVM::AssumeOpthat used OperandBundleDefT without good reason and introduced a header unnecessarily.