0
0
mirror of https://github.com/llvm/llvm-project.git synced 2025-04-21 13:36:50 +00:00

[flang-rt] Added IsContiguousUpTo runtime function. ()

I want to be able to check if the storage is contiguous
in the innermost dimension, so I decided to add an entry point
that takes `dim` as the number of leading dimensions to check.
It seems that a runtime call might result in less code size
even when `dim` is 1, so here it is.
For opt-for-speed I am going to inline it in FIR.

Depends on .
This commit is contained in:
Slava Zakharin 2025-03-14 17:13:21 -07:00 committed by GitHub
parent b4f5dcc65a
commit f326036767
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions
flang-rt
lib/runtime
unittests/Runtime

@ -19,6 +19,10 @@ bool RTDEF(IsContiguous)(const Descriptor &descriptor) {
return descriptor.IsContiguous();
}
bool RTDEF(IsContiguousUpTo)(const Descriptor &descriptor, int dim) {
return descriptor.IsContiguous(dim);
}
bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) {
return ISO::IsAssumedSize(&descriptor.raw());
}

@ -78,3 +78,23 @@ TEST(DescriptorBytesFor, Basic) {
EXPECT_GT(b, 0U);
}
}
TEST(IsContiguous, Basic) {
// ARRAY 1 3 5
// 2 4 6
auto array{MakeArray<TypeCategory::Integer, 4>(
std::vector<int>{2, 3}, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
StaticDescriptor<2> sectionStaticDesc;
Descriptor &section{sectionStaticDesc.descriptor()};
section.Establish(array->type(), array->ElementBytes(),
/*p=*/nullptr, /*rank=*/2);
static const SubscriptValue lbs[]{1, 1}, ubs[]{2, 3}, strides[]{1, 2};
const auto error{
CFI_section(&section.raw(), &array->raw(), lbs, ubs, strides)};
ASSERT_EQ(error, 0) << "CFI_section failed for array: " << error;
EXPECT_TRUE(RTNAME(IsContiguous)(*array));
EXPECT_FALSE(RTNAME(IsContiguous)(section));
EXPECT_TRUE(RTNAME(IsContiguousUpTo)(section, 1));
EXPECT_FALSE(RTNAME(IsContiguousUpTo)(section, 2));
}