Skip to content

Commit 6ec8b4b

Browse files
committed
[mlir][llvm] Move llvm attribute bases to utils
This enables other attributes, not necessarily defined in LLVMEnums.td, to be used with `gen-enum-to/from-llvmir-conversions`.
1 parent 7802fb5 commit 6ec8b4b

File tree

2 files changed

+72
-53
lines changed

2 files changed

+72
-53
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,9 @@
1010
#define LLVMIR_ENUMS
1111

1212
include "mlir/Dialect/LLVMIR/LLVMDialect.td"
13+
include "mlir/Dialect/LLVMIR/Utils.td"
1314
include "mlir/IR/EnumAttr.td"
1415

15-
//===----------------------------------------------------------------------===//
16-
// Base classes for LLVM enum attributes.
17-
//===----------------------------------------------------------------------===//
18-
19-
// Case of the LLVM enum attribute backed by I64Attr with customized string
20-
// representation that corresponds to what is visible in the textual IR form.
21-
// The parameters are as follows:
22-
// - `cppSym`: name of the C++ enumerant for this case in MLIR API;
23-
// - `irSym`: keyword used in the custom form of MLIR operation;
24-
// - `llvmSym`: name of the C++ enumerant for this case in LLVM API.
25-
// For example, `LLVM_EnumAttrCase<"Weak", "weak", "WeakAnyLinkage">` is usable
26-
// as `<MlirEnumName>::Weak` in MLIR API, `WeakAnyLinkage` in LLVM API and
27-
// is printed/parsed as `weak` in MLIR custom textual format.
28-
class LLVM_EnumAttrCase<string cppSym, string irSym, string llvmSym, int val> :
29-
I64EnumAttrCase<cppSym, val, irSym> {
30-
// The name of the equivalent enumerant in LLVM.
31-
string llvmEnumerant = llvmSym;
32-
}
33-
34-
// LLVM enum attribute backed by I64Attr with string representation
35-
// corresponding to what is visible in the textual IR form.
36-
// The parameters are as follows:
37-
// - `name`: name of the C++ enum class in MLIR API;
38-
// - `llvmName`: name of the C++ enum in LLVM API;
39-
// - `description`: textual description for documentation purposes;
40-
// - `cases`: list of enum cases;
41-
// - `unsupportedCases`: optional list of unsupported enum cases.
42-
// For example, `LLVM_EnumAttr<Linkage, "::llvm::GlobalValue::LinkageTypes`
43-
// produces `mlir::LLVM::Linkage` enum class in MLIR API that corresponds to (a
44-
// subset of) values in the `llvm::GlobalValue::LinkageTypes` in LLVM API.
45-
// All unsupported cases are excluded from the MLIR enum and trigger an error
46-
// during the import from LLVM IR. They are useful to handle sentinel values
47-
// such as `llvm::AtomicRMWInst::BinOp::BAD_BINOP` that LLVM commonly uses to
48-
// terminate its enums.
49-
class LLVM_EnumAttr<string name, string llvmName, string description,
50-
list<LLVM_EnumAttrCase> cases,
51-
list<LLVM_EnumAttrCase> unsupportedCases = []> :
52-
I64EnumAttr<name, description, cases> {
53-
// List of unsupported cases that have no conversion to an MLIR value.
54-
list<LLVM_EnumAttrCase> unsupported = unsupportedCases;
55-
56-
// The equivalent enum class name in LLVM.
57-
string llvmClassName = llvmName;
58-
}
59-
60-
// LLVM_CEnumAttr is functionally identical to LLVM_EnumAttr, but to be used for
61-
// non-class enums.
62-
class LLVM_CEnumAttr<string name, string llvmNS, string description,
63-
list<LLVM_EnumAttrCase> cases> :
64-
I64EnumAttr<name, description, cases> {
65-
string llvmClassName = llvmNS;
66-
}
67-
6816
//===----------------------------------------------------------------------===//
6917
// AsmDialect
7018
//===----------------------------------------------------------------------===//
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===-- Utils.td - MLIR LLVM IR utilities file -------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains utilities to map from MLIR LLVM IR dialect to LLVM IR.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_LLVMIR_UTILS_TD
14+
#define MLIR_DIALECT_LLVMIR_UTILS_TD
15+
16+
include "mlir/IR/EnumAttr.td"
17+
18+
//===----------------------------------------------------------------------===//
19+
// Base classes for LLVM enum attributes.
20+
//===----------------------------------------------------------------------===//
21+
22+
// Case of the LLVM enum attribute backed by I64Attr with customized string
23+
// representation that corresponds to what is visible in the textual IR form.
24+
// The parameters are as follows:
25+
// - `cppSym`: name of the C++ enumerant for this case in MLIR API;
26+
// - `irSym`: keyword used in the custom form of MLIR operation;
27+
// - `llvmSym`: name of the C++ enumerant for this case in LLVM API.
28+
// For example, `LLVM_EnumAttrCase<"Weak", "weak", "WeakAnyLinkage">` is usable
29+
// as `<MlirEnumName>::Weak` in MLIR API, `WeakAnyLinkage` in LLVM API and
30+
// is printed/parsed as `weak` in MLIR custom textual format.
31+
class LLVM_EnumAttrCase<string cppSym, string irSym, string llvmSym, int val> :
32+
I64EnumAttrCase<cppSym, val, irSym> {
33+
// The name of the equivalent enumerant in LLVM.
34+
string llvmEnumerant = llvmSym;
35+
}
36+
37+
// LLVM enum attribute backed by I64Attr with string representation
38+
// corresponding to what is visible in the textual IR form.
39+
// The parameters are as follows:
40+
// - `name`: name of the C++ enum class in MLIR API;
41+
// - `llvmName`: name of the C++ enum in LLVM API;
42+
// - `description`: textual description for documentation purposes;
43+
// - `cases`: list of enum cases;
44+
// - `unsupportedCases`: optional list of unsupported enum cases.
45+
// For example, `LLVM_EnumAttr<Linkage, "::llvm::GlobalValue::LinkageTypes`
46+
// produces `mlir::LLVM::Linkage` enum class in MLIR API that corresponds to (a
47+
// subset of) values in the `llvm::GlobalValue::LinkageTypes` in LLVM API.
48+
// All unsupported cases are excluded from the MLIR enum and trigger an error
49+
// during the import from LLVM IR. They are useful to handle sentinel values
50+
// such as `llvm::AtomicRMWInst::BinOp::BAD_BINOP` that LLVM commonly uses to
51+
// terminate its enums.
52+
class LLVM_EnumAttr<string name, string llvmName, string description,
53+
list<LLVM_EnumAttrCase> cases,
54+
list<LLVM_EnumAttrCase> unsupportedCases = []> :
55+
I64EnumAttr<name, description, cases> {
56+
// List of unsupported cases that have no conversion to an MLIR value.
57+
list<LLVM_EnumAttrCase> unsupported = unsupportedCases;
58+
59+
// The equivalent enum class name in LLVM.
60+
string llvmClassName = llvmName;
61+
}
62+
63+
// LLVM_CEnumAttr is functionally identical to LLVM_EnumAttr, but to be used for
64+
// non-class enums.
65+
class LLVM_CEnumAttr<string name, string llvmNS, string description,
66+
list<LLVM_EnumAttrCase> cases> :
67+
I64EnumAttr<name, description, cases> {
68+
string llvmClassName = llvmNS;
69+
}
70+
71+
#endif // MLIR_DIALECT_LLVMIR_UTILS_TD

0 commit comments

Comments
 (0)