-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Pass to add frame pointer attribute #74598
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
Changes from all commits
fda39a4
85b8de6
6e44350
34ea42a
574e247
fac406c
a675d75
104c3d4
11e3a3a
0a3fbca
a7887f1
6eb06ac
cef574b
bcd3079
461db3f
af00662
9e3758c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//===- FunctionAttr.cpp ---------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This is a generic pass for adding attributes to functions. | ||
//===----------------------------------------------------------------------===// | ||
#include "flang/Optimizer/Transforms/Passes.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h" | ||
|
||
namespace fir { | ||
#define GEN_PASS_DECL_FUNCTIONATTR | ||
#define GEN_PASS_DEF_FUNCTIONATTR | ||
#include "flang/Optimizer/Transforms/Passes.h.inc" | ||
} // namespace fir | ||
|
||
#define DEBUG_TYPE "func-attr" | ||
|
||
namespace { | ||
|
||
class FunctionAttrPass : public fir::impl::FunctionAttrBase<FunctionAttrPass> { | ||
public: | ||
FunctionAttrPass(const fir::FunctionAttrOptions &options) { | ||
framePointerKind = options.framePointerKind; | ||
} | ||
FunctionAttrPass() {} | ||
void runOnOperation() override; | ||
}; | ||
|
||
} // namespace | ||
|
||
void FunctionAttrPass::runOnOperation() { | ||
LLVM_DEBUG(llvm::dbgs() << "=== Begin " DEBUG_TYPE " ===\n"); | ||
mlir::func::FuncOp func = getOperation(); | ||
|
||
LLVM_DEBUG(llvm::dbgs() << "Func-name:" << func.getSymName() << "\n"); | ||
|
||
mlir::MLIRContext *context = &getContext(); | ||
if (framePointerKind != mlir::LLVM::framePointerKind::FramePointerKind::None) | ||
func->setAttr("frame_pointer", mlir::LLVM::FramePointerKindAttr::get( | ||
context, framePointerKind)); | ||
|
||
LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n"); | ||
} | ||
|
||
std::unique_ptr<mlir::Pass> | ||
fir::createFunctionAttrPass(fir::FunctionAttrTypes &functionAttr) { | ||
FunctionAttrOptions opts; | ||
// Frame pointer | ||
opts.framePointerKind = functionAttr.framePointerKind; | ||
|
||
return std::make_unique<FunctionAttrPass>(opts); | ||
} | ||
|
||
std::unique_ptr<mlir::Pass> fir::createFunctionAttrPass() { | ||
return std::make_unique<FunctionAttrPass>(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
! Test that flang-new forwards -fno-omit-frame-pointer and -fomit-frame-pointer Flang frontend | ||
! RUN: %flang -fno-omit-frame-pointer --target=x86-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s | ||
! CHECK: "-mframe-pointer=all" | ||
! RUN: %flang --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOVALUE | ||
! CHECK-NOVALUE: "-fc1"{{.*}}"-mframe-pointer=non-leaf" | ||
|
||
! RUN: %flang -fomit-frame-pointer --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NONEFP | ||
! CHECK-NONEFP: "-fc1"{{.*}}"-mframe-pointer=none" | ||
|
||
! RUN: %flang -fno-omit-frame-pointer --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NONLEAFFP | ||
! CHECK-NONLEAFFP: "-mframe-pointer=non-leaf" | ||
! CHECK-NONLEAFFP: "-fc1"{{.*}}"-mframe-pointer=non-leaf" | ||
|
||
! RUN: %flang -fomit-frame-pointer --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NONEFP | ||
! CHECK-NONEFP: "-mframe-pointer=none" | ||
! RUN: %flang -fno-omit-frame-pointer --target=x86-none-none -fsyntax-only -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-ALLFP | ||
! CHECK-ALLFP: "-fc1"{{.*}}"-mframe-pointer=all" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
! Test that -mframe-pointer can accept only specific values and when given an invalid value, check it raises an error. | ||
|
||
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=none -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NONEFP | ||
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=non-leaf -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NONLEAFFP | ||
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=all -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-ALLFP | ||
! RUN: not %flang_fc1 -triple aarch64-none-none -mframe-pointer=wrongval -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-WRONGVALUEFP | ||
|
||
! CHECK-NONEFP-LABEL: @func_() { | ||
|
||
! CHECK-NONLEAFFP-LABEL: @func_() | ||
! CHECK-NONLEAFFP-SAME: #0 | ||
|
||
! CHECK-ALLFP-LABEL: @func_() | ||
! CHECK-ALLFP-SAME: #0 | ||
|
||
subroutine func | ||
end subroutine func | ||
|
||
! CHECK-NONEFP-NOT: attributes #0 = { "frame-pointer"="{{.*}}" } | ||
! CHECK-NONLEAFFP: attributes #0 = { "frame-pointer"="non-leaf" } | ||
! CHECK-ALLFP: attributes #0 = { "frame-pointer"="all" } | ||
|
||
! CHECK-WRONGVALUEFP:error: invalid value 'wrongval' in '-mframe-pointer=wrongval' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,9 @@ | |
! Content to check from the MLIR outputs | ||
!-------------------------- | ||
! MLIR-FIR-NOT: llvm.func | ||
! MLIR-FIR: func.func @{{.*}}main() { | ||
! MLIR-FIR: func.func @{{.*}}main(){{.*}}{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do these extra braces capture? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added due to failing the test when it was a default parameter. I do not see how having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why it was failing? I just don't see how this particular change is related to what this PR is implementing. It would help if you included code "before" and "after" this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is target dependent, frame pointer will be added or not. It is either adding |
||
|
||
! MLIR-FIR-NOT: func.func | ||
! MLIR-LLVMIR: llvm.func @{{.*}}main() { | ||
! MLIR-LLVMIR: llvm.func @{{.*}}main(){{.*}}{ | ||
|
||
end program |
Uh oh!
There was an error while loading. Please reload this page.