Skip to content

Commit 51e2c8c

Browse files
[fir] Add assignment runtime API builder
This patch adds the builder that generate assignment runtime API calls. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: rovka, awarzynski Differential Revision: https://reviews.llvm.org/D114475 Co-authored-by: Jean Perier <[email protected]>
1 parent 18452d1 commit 51e2c8c

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- Assign.h - generate assignment runtime API calls --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ASSIGN_H
10+
#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ASSIGN_H
11+
12+
namespace mlir {
13+
class Value;
14+
class Location;
15+
} // namespace mlir
16+
17+
namespace fir {
18+
class FirOpBuilder;
19+
}
20+
21+
namespace fir::runtime {
22+
23+
/// Generate runtime call to assign \p sourceBox to \p destBox.
24+
/// \p destBox must be a fir.ref<fir.box<T>> and \p sourceBox a fir.box<T>.
25+
/// \p destBox Fortran descriptor may be modified if destBox is an allocatable
26+
/// according to Fortran allocatable assignment rules, otherwise it is not
27+
/// modified.
28+
void genAssign(fir::FirOpBuilder &builder, mlir::Location loc,
29+
mlir::Value destBox, mlir::Value sourceBox);
30+
31+
} // namespace fir::runtime
32+
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ASSIGN_H

flang/lib/Optimizer/Builder/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_flang_library(FIRBuilder
77
DoLoopHelper.cpp
88
FIRBuilder.cpp
99
MutableBox.cpp
10+
Runtime/Assign.cpp
1011
Runtime/Transformational.cpp
1112

1213
DEPENDS
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Assign.cpp -- generate assignment runtime API calls ---------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "flang/Optimizer/Builder/Runtime/Assign.h"
10+
#include "flang/Optimizer/Builder/FIRBuilder.h"
11+
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
12+
#include "flang/Runtime/assign.h"
13+
14+
using namespace Fortran::runtime;
15+
16+
void fir::runtime::genAssign(fir::FirOpBuilder &builder, mlir::Location loc,
17+
mlir::Value destBox, mlir::Value sourceBox) {
18+
auto func = fir::runtime::getRuntimeFunc<mkRTKey(Assign)>(loc, builder);
19+
auto fTy = func.getType();
20+
auto sourceFile = fir::factory::locationToFilename(builder, loc);
21+
auto sourceLine =
22+
fir::factory::locationToLineNo(builder, loc, fTy.getInput(3));
23+
auto args = fir::runtime::createArguments(builder, loc, fTy, destBox,
24+
sourceBox, sourceFile, sourceLine);
25+
builder.create<fir::CallOp>(loc, func, args);
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===- AssignTest.cpp -- assignment runtime builder unit tests ------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "flang/Optimizer/Builder/Runtime/Assign.h"
10+
#include "RuntimeCallTestBase.h"
11+
#include "gtest/gtest.h"
12+
13+
TEST_F(RuntimeCallTest, genDerivedTypeAssign) {
14+
auto loc = firBuilder->getUnknownLoc();
15+
mlir::Type seqTy =
16+
fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
17+
mlir::Value source = firBuilder->create<fir::UndefOp>(loc, seqTy);
18+
mlir::Value dest = firBuilder->create<fir::UndefOp>(loc, seqTy);
19+
fir::runtime::genAssign(*firBuilder, loc, dest, source);
20+
checkCallOpFromResultBox(dest, "_FortranAAssign", 2);
21+
}

flang/unittests/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_flang_unittest(FlangOptimizerTests
1313
Builder/ComplexTest.cpp
1414
Builder/DoLoopHelperTest.cpp
1515
Builder/FIRBuilderTest.cpp
16+
Builder/Runtime/AssignTest.cpp
1617
Builder/Runtime/TransformationalTest.cpp
1718
FIRContextTest.cpp
1819
InternalNamesTest.cpp

0 commit comments

Comments
 (0)