[llvm-branch-commits] [mlir] [mlir][ODS] Add so-called "Natural Sharding" to ops (PR #239254)

Krzysztof Drewniak via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 5 13:49:26 PST 2026


================
@@ -1370,6 +1370,110 @@ cc_library(
 )
 ```
 
+#### Natural Sharding with Op Partitions
+
+Sharding by index splits the ops arbitrarily: which shard an op ends up in
+depends on the number of shards and on the names of all other ops. As an
+alternative, a dialect can shard its ops "naturally" by grouping them into
+named *op partitions*, such as arithmetic, memory or control flow ops. Each
+partition is generated into its own declaration and definition files, almost as
+if it were a dialect of its own, but all ops are still registered in one
+dialect.
+
+Partitions are `Partition` records with a name, which must be a C++
+identifier. The dialect lists its partitions, and every op sets its `partition`
+to one of these records (a different record with the same name is rejected),
+typically with a `let` around a group of ops:
+
+```tablegen
+def MyDialect_ArithPartition : Partition<"Arith">;
+def MyDialect_MemoryPartition : Partition<"Memory">;
+
+def MyDialect : Dialect {
+  let name = "my_dialect";
+  let opPartitions = [MyDialect_ArithPartition, MyDialect_MemoryPartition];
+}
+
+let partition = MyDialect_ArithPartition in {
----------------
krzysz00 wrote:

High-level thought: Tablegen has the ability to gather up records using `defset`, and I'd argue that having blocks of the file wrapped in a 
```
defset list<Operation> SomePartition {
...
} // end SomePartition
```
and then you could do something like `def : DialectPartition<MyDialect, SomePartition>` to create them, and have an implicit default partition?

But I'm not 100% on this design, just flagging something that'd allow us to avoid repeating this on every op.

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


More information about the llvm-branch-commits mailing list