mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-21 13:36:50 +00:00
[flang-rt] Added IsContiguousUpTo runtime function. (#131048)
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 #131047.
This commit is contained in:
parent
b4f5dcc65a
commit
f326036767
flang-rt
@ -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 §ion{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(§ion.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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user