You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 714cac9
Browse filesBrowse the repository at this point in the historyBrowse files
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):
// %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>`,
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>`,
0 commit comments