# tablegen

Published articles for tablegen.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## MLIR -- Defining Patterns with PDLL

DevFeed: [MLIR -- Defining Patterns with PDLL](<https://devfeed.tech/articles/mlir-defining-patterns-with-pdll-40485.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2024/08/04/mlir-pdll/>)

Published: 2024-08-04T14:00:00Z

Content type: tutorial

Language: en

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

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Developer Tools](<https://devfeed.tech/topics/developer-tools.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [heir](<https://devfeed.tech/tags/heir.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [primer](<https://devfeed.tech/tags/primer.md>), [programming](<https://devfeed.tech/tags/programming.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>)

### AI overview

A tutorial on using PDLL to define MLIR patterns. It explains PDLL's relationship to PDL, its intended role as an alternative to TableGen pattern definitions, and how PDLL files are transformed into IR and then C++ code for compilation into a pass.

### Source excerpt

Table of Contents In this article I'll show how to use PDLL, a tool for defining MLIR patterns, which itself is built with MLIR. PDLL is intended to be a replacement for defining patterns in tablegen, though there are few public examples of its use. In fact, the main impetus for PDLL is that tablegen makes it difficult to express things like: Operations that return multiple results Operations with regions Operations with variadic operands Arithmetic on static values While not all these features are fully supported in PDLL yet, they are within scope of the language and tooling.

## Tools for Learning LLVM TableGen

DevFeed: [Tools for Learning LLVM TableGen](<https://devfeed.tech/articles/tools-for-learning-llvm-tablegen-43098.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2023-12-07-tools-for-learning-llvm-tablegen/>)

Author: David Spickett

Published: 2023-12-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Compiler](<https://devfeed.tech/topics/compiler.md>), [domain-specific language](<https://devfeed.tech/topics/domain-specific-language.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Code](<https://devfeed.tech/topics/code.md>), [Documentation](<https://devfeed.tech/topics/documentation.md>), [Repository](<https://devfeed.tech/topics/repository.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [cpu](<https://devfeed.tech/topics/cpu.md>), [Learning](<https://devfeed.tech/topics/learning.md>), [mlir](<https://devfeed.tech/topics/mlir.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Hackathon-Kit](<https://devfeed.tech/topics/hackathon-kit.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code-documentation](<https://devfeed.tech/tags/code-documentation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [contributing](<https://devfeed.tech/tags/contributing.md>), [data](<https://devfeed.tech/tags/data.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [domain-specific-language](<https://devfeed.tech/tags/domain-specific-language.md>), [dsl](<https://devfeed.tech/tags/dsl.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [language](<https://devfeed.tech/tags/language.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvm-ir](<https://devfeed.tech/tags/llvm-ir.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [repository](<https://devfeed.tech/tags/repository.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>)

### AI overview

A tutorial introduces LLVM TableGen, a domain-specific language used to generate files such as C++ code, documentation, command-line options, and architecture instruction definitions. It explains TableGen's compiler, intermediate representation, and backends, including examples involving Arm's AArch64 registers and outputs such as C++ code, C headers, and reStructuredText documentation.

### Source excerpt

TableGenis a language used within the LLVM project for generating a variety of files,when manual maintenance would be very difficult. For example, it is used to define all of the instructions that can be used on aparticular architecture. The information is defined in TableGen and we canproduce many things based on that single source file. C++ code, documentation,command line options, and so on. TableGen has been in existence sincebeforethe first official release of LLVM, over 20 years ago. Today in the LLVM project repository there areover a thousand TableGen source files totalling over 500,000 lines of code.Making it the 5th most popular language in the repository. LanguagefilesblankcommentcodeC++2964295854218701015544445C/C++ Header118443168064998451486165C1053525990016035941011269Assembly106944780351222315820236TableGen13129411283616580289 (Counted fromthis commit,rest of table omitted) With projects such as MLIRembracing TableGen,it is only going to grow. So if you are contributing to LLVM, you will encounterit at some point. Which might be a problem as TableGen only exists within LLVM. Unlike a languagesuch as C++, TableGen does not have a large array of resources. So, as well as joining a new project, you also need to learn a newDomain Specific Language (DSL). You did not come to LLVM to learn a DSL, youprobably came here to write a compiler. I cannot say when this problem might be solved, but the situation is not asbleak as it appears. There have been big improvements in TableGen toolsrecently, which means you can put more of your energy into the goals thatbrought you to LLVM in the first place. A Brief Introduction to TableGen Imagine you wanted to represent the registers of an architecture. I am going touse Arm's AArch64 in particular here. You could describe them in TableGen as: $ cat register.tdclass Register<int _size, string _alias=""> { int size = _size; string alias = _alias;}// 64 bit general purpose registers are X<N>.def X0: Register<8> {}// Some h

## MLIR -- Canonicalizers and Declarative Rewrite Patterns

DevFeed: [MLIR -- Canonicalizers and Declarative Rewrite Patterns](<https://devfeed.tech/articles/mlir-canonicalizers-and-declarative-rewrite-patterns-40477.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/>)

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

Content type: tutorial

Language: en

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

Topics: [Code](<https://devfeed.tech/topics/code.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [software-development](<https://devfeed.tech/topics/software-development.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [canonicalization](<https://devfeed.tech/tags/canonicalization.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [complex-numbers](<https://devfeed.tech/tags/complex-numbers.md>), [declarative](<https://devfeed.tech/tags/declarative.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [maintenance](<https://devfeed.tech/tags/maintenance.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [polynomials](<https://devfeed.tech/tags/polynomials.md>), [primer](<https://devfeed.tech/tags/primer.md>), [programming](<https://devfeed.tech/tags/programming.md>), [rewrite](<https://devfeed.tech/tags/rewrite.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>), [test](<https://devfeed.tech/tags/test.md>)

### AI overview

This tutorial explains how to implement general canonicalization patterns in MLIR. It covers both C++ canonicalizers and declarative rewrite rules in TableGen, including an identity-based polynomial rewrite and its testing considerations.

### Source excerpt

Table of Contents In a previous article we defined folding functions, and used them to enable some canonicalization and the sccp constant propagation pass for the poly dialect. This time we'll see how to add more general canonicalization patterns. The code for this article is in this pull request, and as usual the commits are organized to be read in order. Why is Canonicalization Needed? MLIR provides folding as a mechanism to simplify an IR, which can result in simpler, more efficient ops (e.

## MLIR -- Defining a New Dialect

DevFeed: [MLIR -- Defining a New Dialect](<https://devfeed.tech/articles/mlir-defining-a-new-dialect-40471.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/>)

Published: 2023-08-21T08:00:00Z

Content type: tutorial

Language: en

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

Topics: [Code generation](<https://devfeed.tech/topics/code-generation.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [polynomials](<https://devfeed.tech/topics/polynomials.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [define](<https://devfeed.tech/tags/define.md>), [endif](<https://devfeed.tech/tags/endif.md>), [ifdef](<https://devfeed.tech/tags/ifdef.md>), [include](<https://devfeed.tech/tags/include.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [polynomials](<https://devfeed.tech/tags/polynomials.md>), [programming](<https://devfeed.tech/tags/programming.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [undef](<https://devfeed.tech/tags/undef.md>)

### AI overview

This tutorial explains how to define a new MLIR dialect for arithmetic on single-variable polynomials with 32-bit unsigned integer coefficients. It covers the design, an empty dialect, generated code, registration, and a simple custom type.

### Source excerpt

Table of Contents In the last article in the series, we migrated the passes we had written to use the tablegen code generation framework. That was a preface to using tablegen to define dialects. In this article we'll define a dialect that represents arithmetic on single-variable polynomials, with coefficients in $\mathbb{Z} / 2^{32} \mathbb{Z}$ (32-bit unsigned integers). The code for this article is in this pull request, and as usual the commits are organized to be read in order.

## MLIR -- Using Tablegen for Passes

DevFeed: [MLIR -- Using Tablegen for Passes](<https://devfeed.tech/articles/mlir-using-tablegen-for-passes-40469.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/>)

Published: 2023-08-10T14:41:45Z

Content type: tutorial

Language: en

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

Topics: [Code generation](<https://devfeed.tech/topics/code-generation.md>), [Code](<https://devfeed.tech/topics/code.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>)

Tags: [boilerplate](<https://devfeed.tech/tags/boilerplate.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [define](<https://devfeed.tech/tags/define.md>), [endif](<https://devfeed.tech/tags/endif.md>), [fhe](<https://devfeed.tech/tags/fhe.md>), [ifdef](<https://devfeed.tech/tags/ifdef.md>), [include](<https://devfeed.tech/tags/include.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [mathematics](<https://devfeed.tech/tags/mathematics.md>), [mlir](<https://devfeed.tech/tags/mlir.md>), [programming](<https://devfeed.tech/tags/programming.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>), [undef](<https://devfeed.tech/tags/undef.md>)

### AI overview

This article explains how MLIR developers can use TableGen to define passes and generate boilerplate code, headers, documentation, and registration hooks. It also discusses the need to understand the generated C++ code and the tool's limited diagnostic information.

### Source excerpt

Table of Contents In the last article in this series, we defined some custom lowering passes that modified an MLIR program. Notably, we accomplished that by implementing the required interfaces of the MLIR API directly. This is not the way that most MLIR developers work. Instead, they use a code generation tool called tablegen to generate boilerplate for them, and then only add the implementation methods that are custom to their work.

## Instruction Relationship Framework in LLVM

DevFeed: [Instruction Relationship Framework in LLVM](<https://devfeed.tech/articles/instruction-relationship-framework-in-llvm-42873.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2013/03/instruction-relationship-framework-in.html>)

Author: Jyotsna Verma

Published: 2013-03-20T13:42:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [Code](<https://devfeed.tech/topics/code.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [Code quality](<https://devfeed.tech/topics/code-quality.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>)

Tags: [code-quality](<https://devfeed.tech/tags/code-quality.md>), [codegen](<https://devfeed.tech/tags/codegen.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [mc](<https://devfeed.tech/tags/mc.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [review](<https://devfeed.tech/tags/review.md>), [tablegen](<https://devfeed.tech/tags/tablegen.md>), [transformation](<https://devfeed.tech/tags/transformation.md>)

### AI overview

An overview of LLVM TableGen's Relationship framework, which models relationships between instruction variants for use in machine instruction passes. The article explains how it replaces large switch-case implementations in the Hexagon backend with a queryable relationship model intended to improve maintainability, scalability, and code quality.

### Source excerpt

The article provides an overview of the new Relationship framework of TableGen. This TableGen feature is used to describe user defined relationships between instructions. It was added to LLVM in October 2012. Motivation: The motivation for this feature stemmed from the Hexagon backend. Much like other processors, Hexagon provides multiple variations for many instructions. It is a common requirement in machine instruction passes to switch between various formats of the same instruction. For example, consider an Add instruction with predicated true (Add_pt) and predicated false (Add_pf) forms. Let's assume that a non-predicated Add instruction is selected during target lowering. However, during if-conversion, the optimization pass might decide to change the non-predicated Add into the predicated true Add_pt form. These transformations require a framework to relate non-predicated forms to the respective predicated forms. In the absence of such a framework, this transformation is typically achieved using large switch cases. There are many deficiencies in using a switch case based approach. The manual implementation of switch case clauses requires a very high maintenance cost. It also results in lost optimization opportunities due to incomplete implementation of switch cases. The lack of a relationship model resulted in around 15% of Hexagon backend code dedicated to switch cases with several of those functions growing to over thousands of lines of code. This problem inspired us to explore some alternatives. We started to look for a framework that was easy to maintain, flexible, scalable, and less error prone. After some initial discussions and brainstorming in the Hexagon group, we decided to modify TableGen to express instruction relations. The initial design was submitted to the LLVM-dev mailing list for review. Jakob Stoklund gave valuable suggestions and helped with the design of the relationship framework. The idea was to add a query language that can be used to de