Skip to content

Commit 714cac9

Browse files
Compile knowledge: Bufferization, Canonicalization, Rationale
Iteration 3: - Added Bufferization concept (DPS, tensor→memref, conflict analysis) - Added Fold concept (local simplification, first-choice canonicalization) - Enriched understanding of the design philosophy from Rationale doc - Total concepts now: 20 rich definitions in the wiki
1 parent db389da commit 714cac9

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎site/data.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,50 @@ struct AddZeroElim : public OpRewritePattern<arith::AddIOp> {
13471347
sources: [
13481348
{ label: "MLIR Pattern Rewriting", url: "https://mlir.llvm.org/docs/PatternRewriter/" }
13491349
]
1350+
},
1351+
bufferization: {
1352+
name: "Bufferization",
1353+
role: "Transformation",
1354+
summary: "Converting tensor (value-semantics) IR to memref (side-effecting buffer) IR. Determines where to allocate memory and where copies are needed.",
1355+
definition: "Bufferization is the tensor→memref transition: it converts immutable, value-semantic tensor operations into side-effecting buffer (memref) operations with explicit memory allocation. One-Shot Bufferize performs whole-function analysis to maximize in-place writes (reusing input buffers for outputs) and only inserts copies where read-after-write conflicts force it. Destination-Passing Style (DPS) — where ops declare an 'outs' operand — provides the bufferization anchor for in-place reuse.",
1356+
examples: `<pre>// Before bufferization (tensor — value semantics):
1357+
%0 = linalg.matmul ins(%A, %B : tensor<8x8xf32>, tensor<8x8xf32>)
1358+
outs(%C : tensor<8x8xf32>) -> tensor<8x8xf32>
1359+
// ↑ DPS: 'outs' is the bufferization anchor
1360+
1361+
// After bufferization (memref — side-effecting):
1362+
linalg.matmul ins(%A_buf, %B_buf : memref<8x8xf32>, memref<8x8xf32>)
1363+
outs(%C_buf : memref<8x8xf32>)
1364+
// %C_buf may alias %C's original buffer (in-place) or be freshly allocated
1365+
// depending on conflict analysis</pre>
1366+
<p>Key insight: bufferization ≠ lowering ≠ deallocation. These are separate pipeline stages. Non-DPS tensor ops always allocate; DPS ops can reuse their destination buffer.</p>`,
1367+
related: ["Lowering", "TypeConverter", "Operation"],
1368+
usedIn: ["mlir", "lowering-pipelines"],
1369+
sources: [
1370+
{ label: "MLIR Bufferization", url: "https://mlir.llvm.org/docs/Bufferization/" }
1371+
]
1372+
},
1373+
fold: {
1374+
name: "Fold",
1375+
role: "Local simplification",
1376+
summary: "Operation's preferred canonicalization hook: replaces an op with existing values/attributes without creating new IR. First-choice for cheap simplifications.",
1377+
definition: "Fold is a constrained simplification method on an operation that can (1) no-op, (2) mutate the op in place, or (3) return existing Values/Attributes to substitute for the op's results. Unlike RewritePattern, fold cannot create new operations or SSA values. Attribute results are materialized into constant ops via DialectFoldInterface. Fold is the first-choice for canonicalization — invocable anywhere (OpBuilder::createOrFold, dialect conversion), while RewritePattern handles structural changes.",
1378+
examples: `<pre>// Fold: constant folding of arith.addi
1379+
// Input: %c1 = arith.constant 2 : i32
1380+
// %c2 = arith.constant 3 : i32
1381+
// %r = arith.addi %c1, %c2 : i32
1382+
// Fold returns: IntegerAttr(5) → materialized as arith.constant 5
1383+
1384+
// Fold vs RewritePattern:
1385+
// fold: x + 0 → return {x} (no new ops)
1386+
// pattern: br ^bb1 when ^bb1 is only successor → erase branch + merge blocks
1387+
// (needs structural change → must use RewritePattern)</pre>
1388+
<p>Canonicalization uses a single greedy pass that runs all dialects' fold methods and patterns until fixpoint. Rules must converge cheaply — cyclic rewrites are bugs.</p>`,
1389+
related: ["RewritePattern", "Pass", "Operation"],
1390+
usedIn: ["mlir", "ir-design"],
1391+
sources: [
1392+
{ label: "MLIR Canonicalization", url: "https://mlir.llvm.org/docs/Canonicalization/" }
1393+
]
13501394
}
13511395
}
13521396
};

0 commit comments

Comments
 (0)