Skip to content

[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

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -1365,4 +1365,13 @@ 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
21 changes: 21 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMEnums.td
Original file line number Diff line number Diff line change
Expand Up @@ -855,4 +855,25 @@ 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>;

// UWTableKind::Default 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
3 changes: 2 additions & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ static constexpr std::array kExplicitAttributes{
StringLiteral("target-features"),
StringLiteral("tune-cpu"),
StringLiteral("unsafe-fp-math"),
StringLiteral("uwtable"),
StringLiteral("vscale_range"),
StringLiteral("willreturn"),
};
Expand Down Expand Up @@ -2237,6 +2238,12 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
if (llvm::Attribute attr = func->getFnAttribute("fp-contract");
attr.isStringAttribute())
funcOp.setFpContractAttr(StringAttr::get(context, attr.getValueAsString()));

if (func->hasUWTable()) {
::llvm::UWTableKind uwtableKind = func->getUWTableKind();
funcOp.setUwtableKindAttr(LLVM::UWTableKindAttr::get(
funcOp.getContext(), convertUWTableKindFromLLVM(uwtableKind)));
}
}

DictionaryAttr
Expand Down
3 changes: 3 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,9 @@ 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);
}

Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Target/LLVMIR/Import/uwtable.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

; CHECK-LABEL: llvm.func @uwtable_func
; CHECK-SAME: attributes {uwtable_kind = #llvm.uwtableKind<sync>}
define void @uwtable_func() uwtable(sync) {
ret void
}
8 changes: 8 additions & 0 deletions mlir/test/Target/LLVMIR/uwtable.mlir
Original file line number Diff line number Diff line change
@@ -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) }
Loading