CINXE.COM

'scf' Dialect - MLIR

<!doctype html><html lang=en-us><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>'scf' Dialect - MLIR</title><meta name=description content="Multi-Level IR Compiler Framework"><meta name=generator content="Hugo 0.119.0"><link href=https://mlir.llvm.org/index.xml rel=alternate type=application/rss+xml><link rel=canonical href=https://mlir.llvm.org/docs/Dialects/SCFDialect/><link rel=stylesheet href=https://mlir.llvm.org/css/theme.css><script src=https://use.fontawesome.com/releases/v5.0.6/js/all.js></script> <link rel=stylesheet href=https://mlir.llvm.org/css/chroma.min.css><script src=https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js></script> <script src=https://cdn.jsdelivr.net/npm/jquery.easing@1.4.1/jquery.easing.min.js></script> <script src=https://mlir.llvm.org/js/bundle.js></script> <script type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type=text/x-mathjax-config> MathJax.Hub.Config({ tex2jax: { inlineMath: [['$', '$'] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ] } }); </script><link rel=apple-touch-icon sizes=180x180 href="/apple-touch-icon.png?v=1"><link rel=icon type=image/png sizes=32x32 href="/favicon-32x32.png?v=1"><link rel=icon type=image/png sizes=16x16 href="/favicon-16x16.png?v=1"><link rel=manifest href="/site.webmanifest?v=1"><link rel=mask-icon href="/safari-pinned-tab.svg?v=1" color=#3775e0><link rel="shortcut icon" href="/favicon.ico?v=1"><meta name=msapplication-TileColor content="#2d89ef"><meta name=theme-color content="#ffffff"><link rel=icon href=/favicon.svg type=image/svg+xml sizes=any><style>:root{}</style></head><body><div class=container><header><h1><div><img src=https://mlir.llvm.org//mlir-logo.png width=40px align=absmiddle> MLIR</div></h1><p class=description>Multi-Level IR Compiler Framework</p></header><div class=global-menu><nav><ul><li class=parent><a href>Community<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=https://llvm.discourse.group/c/mlir/31>Forums</a></li><li class=child><a href=https://discord.gg/xS7Z362>Chat</a></li></ul></li><li><a href=/getting_started/Debugging/>Debugging Tips</a></li><li><a href=/getting_started/Faq/>FAQ</a></li><li class=parent><a href=https://github.com/llvm/llvm-project/tree/main/mlir>Source<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=/doxygen/>Doxygen</a></li><li class=child><a href=https://github.com/llvm/llvm-project/tree/main/mlir>GitHub</a></li></ul></li><li><a href="https://bugs.llvm.org/buglist.cgi?bug_status=__open__&amp;list_id=177877&amp;order=changeddate%20DESC%2Cpriority%2Cbug_severity&amp;product=MLIR&amp;query_format=specific">Bugs</a></li><li><a href=https://github.com/llvm/mlir-www/tree/main/website/static/LogoAssets>Logo Assets</a></li><li><a href=https://www.youtube.com/MLIRCompiler>Youtube Channel</a></li></ul></nav></div><div class=content-container><main><h1>'scf' Dialect</h1><p>The <code>scf</code> (structured control flow) dialect contains operations that represent control flow constructs such as <code>if</code> and <code>for</code>. Being <em>structured</em> means that the control flow has a structure unlike, for example, <code>goto</code>s or <code>assert</code>s. Unstructured control flow operations are located in the <code>cf</code> (control flow) dialect.</p><p>Originally, this dialect was developed as a common lowering stage for the <code>affine</code> and <code>linalg</code> dialects. Both convert to SCF loops instead of targeting branch-based CFGs directly. Typically, <code>scf</code> is lowered to <code>cf</code> and then lowered to some final target like LLVM or SPIR-V.</p><p><nav id=TableOfContents><ul><li><a href=#operations>Operations</a><ul><li><a href=#scfcondition-scfconditionop><code>scf.condition</code> (scf::ConditionOp)</a></li><li><a href=#scfexecute_region-scfexecuteregionop><code>scf.execute_region</code> (scf::ExecuteRegionOp)</a></li><li><a href=#scffor-scfforop><code>scf.for</code> (scf::ForOp)</a></li><li><a href=#scfforall-scfforallop><code>scf.forall</code> (scf::ForallOp)</a></li><li><a href=#scfforallin_parallel-scfinparallelop><code>scf.forall.in_parallel</code> (scf::InParallelOp)</a></li><li><a href=#scfif-scfifop><code>scf.if</code> (scf::IfOp)</a></li><li><a href=#scfindex_switch-scfindexswitchop><code>scf.index_switch</code> (scf::IndexSwitchOp)</a></li><li><a href=#scfparallel-scfparallelop><code>scf.parallel</code> (scf::ParallelOp)</a></li><li><a href=#scfreduce-scfreduceop><code>scf.reduce</code> (scf::ReduceOp)</a></li><li><a href=#scfreducereturn-scfreducereturnop><code>scf.reduce.return</code> (scf::ReduceReturnOp)</a></li><li><a href=#scfwhile-scfwhileop><code>scf.while</code> (scf::WhileOp)</a></li><li><a href=#scfyield-scfyieldop><code>scf.yield</code> (scf::YieldOp)</a></li></ul></li></ul></nav><h2 id=operations>Operations&nbsp;<a class=headline-hash href=#operations>¶</a></h2><p><a href=https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td>source</a></p><h3 id=scfcondition-scfconditionop><code>scf.condition</code> (scf::ConditionOp)&nbsp;<a class=headline-hash href=#scfcondition-scfconditionop>¶</a></h3><p><em>Loop continuation condition</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `scf.condition` `(` $condition `)` attr-dict ($args^ `:` type($args))? </code></pre><p>This operation accepts the continuation (i.e., inverse of exit) condition of the <code>scf.while</code> construct. If its first argument is true, the &ldquo;after&rdquo; region of <code>scf.while</code> is executed, with the remaining arguments forwarded to the entry block of the region. Otherwise, the loop terminates.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasParent&lt;WhileOp></code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>RegionBranchTerminatorOpInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=operands>Operands:&nbsp;<a class=headline-hash href=#operands>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>condition</code></td><td>1-bit signless integer</td></tr><tr><td style=text-align:center><code>args</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfexecute_region-scfexecuteregionop><code>scf.execute_region</code> (scf::ExecuteRegionOp)&nbsp;<a class=headline-hash href=#scfexecute_region-scfexecuteregionop>¶</a></h3><p><em>Operation that executes its region exactly once</em></p><p>The <code>scf.execute_region</code> operation is used to allow multiple blocks within SCF and other operations which can hold only one block. The <code>scf.execute_region</code> operation executes the region held exactly once and cannot have any operands. As such, its region has no arguments. All SSA values that dominate the op can be accessed inside the op. The op&rsquo;s region can have multiple blocks and the blocks can have multiple distinct terminators. Values returned from this op&rsquo;s region define the op&rsquo;s results.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>scf<span class=p>.</span>for <span class=nv>%i</span> <span class=p>=</span> <span class=m>0</span> to <span class=m>128</span> step <span class=nv>%c1</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%y</span> <span class=p>=</span> scf<span class=p>.</span>execute_region <span class=p>-&gt;</span> <span class=k>i32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%x</span> <span class=p>=</span> load <span class=nv>%A</span><span class=p>[</span><span class=nv>%i</span><span class=p>]</span> <span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>128x</span><span class=k>i32</span><span class=p>&gt;</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%x</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl>affine<span class=p>.</span>for <span class=nv>%i</span> <span class=p>=</span> <span class=m>0</span> to <span class=m>100</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=s>&#34;foo&#34;</span><span class=p>()</span> <span class=p>:</span> <span class=p>()</span> <span class=p>-&gt;</span> <span class=p>()</span> </span></span><span class=line><span class=cl> <span class=nv>%v</span> <span class=p>=</span> scf<span class=p>.</span>execute_region <span class=p>-&gt;</span> <span class=k>i64</span> <span class=p>{</span> </span></span><span class=line><span class=cl> cf<span class=p>.</span>cond_br <span class=nv>%cond</span><span class=p>,</span> <span class=nl>^bb1</span><span class=p>,</span> <span class=nl>^bb2 </span></span></span><span class=line><span class=cl><span class=nl> </span></span></span><span class=line><span class=cl><span class=nl> ^bb1</span><span class=p>:</span> </span></span><span class=line><span class=cl> <span class=nv>%c1</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>1</span> <span class=p>:</span> <span class=k>i64</span> </span></span><span class=line><span class=cl> cf<span class=p>.</span>br <span class=nl>^bb3</span><span class=p>(</span><span class=nv>%c1</span> <span class=p>:</span> <span class=k>i64</span><span class=p>)</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=nl>^bb2</span><span class=p>:</span> </span></span><span class=line><span class=cl> <span class=nv>%c2</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>2</span> <span class=p>:</span> <span class=k>i64</span> </span></span><span class=line><span class=cl> cf<span class=p>.</span>br <span class=nl>^bb3</span><span class=p>(</span><span class=nv>%c2</span> <span class=p>:</span> <span class=k>i64</span><span class=p>)</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=nl>^bb3</span><span class=p>(</span><span class=nv>%x</span> <span class=p>:</span> <span class=k>i64</span><span class=p>):</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%x</span> <span class=p>:</span> <span class=k>i64</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl> <span class=s>&#34;bar&#34;</span><span class=p>(</span><span class=nv>%v</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>i64</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=p>()</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Interfaces: <code>RegionBranchOpInterface</code></p><h4 id=results>Results:&nbsp;<a class=headline-hash href=#results>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center>«unnamed»</td><td>variadic of any type</td></tr></tbody></table><h3 id=scffor-scfforop><code>scf.for</code> (scf::ForOp)&nbsp;<a class=headline-hash href=#scffor-scfforop>¶</a></h3><p><em>For operation</em></p><p>The <code>scf.for</code> operation represents a loop taking 3 SSA value as operands that represent the lower bound, upper bound and step respectively. The operation defines an SSA value for its induction variable. It has one region capturing the loop body. The induction variable is represented as an argument of this region. This SSA value is a signless integer or index. The step is a value of same type but required to be positive. The lower and upper bounds specify a half-open range: the range includes the lower bound but does not include the upper bound.</p><p>The body region must contain exactly one block that terminates with <code>scf.yield</code>. Calling ForOp::build will create such a region and insert the terminator implicitly if none is defined, so will the parsing even in cases when it is absent from the custom format. For example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=c>// Index case. </span></span></span><span class=line><span class=cl><span class=c></span>scf<span class=p>.</span>for <span class=nv>%iv</span> <span class=p>=</span> <span class=nv>%lb</span> to <span class=nv>%ub</span> step <span class=nv>%step</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> <span class=c>// body </span></span></span><span class=line><span class=cl><span class=c></span><span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>...</span> </span></span><span class=line><span class=cl><span class=c>// Integer case. </span></span></span><span class=line><span class=cl><span class=c></span>scf<span class=p>.</span>for <span class=nv>%iv_32</span> <span class=p>=</span> <span class=nv>%lb_32</span> to <span class=nv>%ub_32</span> step <span class=nv>%step_32</span> <span class=p>:</span> <span class=k>i32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> <span class=c>// body </span></span></span><span class=line><span class=cl><span class=c></span><span class=p>}</span> </span></span></code></pre></div><p><code>scf.for</code> can also operate on loop-carried variables and returns the final values after loop termination. The initial values of the variables are passed as additional SSA operands to the <code>scf.for</code> following the 3 loop control SSA values mentioned above (lower bound, upper bound and step). The operation region has an argument for the induction variable, followed by one argument for each loop-carried variable, representing the value of the variable at the current iteration.</p><p>The region must terminate with a <code>scf.yield</code> that passes the current values of all loop-carried variables to the next iteration, or to the <code>scf.for</code> result, if at the last iteration. The static type of a loop-carried variable may not change with iterations; its runtime type is allowed to change. Note, that when the loop-carried variables are present, calling ForOp::build will not insert the terminator implicitly. The caller must insert <code>scf.yield</code> in that case.</p><p><code>scf.for</code> results hold the final values after the last iteration. For example, to sum-reduce a memref:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=kt>func</span><span class=p>.</span><span class=kt>func</span> <span class=nf>@reduce</span><span class=p>(</span><span class=nv>%buffer</span><span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>1024x</span><span class=k>f32</span><span class=p>&gt;,</span> <span class=nv>%lb</span><span class=p>:</span> <span class=k>index</span><span class=p>,</span> </span></span><span class=line><span class=cl> <span class=nv>%ub</span><span class=p>:</span> <span class=k>index</span><span class=p>,</span> <span class=nv>%step</span><span class=p>:</span> <span class=k>index</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// Initial sum set to 0. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%sum_0</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>0.0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=c>// iter_args binds initial values to the loop&#39;s region arguments. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%sum</span> <span class=p>=</span> scf<span class=p>.</span>for <span class=nv>%iv</span> <span class=p>=</span> <span class=nv>%lb</span> to <span class=nv>%ub</span> step <span class=nv>%step</span> </span></span><span class=line><span class=cl> iter_args<span class=p>(</span><span class=nv>%sum_iter</span> <span class=p>=</span> <span class=nv>%sum_0</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%t</span> <span class=p>=</span> load <span class=nv>%buffer</span><span class=p>[</span><span class=nv>%iv</span><span class=p>]</span> <span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>1024x</span><span class=k>f32</span><span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sum_next</span> <span class=p>=</span> arith<span class=p>.</span>addf <span class=nv>%sum_iter</span><span class=p>,</span> <span class=nv>%t</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=c>// Yield current iteration sum to next iteration %sum_iter or to %sum </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// if final iteration. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>yield <span class=nv>%sum_next</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl> <span class=kt>return</span> <span class=nv>%sum</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>If the <code>scf.for</code> defines any values, a yield must be explicitly present. The number and types of the <code>scf.for</code> results must match the initial values in the <code>iter_args</code> binding and the yield operands.</p><p>Another example with a nested <code>scf.if</code> (see <code>scf.if</code> for details) to perform conditional reduction:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=kt>func</span><span class=p>.</span><span class=kt>func</span> <span class=nf>@conditional_reduce</span><span class=p>(</span><span class=nv>%buffer</span><span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>1024x</span><span class=k>f32</span><span class=p>&gt;,</span> <span class=nv>%lb</span><span class=p>:</span> <span class=k>index</span><span class=p>,</span> </span></span><span class=line><span class=cl> <span class=nv>%ub</span><span class=p>:</span> <span class=k>index</span><span class=p>,</span> <span class=nv>%step</span><span class=p>:</span> <span class=k>index</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%sum_0</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>0.0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=nv>%c0</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>0.0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=nv>%sum</span> <span class=p>=</span> scf<span class=p>.</span>for <span class=nv>%iv</span> <span class=p>=</span> <span class=nv>%lb</span> to <span class=nv>%ub</span> step <span class=nv>%step</span> </span></span><span class=line><span class=cl> iter_args<span class=p>(</span><span class=nv>%sum_iter</span> <span class=p>=</span> <span class=nv>%sum_0</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%t</span> <span class=p>=</span> load <span class=nv>%buffer</span><span class=p>[</span><span class=nv>%iv</span><span class=p>]</span> <span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>1024x</span><span class=k>f32</span><span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%cond</span> <span class=p>=</span> arith<span class=p>.</span>cmpf <span class=s>&#34;ugt&#34;</span><span class=p>,</span> <span class=nv>%t</span><span class=p>,</span> <span class=nv>%c0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=nv>%sum_next</span> <span class=p>=</span> scf<span class=p>.</span>if <span class=nv>%cond</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%new_sum</span> <span class=p>=</span> arith<span class=p>.</span>addf <span class=nv>%sum_iter</span><span class=p>,</span> <span class=nv>%t</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%new_sum</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> else <span class=p>{</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%sum_iter</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%sum_next</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl> <span class=kt>return</span> <span class=nv>%sum</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>AutomaticAllocationScope</code>, <code>RecursiveMemoryEffects</code>, <code>SingleBlockImplicitTerminator&lt;scf::YieldOp></code>, <code>SingleBlock</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>LoopLikeOpInterface</code>, <code>RegionBranchOpInterface</code></p><h4 id=operands-1>Operands:&nbsp;<a class=headline-hash href=#operands-1>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>lowerBound</code></td><td>signless integer or index</td></tr><tr><td style=text-align:center><code>upperBound</code></td><td>signless integer or index</td></tr><tr><td style=text-align:center><code>step</code></td><td>signless integer or index</td></tr><tr><td style=text-align:center><code>initArgs</code></td><td>variadic of any type</td></tr></tbody></table><h4 id=results-1>Results:&nbsp;<a class=headline-hash href=#results-1>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfforall-scfforallop><code>scf.forall</code> (scf::ForallOp)&nbsp;<a class=headline-hash href=#scfforall-scfforallop>¶</a></h3><p><em>Evaluate a block multiple times in parallel</em></p><p><code>scf.forall</code> is a target-independent multi-dimensional parallel region application operation. It has exactly one block that represents the parallel body and it takes index operands that specify lower bounds, upper bounds and steps.</p><p>The op also takes a variadic number of tensor operands (<code>shared_outs</code>). The future buffers corresponding to these tensors are shared among all threads. Shared tensors should be accessed via their corresponding block arguments. If multiple threads write to a shared buffer in a racy fashion, these writes will execute in some unspecified order. Tensors that are not shared can be used inside the body (i.e., the op is not isolated from above); however, if a use of such a tensor bufferizes to a memory write, the tensor is privatized, i.e., a thread-local copy of the tensor is used. This ensures that memory side effects of a thread are not visible to other threads (or in the parent body), apart from explicitly shared tensors.</p><p>The name &ldquo;thread&rdquo; conveys the fact that the parallel execution is mapped (i.e. distributed) to a set of virtual threads of execution, one function application per thread. Further lowerings are responsible for specifying how this is materialized on concrete hardware resources.</p><p>An optional <code>mapping</code> is an attribute array that specifies processing units with their dimension, how it remaps 1-1 to a set of concrete processing element resources (e.g. a CUDA grid dimension or a level of concrete nested async parallelism). It is expressed via any attribute that implements the device mapping interface. It is the reponsibility of the lowering mechanism to interpret the <code>mapping</code> attributes in the context of the concrete target the op is lowered to, or to ignore it when the specification is ill-formed or unsupported for a particular target.</p><p>The only allowed terminator is <code>scf.forall.in_parallel</code>. <code>scf.forall</code> returns one value per <code>shared_out</code> operand. The actions of the <code>scf.forall.in_parallel</code> terminators specify how to combine the partial results of all parallel invocations into a full value, in some unspecified order. The &ldquo;destination&rdquo; of each such op must be a <code>shared_out</code> block argument of the <code>scf.forall</code> op.</p><p>The actions involved in constructing the return values are further described by <code>tensor.parallel_insert_slice</code>.</p><p><code>scf.forall</code> acts as an implicit synchronization point.</p><p>When the parallel function body has side effects, their order is unspecified across threads.</p><p><code>scf.forall</code> can be printed in two different ways depending on whether the loop is normalized or not. The loop is &rsquo;normalized&rsquo; when all lower bounds are equal to zero and steps are equal to one. In that case, <code>lowerBound</code> and <code>step</code> operands will be omitted during printing.</p><p>Normalized loop example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span><span class=nv>%matmul_and_pointwise</span><span class=p>:</span><span class=nl>2 =</span> scf<span class=p>.</span>forall <span class=p>(</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>)</span> in </span></span><span class=line><span class=cl> <span class=p>(</span><span class=nv>%num_threads_1</span><span class=p>,</span> <span class=nv>%numthread_id_2</span><span class=p>)</span> shared_outs<span class=p>(</span><span class=nv>%o1</span> <span class=p>=</span> <span class=nv>%C</span><span class=p>,</span> <span class=nv>%o2</span> <span class=p>=</span> <span class=nv>%pointwise</span><span class=p>)</span> </span></span><span class=line><span class=cl> <span class=p>-&gt;</span> <span class=p>(</span><span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;,</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// Parallel context, each thread with id = (%thread_id_1, %thread_id_2) </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// runs its version of the code. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%sA</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%A</span><span class=p>[</span>f<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sB</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%B</span><span class=p>[</span>g<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sC</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%o1</span><span class=p>[</span>h<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sD</span> <span class=p>=</span> linalg<span class=p>.</span>matmul </span></span><span class=line><span class=cl> ins<span class=p>(</span><span class=nv>%sA</span><span class=p>,</span> <span class=nv>%sB</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;,</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;)</span> </span></span><span class=line><span class=cl> outs<span class=p>(</span><span class=nv>%sC</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;)</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=nv>%spointwise</span> <span class=p>=</span> subtensor <span class=nv>%o2</span><span class=p>[</span>i<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sE</span> <span class=p>=</span> linalg<span class=p>.</span>add ins<span class=p>(</span><span class=nv>%spointwise</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;)</span> outs<span class=p>(</span><span class=nv>%sD</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;)</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> scf<span class=p>.</span>forall<span class=p>.</span>in_parallel <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>.</span>parallel_insert_slice <span class=nv>%sD</span> into <span class=nv>%o1</span><span class=p>[</span>h<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> into <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>.</span>parallel_insert_slice <span class=nv>%spointwise</span> into <span class=nv>%o2</span><span class=p>[</span>i<span class=p>((</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>))]:</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;</span> into <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span><span class=line><span class=cl><span class=c>// Implicit synchronization point. </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span></code></pre></div><p>Loop with loop bounds example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span><span class=nv>%pointwise</span> <span class=p>=</span> scf<span class=p>.</span>forall <span class=p>(</span><span class=nv>%i</span><span class=p>,</span> <span class=nv>%j</span><span class=p>)</span> <span class=p>=</span> <span class=p>(</span><span class=m>0</span><span class=p>,</span> <span class=m>0</span><span class=p>)</span> to <span class=p>(</span><span class=nv>%dim1</span><span class=p>,</span> <span class=nv>%dim2</span><span class=p>)</span> </span></span><span class=line><span class=cl> step <span class=p>(</span><span class=nv>%tileSize1</span><span class=p>,</span> <span class=nv>%tileSize2</span><span class=p>)</span> shared_outs<span class=p>(</span><span class=nv>%o1</span> <span class=p>=</span> <span class=nv>%out</span><span class=p>)</span> </span></span><span class=line><span class=cl> <span class=p>-&gt;</span> <span class=p>(</span><span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;,</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// Parallel context. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%sA</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%A</span><span class=p>[</span><span class=nv>%i</span><span class=p>,</span> <span class=nv>%j</span><span class=p>][</span><span class=nv>%tileSize1</span><span class=p>,</span> <span class=nv>%tileSize2</span><span class=p>][</span><span class=m>1</span><span class=p>,</span> <span class=m>1</span><span class=p>]</span> </span></span><span class=line><span class=cl> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sB</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%B</span><span class=p>[</span><span class=nv>%i</span><span class=p>,</span> <span class=nv>%j</span><span class=p>][</span><span class=nv>%tileSize1</span><span class=p>,</span> <span class=nv>%tileSize2</span><span class=p>][</span><span class=m>1</span><span class=p>,</span> <span class=m>1</span><span class=p>]</span> </span></span><span class=line><span class=cl> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%sC</span> <span class=p>=</span> <span class=kt>tensor</span><span class=p>.</span>extract_slice <span class=nv>%o</span><span class=p>[</span><span class=nv>%i</span><span class=p>,</span> <span class=nv>%j</span><span class=p>][</span><span class=nv>%tileSize1</span><span class=p>,</span> <span class=nv>%tileSize2</span><span class=p>][</span><span class=m>1</span><span class=p>,</span> <span class=m>1</span><span class=p>]</span> </span></span><span class=line><span class=cl> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> to <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=nv>%add</span> <span class=p>=</span> linalg<span class=p>.</span>map <span class=p>{</span><span class=s>&#34;arith.addf&#34;</span><span class=p>}</span> </span></span><span class=line><span class=cl> ins<span class=p>(</span><span class=nv>%sA</span><span class=p>,</span> <span class=nv>%sB</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;,</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;)</span> </span></span><span class=line><span class=cl> outs<span class=p>(</span><span class=nv>%sC</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;)</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> scf<span class=p>.</span>forall<span class=p>.</span>in_parallel <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=kt>tensor</span><span class=p>.</span>parallel_insert_slice <span class=nv>%add</span> into </span></span><span class=line><span class=cl> <span class=nv>%o</span><span class=p>[</span><span class=nv>%i</span><span class=p>,</span> <span class=nv>%j</span><span class=p>][</span><span class=nv>%tileSize1</span><span class=p>,</span> <span class=nv>%tileSize2</span><span class=p>][</span><span class=m>1</span><span class=p>,</span> <span class=m>1</span><span class=p>]</span> </span></span><span class=line><span class=cl> <span class=p>:</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> into <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span><span class=line><span class=cl><span class=c>// Implicit synchronization point. </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span></code></pre></div><p>Example with mapping attribute:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. Here `mapping` is expressed as GPU thread mapping </span></span></span><span class=line><span class=cl><span class=c>// attributes </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span><span class=nv>%matmul_and_pointwise</span><span class=p>:</span><span class=nl>2 =</span> scf<span class=p>.</span>forall <span class=p>(</span><span class=nv>%thread_id_1</span><span class=p>,</span> <span class=nv>%thread_id_2</span><span class=p>)</span> in </span></span><span class=line><span class=cl> <span class=p>(</span><span class=nv>%num_threads_1</span><span class=p>,</span> <span class=nv>%numthread_id_2</span><span class=p>)</span> shared_outs<span class=p>(...)</span> </span></span><span class=line><span class=cl> <span class=p>-&gt;</span> <span class=p>(</span><span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x?x</span>T<span class=p>&gt;,</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span>T<span class=p>&gt;)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// Parallel context, each thread with id = **(%thread_id_2, %thread_id_1)** </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// runs its version of the code. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>forall<span class=p>.</span>in_parallel <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>}</span> <span class=p>{</span> <span class=nl>mapping =</span> <span class=p>[</span><span class=nv>#gpu.thread</span><span class=p>&lt;</span>y<span class=p>&gt;,</span> <span class=nv>#gpu.thread</span><span class=p>&lt;x&gt;]</span> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=c>// Implicit synchronization point. </span></span></span><span class=line><span class=cl><span class=c>// Sequential context. </span></span></span><span class=line><span class=cl><span class=c>// </span></span></span></code></pre></div><p>Example with privatized tensors:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%t0</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl><span class=nv>%t1</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl><span class=nv>%r</span> <span class=p>=</span> scf<span class=p>.</span>forall <span class=p>...</span> shared_outs<span class=p>(</span><span class=nv>%o</span> <span class=p>=</span> t0<span class=p>)</span> <span class=p>-&gt;</span> <span class=kt>tensor</span><span class=p>&lt;</span><span class=m>?x</span><span class=k>f32</span><span class=p>&gt;</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// %t0 and %t1 are privatized. %t0 is definitely copied for each thread </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// because the scf.forall op&#39;s %t0 use bufferizes to a memory </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// write. In the absence of other conflicts, %t1 is copied only if there </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// are uses of %t1 in the body that bufferize to a memory read and to a </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// memory write. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=s>&#34;some_use&#34;</span><span class=p>(</span><span class=nv>%t0</span><span class=p>)</span> </span></span><span class=line><span class=cl> <span class=s>&#34;some_use&#34;</span><span class=p>(</span><span class=nv>%t1</span><span class=p>)</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>AttrSizedOperandSegments</code>, <code>AutomaticAllocationScope</code>, <code>HasParallelRegion</code>, <code>RecursiveMemoryEffects</code>, <code>SingleBlockImplicitTerminator&lt;scf::InParallelOp></code>, <code>SingleBlock</code></p><p>Interfaces: <code>DestinationStyleOpInterface</code>, <code>LoopLikeOpInterface</code>, <code>RegionBranchOpInterface</code></p><h4 id=attributes>Attributes:&nbsp;<a class=headline-hash href=#attributes>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>staticLowerBound</code></td><td>::mlir::DenseI64ArrayAttr</td><td>i64 dense array attribute</td></tr><tr><td><code>staticUpperBound</code></td><td>::mlir::DenseI64ArrayAttr</td><td>i64 dense array attribute</td></tr><tr><td><code>staticStep</code></td><td>::mlir::DenseI64ArrayAttr</td><td>i64 dense array attribute</td></tr><tr><td><code>mapping</code></td><td>::mlir::ArrayAttr</td><td>Device Mapping array attribute</td></tr></table><h4 id=operands-2>Operands:&nbsp;<a class=headline-hash href=#operands-2>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>dynamicLowerBound</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>dynamicUpperBound</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>dynamicStep</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>outputs</code></td><td>variadic of ranked tensor of any type values</td></tr></tbody></table><h4 id=results-2>Results:&nbsp;<a class=headline-hash href=#results-2>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfforallin_parallel-scfinparallelop><code>scf.forall.in_parallel</code> (scf::InParallelOp)&nbsp;<a class=headline-hash href=#scfforallin_parallel-scfinparallelop>¶</a></h3><p><em>Terminates a <code>forall</code> block</em></p><p>The <code>scf.forall.in_parallel</code> is a designated terminator for the <code>scf.forall</code> operation.</p><p>It has a single region with a single block that contains a flat list of ops. Each such op participates in the aggregate formation of a single result of the enclosing <code>scf.forall</code>. The result number corresponds to the position of the op in the terminator.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasOnlyGraphRegion</code>, <code>HasParent&lt;ForallOp></code>, <code>NoTerminator</code>, <code>SingleBlock</code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>ParallelCombiningOpInterface</code>, <code>RegionKindInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h3 id=scfif-scfifop><code>scf.if</code> (scf::IfOp)&nbsp;<a class=headline-hash href=#scfif-scfifop>¶</a></h3><p><em>If-then-else operation</em></p><p>The <code>scf.if</code> operation represents an if-then-else construct for conditionally executing two regions of code. The operand to an if operation is a boolean value. For example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>scf<span class=p>.</span>if <span class=nv>%b</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> </span></span><span class=line><span class=cl><span class=p>}</span> else <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p><code>scf.if</code> may also produce results. Which values are returned depends on which execution path is taken.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%x</span><span class=p>,</span> <span class=nv>%y</span> <span class=p>=</span> scf<span class=p>.</span>if <span class=nv>%b</span> <span class=p>-&gt;</span> <span class=p>(</span><span class=k>f32</span><span class=p>,</span> <span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%x_true</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl> <span class=nv>%y_true</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%x_true</span><span class=p>,</span> <span class=nv>%y_true</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> else <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%x_false</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl> <span class=nv>%y_false</span> <span class=p>=</span> <span class=p>...</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%x_false</span><span class=p>,</span> <span class=nv>%y_false</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>The &ldquo;then&rdquo; region has exactly 1 block. The &ldquo;else&rdquo; region may have 0 or 1 block. In case the <code>scf.if</code> produces results, the &ldquo;else&rdquo; region must also have exactly 1 block.</p><p>The blocks are always terminated with <code>scf.yield</code>. If <code>scf.if</code> defines no values, the <code>scf.yield</code> can be left out, and will be inserted implicitly. Otherwise, it must be explicit.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>scf<span class=p>.</span>if <span class=nv>%b</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=p>...</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>The types of the yielded values must match the result types of the <code>scf.if</code>.</p><p>Traits: <code>InferTypeOpAdaptor</code>, <code>NoRegionArguments</code>, <code>RecursiveMemoryEffects</code>, <code>SingleBlockImplicitTerminator&lt;scf::YieldOp></code>, <code>SingleBlock</code></p><p>Interfaces: <code>InferTypeOpInterface</code>, <code>RegionBranchOpInterface</code></p><h4 id=operands-3>Operands:&nbsp;<a class=headline-hash href=#operands-3>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>condition</code></td><td>1-bit signless integer</td></tr></tbody></table><h4 id=results-3>Results:&nbsp;<a class=headline-hash href=#results-3>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfindex_switch-scfindexswitchop><code>scf.index_switch</code> (scf::IndexSwitchOp)&nbsp;<a class=headline-hash href=#scfindex_switch-scfindexswitchop>¶</a></h3><p><em>Switch-case operation on an index argument</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `scf.index_switch` $arg attr-dict (`-&gt;` type($results)^)? custom&lt;SwitchCases&gt;($cases, $caseRegions) `\n` `` `default` $defaultRegion </code></pre><p>The <code>scf.index_switch</code> is a control-flow operation that branches to one of the given regions based on the values of the argument and the cases. The argument is always of type <code>index</code>.</p><p>The operation always has a &ldquo;default&rdquo; region and any number of case regions denoted by integer constants. Control-flow transfers to the case region whose constant value equals the value of the argument. If the argument does not equal any of the case values, control-flow transfer to the &ldquo;default&rdquo; region.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%0</span> <span class=p>=</span> scf<span class=p>.</span><span class=k>index</span>_switch <span class=nv>%arg0</span> <span class=p>:</span> <span class=k>index</span> <span class=p>-&gt;</span> <span class=k>i32</span> </span></span><span class=line><span class=cl>case <span class=m>2</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%1</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>10</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%1</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span><span class=line><span class=cl>case <span class=m>5</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%2</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>20</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%2</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span><span class=line><span class=cl>default <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%3</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>30</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>yield <span class=nv>%3</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>RecursiveMemoryEffects</code>, <code>SingleBlockImplicitTerminator&lt;scf::YieldOp></code>, <code>SingleBlock</code></p><p>Interfaces: <code>RegionBranchOpInterface</code></p><h4 id=attributes-1>Attributes:&nbsp;<a class=headline-hash href=#attributes-1>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>cases</code></td><td>::mlir::DenseI64ArrayAttr</td><td>i64 dense array attribute</td></tr></table><h4 id=operands-4>Operands:&nbsp;<a class=headline-hash href=#operands-4>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>arg</code></td><td>index</td></tr></tbody></table><h4 id=results-4>Results:&nbsp;<a class=headline-hash href=#results-4>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfparallel-scfparallelop><code>scf.parallel</code> (scf::ParallelOp)&nbsp;<a class=headline-hash href=#scfparallel-scfparallelop>¶</a></h3><p><em>Parallel for operation</em></p><p>The <code>scf.parallel</code> operation represents a loop nest taking 4 groups of SSA values as operands that represent the lower bounds, upper bounds, steps and initial values, respectively. The operation defines a variadic number of SSA values for its induction variables. It has one region capturing the loop body. The induction variables are represented as an argument of this region. These SSA values always have type index, which is the size of the machine word. The steps are values of type index, required to be positive. The lower and upper bounds specify a half-open range: the range includes the lower bound but does not include the upper bound. The initial values have the same types as results of <code>scf.parallel</code>. If there are no results, the keyword <code>init</code> can be omitted.</p><p>Semantically we require that the iteration space can be iterated in any order, and the loop body can be executed in parallel. If there are data races, the behavior is undefined.</p><p>The parallel loop operation supports reduction of values produced by individual iterations into a single result. This is modeled using the <code>scf.reduce</code> terminator operation (see <code>scf.reduce</code> for details). The i-th result of an <code>scf.parallel</code> operation is associated with the i-th initial value operand, the i-th operand of the <code>scf.reduce</code> operation (the value to be reduced) and the i-th region of the <code>scf.reduce</code> operation (the reduction function). Consequently, we require that the number of results of an <code>scf.parallel</code> op matches the number of initial values and the the number of reductions in the <code>scf.reduce</code> terminator.</p><p>The body region must contain exactly one block that terminates with a <code>scf.reduce</code> operation. If an <code>scf.parallel</code> op has no reductions, the terminator has no operands and no regions. The <code>scf.parallel</code> parser will automatically insert the terminator for ops that have no reductions if it is absent.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%init</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>0.0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=nv>%r</span><span class=p>:</span><span class=nl>2 =</span> scf<span class=p>.</span>parallel <span class=p>(</span><span class=nv>%iv</span><span class=p>)</span> <span class=p>=</span> <span class=p>(</span><span class=nv>%lb</span><span class=p>)</span> to <span class=p>(</span><span class=nv>%ub</span><span class=p>)</span> step <span class=p>(</span><span class=nv>%step</span><span class=p>)</span> init <span class=p>(</span><span class=nv>%init</span><span class=p>,</span> <span class=nv>%init</span><span class=p>)</span> </span></span><span class=line><span class=cl> <span class=p>-&gt;</span> <span class=k>f32</span><span class=p>,</span> <span class=k>f32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nv>%elem_to_reduce1</span> <span class=p>=</span> load <span class=nv>%buffer1</span><span class=p>[</span><span class=nv>%iv</span><span class=p>]</span> <span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>100x</span><span class=k>f32</span><span class=p>&gt;</span> </span></span><span class=line><span class=cl> <span class=nv>%elem_to_reduce2</span> <span class=p>=</span> load <span class=nv>%buffer2</span><span class=p>[</span><span class=nv>%iv</span><span class=p>]</span> <span class=p>:</span> <span class=kt>memref</span><span class=p>&lt;</span><span class=m>100x</span><span class=k>f32</span><span class=p>&gt;</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>reduce<span class=p>(</span><span class=nv>%elem_to_reduce1</span><span class=p>,</span> <span class=nv>%elem_to_reduce2</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nl>^bb0</span><span class=p>(</span><span class=nv>%lhs</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=nv>%rhs</span><span class=p>:</span> <span class=k>f32</span><span class=p>):</span> </span></span><span class=line><span class=cl> <span class=nv>%res</span> <span class=p>=</span> arith<span class=p>.</span>addf <span class=nv>%lhs</span><span class=p>,</span> <span class=nv>%rhs</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>reduce<span class=p>.</span><span class=kt>return</span> <span class=nv>%res</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>},</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nl>^bb0</span><span class=p>(</span><span class=nv>%lhs</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=nv>%rhs</span><span class=p>:</span> <span class=k>f32</span><span class=p>):</span> </span></span><span class=line><span class=cl> <span class=nv>%res</span> <span class=p>=</span> arith<span class=p>.</span>mulf <span class=nv>%lhs</span><span class=p>,</span> <span class=nv>%rhs</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>reduce<span class=p>.</span><span class=kt>return</span> <span class=nv>%res</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> <span class=p>}</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>AttrSizedOperandSegments</code>, <code>AutomaticAllocationScope</code>, <code>HasParallelRegion</code>, <code>RecursiveMemoryEffects</code>, <code>SingleBlockImplicitTerminator&lt;scf::ReduceOp></code>, <code>SingleBlock</code></p><p>Interfaces: <code>LoopLikeOpInterface</code>, <code>RegionBranchOpInterface</code></p><h4 id=operands-5>Operands:&nbsp;<a class=headline-hash href=#operands-5>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>lowerBound</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>upperBound</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>step</code></td><td>variadic of index</td></tr><tr><td style=text-align:center><code>initVals</code></td><td>variadic of any type</td></tr></tbody></table><h4 id=results-5>Results:&nbsp;<a class=headline-hash href=#results-5>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfreduce-scfreduceop><code>scf.reduce</code> (scf::ReduceOp)&nbsp;<a class=headline-hash href=#scfreduce-scfreduceop>¶</a></h3><p><em>Reduce operation for scf.parallel</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `scf.reduce` (`(` $operands^ `:` type($operands) `)`)? $reductions attr-dict </code></pre><p>The <code>scf.reduce</code> operation is the terminator for <code>scf.parallel</code> operations. It can model an arbitrary number of reductions. It has one region per reduction. Each region has one block with two arguments which have the same type as the corresponding operand of <code>scf.reduce</code>. The operands of the op are the values that should be reduce; one value per reduction.</p><p>The i-th reduction (i.e., the i-th region and the i-th operand) corresponds the i-th initial value and the i-th result of the enclosing <code>scf.parallel</code> op.</p><p>The <code>scf.reduce</code> operation contains regions whose entry blocks expect two arguments of the same type as the corresponding operand. As the iteration order of the enclosing parallel loop and hence reduction order is unspecified, the results of the reductions may be non-deterministic unless the reductions are associative and commutative.</p><p>The result of a reduction region (<code>scf.reduce.return</code> operand) must have the same type as the corresponding <code>scf.reduce</code> operand and the corresponding <code>scf.parallel</code> initial value.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%operand</span> <span class=p>=</span> arith<span class=p>.</span><span class=kt>constant</span> <span class=m>1.0</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl>scf<span class=p>.</span>reduce<span class=p>(</span><span class=nv>%operand</span> <span class=p>:</span> <span class=k>f32</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=nl>^bb0</span><span class=p>(</span><span class=nv>%lhs</span> <span class=p>:</span> <span class=k>f32</span><span class=p>,</span> <span class=nv>%rhs</span><span class=p>:</span> <span class=k>f32</span><span class=p>):</span> </span></span><span class=line><span class=cl> <span class=nv>%res</span> <span class=p>=</span> arith<span class=p>.</span>addf <span class=nv>%lhs</span><span class=p>,</span> <span class=nv>%rhs</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> scf<span class=p>.</span>reduce<span class=p>.</span><span class=kt>return</span> <span class=nv>%res</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>HasParent&lt;ParallelOp></code>, <code>RecursiveMemoryEffects</code>, <code>Terminator</code></p><p>Interfaces: <code>RegionBranchTerminatorOpInterface</code></p><h4 id=operands-6>Operands:&nbsp;<a class=headline-hash href=#operands-6>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>operands</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfreducereturn-scfreducereturnop><code>scf.reduce.return</code> (scf::ReduceReturnOp)&nbsp;<a class=headline-hash href=#scfreducereturn-scfreducereturnop>¶</a></h3><p><em>Terminator for reduce operation</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `scf.reduce.return` $result attr-dict `:` type($result) </code></pre><p>The <code>scf.reduce.return</code> operation is a special terminator operation for the block inside <code>scf.reduce</code> regions. It terminates the region. It should have the same operand type as the corresponding operand of the enclosing <code>scf.reduce</code> op.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>scf<span class=p>.</span>reduce<span class=p>.</span><span class=kt>return</span> <span class=nv>%res</span> <span class=p>:</span> <span class=k>f32</span> </span></span></code></pre></div><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasParent&lt;ReduceOp></code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=operands-7>Operands:&nbsp;<a class=headline-hash href=#operands-7>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>result</code></td><td>any type</td></tr></tbody></table><h3 id=scfwhile-scfwhileop><code>scf.while</code> (scf::WhileOp)&nbsp;<a class=headline-hash href=#scfwhile-scfwhileop>¶</a></h3><p><em>A generic &lsquo;while&rsquo; loop</em></p><p>This operation represents a generic &ldquo;while&rdquo;/&ldquo;do-while&rdquo; loop that keeps iterating as long as a condition is satisfied. There is no restriction on the complexity of the condition. It consists of two regions (with single block each): &ldquo;before&rdquo; region and &ldquo;after&rdquo; region. The names of regions indicates whether they execute before or after the condition check. Therefore, if the main loop payload is located in the &ldquo;before&rdquo; region, the operation is a &ldquo;do-while&rdquo; loop. Otherwise, it is a &ldquo;while&rdquo; loop.</p><p>The &ldquo;before&rdquo; region terminates with a special operation, <code>scf.condition</code>, that accepts as its first operand an <code>i1</code> value indicating whether to proceed to the &ldquo;after&rdquo; region (value is <code>true</code>) or not. The two regions communicate by means of region arguments. Initially, the &ldquo;before&rdquo; region accepts as arguments the operands of the <code>scf.while</code> operation and uses them to evaluate the condition. It forwards the trailing, non-condition operands of the <code>scf.condition</code> terminator either to the &ldquo;after&rdquo; region if the control flow is transferred there or to results of the <code>scf.while</code> operation otherwise. The &ldquo;after&rdquo; region takes as arguments the values produced by the &ldquo;before&rdquo; region and uses <code>scf.yield</code> to supply new arguments for the &ldquo;before&rdquo; region, into which it transfers the control flow unconditionally.</p><p>A simple &ldquo;while&rdquo; loop can be represented as follows.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%res</span> <span class=p>=</span> scf<span class=p>.</span>while <span class=p>(</span><span class=nv>%arg1</span> <span class=p>=</span> <span class=nv>%init1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>f32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// &#34;Before&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// In a &#34;while&#34; loop, this region computes the condition. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%condition</span> <span class=p>=</span> call <span class=nf>@evaluate_condition</span><span class=p>(</span><span class=nv>%arg1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>i1</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Forward the argument (as result or &#34;after&#34; region argument). </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>condition<span class=p>(</span><span class=nv>%condition</span><span class=p>)</span> <span class=nv>%arg1</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl><span class=p>}</span> do <span class=p>{</span> </span></span><span class=line><span class=cl><span class=nl>^bb0</span><span class=p>(</span><span class=nv>%arg2</span><span class=p>:</span> <span class=k>f32</span><span class=p>):</span> </span></span><span class=line><span class=cl> <span class=c>// &#34;After&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// In a &#34;while&#34; loop, this region is the loop body. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%next</span> <span class=p>=</span> call <span class=nf>@payload</span><span class=p>(</span><span class=nv>%arg2</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Forward the new value to the &#34;before&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// The operand types must match the types of the `scf.while` operands. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>yield <span class=nv>%next</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>A simple &ldquo;do-while&rdquo; loop can be represented by reducing the &ldquo;after&rdquo; block to a simple forwarder.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%res</span> <span class=p>=</span> scf<span class=p>.</span>while <span class=p>(</span><span class=nv>%arg1</span> <span class=p>=</span> <span class=nv>%init1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>f32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// &#34;Before&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// In a &#34;do-while&#34; loop, this region contains the loop body. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%next</span> <span class=p>=</span> call <span class=nf>@payload</span><span class=p>(</span><span class=nv>%arg1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// And also evaluates the condition. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%condition</span> <span class=p>=</span> call <span class=nf>@evaluate_condition</span><span class=p>(</span><span class=nv>%arg1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>i1</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Loop through the &#34;after&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>condition<span class=p>(</span><span class=nv>%condition</span><span class=p>)</span> <span class=nv>%next</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl><span class=p>}</span> do <span class=p>{</span> </span></span><span class=line><span class=cl><span class=nl>^bb0</span><span class=p>(</span><span class=nv>%arg2</span><span class=p>:</span> <span class=k>f32</span><span class=p>):</span> </span></span><span class=line><span class=cl> <span class=c>// &#34;After&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// Forwards the values back to &#34;before&#34; region unmodified. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>yield <span class=nv>%arg2</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Note that the types of region arguments need not to match with each other. The op expects the operand types to match with argument types of the &ldquo;before&rdquo; region; the result types to match with the trailing operand types of the terminator of the &ldquo;before&rdquo; region, and with the argument types of the &ldquo;after&rdquo; region. The following scheme can be used to share the results of some operations executed in the &ldquo;before&rdquo; region with the &ldquo;after&rdquo; region, avoiding the need to recompute them.</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%res</span> <span class=p>=</span> scf<span class=p>.</span>while <span class=p>(</span><span class=nv>%arg1</span> <span class=p>=</span> <span class=nv>%init1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>i64</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// One can perform some computations, e.g., necessary to evaluate the </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// condition, in the &#34;before&#34; region and forward their results to the </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// &#34;after&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%shared</span> <span class=p>=</span> call <span class=nf>@shared_compute</span><span class=p>(</span><span class=nv>%arg1</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>i64</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Evaluate the condition. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%condition</span> <span class=p>=</span> call <span class=nf>@evaluate_condition</span><span class=p>(</span><span class=nv>%arg1</span><span class=p>,</span> <span class=nv>%shared</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>f32</span><span class=p>,</span> <span class=k>i64</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>i1</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Forward the result of the shared computation to the &#34;after&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// The types must match the arguments of the &#34;after&#34; region as well as </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// those of the `scf.while` results. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>condition<span class=p>(</span><span class=nv>%condition</span><span class=p>)</span> <span class=nv>%shared</span> <span class=p>:</span> <span class=k>i64</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl><span class=p>}</span> do <span class=p>{</span> </span></span><span class=line><span class=cl><span class=nl>^bb0</span><span class=p>(</span><span class=nv>%arg2</span><span class=p>:</span> <span class=k>i64</span><span class=p>)</span> <span class=p>{</span> </span></span><span class=line><span class=cl> <span class=c>// Use the partial result to compute the rest of the payload in the </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// &#34;after&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=nv>%res</span> <span class=p>=</span> call <span class=nf>@payload</span><span class=p>(</span><span class=nv>%arg2</span><span class=p>)</span> <span class=p>:</span> <span class=p>(</span><span class=k>i64</span><span class=p>)</span> <span class=p>-&gt;</span> <span class=k>f32</span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl> <span class=c>// Forward the new value to the &#34;before&#34; region. </span></span></span><span class=line><span class=cl><span class=c></span> <span class=c>// The operand types must match the types of the `scf.while` operands. </span></span></span><span class=line><span class=cl><span class=c></span> scf<span class=p>.</span>yield <span class=nv>%res</span> <span class=p>:</span> <span class=k>f32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>The custom syntax for this operation is as follows.</p><pre tabindex=0><code>op ::= `scf.while` assignments `:` function-type region `do` region `attributes` attribute-dict initializer ::= /* empty */ | `(` assignment-list `)` assignment-list ::= assignment | assignment `,` assignment-list assignment ::= ssa-value `=` ssa-value </code></pre><p>Traits: <code>RecursiveMemoryEffects</code>, <code>SingleBlock</code></p><p>Interfaces: <code>LoopLikeOpInterface</code>, <code>RegionBranchOpInterface</code></p><h4 id=operands-8>Operands:&nbsp;<a class=headline-hash href=#operands-8>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>inits</code></td><td>variadic of any type</td></tr></tbody></table><h4 id=results-6>Results:&nbsp;<a class=headline-hash href=#results-6>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=scfyield-scfyieldop><code>scf.yield</code> (scf::YieldOp)&nbsp;<a class=headline-hash href=#scfyield-scfyieldop>¶</a></h3><p><em>Loop yield and termination operation</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `scf.yield` attr-dict ($results^ `:` type($results))? </code></pre><p>The <code>scf.yield</code> operation yields an SSA value from the SCF dialect op region and terminates the regions. The semantics of how the values are yielded is defined by the parent operation. If <code>scf.yield</code> has any operands, the operands must match the parent operation&rsquo;s results. If the parent operation defines no values, then the <code>scf.yield</code> may be left out in the custom syntax and the builders will insert one implicitly. Otherwise, it has to be present in the syntax to indicate which values are yielded.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasParent&lt;ExecuteRegionOp, ForOp, IfOp, IndexSwitchOp, WhileOp></code>, <code>ReturnLike</code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>RegionBranchTerminatorOpInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=operands-9>Operands:&nbsp;<a class=headline-hash href=#operands-9>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>results</code></td><td>variadic of any type</td></tr></tbody></table><div class=edit-meta><br></div><nav class=pagination><a class="nav nav-prev" href=https://mlir.llvm.org/docs/Dialects/ROCDLDialect/ title="'rocdl' Dialect"><i class="fas fa-arrow-left" aria-hidden=true></i> Prev - 'rocdl' Dialect</a> <a class="nav nav-next" href=https://mlir.llvm.org/docs/Dialects/ShapeDialect/ title="'shape' Dialect">Next - 'shape' Dialect <i class="fas fa-arrow-right" aria-hidden=true></i></a></nav><footer><p class=powered>Powered by <a href=https://gohugo.io>Hugo</a>. Theme by <a href=https://themes.gohugo.io/hugo-theme-techdoc/>TechDoc</a>. Designed by <a href=https://github.com/thingsym/hugo-theme-techdoc>Thingsym</a>.</p></footer></main><div class=sidebar><nav class=slide-menu><ul><li><a href=https://mlir.llvm.org/>Home</a></li><li><a href=https://mlir.llvm.org/users/>Users of MLIR</a></li><li><a href=https://mlir.llvm.org/pubs/>MLIR Related Publications</a></li><li><a href=https://mlir.llvm.org/talks/>Talks</a></li><li><a href=https://mlir.llvm.org/deprecation/>Deprecations & Current Refactoring</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/getting_started/>Getting Started<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/getting_started/ReportingIssues/>Reporting Issues</a></li><li><a href=https://mlir.llvm.org/getting_started/Debugging/>Debugging Tips</a></li><li><a href=https://mlir.llvm.org/getting_started/Faq/>FAQ</a></li><li><a href=https://mlir.llvm.org/getting_started/Contributing/>How to Contribute</a></li><li><a href=https://mlir.llvm.org/getting_started/DeveloperGuide/>Developer Guide</a></li><li><a href=https://mlir.llvm.org/getting_started/openprojects/>Open Projects</a></li><li><a href=https://mlir.llvm.org/getting_started/Glossary/>Glossary</a></li><li><a href=https://mlir.llvm.org/getting_started/TestingGuide/>Testing Guide</a></li></ul></li><li class="parent has-sub-menu"><a href=https://mlir.llvm.org/docs/>Code Documentation<span class="mark opened">-</span></a><ul class=sub-menu><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Bindings/>Bindings<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Bindings/Python/>MLIR Python Bindings</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tools/>Tools<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tools/MLIRLSP/>MLIR : Language Server Protocol</a></li><li><a href=https://mlir.llvm.org/docs/Tools/mlir-reduce/>MLIR Reduce</a></li><li><a href=https://mlir.llvm.org/docs/Tools/mlir-rewrite/>mlir-rewrite</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/QuantPasses/></a></li><li><a href=https://mlir.llvm.org/docs/ActionTracing/>Action: Tracing and Debugging MLIR-based Compilers</a></li><li><a href=https://mlir.llvm.org/docs/BufferDeallocationInternals/>Buffer Deallocation - Internals</a></li><li><a href=https://mlir.llvm.org/docs/Bufferization/>Bufferization</a></li><li><a href=https://mlir.llvm.org/docs/DataLayout/>Data Layout Modeling</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/DefiningDialects/>Defining Dialects<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/DefiningDialects/Constraints/>Constraints</a></li><li><a href=https://mlir.llvm.org/docs/DefiningDialects/AttributesAndTypes/>Defining Dialect Attributes and Types</a></li><li><a href=https://mlir.llvm.org/docs/DefiningDialects/Operations/>Operation Definition Specification (ODS)</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Diagnostics/>Diagnostic Infrastructure</a></li><li><a href=https://mlir.llvm.org/docs/DialectConversion/>Dialect Conversion</a></li><li class="parent has-sub-menu"><a href=https://mlir.llvm.org/docs/Dialects/>Dialects<span class="mark opened">-</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/DLTITransformOps/></a></li><li><a href=https://mlir.llvm.org/docs/Dialects/OpenACCDialect/>'acc' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Affine/>'affine' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AMDGPU/>'amdgpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AMX/>'amx' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArithOps/>'arith' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmNeon/>'arm_neon' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmSVE/>'arm_sve' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmSME/>'ArmSME' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AsyncDialect/>'async' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/BufferizationOps/>'bufferization' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ControlFlowDialect/>'cf' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ComplexOps/>'complex' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/DLTIDialect/>'dlti' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/EmitC/>'emitc' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Func/>'func' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/GPU/>'gpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/IndexOps/>'index' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/IRDL/>'irdl' Dialect</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Dialects/Linalg/>'linalg' Dialect<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/Linalg/OpDSL/>Linalg OpDSL</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Dialects/LLVM/>'llvm' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MathOps/>'math' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MemRef/>'memref' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Mesh/>'mesh' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MLProgramOps/>'ml_program' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MPI/>'mpi' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/NVGPU/>'nvgpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/NVVMDialect/>'nvvm' Dialect</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Dialects/OpenMPDialect/>'omp' Dialect<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/OpenMPDialect/ODS/>ODS Documentation</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Dialects/PDLInterpOps/>'pdl_interp' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PDLOps/>'pdl' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PolynomialDialect/>'polynomial' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PtrOps/>'ptr' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/QuantDialect/>'quant' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ROCDLDialect/>'rocdl' Dialect</a></li><li class=active><a href=https://mlir.llvm.org/docs/Dialects/SCFDialect/>'scf' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ShapeDialect/>'shape' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/SparseTensorOps/>'sparse_tensor' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/TensorOps/>'tensor' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/UBOps/>'ub' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/VCIXDialect/>'vcix' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Vector/>'vector' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/X86Vector/>'x86vector' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/XeGPU/>'xegpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Builtin/>Builtin Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MatchOpInterfaces/>OpInterface definitions</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/SPIR-V/>SPIR-V Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/TOSA/>Tensor Operator Set Architecture (TOSA) Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Transform/>Transform Dialect</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Interfaces/>Interfaces</a></li><li><a href=https://mlir.llvm.org/docs/TargetLLVMIR/>LLVM IR Target</a></li><li><a href=https://mlir.llvm.org/docs/BytecodeFormat/>MLIR Bytecode Format</a></li><li><a href=https://mlir.llvm.org/docs/CAPI/>MLIR C API</a></li><li><a href=https://mlir.llvm.org/docs/LangRef/>MLIR Language Reference</a></li><li><a href=https://mlir.llvm.org/docs/ReleaseNotes/>MLIR Release Notes</a></li><li><a href=https://mlir.llvm.org/docs/Canonicalization/>Operation Canonicalization</a></li><li><a href=https://mlir.llvm.org/docs/OwnershipBasedBufferDeallocation/>Ownership-based Buffer Deallocation</a></li><li><a href=https://mlir.llvm.org/docs/PassManagement/>Pass Infrastructure</a></li><li><a href=https://mlir.llvm.org/docs/Passes/>Passes</a></li><li><a href=https://mlir.llvm.org/docs/PatternRewriter/>Pattern Rewriting : Generic DAG-to-DAG Rewriting</a></li><li><a href=https://mlir.llvm.org/docs/PDLL/>PDLL - PDL Language</a></li><li><a href=https://mlir.llvm.org/docs/Quantization/>Quantization</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Rationale/>Rationale<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleGenericDAGRewriter/>Generic DAG Rewriter Infrastructure Rationale</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleLinalgDialect/>Linalg Dialect Rationale: The Case For Compiler-Friendly Custom Operations</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/Rationale/>MLIR Rationale</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/MLIRForGraphAlgorithms/>MLIR: Incremental Application to Graph Algorithms in ML Frameworks</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleSimplifiedPolyhedralForm/>MLIR: The case for a simplified polyhedral form</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/SideEffectsAndSpeculation/>Side Effects & Speculation</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/UsageOfConst/>Usage of 'const' in MLIR, for core IR types</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/ShapeInference/>Shape Inference</a></li><li><a href=https://mlir.llvm.org/docs/SPIRVToLLVMDialectConversion/>SPIR-V Dialect to LLVM Dialect conversion manual</a></li><li><a href=https://mlir.llvm.org/docs/SymbolsAndSymbolTables/>Symbols and Symbol Tables</a></li><li><a href=https://mlir.llvm.org/docs/DeclarativeRewrites/>Table-driven Declarative Rewrite Rule (DRR)</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Traits/>Traits<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Traits/Broadcastable/>The `Broadcastable` Trait</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/>Tutorials<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/CreatingADialect/>Creating a Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/QuickstartRewrites/>Quickstart tutorial to adding MLIR graph rewrite</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/Toy/>Toy Tutorial<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-1/>Chapter 1: Toy Language and AST</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-2/>Chapter 2: Emitting Basic MLIR</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-3/>Chapter 3: High-level Language-Specific Analysis and Transformation</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-4/>Chapter 4: Enabling Generic Transformation with Interfaces</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-5/>Chapter 5: Partial Lowering to Lower-Level Dialects for Optimization</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-6/>Chapter 6: Lowering to LLVM and CodeGeneration</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-7/>Chapter 7: Adding a Composite Type to Toy</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/transform/>Transform Dialect Tutorial<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch0/>Chapter 0: A Primer on “Structured” Linalg Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch1/>Chapter 1: Combining Existing Transformations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch2/>Chapter 2: Adding a Simple New Transformation Operation</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch3/>Chapter 3: More than Simple Transform Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch4/>Chapter 4: Matching Payload with Transform Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/ChH/>Chapter H: Reproducing Halide Schedule</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Tutorials/UnderstandingTheIRStructure/>Understanding the IR Structure</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/MlirOpt/>Using `mlir-opt`</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/DataFlowAnalysis/>Writing DataFlow Analyses in MLIR</a></li></ul></li></ul></li></ul></nav><div class=sidebar-footer></div></div></div><a href=# id=backtothetop-fixed class=backtothetop data-backtothetop-duration=600 data-backtothetop-easing=easeOutQuart data-backtothetop-fixed-fadein=1000 data-backtothetop-fixed-fadeout=1000 data-backtothetop-fixed-bottom=10 data-backtothetop-fixed-right=20><span class="fa-layers fa-fw"><i class="fas fa-circle"></i> <i class="fas fa-arrow-circle-up"></i></span></a></div></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10