-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[MLIR:LLVM] Add UWTableKind attribute #135811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mlir-llvm Author: Will Froom (WillFroom) ChangesAdd Full diff: https://github.com/llvm/llvm-project/pull/135811.diff 5 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 690243525ede4..e2bea7f8d3d23 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -1365,4 +1365,14 @@ def LLVM_DependentLibrariesAttr
let assemblyFormat = "`<` $libs `>`";
}
+//===----------------------------------------------------------------------===//
+// UWTableKindAttr
+//===----------------------------------------------------------------------===//
+
+def UWTableKindAttr : LLVM_Attr<"UWTableKind", "uwtableKind"> {
+ let parameters = (ins "uwtable::UWTableKind":$uwtableKind);
+ let assemblyFormat = "`<` $uwtableKind `>`";
+}
+
+
#endif // LLVMIR_ATTRDEFS
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 34a30a00790ea..52bce96c8a990 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -855,4 +855,27 @@ def ModFlagBehaviorAttr : LLVM_EnumAttr<
let cppNamespace = "::mlir::LLVM";
}
+//===----------------------------------------------------------------------===//
+// UWTableKind
+//===----------------------------------------------------------------------===//
+
+def UWTableKindNone
+ : LLVM_EnumAttrCase<"None", "none", "None", 0>;
+def UWTableKindSync
+ : LLVM_EnumAttrCase<"Sync", "sync", "Sync", 1>;
+def UWTableKindAsync
+ : LLVM_EnumAttrCase<"Async", "async", "Async", 2>;
+def UWTableKindDefault
+ : LLVM_EnumAttrCase<"Default", "default", "Default", 2>;
+
+// UWTableKindDefault is unsupported as the llvm enum value is the same as async
+// which the generated enum converters can't deal with.
+def UWTableKindEnum : LLVM_EnumAttr<
+ "UWTableKind",
+ "::llvm::UWTableKind",
+ "LLVM Unwind Behavior",
+ [UWTableKindNone, UWTableKindSync, UWTableKindAsync]> {
+ let cppNamespace = "::mlir::LLVM::uwtable";
+}
+
#endif // LLVMIR_ENUMS
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index e89e78aec7147..76a2ec47b3a22 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1842,7 +1842,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
OptionalAttr<LLVM_VecTypeHintAttr>:$vec_type_hint,
OptionalAttr<DenseI32ArrayAttr>:$work_group_size_hint,
OptionalAttr<DenseI32ArrayAttr>:$reqd_work_group_size,
- OptionalAttr<I32Attr>:$intel_reqd_sub_group_size
+ OptionalAttr<I32Attr>:$intel_reqd_sub_group_size,
+ OptionalAttr<UWTableKindAttr>:$uwtable_kind
);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index ee7dc3a5231f4..6531b233b94a0 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1602,6 +1602,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
if (FramePointerKindAttr fpAttr = func.getFramePointerAttr())
llvmFunc->addFnAttr("frame-pointer", stringifyFramePointerKind(
fpAttr.getFramePointerKind()));
+ if (UWTableKindAttr uwTableKindAttr = func.getUwtableKindAttr())
+ llvmFunc->setUWTableKind(convertUWTableKindToLLVM(uwTableKindAttr.getUwtableKind()));
convertFunctionMemoryAttributes(func, llvmFunc);
}
diff --git a/mlir/test/Target/LLVMIR/uwtable.mlir b/mlir/test/Target/LLVMIR/uwtable.mlir
new file mode 100644
index 0000000000000..3e1d5b566f01b
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/uwtable.mlir
@@ -0,0 +1,8 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// CHECK-LABEL: define void @uwtable_func()
+// CHECK-SAME: #[[ATTRS:[0-9]+]]
+llvm.func @uwtable_func() attributes {uwtable_kind = #llvm.uwtableKind<"sync">} {
+ llvm.return
+}
+// CHECK: attributes #[[ATTRS]] = { uwtable(sync) }
|
@llvm/pr-subscribers-mlir Author: Will Froom (WillFroom) ChangesAdd Full diff: https://github.com/llvm/llvm-project/pull/135811.diff 5 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 690243525ede4..e2bea7f8d3d23 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -1365,4 +1365,14 @@ def LLVM_DependentLibrariesAttr
let assemblyFormat = "`<` $libs `>`";
}
+//===----------------------------------------------------------------------===//
+// UWTableKindAttr
+//===----------------------------------------------------------------------===//
+
+def UWTableKindAttr : LLVM_Attr<"UWTableKind", "uwtableKind"> {
+ let parameters = (ins "uwtable::UWTableKind":$uwtableKind);
+ let assemblyFormat = "`<` $uwtableKind `>`";
+}
+
+
#endif // LLVMIR_ATTRDEFS
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
index 34a30a00790ea..52bce96c8a990 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
@@ -855,4 +855,27 @@ def ModFlagBehaviorAttr : LLVM_EnumAttr<
let cppNamespace = "::mlir::LLVM";
}
+//===----------------------------------------------------------------------===//
+// UWTableKind
+//===----------------------------------------------------------------------===//
+
+def UWTableKindNone
+ : LLVM_EnumAttrCase<"None", "none", "None", 0>;
+def UWTableKindSync
+ : LLVM_EnumAttrCase<"Sync", "sync", "Sync", 1>;
+def UWTableKindAsync
+ : LLVM_EnumAttrCase<"Async", "async", "Async", 2>;
+def UWTableKindDefault
+ : LLVM_EnumAttrCase<"Default", "default", "Default", 2>;
+
+// UWTableKindDefault is unsupported as the llvm enum value is the same as async
+// which the generated enum converters can't deal with.
+def UWTableKindEnum : LLVM_EnumAttr<
+ "UWTableKind",
+ "::llvm::UWTableKind",
+ "LLVM Unwind Behavior",
+ [UWTableKindNone, UWTableKindSync, UWTableKindAsync]> {
+ let cppNamespace = "::mlir::LLVM::uwtable";
+}
+
#endif // LLVMIR_ENUMS
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index e89e78aec7147..76a2ec47b3a22 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1842,7 +1842,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
OptionalAttr<LLVM_VecTypeHintAttr>:$vec_type_hint,
OptionalAttr<DenseI32ArrayAttr>:$work_group_size_hint,
OptionalAttr<DenseI32ArrayAttr>:$reqd_work_group_size,
- OptionalAttr<I32Attr>:$intel_reqd_sub_group_size
+ OptionalAttr<I32Attr>:$intel_reqd_sub_group_size,
+ OptionalAttr<UWTableKindAttr>:$uwtable_kind
);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index ee7dc3a5231f4..6531b233b94a0 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1602,6 +1602,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
if (FramePointerKindAttr fpAttr = func.getFramePointerAttr())
llvmFunc->addFnAttr("frame-pointer", stringifyFramePointerKind(
fpAttr.getFramePointerKind()));
+ if (UWTableKindAttr uwTableKindAttr = func.getUwtableKindAttr())
+ llvmFunc->setUWTableKind(convertUWTableKindToLLVM(uwTableKindAttr.getUwtableKind()));
convertFunctionMemoryAttributes(func, llvmFunc);
}
diff --git a/mlir/test/Target/LLVMIR/uwtable.mlir b/mlir/test/Target/LLVMIR/uwtable.mlir
new file mode 100644
index 0000000000000..3e1d5b566f01b
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/uwtable.mlir
@@ -0,0 +1,8 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// CHECK-LABEL: define void @uwtable_func()
+// CHECK-SAME: #[[ATTRS:[0-9]+]]
+llvm.func @uwtable_func() attributes {uwtable_kind = #llvm.uwtableKind<"sync">} {
+ llvm.return
+}
+// CHECK: attributes #[[ATTRS]] = { uwtable(sync) }
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
// UWTableKindDefault is unsupported as the llvm enum value is the same as async | ||
// which the generated enum converters can't deal with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the best way of dealing with this is, or if we are happy with this behavior (the issue is duplicate case
s in the switch
in the generated converter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah lets drop the default kind above then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
882829b
to
0359620
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Can you add the attribute to ModuleImport.cpp as well so that we can import it from LLVM IR. The easiest way is to search for frame-pointer in ModuleImport.cpp and perform the same changes for the new attribute. A small import test makes sense as well.
: LLVM_EnumAttrCase<"Sync", "sync", "Sync", 1>; | ||
def UWTableKindAsync | ||
: LLVM_EnumAttrCase<"Async", "async", "Async", 2>; | ||
def UWTableKindDefault |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you delete UWTableKindDefault
since it seems to be unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// UWTableKindDefault is unsupported as the llvm enum value is the same as async | ||
// which the generated enum converters can't deal with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah lets drop the default kind above then?
0a2695d
to
d157475
Compare
Done & added test |
Thanks for the review @gysit, feel free to merge if you are happy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
LGTM modulo some last nits.
Especially, keeping kExplicitAttributes sorted would be great. I am happy to land the PR once the last nits have been addressed.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ultra nit: drop extra newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -2077,6 +2077,7 @@ static constexpr std::array kExplicitAttributes{ | |||
StringLiteral("unsafe-fp-math"), | |||
StringLiteral("vscale_range"), | |||
StringLiteral("willreturn"), | |||
StringLiteral("uwtable"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you sort in alphabetical order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
; CHECK-LABEL: llvm.func @uwtable_func | ||
; CHECK-SAME: attributes {uwtable_kind = #llvm.uwtableKind<sync>} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ultra nit: drop extra newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d157475
to
30bd5a3
Compare
Thanks again @gysit for the review, I had @basioli-k land it, hope that's ok |
of course no problem! |
Add `UWTableKind` enum and corresponding attribute to `llvm.func` including translation to `llvm::Function` attribute.
Add
UWTableKind
enum and corresponding attribute tollvm.func
including translation tollvm::Function
attribute.