[Mlir-commits] [mlir] [mlir][llvm] Fix linkage enum order (PR #118484)
Henrich Lauko
llvmlistbot at llvm.org
Tue Dec 3 06:27:48 PST 2024
https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/118484
>From 6a91c645deb907d64d79bfe8bc79fe3638fcdf0c Mon Sep 17 00:00:00 2001
From: xlauko <xlauko at mail.muni.cz>
Date: Tue, 3 Dec 2024 13:50:23 +0100
Subject: [PATCH] [mlir][llvm] Align linkage enum order with LLVM (NFC)
This change doesn't introduce any functional differences but aligns the
MLIR Linkage EnumAttr with LLVM's representation order. Previously, the
code generated a lookup table to map MLIR enums to LLVM enums due to the
lack of one-to-one correspondence. With this refactoring, the generated
code now casts directly from one enum to another.
---
mlir/include/mlir-c/Dialect/LLVM.h | 18 ++++----
mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td | 42 +++++++++----------
2 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 0e6434073437a5..ed9b23c343150c 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -175,17 +175,17 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx,
MlirLLVMComdat comdat);
enum MlirLLVMLinkage {
- MlirLLVMLinkagePrivate = 0,
- MlirLLVMLinkageInternal = 1,
- MlirLLVMLinkageAvailableExternally = 2,
- MlirLLVMLinkageLinkonce = 3,
+ MlirLLVMLinkageExternal = 0,
+ MlirLLVMLinkageAvailableExternally = 1,
+ MlirLLVMLinkageLinkonce = 2,
+ MlirLLVMLinkageLinkonceODR = 3,
MlirLLVMLinkageWeak = 4,
- MlirLLVMLinkageCommon = 5,
+ MlirLLVMLinkageWeakODR = 5,
MlirLLVMLinkageAppending = 6,
- MlirLLVMLinkageExternWeak = 7,
- MlirLLVMLinkageLinkonceODR = 8,
- MlirLLVMLinkageWeakODR = 9,
- MlirLLVMLinkageExternal = 10,
+ MlirLLVMLinkageInternal = 7,
+ MlirLLVMLinkagePrivate = 8,
+ MlirLLVMLinkageExternWeak = 9,
+ MlirLLVMLinkageCommon = 10,
};
typedef enum MlirLLVMLinkage MlirLLVMLinkage;
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 4a43c16903394f..c08b75de036473 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -615,40 +615,40 @@ def ICmpPredicate : LLVM_EnumAttr<
//===----------------------------------------------------------------------===//
// Linkage attribute is used on functions and globals. The order follows that of
-// https://llvm.org/docs/LangRef.html#linkage-types. The names are equivalent to
-// visible names in the IR rather than to enum values names in llvm::GlobalValue
-// since the latter is easier to change.
-def LinkagePrivate
- : LLVM_EnumAttrCase<"Private", "private", "PrivateLinkage", 0>;
-def LinkageInternal
- : LLVM_EnumAttrCase<"Internal", "internal", "InternalLinkage", 1>;
+// llvm::GlobalValue::LinkageTypes from llvm/IR/GlobalValue.h. The names are
+// equivalent to visible names in the IR rather than to enum values names in
+// llvm::GlobalValue since the latter is easier to change.
+def LinkageExternal
+ : LLVM_EnumAttrCase<"External", "external", "ExternalLinkage", 0>;
def LinkageAvailableExternally
: LLVM_EnumAttrCase<"AvailableExternally", "available_externally",
- "AvailableExternallyLinkage", 2>;
+ "AvailableExternallyLinkage", 1>;
def LinkageLinkonce
- : LLVM_EnumAttrCase<"Linkonce", "linkonce", "LinkOnceAnyLinkage", 3>;
+ : LLVM_EnumAttrCase<"Linkonce", "linkonce", "LinkOnceAnyLinkage", 2>;
+def LinkageLinkonceODR
+ : LLVM_EnumAttrCase<"LinkonceODR", "linkonce_odr", "LinkOnceODRLinkage", 3>;
def LinkageWeak
: LLVM_EnumAttrCase<"Weak", "weak", "WeakAnyLinkage", 4>;
-def LinkageCommon
- : LLVM_EnumAttrCase<"Common", "common", "CommonLinkage", 5>;
+def LinkageWeakODR
+ : LLVM_EnumAttrCase<"WeakODR", "weak_odr", "WeakODRLinkage", 5>;
def LinkageAppending
: LLVM_EnumAttrCase<"Appending", "appending", "AppendingLinkage", 6>;
+def LinkageInternal
+ : LLVM_EnumAttrCase<"Internal", "internal", "InternalLinkage", 7>;
+def LinkagePrivate
+ : LLVM_EnumAttrCase<"Private", "private", "PrivateLinkage", 8>;
def LinkageExternWeak
- : LLVM_EnumAttrCase<"ExternWeak", "extern_weak", "ExternalWeakLinkage", 7>;
-def LinkageLinkonceODR
- : LLVM_EnumAttrCase<"LinkonceODR", "linkonce_odr", "LinkOnceODRLinkage", 8>;
-def LinkageWeakODR
- : LLVM_EnumAttrCase<"WeakODR", "weak_odr", "WeakODRLinkage", 9>;
-def LinkageExternal
- : LLVM_EnumAttrCase<"External", "external", "ExternalLinkage", 10>;
+ : LLVM_EnumAttrCase<"ExternWeak", "extern_weak", "ExternalWeakLinkage", 9>;
+def LinkageCommon
+ : LLVM_EnumAttrCase<"Common", "common", "CommonLinkage", 10>;
def LinkageEnum : LLVM_EnumAttr<
"Linkage",
"::llvm::GlobalValue::LinkageTypes",
"LLVM linkage types",
- [LinkagePrivate, LinkageInternal, LinkageAvailableExternally,
- LinkageLinkonce, LinkageWeak, LinkageCommon, LinkageAppending,
- LinkageExternWeak, LinkageLinkonceODR, LinkageWeakODR, LinkageExternal]> {
+ [LinkageExternal, LinkageAvailableExternally, LinkageLinkonce,
+ LinkageLinkonceODR, LinkageWeak, LinkageWeakODR, LinkageAppending,
+ LinkageInternal, LinkagePrivate, LinkageExternWeak, LinkageCommon]> {
let cppNamespace = "::mlir::LLVM::linkage";
}
More information about the Mlir-commits
mailing list