Skip to content

Conversation

josephbak
Copy link
Contributor

Fixes a small typo in the Creating a Dialect tutorial.

The rewrite rules format should be DRR (Declarative Rewrite Rules), not DDR.

@llvmbot llvmbot added the mlir label Oct 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2025

@llvm/pr-subscribers-mlir

Author: Joseph Bak (josephbak)

Changes

Fixes a small typo in the Creating a Dialect tutorial.

The rewrite rules format should be DRR (Declarative Rewrite Rules), not DDR.


Full diff: https://github.com/llvm/llvm-project/pull/161965.diff

3 Files Affected:

  • (modified) llvm/examples/Kaleidoscope/Chapter2/toy.cpp (+3-1)
  • (modified) mlir/docs/Tutorials/CreatingADialect.md (+1-1)
  • (added) tmp/ToyDialect.md (+259)
diff --git a/llvm/examples/Kaleidoscope/Chapter2/toy.cpp b/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
index 882613533bb67..6a774cd8cbbab 100644
--- a/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
@@ -33,9 +33,11 @@ static int gettok() {
   static int LastChar = ' ';
 
   // Skip any whitespace.
-  while (isspace(LastChar))
+  while (isspace(LastChar)){
     LastChar = getchar();
+  }
 
+  // Get identifier
   if (isalpha(LastChar)) { // identifier: [a-zA-Z][a-zA-Z0-9]*
     IdentifierStr = LastChar;
     while (isalnum((LastChar = getchar())))
diff --git a/mlir/docs/Tutorials/CreatingADialect.md b/mlir/docs/Tutorials/CreatingADialect.md
index af709fc46eff5..e30b80bc5207c 100644
--- a/mlir/docs/Tutorials/CreatingADialect.md
+++ b/mlir/docs/Tutorials/CreatingADialect.md
@@ -22,7 +22,7 @@ typically defined in FooDialect.cpp, which includes FooOps.cpp.inc and
 FooOpsInterfaces.h.inc.
 
 The 'Transforms' directory contains rewrite rules for the dialect,
-typically described in TableGen file using the [DDR
+typically described in TableGen file using the [DRR
 format](../DeclarativeRewrites.md).
 
 Note that dialect names should not generally be suffixed with “Ops”,
diff --git a/tmp/ToyDialect.md b/tmp/ToyDialect.md
new file mode 100644
index 0000000000000..a991811f4267c
--- /dev/null
+++ b/tmp/ToyDialect.md
@@ -0,0 +1,259 @@
+<!-- Autogenerated by mlir-tblgen; don't manually edit -->
+
+### `toy.add` (toy::AddOp)
+
+_Element-wise addition operation_
+
+The "add" operation performs element-wise addition between two tensors.
+The shapes of the tensor operands are expected to match.
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `lhs` | tensor of 64-bit float values |
+| `rhs` | tensor of 64-bit float values |
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | tensor of 64-bit float values |
+
+
+### `toy.constant` (toy::ConstantOp)
+
+_Constant_
+
+Constant operation turns a literal into an SSA value. The data is attached
+to the operation as an attribute. For example:
+
+```mlir
+  %0 = toy.constant dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]>
+                    : tensor<2x3xf64>
+```
+
+Traits: `AlwaysSpeculatableImplTrait`
+
+Interfaces: `ConditionallySpeculatable`, `NoMemoryEffect (MemoryEffectOpInterface)`
+
+Effects: `MemoryEffects::Effect{}`
+
+#### Attributes:
+
+<table>
+<tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr>
+<tr><td><code>value</code></td><td>::mlir::DenseElementsAttr</td><td>64-bit float elements attribute</td></tr>
+</table>
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | tensor of 64-bit float values |
+
+
+### `toy.func` (toy::FuncOp)
+
+_User defined function operation_
+
+The "toy.func" operation represents a user defined function. These are
+callable SSA-region operations that contain toy computations.
+
+Example:
+
+```mlir
+toy.func @main() {
+  %0 = toy.constant dense<5.500000e+00> : tensor<f64>
+  %1 = toy.reshape(%0 : tensor<f64>) to tensor<2x2xf64>
+  toy.print %1 : tensor<2x2xf64>
+  toy.return
+}
+```
+
+Traits: `IsolatedFromAbove`
+
+Interfaces: `ArgAndResultAttrsOpInterface`, `CallableOpInterface`, `FunctionOpInterface`, `Symbol`
+
+#### Attributes:
+
+<table>
+<tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr>
+<tr><td><code>sym_name</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr>
+<tr><td><code>function_type</code></td><td>::mlir::TypeAttr</td><td>type attribute of function type</td></tr>
+<tr><td><code>arg_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr>
+<tr><td><code>res_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr>
+</table>
+
+
+### `toy.generic_call` (toy::GenericCallOp)
+
+_Generic call operation_
+
+Syntax:
+
+```
+operation ::= `toy.generic_call` $callee `(` $inputs `)` attr-dict `:` functional-type($inputs, results)
+```
+
+Generic calls represent calls to a user defined function that needs to
+be specialized for the shape of its arguments. The callee name is attached
+as a symbol reference via an attribute. The arguments list must match the
+arguments expected by the callee. For example:
+
+```mlir
+ %4 = toy.generic_call @my_func(%1, %3)
+       : (tensor<2x3xf64>, tensor<2x3xf64>) -> tensor<*xf64>
+```
+
+This is only valid if a function named "my_func" exists and takes two
+arguments.
+
+#### Attributes:
+
+<table>
+<tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr>
+<tr><td><code>callee</code></td><td>::mlir::FlatSymbolRefAttr</td><td>flat symbol reference attribute</td></tr>
+</table>
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `inputs` | variadic of tensor of 64-bit float values |
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | tensor of 64-bit float values |
+
+
+### `toy.mul` (toy::MulOp)
+
+_Element-wise multiplication operation_
+
+The "mul" operation performs element-wise multiplication between two
+tensors. The shapes of the tensor operands are expected to match.
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `lhs` | tensor of 64-bit float values |
+| `rhs` | tensor of 64-bit float values |
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | tensor of 64-bit float values |
+
+
+### `toy.print` (toy::PrintOp)
+
+_Print operation_
+
+Syntax:
+
+```
+operation ::= `toy.print` $input attr-dict `:` type($input)
+```
+
+The "print" builtin operation prints a given input tensor, and produces
+no results.
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `input` | tensor of 64-bit float values |
+
+
+### `toy.reshape` (toy::ReshapeOp)
+
+_Tensor reshape operation_
+
+Syntax:
+
+```
+operation ::= `toy.reshape` `(` $input `:` type($input) `)` attr-dict `to` type(results)
+```
+
+Reshape operation is transforming its input tensor into a new tensor with
+the same number of elements but different shapes. For example:
+
+```mlir
+   %0 = toy.reshape (%arg1 : tensor<10xf64>) to tensor<5x2xf64>
+```
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `input` | tensor of 64-bit float values |
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | statically shaped tensor of 64-bit float values |
+
+
+### `toy.return` (toy::ReturnOp)
+
+_Return operation_
+
+Syntax:
+
+```
+operation ::= `toy.return` ($input^ `:` type($input))? attr-dict
+```
+
+The "return" operation represents a return operation within a function.
+The operation takes an optional tensor operand and produces no results.
+The operand type must match the signature of the function that contains
+the operation. For example:
+
+```mlir
+  toy.func @foo() -> tensor<2xf64> {
+    ...
+    toy.return %0 : tensor<2xf64>
+  }
+```
+
+Traits: `AlwaysSpeculatableImplTrait`, `HasParent<FuncOp>`, `Terminator`
+
+Interfaces: `ConditionallySpeculatable`, `NoMemoryEffect (MemoryEffectOpInterface)`
+
+Effects: `MemoryEffects::Effect{}`
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `input` | variadic of tensor of 64-bit float values |
+
+
+### `toy.transpose` (toy::TransposeOp)
+
+_Transpose operation_
+
+Syntax:
+
+```
+operation ::= `toy.transpose` `(` $input `:` type($input) `)` attr-dict `to` type(results)
+```
+
+#### Operands:
+
+| Operand | Description |
+| :-----: | ----------- |
+| `input` | tensor of 64-bit float values |
+
+#### Results:
+
+| Result | Description |
+| :----: | ----------- |
+| &laquo;unnamed&raquo; | tensor of 64-bit float values |
+

@josephbak josephbak closed this Oct 4, 2025
Copy link

github-actions bot commented Oct 4, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/examples/Kaleidoscope/Chapter2/toy.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/examples/Kaleidoscope/Chapter2/toy.cpp b/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
index 6a774cd8c..6e51f9882 100644
--- a/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter2/toy.cpp
@@ -33,7 +33,7 @@ static int gettok() {
   static int LastChar = ' ';
 
   // Skip any whitespace.
-  while (isspace(LastChar)){
+  while (isspace(LastChar)) {
     LastChar = getchar();
   }
 

@josephbak josephbak deleted the fix-drr-typo branch October 4, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants