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 @@ + + +### `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 | +| :----: | ----------- | +| «unnamed» | 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: + + + + +
AttributeMLIR TypeDescription
value::mlir::DenseElementsAttr64-bit float elements attribute
+ +#### Results: + +| Result | Description | +| :----: | ----------- | +| «unnamed» | 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 + %1 = toy.reshape(%0 : tensor) to tensor<2x2xf64> + toy.print %1 : tensor<2x2xf64> + toy.return +} +``` + +Traits: `IsolatedFromAbove` + +Interfaces: `ArgAndResultAttrsOpInterface`, `CallableOpInterface`, `FunctionOpInterface`, `Symbol` + +#### Attributes: + + + + + + + +
AttributeMLIR TypeDescription
sym_name::mlir::StringAttrstring attribute
function_type::mlir::TypeAttrtype attribute of function type
arg_attrs::mlir::ArrayAttrArray of dictionary attributes
res_attrs::mlir::ArrayAttrArray of dictionary attributes
+ + +### `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: + + + + +
AttributeMLIR TypeDescription
callee::mlir::FlatSymbolRefAttrflat symbol reference attribute
+ +#### Operands: + +| Operand | Description | +| :-----: | ----------- | +| `inputs` | variadic of tensor of 64-bit float values | + +#### Results: + +| Result | Description | +| :----: | ----------- | +| «unnamed» | 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 | +| :----: | ----------- | +| «unnamed» | 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 | +| :----: | ----------- | +| «unnamed» | 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`, `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 | +| :----: | ----------- | +| «unnamed» | tensor of 64-bit float values | +