[llvm-branch-commits] [clang] [flang] [mlir] [mlir][LLVM] Include LLVM dialect partition headers instead of LLVMDialect.h (PR #242307)

Eugene Epshteyn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 15 13:36:13 PST 2026


================
@@ -11,10 +11,14 @@
 
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
 #include "mlir/Conversion/LLVMCommon/Pattern.h"
-#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/LLVMIR/LLVMMemoryOps.h"
----------------
eugeneepshteyn wrote:

(This comment was generated with the help of AI)

This doesn't take `LLVMDialect.h` away from includers of this header: `TypeConverter.h` (included above) includes `TBAABuilder.h`, and `TBAABuilder.h:17` still includes `mlir/Dialect/LLVMIR/LLVMDialect.h`. A TU that includes only this header still compiles the whole dialect:

```cpp
// x.cpp
#include "flang/Optimizer/CodeGen/FIROpPatterns.h"
```

```console
$ clang++ -std=c++17 -fsyntax-only -H <flang/mlir/llvm include flags> x.cpp 2>&1 | grep -E 'FIROpPatterns|TBAABuilder|LLVMDialect\.h|CodeGen/TypeConverter'
. flang/Optimizer/CodeGen/FIROpPatterns.h
.. flang/Optimizer/CodeGen/TypeConverter.h
... flang/Optimizer/CodeGen/TBAABuilder.h
.... mlir/Dialect/LLVMIR/LLVMDialect.h
```

(include paths shortened.) `flang/Optimizer/Support/Utils.h` and `flang/Optimizer/Transforms/DebugTypeGenerator.h` include `CodeGen/TypeConverter.h` too, so the umbrella still reaches much of flang through this chain. Some flang files rely on that: `Support/Utils.cpp` uses `LLVM::ConstantOp`, `TruncOp` and `SExtOp`, and `DebugTypeGenerator.cpp` uses `LLVM::DbgValueOp`, with no LLVM dialect include of their own.

Could `TBAABuilder.h` be narrowed in this PR as well (with partition includes added where flang uses ops through it)? If flang CodeGen is meant to stay on the umbrella, please say so in the description, so the 386 -> 41 count is clear about what it covers.


https://github.com/llvm/llvm-project/pull/242307


More information about the llvm-branch-commits mailing list