[flang-commits] [mlir] [clang] [flang] [Flang][Driver][MLIR] Add support for fomit-frame-pointer (PR #72135)
via flang-commits
flang-commits at lists.llvm.org
Mon Nov 13 08:56:31 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 0e42df4031e8b2fec357e07ca5ca3b81adf0b5ad cd5cbb9ebd0f075b436b5b00b9b43e28551f5a07 -- clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Flang.cpp flang/include/flang/Frontend/CodeGenOptions.h flang/include/flang/Tools/CrossToolHelpers.h flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Frontend/FrontendActions.cpp 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/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f81bca1436..f72aa839b5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -123,7 +123,7 @@ static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
return !clang::driver::tools::areOptimizationsEnabled(Args);
}
- //if (Triple.isOSLinux() || Triple.getOS() == llvm::Triple::CloudABI ||
+ // if (Triple.isOSLinux() || Triple.getOS() == llvm::Triple::CloudABI ||
if (Triple.isOSLinux() || Triple.isOSHurd()) {
switch (Triple.getArch()) {
// Don't use a frame pointer on linux if optimizing for certain targets.
@@ -176,7 +176,7 @@ static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
}
}
-clang::CodeGenOptions::FramePointerKind
+clang::CodeGenOptions::FramePointerKind
getFramePointerKind(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple) {
// We have 4 states:
@@ -211,7 +211,6 @@ getFramePointerKind(const llvm::opt::ArgList &Args,
return clang::CodeGenOptions::FramePointerKind::None;
}
-
static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs,
const StringRef PluginOptPrefix) {
if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h
index abe8948c53..25d68345a9 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -216,7 +216,7 @@ void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
} // end namespace driver
} // end namespace clang
-clang::CodeGenOptions::FramePointerKind getFramePointerKind(
- const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
+clang::CodeGenOptions::FramePointerKind
+getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index d53bed8e6c..0b584941ec 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -608,7 +608,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
CodeGenOptions::FramePointerKind FPKeepKind =
- getFramePointerKind(Args, Triple);
+ getFramePointerKind(Args, Triple);
const char *FPKeepKindStr = nullptr;
switch (FPKeepKind) {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h
index 9ccd567678..8caf8c7059 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -49,12 +49,12 @@ protected:
class CodeGenOptions : public CodeGenOptionsBase {
public:
- //Added
+ // Added
///*
enum class FramePointerKind {
- None, // Omit all frame pointers.
- NonLeaf, // Keep non-leaf frame pointers.
- All, // Keep all frame pointers.
+ None, // Omit all frame pointers.
+ NonLeaf, // Keep non-leaf frame pointers.
+ All, // Keep all frame pointers.
};
static llvm::StringRef getFramePointerKindName(FramePointerKind Kind) {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 4340981ae9..ca000370c8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -250,14 +250,13 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_mframe_pointer_EQ)) {
llvm::StringRef s = a->getValue();
- assert(s == "none" || s == "non-leaf"|| s == "all");
+ assert(s == "none" || s == "non-leaf" || s == "all");
if (s == "none")
opts.setFramePointer(CodeGenOptions::FramePointerKind::None);
+ else if (s == "non-leaf")
+ opts.setFramePointer(CodeGenOptions::FramePointerKind::NonLeaf);
else
- if (s == "non-leaf")
- opts.setFramePointer(CodeGenOptions::FramePointerKind::NonLeaf);
- else
- opts.setFramePointer(CodeGenOptions::FramePointerKind::All);
+ opts.setFramePointer(CodeGenOptions::FramePointerKind::All);
}
for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 06273a07e8..56969dd914 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -783,11 +783,10 @@ void CodeGenAction::generateLLVMIR() {
llvmModule->setPIELevel(
static_cast<llvm::PIELevel::Level>(opts.PICLevel));
}
-
+
// Set FramePointer LLVM module flag.
llvmModule->setFramePointer(
- static_cast<llvm::FramePointerKind>(opts.getFramePointer()));
-
+ static_cast<llvm::FramePointerKind>(opts.getFramePointer()));
}
bool CodeGenAction::setUpTargetMachine() {
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/72135
More information about the flang-commits
mailing list