[Mlir-commits] [mlir] [MLIR] Add support for frame pointers in MLIR (PR #72145)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Nov 13 10:15:59 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff ad20a9e1a15d1694f7ab3d878bcfaab3d52c5abf d53a30813d5ab1ffcb1f9a5844af3ea782361c38 -- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp mlir/lib/Target/LLVMIR/ModuleImport.cpp mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 510d81e46c..752aeeba84 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2322,18 +2322,19 @@ ParseResult LLVMFuncOp::parse(OpAsmParser &parser, OperationState &result) {
// Parse the optional frame_pointer
if (succeeded(parser.parseOptionalKeyword("frame_pointer"))) {
std::string string;
-
+
if (parser.parseEqual() || parser.parseString(&string))
return failure();
- if (!LLVM::symbolizeFramePointerKind(string))
- {
- llvm::outs() << "failure: frame-pointer option not recognized: " << string << "\n";
+ if (!LLVM::symbolizeFramePointerKind(string)) {
+ llvm::outs() << "failure: frame-pointer option not recognized: " << string
+ << "\n";
return failure();
}
- result.addAttribute(getFramePointerAttrName(result.name),
- LLVM::FramePointerKindAttr::get(parser.getContext(),
- LLVM::symbolizeFramePointerKind(string).value()));
+ result.addAttribute(getFramePointerAttrName(result.name),
+ LLVM::FramePointerKindAttr::get(
+ parser.getContext(),
+ LLVM::symbolizeFramePointerKind(string).value()));
}
if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes)))
@@ -2390,17 +2391,18 @@ void LLVMFuncOp::print(OpAsmPrinter &p) {
// Print the optional comdat selector.
if (auto comdat = getComdat())
p << " comdat(" << *comdat << ')';
-
+
// Print the optional frame pointer option.
if (std::optional<FramePointerKind> frame_pointer = getFramePointer())
- p << " frame_pointer=" << "\"" << stringifyFramePointerKind(frame_pointer.value()) << "\"";
+ p << " frame_pointer="
+ << "\"" << stringifyFramePointerKind(frame_pointer.value()) << "\"";
function_interface_impl::printFunctionAttributes(
p, *this,
{getFunctionTypeAttrName(), getArgAttrsAttrName(), getResAttrsAttrName(),
getLinkageAttrName(), getCConvAttrName(), getVisibility_AttrName(),
- getComdatAttrName(), getUnnamedAddrAttrName(),
- getVscaleRangeAttrName(), getFramePointerAttrName()});
+ getComdatAttrName(), getUnnamedAddrAttrName(), getVscaleRangeAttrName(),
+ getFramePointerAttrName()});
// Print the body if this is not an external function.
Region &body = getBody();
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index e3b08ce4e8..d64b62fe3a 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -1602,8 +1602,7 @@ static void processPassthroughAttrs(llvm::Function *func, LLVMFuncOp funcOp) {
// explicit attribute.
// Also skip the vscale_range, it is also an explicit attribute.
if (attrName == "aarch64_pstate_sm_enabled" ||
- attrName == "aarch64_pstate_sm_body" ||
- attrName == "vscale_range" ||
+ attrName == "aarch64_pstate_sm_body" || attrName == "vscale_range" ||
attrName == "frame-pointer")
continue;
@@ -1655,9 +1654,11 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
// Process frame-pointer attribute
if (func->hasFnAttribute("frame-pointer")) {
- llvm::StringRef stringRefFramePointerKind = func->getFnAttribute("frame-pointer").getValueAsString();
- funcOp.setFramePointerAttr(LLVM::FramePointerKindAttr::get(funcOp.getContext(),
- symbolizeFramePointerKind(stringRefFramePointerKind).value()));
+ llvm::StringRef stringRefFramePointerKind =
+ func->getFnAttribute("frame-pointer").getValueAsString();
+ funcOp.setFramePointerAttr(LLVM::FramePointerKindAttr::get(
+ funcOp.getContext(),
+ symbolizeFramePointerKind(stringRefFramePointerKind).value()));
}
}
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index d97d4a1b1e..8dcf83b465 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -894,10 +894,11 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
llvmFunc->addFnAttr(llvm::Attribute::getWithVScaleRangeArgs(
getLLVMContext(), attr->getMinRange().getInt(),
attr->getMaxRange().getInt()));
-
+
// Add function attribute frame-pointer, if found.
- if (auto attr = func.getFramePointerAttr())
- llvmFunc->addFnAttr("frame-pointer", stringifyFramePointerKind(attr.getValue()));
+ if (auto attr = func.getFramePointerAttr())
+ llvmFunc->addFnAttr("frame-pointer",
+ stringifyFramePointerKind(attr.getValue()));
// First, create all blocks so we can jump to them.
llvm::LLVMContext &llvmContext = llvmFunc->getContext();
``````````
</details>
https://github.com/llvm/llvm-project/pull/72145
More information about the Mlir-commits
mailing list