[all-commits] [llvm/llvm-project] 67aaa0: [mlir][IR] Add builtin `TokenType` (#195640)

Matthias Springer via All-commits all-commits at lists.llvm.org
Tue Jun 2 03:34:08 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 67aaa03dac582b5ccf65776e449eb6c7517eb11c
      https://github.com/llvm/llvm-project/commit/67aaa03dac582b5ccf65776e449eb6c7517eb11c
  Author: Matthias Springer <me at m-sp.org>
  Date:   2026-06-02 (Tue, 02 Jun 2026)

  Changed paths:
    M mlir/docs/Dialects/LLVM.md
    M mlir/docs/LangRef.md
    A mlir/docs/Tokens.md
    M mlir/docs/Traits/_index.md
    M mlir/include/mlir/Dialect/Async/IR/Async.h
    M mlir/include/mlir/Dialect/Async/IR/AsyncOps.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h
    M mlir/include/mlir/IR/BuiltinDialectBytecode.td
    M mlir/include/mlir/IR/BuiltinTypes.td
    M mlir/include/mlir/IR/CommonTypeConstraints.td
    M mlir/include/mlir/IR/OpBase.td
    M mlir/include/mlir/IR/OpDefinition.h
    M mlir/lib/AsmParser/TokenKinds.def
    M mlir/lib/AsmParser/TypeParser.cpp
    M mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp
    M mlir/lib/Dialect/Async/IR/Async.cpp
    M mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
    M mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/lib/IR/Verifier.cpp
    M mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp
    M mlir/lib/Target/LLVMIR/TypeToLLVM.cpp
    M mlir/test/Conversion/AsyncToLLVM/convert-coro-to-llvm.mlir
    M mlir/test/Dialect/ArmSME/invalid.mlir
    M mlir/test/Dialect/Builtin/Bytecode/builtin_fixed.mlir
    M mlir/test/Dialect/Builtin/Bytecode/builtin_fixed_0.mlirbc
    M mlir/test/Dialect/Builtin/Bytecode/types.mlir
    M mlir/test/Dialect/LLVMIR/types.mlir
    M mlir/test/Dialect/Linalg/invalid.mlir
    M mlir/test/Dialect/MemRef/invalid.mlir
    M mlir/test/Dialect/SparseTensor/invalid.mlir
    M mlir/test/Dialect/Tensor/invalid.mlir
    M mlir/test/Dialect/Vector/invalid.mlir
    M mlir/test/Dialect/traits.mlir
    M mlir/test/IR/operand.mlir
    M mlir/test/IR/result.mlir
    A mlir/test/IR/token-type.mlir
    M mlir/test/Target/LLVMIR/Import/intrinsic.ll
    M mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/mlir-tblgen/predicate.td
    M mlir/test/mlir-tblgen/types.mlir
    M mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

  Log Message:
  -----------
  [mlir][IR] Add builtin `TokenType` (#195640)

Introduces a new parameterless, opaque, builtin SSA value type,
`!token`. A token cannot appear in a value-forwarding position such as
`cf.br`, `arith.select`, `scf.for` iter-args or function call/return.
Walking back from any token use reaches the producing operation without
crossing such a boundary. Tokens carry no runtime data and cannot
constant-fold.

This contract is enforced by changing the default ODS `AnyType`
predicate to exclude tokens. In addition, token-producing and
token-consuming ops must opt in by implementing the `ProducesToken` and
`ConsumesToken` traits. The IR verifier checks for the presence of these
traits.

Note: CSE, DCE, hoisting, and `OperationEquivalence` remain unchanged. A
stronger contract (e.g., uniqueness, arity, paired lifetime), if
desirable based on the semantics of token-producing and token-consuming
ops, can be expressed at the op level via existing mechanisms (side
effects, block arguments, traits, attributes), keeping the type
orthogonal to operation-level transformations. This mirrors LLVM's
`token` type.

Other changes:
* Builtin bytecode: new entry for `TokenType`.
* AsmParser / AsmPrinter: `token` keyword for the textual format.
* Remove `LLVMTokenType` from the LLVM dialect and use the builtin
`TokenType` instead.
* Async dialect: references to `async::TokenType` are qualified to
disambiguate from the new builtin `TokenType`.
* Documentation: new `mlir/docs/Tokens.md` covering the structural
contract, design rationale, and ODS integration.

No changes to `Operation`, the generic op syntax, the bytecode op
encoding, or core C++ APIs around `Operation`.

This commit is in preparation of adding support for breaking exit from
regions. (E.g., early exit from loops.)

RFC:
https://discourse.llvm.org/t/rfc-add-a-builtin-token-type-to-mlir/90706

Assisted-by: claude-opus-4.7-thinking-high

---------

Co-authored-by: Mehdi Amini <joker.eph at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list