Skip to content

Commit 00799b0

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c7d237085bf9 into amd-gfx:4b28d14fac77
Local branch amd-gfx 4b28d14 Merged main:79af7bdd4e41 into amd-gfx:4096badd6dbc Remote branch main c7d2370 [mlir] add a simple pygments lexer (llvm#120942)
2 parents 4b28d14 + c7d2370 commit 00799b0

File tree

5 files changed

+103
-6
lines changed

5 files changed

+103
-6
lines changed

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 522509
19+
#define LLVM_MAIN_REVISION 522511
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23088,8 +23088,11 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
2308823088
if (ExtractIndex == BCTruncElt && BCSrc.getValueType().isScalarInteger())
2308923089
return DAG.getAnyExtOrTrunc(BCSrc, DL, ScalarVT);
2309023090

23091+
// TODO: Add support for SCALAR_TO_VECTOR implicit truncation.
2309123092
if (LegalTypes && BCSrc.getValueType().isInteger() &&
23092-
BCSrc.getOpcode() == ISD::SCALAR_TO_VECTOR) {
23093+
BCSrc.getOpcode() == ISD::SCALAR_TO_VECTOR &&
23094+
BCSrc.getScalarValueSizeInBits() ==
23095+
BCSrc.getOperand(0).getScalarValueSizeInBits()) {
2309323096
// ext_elt (bitcast (scalar_to_vec i64 X to v2i64) to v4i32), TruncElt -->
2309423097
// trunc i64 X to i32
2309523098
SDValue X = BCSrc.getOperand(0);

llvm/test/CodeGen/PowerPC/scalar_vector_test_5.ll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,35 @@
1111
define i8 @scalar_to_vector_half(ptr nocapture readonly %ad) {
1212
; P9LE-LABEL: scalar_to_vector_half:
1313
; P9LE: # %bb.0: # %entry
14-
; P9LE-NEXT: lhz r3, 0(r3)
14+
; P9LE-NEXT: lxsihzx v2, 0, r3
15+
; P9LE-NEXT: li r3, 0
16+
; P9LE-NEXT: vsplth v2, v2, 3
17+
; P9LE-NEXT: vextubrx r3, r3, v2
1518
; P9LE-NEXT: blr
1619
;
1720
; P9BE-LABEL: scalar_to_vector_half:
1821
; P9BE: # %bb.0: # %entry
19-
; P9BE-NEXT: lhz r3, 0(r3)
20-
; P9BE-NEXT: srwi r3, r3, 24
22+
; P9BE-NEXT: lxsihzx v2, 0, r3
23+
; P9BE-NEXT: li r3, 0
24+
; P9BE-NEXT: vsplth v2, v2, 3
25+
; P9BE-NEXT: vextublx r3, r3, v2
2126
; P9BE-NEXT: blr
2227
;
2328
; P8LE-LABEL: scalar_to_vector_half:
2429
; P8LE: # %bb.0: # %entry
2530
; P8LE-NEXT: lhz r3, 0(r3)
31+
; P8LE-NEXT: mtfprd f0, r3
32+
; P8LE-NEXT: mffprd r3, f0
33+
; P8LE-NEXT: clrldi r3, r3, 56
2634
; P8LE-NEXT: blr
2735
;
2836
; P8BE-LABEL: scalar_to_vector_half:
2937
; P8BE: # %bb.0: # %entry
3038
; P8BE-NEXT: lhz r3, 0(r3)
31-
; P8BE-NEXT: srwi r3, r3, 24
39+
; P8BE-NEXT: sldi r3, r3, 48
40+
; P8BE-NEXT: mtfprd f0, r3
41+
; P8BE-NEXT: mffprd r3, f0
42+
; P8BE-NEXT: rldicl r3, r3, 8, 56
3243
; P8BE-NEXT: blr
3344
entry:
3445
%0 = load <2 x i8>, ptr %ad, align 1

mlir/utils/pygments/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Pygments Lexer for MLIR
2+
3+
This file contains a simple Pygments lexer configuration for MLIR, derived from
4+
the version used in the original CGO paper. Pygments allows for advanced
5+
configurable syntax highlighting of any code. This lexer is known to be
6+
incomplete and support mostly core IR with a subset of built-in types.
7+
Additions and customizations are welcome.
8+
9+
### Standalone Usage
10+
11+
Install Pygments, e.g., by running `pip install Pygments` or a Python package
12+
manager of your choosing. Use the standalone `pygmentize` command by
13+
instructing it to load the custom lexer:
14+
15+
```
16+
pygmentize -l /path/to/mlir_lexer.py:MlirLexer -x myfile.mlir
17+
```
18+
19+
This will produce highlighted output in the terminal. Other output formats are
20+
available, see Pygments [documentation](https://pygments.org/docs/) for more
21+
information.
22+
23+
### LaTeX Usage
24+
25+
First, make sure your distribution includes the `minted` package and list in
26+
the preamble.
27+
28+
```latex
29+
\usepackage{minted}
30+
```
31+
32+
Place the `mlir_lexer.py` in a place where the `latex` binary can find it,
33+
typically in the working directory next to the main `.tex` file. Note that you
34+
will have to invoke `latex` with the `-shell-escape` flag. See the `minted`
35+
package [documentation](https://ctan.org/pkg/minted?lang=en) for more
36+
information.
37+
38+
Leverage the custom lexer facility of `minted` to use this lexer in your
39+
document as:
40+
41+
```latex
42+
\begin{minted}{mlir_lexer.py:MlirLexer -x}
43+
... your code here ...
44+
\end{minted}
45+
```

mlir/utils/pygments/mlir_lexer.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
from pygments.lexer import RegexLexer
6+
from pygments.token import *
7+
8+
9+
class MlirLexer(RegexLexer):
10+
name = "MLIR"
11+
aliases = ["mlir"]
12+
filenames = ["*.mlir"]
13+
14+
tokens = {
15+
"root": [
16+
(r"%[a-zA-Z0-9_]+", Name.Variable),
17+
(r"@[a-zA-Z_][a-zA-Z0-9_]+", Name.Function),
18+
(r"\^[a-zA-Z0-9_]+", Name.Label),
19+
(r"#[a-zA-Z0-9_]+", Name.Constant),
20+
(r"![a-zA-Z0-9_]+", Keyword.Type),
21+
(r"[a-zA-Z_][a-zA-Z0-9_]*\.", Name.Entity),
22+
(r"memref[^.]", Keyword.Type),
23+
(r"index", Keyword.Type),
24+
(r"i[0-9]+", Keyword.Type),
25+
(r"f[0-9]+", Keyword.Type),
26+
(r"[0-9]+", Number.Integer),
27+
(r"[0-9]*\.[0-9]*", Number.Float),
28+
(r'"[^"]*"', String.Double),
29+
(r"affine_map", Keyword.Reserved),
30+
# TODO: this should be within affine maps only
31+
(r"\+-\*\/", Operator),
32+
(r"floordiv", Operator.Word),
33+
(r"ceildiv", Operator.Word),
34+
(r"mod", Operator.Word),
35+
(r"()\[\]<>,{}", Punctuation),
36+
(r"\/\/.*\n", Comment.Single),
37+
]
38+
}

0 commit comments

Comments
 (0)