[flang] Delete the unused ragged-array runtime builders (#213160)
The ragged-array machinery served the legacy FORALL mask temporaries, whose lowering was removed with the legacy expression lowering (#210639, #210873) and the array-value-copy pass (#212643). The builders (fir::runtime::genRaggedArrayAllocate/Deallocate) and the getRaggedArrayHeaderType helper have no compiler callers left; only their own unit test exercised them. Delete the builders, the helper, and the unit test. The flang-rt runtime entry points (RaggedArrayAllocate/RaggedArrayDeallocate in flang-rt/lib/runtime/ragged.cpp and their declarations in flang/include/flang/Runtime/ragged.h) are ABI and remain. Assisted-by: AI
This commit is contained in:
parent
5df5e8d9fd
commit
d73beb2ee6
8 changed files with 6 additions and 164 deletions
|
|
@ -856,11 +856,6 @@ void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
|
|||
bool needFinalization = false,
|
||||
bool isTemporaryLHS = false);
|
||||
|
||||
/// Builds and returns the type of a ragged array header used to cache mask
|
||||
/// evaluations. RaggedArrayHeader is defined in
|
||||
/// flang/include/flang/Runtime/ragged.h.
|
||||
mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder);
|
||||
|
||||
/// Create the zero value of a given the numerical or logical \p type (`false`
|
||||
/// for logical types).
|
||||
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
//===-- Ragged.h ------------------------------------------------*- 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_RAGGED_H
|
||||
#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RAGGED_H
|
||||
|
||||
namespace mlir {
|
||||
class Location;
|
||||
class Value;
|
||||
class ValueRange;
|
||||
} // namespace mlir
|
||||
|
||||
namespace fir {
|
||||
class FirOpBuilder;
|
||||
} // namespace fir
|
||||
|
||||
namespace fir::runtime {
|
||||
|
||||
/// Generate code to instantiate a section of a ragged array. Calls the runtime
|
||||
/// to initialize the data buffer. \p header must be a ragged buffer header (on
|
||||
/// the heap) and will be initialized, if and only if the rank of \p extents is
|
||||
/// at least 1 and all values in the vector of extents are positive. \p extents
|
||||
/// must be a vector of Value of type `i64`. \p eleSize is in bytes, not bits.
|
||||
void genRaggedArrayAllocate(mlir::Location loc, fir::FirOpBuilder &builder,
|
||||
mlir::Value header, bool asHeaders,
|
||||
mlir::Value eleSize, mlir::ValueRange extents);
|
||||
|
||||
/// Generate a call to the runtime routine to deallocate a ragged array data
|
||||
/// structure on the heap.
|
||||
void genRaggedArrayDeallocate(mlir::Location loc, fir::FirOpBuilder &builder,
|
||||
mlir::Value header);
|
||||
|
||||
} // namespace fir::runtime
|
||||
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RAGGED_H
|
||||
|
|
@ -22,7 +22,8 @@ namespace Fortran::runtime {
|
|||
// through `extentPointer`. The `bufferPointer` is overloaded
|
||||
// and is null, points to an array of headers (isIndirection), or data.
|
||||
// By default, a header is set to zero, which is its unused state.
|
||||
// The layout of a ragged buffer header is mirrored in the compiler.
|
||||
// This layout is runtime ABI; compiler-generated code from older flang
|
||||
// versions may allocate and access ragged arrays with it.
|
||||
struct RaggedArrayHeader {
|
||||
std::uint64_t flags;
|
||||
void *bufferPointer;
|
||||
|
|
@ -31,9 +32,10 @@ struct RaggedArrayHeader {
|
|||
|
||||
extern "C" {
|
||||
|
||||
// For more on ragged arrays see https://en.wikipedia.org/wiki/Jagged_array. The
|
||||
// Flang compiler allocates ragged arrays as a generalization for
|
||||
// non-rectangular array temporaries. Ragged arrays can be allocated recursively
|
||||
// For more on ragged arrays see https://en.wikipedia.org/wiki/Jagged_array.
|
||||
// Flang historically generated ragged arrays as a generalization for
|
||||
// non-rectangular array temporaries; these entry points are retained as ABI
|
||||
// for previously compiled objects. Ragged arrays can be allocated recursively
|
||||
// and on demand. Structurally, each leaf is an optional rectangular array of
|
||||
// elements. The shape of each leaf is independent and may be computed on
|
||||
// demand. Each branch node is an optional, possibly sparse rectangular array of
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ add_flang_library(FIRBuilder
|
|||
Runtime/Main.cpp
|
||||
Runtime/Numeric.cpp
|
||||
Runtime/Pointer.cpp
|
||||
Runtime/Ragged.cpp
|
||||
Runtime/Reduction.cpp
|
||||
Runtime/Stop.cpp
|
||||
Runtime/Support.cpp
|
||||
|
|
|
|||
|
|
@ -1556,16 +1556,6 @@ void fir::factory::genRecordAssignment(fir::FirOpBuilder &builder,
|
|||
genComponentByComponentAssignment(builder, loc, lhs, rhs, isTemporaryLHS);
|
||||
}
|
||||
|
||||
mlir::TupleType
|
||||
fir::factory::getRaggedArrayHeaderType(fir::FirOpBuilder &builder) {
|
||||
mlir::IntegerType i64Ty = builder.getIntegerType(64);
|
||||
auto arrTy = fir::SequenceType::get(builder.getIntegerType(8), 1);
|
||||
auto buffTy = fir::HeapType::get(arrTy);
|
||||
auto extTy = fir::SequenceType::get(i64Ty, 1);
|
||||
auto shTy = fir::HeapType::get(extTy);
|
||||
return mlir::TupleType::get(builder.getContext(), {i64Ty, buffTy, shTy});
|
||||
}
|
||||
|
||||
mlir::Value fir::factory::createZeroValue(fir::FirOpBuilder &builder,
|
||||
mlir::Location loc, mlir::Type type) {
|
||||
mlir::Type i1 = builder.getIntegerType(1);
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
//===-- Ragged.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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "flang/Optimizer/Builder/Runtime/Ragged.h"
|
||||
#include "flang/Optimizer/Builder/FIRBuilder.h"
|
||||
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
|
||||
#include "flang/Runtime/ragged.h"
|
||||
|
||||
using namespace Fortran::runtime;
|
||||
|
||||
void fir::runtime::genRaggedArrayAllocate(mlir::Location loc,
|
||||
fir::FirOpBuilder &builder,
|
||||
mlir::Value header, bool asHeaders,
|
||||
mlir::Value eleSize,
|
||||
mlir::ValueRange extents) {
|
||||
auto i32Ty = builder.getIntegerType(32);
|
||||
auto rank = extents.size();
|
||||
auto i64Ty = builder.getIntegerType(64);
|
||||
auto func =
|
||||
fir::runtime::getRuntimeFunc<mkRTKey(RaggedArrayAllocate)>(loc, builder);
|
||||
auto fTy = func.getFunctionType();
|
||||
auto i1Ty = builder.getIntegerType(1);
|
||||
fir::SequenceType::Shape shape = {
|
||||
static_cast<fir::SequenceType::Extent>(rank)};
|
||||
auto extentTy = fir::SequenceType::get(shape, i64Ty);
|
||||
auto refTy = fir::ReferenceType::get(i64Ty);
|
||||
// Position of the bufferPointer in the header struct.
|
||||
auto one = builder.createIntegerConstant(loc, i32Ty, 1);
|
||||
auto eleTy = fir::unwrapSequenceType(fir::unwrapRefType(header.getType()));
|
||||
auto ptrTy =
|
||||
builder.getRefType(mlir::cast<mlir::TupleType>(eleTy).getType(1));
|
||||
auto ptr = fir::CoordinateOp::create(builder, loc, ptrTy, header, one);
|
||||
auto heap = fir::LoadOp::create(builder, loc, ptr);
|
||||
auto cmp = builder.genIsNullAddr(loc, heap);
|
||||
builder.genIfThen(loc, cmp)
|
||||
.genThen([&]() {
|
||||
auto asHeadersVal = builder.createIntegerConstant(loc, i1Ty, asHeaders);
|
||||
auto rankVal = builder.createIntegerConstant(loc, i64Ty, rank);
|
||||
auto buff = fir::AllocMemOp::create(builder, loc, extentTy);
|
||||
// Convert all the extents to i64 and pack them in a buffer on the heap.
|
||||
for (auto i : llvm::enumerate(extents)) {
|
||||
auto offset = builder.createIntegerConstant(loc, i32Ty, i.index());
|
||||
auto addr =
|
||||
fir::CoordinateOp::create(builder, loc, refTy, buff, offset);
|
||||
auto castVal = builder.createConvert(loc, i64Ty, i.value());
|
||||
fir::StoreOp::create(builder, loc, castVal, addr);
|
||||
}
|
||||
auto args = fir::runtime::createArguments(
|
||||
builder, loc, fTy, header, asHeadersVal, rankVal, eleSize, buff);
|
||||
fir::CallOp::create(builder, loc, func, args);
|
||||
})
|
||||
.end();
|
||||
}
|
||||
|
||||
void fir::runtime::genRaggedArrayDeallocate(mlir::Location loc,
|
||||
fir::FirOpBuilder &builder,
|
||||
mlir::Value header) {
|
||||
auto func = fir::runtime::getRuntimeFunc<mkRTKey(RaggedArrayDeallocate)>(
|
||||
loc, builder);
|
||||
auto fTy = func.getFunctionType();
|
||||
auto args = fir::runtime::createArguments(builder, loc, fTy, header);
|
||||
fir::CallOp::create(builder, loc, func, args);
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
//===- RaggedTest.cpp -- Ragged array runtime function 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/Ragged.h"
|
||||
#include "RuntimeCallTestBase.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST_F(RuntimeCallTest, genRaggedArrayAllocateTest) {
|
||||
auto loc = firBuilder->getUnknownLoc();
|
||||
mlir::TupleType headerTy =
|
||||
fir::factory::getRaggedArrayHeaderType(*firBuilder);
|
||||
mlir::Value header = fir::UndefOp::create(*firBuilder, loc, headerTy);
|
||||
mlir::Value eleSize = firBuilder->createIntegerConstant(loc, i32Ty, 1);
|
||||
mlir::Value extent = firBuilder->createIntegerConstant(loc, i32Ty, 1);
|
||||
// Use a dummy header just to test the correctness of the generated call.
|
||||
fir::runtime::genRaggedArrayAllocate(
|
||||
loc, *firBuilder, header, false, eleSize, {extent});
|
||||
checkCallOpFromResultBox(
|
||||
eleSize, "_FortranARaggedArrayAllocate", 5, /*addLocArgs=*/false);
|
||||
}
|
||||
|
||||
TEST_F(RuntimeCallTest, genRaggedArrayDeallocateTest) {
|
||||
auto loc = firBuilder->getUnknownLoc();
|
||||
mlir::TupleType headerTy =
|
||||
fir::factory::getRaggedArrayHeaderType(*firBuilder);
|
||||
// Use a dummy header just to test the correctness of the generated call.
|
||||
mlir::Value header = fir::UndefOp::create(*firBuilder, loc, headerTy);
|
||||
fir::runtime::genRaggedArrayDeallocate(loc, *firBuilder, header);
|
||||
checkCallOpFromResultBox(
|
||||
header, "_FortranARaggedArrayDeallocate", 1, /*addLocArgs=*/false);
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ add_flang_unittest(FlangOptimizerTests
|
|||
Builder/Runtime/DerivedTest.cpp
|
||||
Builder/Runtime/IntrinsicsTest.cpp
|
||||
Builder/Runtime/NumericTest.cpp
|
||||
Builder/Runtime/RaggedTest.cpp
|
||||
Builder/Runtime/ReductionTest.cpp
|
||||
Builder/Runtime/StopTest.cpp
|
||||
Builder/Runtime/TransformationalTest.cpp
|
||||
|
|
|
|||
Loading…
Reference in a new issue