Skip to content

Commit 34a08cb

Browse files
authored
[mlir][LLVM] Remove llvm deps from the LLVM dialect (#150692)
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.
1 parent 6118a25 commit 34a08cb

File tree

13 files changed

+10
-47
lines changed

13 files changed

+10
-47
lines changed

flang/lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_flang_library(flangFrontend
4545
LINK_COMPONENTS
4646
Passes
4747
Analysis
48+
BitReader
4849
Extensions
4950
IRPrinter
5051
IRReader

flang/lib/Optimizer/Dialect/Support/KindMapping.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
1414
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15+
#include "llvm/IR/LLVMContext.h"
1516
#include "llvm/Support/CommandLine.h"
1617

1718
/// Allow the user to set the FIR intrinsic type kind value to LLVM type

mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
#include "mlir/Interfaces/ViewLikeInterface.h"
3333
#include "mlir/Support/ThreadLocalCache.h"
3434
#include "llvm/ADT/PointerEmbeddedInt.h"
35-
#include "llvm/IR/DerivedTypes.h"
36-
#include "llvm/IR/InstrTypes.h"
37-
#include "llvm/IR/LLVMContext.h"
38-
#include "llvm/IR/Module.h"
39-
#include "llvm/IR/Type.h"
4035

4136
namespace llvm {
4237
class Type;

mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,6 @@ def LLVM_AssumeOp
555555

556556
let builders = [
557557
OpBuilder<(ins "Value":$cond)>,
558-
OpBuilder<(ins "Value":$cond,
559-
"ArrayRef<llvm::OperandBundleDefT<Value>>":$opBundles)>,
560558
OpBuilder<(ins "Value":$cond, "llvm::StringRef":$tag, "ValueRange":$args)>,
561559
OpBuilder<(ins "Value":$cond, "AssumeAlignTag":$tag, "Value":$ptr,
562560
"Value":$align)>,

mlir/include/mlir/Target/LLVMIR/ModuleImport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mlir/Target/LLVMIR/Import.h"
2020
#include "mlir/Target/LLVMIR/LLVMImportInterface.h"
2121
#include "mlir/Target/LLVMIR/TypeFromLLVM.h"
22+
#include "llvm/IR/Module.h"
2223

2324
namespace llvm {
2425
class BasicBlock;

mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
3030
#include "mlir/Transforms/DialectConversion.h"
3131
#include "llvm/ADT/APFloat.h"
32+
#include "llvm/IR/LLVMContext.h"
3233
#include "llvm/Support/Casting.h"
34+
3335
#include <optional>
3436

3537
using namespace mlir;

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ add_mlir_dialect_library(MLIRLLVMDialect
2121
intrinsics_gen
2222

2323
LINK_COMPONENTS
24-
AsmParser
2524
BinaryFormat
26-
BitReader
27-
BitWriter
2825
Core
2926

3027
LINK_LIBS PUBLIC

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include "llvm/ADT/APFloat.h"
2828
#include "llvm/ADT/TypeSwitch.h"
29-
#include "llvm/IR/Function.h"
30-
#include "llvm/IR/Type.h"
29+
#include "llvm/IR/DataLayout.h"
3130
#include "llvm/Support/Error.h"
3231

3332
#include <numeric>
@@ -4063,29 +4062,10 @@ void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
40634062
/*op_bundle_tags=*/ArrayAttr{});
40644063
}
40654064

4066-
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
4067-
Value cond,
4068-
ArrayRef<llvm::OperandBundleDefT<Value>> opBundles) {
4069-
SmallVector<ValueRange> opBundleOperands;
4070-
SmallVector<Attribute> opBundleTags;
4071-
opBundleOperands.reserve(opBundles.size());
4072-
opBundleTags.reserve(opBundles.size());
4073-
4074-
for (const llvm::OperandBundleDefT<Value> &bundle : opBundles) {
4075-
opBundleOperands.emplace_back(bundle.inputs());
4076-
opBundleTags.push_back(
4077-
StringAttr::get(builder.getContext(), bundle.getTag()));
4078-
}
4079-
4080-
auto opBundleTagsAttr = ArrayAttr::get(builder.getContext(), opBundleTags);
4081-
return build(builder, state, cond, opBundleOperands, opBundleTagsAttr);
4082-
}
4083-
40844065
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,
40854066
Value cond, llvm::StringRef tag, ValueRange args) {
4086-
llvm::OperandBundleDefT<Value> opBundle(
4087-
tag.str(), SmallVector<Value>(args.begin(), args.end()));
4088-
return build(builder, state, cond, opBundle);
4067+
return build(builder, state, cond, ArrayRef<ValueRange>(args),
4068+
builder.getStrArrayAttr(tag));
40894069
}
40904070

40914071
void LLVM::AssumeOp::build(OpBuilder &builder, OperationState &state,

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@
3030
#include "mlir/IR/Types.h"
3131
#include "llvm/ADT/STLExtras.h"
3232
#include "llvm/ADT/TypeSwitch.h"
33-
#include "llvm/AsmParser/Parser.h"
34-
#include "llvm/IR/Attributes.h"
35-
#include "llvm/IR/Function.h"
36-
#include "llvm/IR/IRBuilder.h"
37-
#include "llvm/IR/IntrinsicsNVPTX.h"
38-
#include "llvm/IR/Type.h"
3933
#include "llvm/Support/Casting.h"
4034
#include "llvm/Support/FormatVariadic.h"
41-
#include "llvm/Support/SourceMgr.h"
4235
#include "llvm/Support/raw_ostream.h"
4336
#include <cassert>
4437
#include <optional>

mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "mlir/IR/MLIRContext.h"
2525
#include "mlir/IR/Operation.h"
2626
#include "llvm/ADT/TypeSwitch.h"
27-
#include "llvm/IR/Type.h"
2827

2928
using namespace mlir;
3029
using namespace ROCDL;

0 commit comments

Comments
 (0)