# MLIR -- Using Traits

DevFeed: [MLIR -- Using Traits](<https://devfeed.tech/articles/mlir-using-traits-40473.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2023/09/07/mlir-using-traits/>)

Published: 2023-09-07T08:00:00Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Compiler](<https://devfeed.tech/topics/compiler.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [optimize](<https://devfeed.tech/topics/optimize.md>), [Code](<https://devfeed.tech/topics/code.md>), [interface](<https://devfeed.tech/topics/interface.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [heir](<https://devfeed.tech/tags/heir.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [optimize](<https://devfeed.tech/tags/optimize.md>), [programming](<https://devfeed.tech/tags/programming.md>), [toolchain](<https://devfeed.tech/tags/toolchain.md>)

## AI overview

This tutorial explains how to add predefined MLIR traits to operations in a polynomial-arithmetic dialect. It shows how traits and interfaces enable reuse of existing compiler passes, including loop-invariant code motion, and support operation verification and type inference.

## Source excerpt

Table of Contents Last time we defined a new dialect poly for polynomial arithmetic. This time we'll spruce up the dialect by adding some pre-defined MLIR traits, and see how the application of traits enables some general purpose passes to optimize poly programs. The code for this article is in this pull request, and as usual the commits are organized to be read in order. Traits and Loop Invariant Code Motion As a compiler toolchain, MLIR heavily emphasizes code reuse.