mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 03:16:37 +00:00

Mostly mechanical changes in preparation of extracting the Flang-RT "subproject" in #110217. This PR intends to only move pre-existing files to the new folder structure, with no behavioral change. Common files (headers, testing, cmake) shared by Flang-RT and Flang remain in `flang/`. Some cosmetic changes and files paths were necessary: * Relative paths to the new path for the source files and `add_subdirectory`. * Add the new location's include directory to `include_directories` * The unittest/Evaluate directory has unitests for flang-rt and Flang. A new `CMakeLists.txt` was introduced for the flang-rt tests. * Change the `#include` paths relative to the include directive * clang-format on the `#include` directives * Since the paths are part if the copyright header and include guards, a script was used to canonicalize those * `test/Runtime` and runtime tests in `test/Driver` are moved, but the lit.cfg.py mechanism to execute the will only be added in #110217.
98 lines
3.4 KiB
C++
98 lines
3.4 KiB
C++
//===-- lib/runtime/inquiry.cpp ---------------------------------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implements the inquiry intrinsic functions of Fortran 2018 that
|
|
// inquire about shape information of arrays -- LBOUND and SIZE.
|
|
|
|
#include "flang/Runtime/inquiry.h"
|
|
#include "copy.h"
|
|
#include "flang-rt/runtime/descriptor.h"
|
|
#include "flang-rt/runtime/terminator.h"
|
|
#include "flang-rt/runtime/tools.h"
|
|
#include <algorithm>
|
|
|
|
namespace Fortran::runtime {
|
|
|
|
template <int KIND> struct RawStoreIntegerAt {
|
|
RT_API_ATTRS void operator()(
|
|
void *contiguousIntegerArray, std::size_t at, std::int64_t value) const {
|
|
reinterpret_cast<Fortran::runtime::CppTypeFor<
|
|
Fortran::common::TypeCategory::Integer, KIND> *>(
|
|
contiguousIntegerArray)[at] = value;
|
|
}
|
|
};
|
|
|
|
extern "C" {
|
|
std::int64_t RTDEF(LboundDim)(
|
|
const Descriptor &array, int dim, const char *sourceFile, int line) {
|
|
if (dim < 1 || dim > array.rank()) {
|
|
Terminator terminator{sourceFile, line};
|
|
terminator.Crash(
|
|
"SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
|
|
}
|
|
const Dimension &dimension{array.GetDimension(dim - 1)};
|
|
return static_cast<std::int64_t>(dimension.LowerBound());
|
|
}
|
|
|
|
void RTDEF(Ubound)(void *result, const Descriptor &array, int kind,
|
|
const char *sourceFile, int line) {
|
|
Terminator terminator{sourceFile, line};
|
|
INTERNAL_CHECK(array.rank() <= common::maxRank);
|
|
for (SubscriptValue i{0}; i < array.rank(); ++i) {
|
|
const Dimension &dimension{array.GetDimension(i)};
|
|
Fortran::runtime::ApplyIntegerKind<RawStoreIntegerAt, void>(
|
|
kind, terminator, result, i, dimension.UpperBound());
|
|
}
|
|
}
|
|
|
|
std::int64_t RTDEF(Size)(
|
|
const Descriptor &array, const char *sourceFile, int line) {
|
|
std::int64_t result{1};
|
|
for (int i = 0; i < array.rank(); ++i) {
|
|
const Dimension &dimension{array.GetDimension(i)};
|
|
result *= dimension.Extent();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::int64_t RTDEF(SizeDim)(
|
|
const Descriptor &array, int dim, const char *sourceFile, int line) {
|
|
if (dim < 1 || dim > array.rank()) {
|
|
Terminator terminator{sourceFile, line};
|
|
terminator.Crash(
|
|
"SIZE: bad DIM=%d for ARRAY with rank=%d", dim, array.rank());
|
|
}
|
|
const Dimension &dimension{array.GetDimension(dim - 1)};
|
|
return static_cast<std::int64_t>(dimension.Extent());
|
|
}
|
|
|
|
void RTDEF(Shape)(void *result, const Descriptor &array, int kind,
|
|
const char *sourceFile, int line) {
|
|
Terminator terminator{sourceFile, line};
|
|
INTERNAL_CHECK(array.rank() <= common::maxRank);
|
|
for (SubscriptValue i{0}; i < array.rank(); ++i) {
|
|
const Dimension &dimension{array.GetDimension(i)};
|
|
Fortran::runtime::ApplyIntegerKind<RawStoreIntegerAt, void>(
|
|
kind, terminator, result, i, dimension.Extent());
|
|
}
|
|
}
|
|
|
|
void RTDEF(Lbound)(void *result, const Descriptor &array, int kind,
|
|
const char *sourceFile, int line) {
|
|
Terminator terminator{sourceFile, line};
|
|
INTERNAL_CHECK(array.rank() <= common::maxRank);
|
|
for (SubscriptValue i{0}; i < array.rank(); ++i) {
|
|
const Dimension &dimension{array.GetDimension(i)};
|
|
Fortran::runtime::ApplyIntegerKind<RawStoreIntegerAt, void>(
|
|
kind, terminator, result, i, dimension.LowerBound());
|
|
}
|
|
}
|
|
|
|
} // extern "C"
|
|
} // namespace Fortran::runtime
|