Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] Upstream partial lowering of EXIT intrinsic
This patch adds partial lowering of the "EXIT" intrinsic to the backend runtime hook implemented in patch D110741. It also adds a helper function to the `RuntimeCallTestBase.h` for testing for an intrinsic function call in a `mlir::Block`. Differential Revision: https://reviews.llvm.org/D118141
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- Stop.h - generate stop runtime API calls ----------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_STOP_H | ||
#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_STOP_H | ||
|
||
namespace mlir { | ||
class Value; | ||
class Location; | ||
} // namespace mlir | ||
|
||
namespace fir { | ||
class FirOpBuilder; | ||
} | ||
|
||
namespace fir::runtime { | ||
|
||
/// Generate call to EXIT intrinsic runtime routine. | ||
void genExit(fir::FirOpBuilder &, mlir::Location, mlir::Value status); | ||
|
||
} // namespace fir::runtime | ||
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_STOP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Stop.h - generate stop runtime API calls ----------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "flang/Optimizer/Builder/Runtime/Stop.h" | ||
#include "flang/Optimizer/Builder/FIRBuilder.h" | ||
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h" | ||
#include "flang/Runtime/stop.h" | ||
|
||
using namespace Fortran::runtime; | ||
|
||
void fir::runtime::genExit(fir::FirOpBuilder &builder, mlir::Location loc, | ||
mlir::Value status) { | ||
auto exitFunc = fir::runtime::getRuntimeFunc<mkRTKey(Exit)>(loc, builder); | ||
llvm::SmallVector<mlir::Value> args = | ||
fir::runtime::createArguments(builder, loc, exitFunc.getType(), status); | ||
builder.create<fir::CallOp>(loc, exitFunc, args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===- StopTest.cpp -- Stop runtime builder unit tests ---------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "flang/Optimizer/Builder/Runtime/Stop.h" | ||
#include "RuntimeCallTestBase.h" | ||
#include "gtest/gtest.h" | ||
|
||
TEST_F(RuntimeCallTest, genExitTest) { | ||
mlir::Location loc = firBuilder->getUnknownLoc(); | ||
mlir::Value status = firBuilder->createIntegerConstant(loc, i32Ty, 0); | ||
fir::runtime::genExit(*firBuilder, loc, status); | ||
mlir::Block *block = firBuilder->getBlock(); | ||
EXPECT_TRUE(block) << "Failed to retrieve the block!"; | ||
checkBlockForCallOp(block, "_FortranAExit", 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters