[flang-commits] [flang] [flang][runtime] Enable more code for offload device builds. (PR #67489)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 26 14:25:17 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 1a5d3b6cda2c56a39bbe2a529db4d3ac3d5ffa0f cc925ab9cabca65b2e872146c435d33956a5eddc -- flang/include/flang/Runtime/api-attrs.h flang/include/flang/Runtime/descriptor.h flang/include/flang/Runtime/memory.h flang/include/flang/Runtime/type-code.h flang/runtime/ISO_Fortran_util.h flang/runtime/derived.h flang/runtime/descriptor.cpp flang/runtime/terminator.cpp flang/runtime/terminator.h flang/runtime/type-code.cpp flang/runtime/type-info.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/include/flang/Runtime/api-attrs.h b/flang/include/flang/Runtime/api-attrs.h
index 0768682cadbd..7420472aed67 100644
--- a/flang/include/flang/Runtime/api-attrs.h
+++ b/flang/include/flang/Runtime/api-attrs.h
@@ -105,7 +105,8 @@
* Note that it can only be used reliably with compilers that perform
* separate host and device compilations.
*/
-#if ((defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)) || (defined(_OPENMP) && (defined(__AMDGCN__) || defined(__NVPTX__)))
+#if ((defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)) || \
+ (defined(_OPENMP) && (defined(__AMDGCN__) || defined(__NVPTX__)))
#define RT_DEVICE_COMPILATION 1
#else
#undef RT_DEVICE_COMPILATION
diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h
index 09077ec849ac..c34078542481 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang/include/flang/Runtime/descriptor.h
@@ -181,20 +181,21 @@ public:
ISO::CFI_attribute_t attribute = CFI_attribute_other);
// CUDA_TODO: Clang does not support unique_ptr on device.
- static RT_API_ATTRS OwningPtr<Descriptor> Create(TypeCode t, std::size_t elementBytes,
- void *p = nullptr, int rank = maxRank,
+ static RT_API_ATTRS OwningPtr<Descriptor> Create(TypeCode t,
+ std::size_t elementBytes, void *p = nullptr, int rank = maxRank,
const SubscriptValue *extent = nullptr,
ISO::CFI_attribute_t attribute = CFI_attribute_other,
int derivedTypeLenParameters = 0);
- static RT_API_ATTRS OwningPtr<Descriptor> Create(TypeCategory, int kind, void *p = nullptr,
- int rank = maxRank, const SubscriptValue *extent = nullptr,
+ static RT_API_ATTRS OwningPtr<Descriptor> Create(TypeCategory, int kind,
+ void *p = nullptr, int rank = maxRank,
+ const SubscriptValue *extent = nullptr,
ISO::CFI_attribute_t attribute = CFI_attribute_other);
static RT_API_ATTRS OwningPtr<Descriptor> Create(int characterKind,
SubscriptValue characters, void *p = nullptr, int rank = maxRank,
const SubscriptValue *extent = nullptr,
ISO::CFI_attribute_t attribute = CFI_attribute_other);
- static RT_API_ATTRS OwningPtr<Descriptor> Create(const typeInfo::DerivedType &dt,
- void *p = nullptr, int rank = maxRank,
+ static RT_API_ATTRS OwningPtr<Descriptor> Create(
+ const typeInfo::DerivedType &dt, void *p = nullptr, int rank = maxRank,
const SubscriptValue *extent = nullptr,
ISO::CFI_attribute_t attribute = CFI_attribute_other);
diff --git a/flang/include/flang/Runtime/memory.h b/flang/include/flang/Runtime/memory.h
index 579ba78a1c93..85196f44e556 100644
--- a/flang/include/flang/Runtime/memory.h
+++ b/flang/include/flang/Runtime/memory.h
@@ -39,15 +39,14 @@ template <typename A> void FreeMemoryAndNullify(A *&p) {
// It should work for any offload device compiler.
// It uses a fixed memory deleter based on FreeMemory(),
// and does not support array objects with runtime length.
-template <typename A>
-class OwningPtr {
+template <typename A> class OwningPtr {
public:
using pointer_type = A *;
OwningPtr() = default;
RT_API_ATTRS explicit OwningPtr(pointer_type p) : ptr_(p) {}
RT_API_ATTRS OwningPtr(const OwningPtr &) = delete;
- RT_API_ATTRS OwningPtr& operator=(const OwningPtr &) = delete;
+ RT_API_ATTRS OwningPtr &operator=(const OwningPtr &) = delete;
RT_API_ATTRS OwningPtr(OwningPtr &&other) {
ptr_ = other.ptr_;
other.ptr_ = pointer_type();
@@ -60,7 +59,7 @@ public:
}
return *this;
}
- constexpr RT_API_ATTRS OwningPtr(std::nullptr_t) : OwningPtr() { }
+ constexpr RT_API_ATTRS OwningPtr(std::nullptr_t) : OwningPtr() {}
// Delete the pointer, if owns one.
RT_API_ATTRS ~OwningPtr() {
@@ -87,14 +86,10 @@ public:
}
// Exchange the pointer with another object.
- RT_API_ATTRS void swap(OwningPtr &other) {
- std::swap(ptr_, other.ptr_);
- }
+ RT_API_ATTRS void swap(OwningPtr &other) { std::swap(ptr_, other.ptr_); }
// Get the stored pointer.
- RT_API_ATTRS pointer_type get() const {
- return ptr_;
- }
+ RT_API_ATTRS pointer_type get() const { return ptr_; }
RT_API_ATTRS explicit operator bool() const {
return get() == pointer_type() ? false : true;
@@ -105,19 +100,16 @@ public:
return *get();
}
- RT_API_ATTRS pointer_type operator->() const {
- return get();
- }
+ RT_API_ATTRS pointer_type operator->() const { return get(); }
private:
- RT_API_ATTRS void delete_ptr(pointer_type p) {
- FreeMemory(p);
- }
+ RT_API_ATTRS void delete_ptr(pointer_type p) { FreeMemory(p); }
pointer_type ptr_{};
};
template <typename X, typename Y>
-inline RT_API_ATTRS bool operator!=(const OwningPtr<X> &x, const OwningPtr<Y> &y) {
+inline RT_API_ATTRS bool operator!=(
+ const OwningPtr<X> &x, const OwningPtr<Y> &y) {
return x.get() != y.get();
}
diff --git a/flang/include/flang/Runtime/type-code.h b/flang/include/flang/Runtime/type-code.h
index 172355609e26..3757840cfdef 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/flang/include/flang/Runtime/type-code.h
@@ -47,8 +47,12 @@ public:
return raw_ == CFI_type_Bool ||
(raw_ >= CFI_type_int_least8_t && raw_ <= CFI_type_int_least64_t);
}
- constexpr RT_API_ATTRS bool IsDerived() const { return raw_ == CFI_type_struct; }
- constexpr RT_API_ATTRS bool IsIntrinsic() const { return IsValid() && !IsDerived(); }
+ constexpr RT_API_ATTRS bool IsDerived() const {
+ return raw_ == CFI_type_struct;
+ }
+ constexpr RT_API_ATTRS bool IsIntrinsic() const {
+ return IsValid() && !IsDerived();
+ }
RT_API_ATTRS std::optional<std::pair<TypeCategory, int>>
GetCategoryAndKind() const;
diff --git a/flang/runtime/ISO_Fortran_util.h b/flang/runtime/ISO_Fortran_util.h
index d63cda8931f3..469067600bd9 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/flang/runtime/ISO_Fortran_util.h
@@ -38,10 +38,10 @@ static inline RT_API_ATTRS std::size_t MinElemLen(CFI_type_t type) {
typeParams->first, typeParams->second);
}
-static inline RT_API_ATTRS int VerifyEstablishParameters(CFI_cdesc_t *descriptor,
- void *base_addr, CFI_attribute_t attribute, CFI_type_t type,
- std::size_t elem_len, CFI_rank_t rank, const CFI_index_t extents[],
- bool external) {
+static inline RT_API_ATTRS int VerifyEstablishParameters(
+ CFI_cdesc_t *descriptor, void *base_addr, CFI_attribute_t attribute,
+ CFI_type_t type, std::size_t elem_len, CFI_rank_t rank,
+ const CFI_index_t extents[], bool external) {
if (attribute != CFI_attribute_other && attribute != CFI_attribute_pointer &&
attribute != CFI_attribute_allocatable) {
return CFI_INVALID_ATTRIBUTE;
@@ -77,9 +77,9 @@ static inline RT_API_ATTRS int VerifyEstablishParameters(CFI_cdesc_t *descriptor
return CFI_SUCCESS;
}
-static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor, void *base_addr,
- CFI_attribute_t attribute, CFI_type_t type, std::size_t elem_len,
- CFI_rank_t rank, const CFI_index_t extents[]) {
+static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
+ void *base_addr, CFI_attribute_t attribute, CFI_type_t type,
+ std::size_t elem_len, CFI_rank_t rank, const CFI_index_t extents[]) {
descriptor->base_addr = base_addr;
descriptor->elem_len = elem_len;
descriptor->version = CFI_VERSION;
diff --git a/flang/runtime/derived.h b/flang/runtime/derived.h
index 6b9ea907fda9..e43ecc34a31d 100644
--- a/flang/runtime/derived.h
+++ b/flang/runtime/derived.h
@@ -23,8 +23,8 @@ class Terminator;
// Perform default component initialization, allocate automatic components.
// Returns a STAT= code (0 when all's well).
-RT_API_ATTRS int Initialize(const Descriptor &, const typeInfo::DerivedType &, Terminator &,
- bool hasStat = false, const Descriptor *errMsg = nullptr);
+RT_API_ATTRS int Initialize(const Descriptor &, const typeInfo::DerivedType &,
+ Terminator &, bool hasStat = false, const Descriptor *errMsg = nullptr);
// Call FINAL subroutines, if any
RT_API_ATTRS void Finalize(
@@ -32,8 +32,8 @@ RT_API_ATTRS void Finalize(
// Call FINAL subroutines, deallocate allocatable & automatic components.
// Does not deallocate the original descriptor.
-RT_API_ATTRS void Destroy(const Descriptor &, bool finalize, const typeInfo::DerivedType &,
- Terminator *);
+RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
+ const typeInfo::DerivedType &, Terminator *);
// Return true if the passed descriptor is for a derived type
// entity that has a dynamic (allocatable, automatic) component.
diff --git a/flang/runtime/descriptor.cpp b/flang/runtime/descriptor.cpp
index 043b73255ab6..b36e4e409f04 100644
--- a/flang/runtime/descriptor.cpp
+++ b/flang/runtime/descriptor.cpp
@@ -29,9 +29,9 @@ RT_API_ATTRS Descriptor &Descriptor::operator=(const Descriptor &that) {
return *this;
}
-RT_API_ATTRS void Descriptor::Establish(TypeCode t, std::size_t elementBytes, void *p,
- int rank, const SubscriptValue *extent, ISO::CFI_attribute_t attribute,
- bool addendum) {
+RT_API_ATTRS void Descriptor::Establish(TypeCode t, std::size_t elementBytes,
+ void *p, int rank, const SubscriptValue *extent,
+ ISO::CFI_attribute_t attribute, bool addendum) {
Terminator terminator{__FILE__, __LINE__};
int cfiStatus{ISO::VerifyEstablishParameters(&raw_, p, attribute, t.raw(),
elementBytes, rank, extent, /*external=*/false)};
@@ -72,22 +72,23 @@ RT_API_ATTRS std::size_t Descriptor::BytesFor(TypeCategory category, int kind) {
return ApplyType<TypeSizeGetter, std::size_t>(category, kind, terminator);
}
-RT_API_ATTRS void Descriptor::Establish(TypeCategory c, int kind, void *p, int rank,
- const SubscriptValue *extent, ISO::CFI_attribute_t attribute,
+RT_API_ATTRS void Descriptor::Establish(TypeCategory c, int kind, void *p,
+ int rank, const SubscriptValue *extent, ISO::CFI_attribute_t attribute,
bool addendum) {
Establish(TypeCode(c, kind), BytesFor(c, kind), p, rank, extent, attribute,
addendum);
}
-RT_API_ATTRS void Descriptor::Establish(int characterKind, std::size_t characters, void *p,
- int rank, const SubscriptValue *extent, ISO::CFI_attribute_t attribute,
- bool addendum) {
+RT_API_ATTRS void Descriptor::Establish(int characterKind,
+ std::size_t characters, void *p, int rank, const SubscriptValue *extent,
+ ISO::CFI_attribute_t attribute, bool addendum) {
Establish(TypeCode{TypeCategory::Character, characterKind},
characterKind * characters, p, rank, extent, attribute, addendum);
}
-RT_API_ATTRS void Descriptor::Establish(const typeInfo::DerivedType &dt, void *p, int rank,
- const SubscriptValue *extent, ISO::CFI_attribute_t attribute) {
+RT_API_ATTRS void Descriptor::Establish(const typeInfo::DerivedType &dt,
+ void *p, int rank, const SubscriptValue *extent,
+ ISO::CFI_attribute_t attribute) {
Establish(TypeCode{TypeCategory::Derived, 0}, dt.sizeInBytes(), p, rank,
extent, attribute, true);
DescriptorAddendum *a{Addendum()};
@@ -96,8 +97,8 @@ RT_API_ATTRS void Descriptor::Establish(const typeInfo::DerivedType &dt, void *p
new (a) DescriptorAddendum{&dt};
}
-RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(TypeCode t, std::size_t elementBytes,
- void *p, int rank, const SubscriptValue *extent,
+RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(TypeCode t,
+ std::size_t elementBytes, void *p, int rank, const SubscriptValue *extent,
ISO::CFI_attribute_t attribute, int derivedTypeLenParameters) {
std::size_t bytes{SizeInBytes(rank, true, derivedTypeLenParameters)};
Terminator terminator{__FILE__, __LINE__};
@@ -107,8 +108,9 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(TypeCode t, std::size_t el
return OwningPtr<Descriptor>{result};
}
-RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(TypeCategory c, int kind, void *p,
- int rank, const SubscriptValue *extent, ISO::CFI_attribute_t attribute) {
+RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(TypeCategory c, int kind,
+ void *p, int rank, const SubscriptValue *extent,
+ ISO::CFI_attribute_t attribute) {
return Create(
TypeCode(c, kind), BytesFor(c, kind), p, rank, extent, attribute);
}
@@ -120,9 +122,9 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(int characterKind,
characterKind * characters, p, rank, extent, attribute);
}
-RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(const typeInfo::DerivedType &dt,
- void *p, int rank, const SubscriptValue *extent,
- ISO::CFI_attribute_t attribute) {
+RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(
+ const typeInfo::DerivedType &dt, void *p, int rank,
+ const SubscriptValue *extent, ISO::CFI_attribute_t attribute) {
return Create(TypeCode{TypeCategory::Derived, 0}, dt.sizeInBytes(), p, rank,
extent, attribute, dt.LenParameters());
}
diff --git a/flang/runtime/terminator.cpp b/flang/runtime/terminator.cpp
index bd86912cd53b..bab9edc64fa3 100644
--- a/flang/runtime/terminator.cpp
+++ b/flang/runtime/terminator.cpp
@@ -13,8 +13,8 @@
namespace Fortran::runtime {
#if !defined(RT_DEVICE_COMPILATION)
-[[maybe_unused]] static void (*crashHandler)(const char *, int, const char *, va_list &){
- nullptr};
+[[maybe_unused]] static void (*crashHandler)(
+ const char *, int, const char *, va_list &){nullptr};
void Terminator::RegisterCrashHandler(
void (*handler)(const char *, int, const char *, va_list &)) {
@@ -95,7 +95,8 @@ RT_API_ATTRS void Terminator::CrashHeader() const {
line);
}
-[[noreturn]] RT_API_ATTRS void Terminator::CheckFailed(const char *predicate) const {
+[[noreturn]] RT_API_ATTRS void Terminator::CheckFailed(
+ const char *predicate) const {
Crash("Internal error: RUNTIME_CHECK(%s) failed at %s(%d)", predicate,
sourceFileName_, sourceLine_);
}
diff --git a/flang/runtime/terminator.h b/flang/runtime/terminator.h
index dc73407093fd..444c68d109ee 100644
--- a/flang/runtime/terminator.h
+++ b/flang/runtime/terminator.h
@@ -31,7 +31,8 @@ public:
RT_API_ATTRS const char *sourceFileName() const { return sourceFileName_; }
RT_API_ATTRS int sourceLine() const { return sourceLine_; }
- RT_API_ATTRS void SetLocation(const char *sourceFileName = nullptr, int sourceLine = 0) {
+ RT_API_ATTRS void SetLocation(
+ const char *sourceFileName = nullptr, int sourceLine = 0) {
sourceFileName_ = sourceFileName;
sourceLine_ = sourceLine;
}
@@ -53,7 +54,8 @@ public:
// to regular printf for the device compilation.
// Try to keep the inline implementations as small as possible.
template <typename... Args>
- [[noreturn]] RT_API_ATTRS const char *Crash(const char *message, Args... args) const {
+ [[noreturn]] RT_API_ATTRS const char *Crash(
+ const char *message, Args... args) const {
#if !defined(RT_DEVICE_COMPILATION)
// Invoke handler set up by the test harness.
InvokeCrashHandler(message, args...);
@@ -82,8 +84,7 @@ public:
[[noreturn]] RT_API_ATTRS void CrashFooter() const;
#if !defined(RT_DEVICE_COMPILATION)
void InvokeCrashHandler(const char *message, ...) const;
- [[noreturn]] void CrashArgs(
- const char *message, va_list &) const;
+ [[noreturn]] void CrashArgs(const char *message, va_list &) const;
#endif
[[noreturn]] RT_API_ATTRS void CheckFailed(
const char *predicate, const char *file, int line) const;
diff --git a/flang/runtime/type-info.h b/flang/runtime/type-info.h
index 7ed17d9ede93..bd8112d9d6d8 100644
--- a/flang/runtime/type-info.h
+++ b/flang/runtime/type-info.h
@@ -39,7 +39,8 @@ public:
LenParameter = 3
};
RT_API_ATTRS Genre genre() const { return genre_; }
- RT_API_ATTRS std::optional<TypeParameterValue> GetValue(const Descriptor *) const;
+ RT_API_ATTRS std::optional<TypeParameterValue> GetValue(
+ const Descriptor *) const;
private:
Genre genre_{Genre::Explicit};
@@ -59,7 +60,9 @@ public:
const RT_API_ATTRS Descriptor &name() const { return name_.descriptor(); }
RT_API_ATTRS Genre genre() const { return genre_; }
- RT_API_ATTRS TypeCategory category() const { return static_cast<TypeCategory>(category_); }
+ RT_API_ATTRS TypeCategory category() const {
+ return static_cast<TypeCategory>(category_);
+ }
RT_API_ATTRS int kind() const { return kind_; }
RT_API_ATTRS int rank() const { return rank_; }
RT_API_ATTRS std::uint64_t offset() const { return offset_; }
@@ -88,8 +91,9 @@ public:
// Creates a pointer descriptor from this component description, possibly
// with subscripts
- RT_API_ATTRS void CreatePointerDescriptor(Descriptor &, const Descriptor &container,
- Terminator &, const SubscriptValue * = nullptr) const;
+ RT_API_ATTRS void CreatePointerDescriptor(Descriptor &,
+ const Descriptor &container, Terminator &,
+ const SubscriptValue * = nullptr) const;
FILE *Dump(FILE * = stdout) const;
@@ -135,8 +139,9 @@ public:
// Special bindings can be created during execution to handle defined
// I/O procedures that are not type-bound.
- RT_API_ATTRS SpecialBinding(Which which, ProcedurePointer proc, std::uint8_t isArgDescSet,
- std::uint8_t isTypeBound, std::uint8_t isArgContiguousSet)
+ RT_API_ATTRS SpecialBinding(Which which, ProcedurePointer proc,
+ std::uint8_t isArgDescSet, std::uint8_t isTypeBound,
+ std::uint8_t isArgContiguousSet)
: which_{which}, isArgDescriptorSet_{isArgDescSet},
isTypeBound_{isTypeBound}, isArgContiguousSet_{isArgContiguousSet},
proc_{proc} {}
@@ -200,7 +205,9 @@ class DerivedType {
public:
~DerivedType(); // never defined
- const RT_API_ATTRS Descriptor &binding() const { return binding_.descriptor(); }
+ const RT_API_ATTRS Descriptor &binding() const {
+ return binding_.descriptor();
+ }
const RT_API_ATTRS Descriptor &name() const { return name_.descriptor(); }
RT_API_ATTRS std::uint64_t sizeInBytes() const { return sizeInBytes_; }
const RT_API_ATTRS Descriptor &uninstatiated() const {
@@ -212,15 +219,27 @@ public:
const RT_API_ATTRS Descriptor &lenParameterKind() const {
return lenParameterKind_.descriptor();
}
- const RT_API_ATTRS Descriptor &component() const { return component_.descriptor(); }
- const RT_API_ATTRS Descriptor &procPtr() const { return procPtr_.descriptor(); }
- const RT_API_ATTRS Descriptor &special() const { return special_.descriptor(); }
+ const RT_API_ATTRS Descriptor &component() const {
+ return component_.descriptor();
+ }
+ const RT_API_ATTRS Descriptor &procPtr() const {
+ return procPtr_.descriptor();
+ }
+ const RT_API_ATTRS Descriptor &special() const {
+ return special_.descriptor();
+ }
RT_API_ATTRS bool hasParent() const { return hasParent_; }
- RT_API_ATTRS bool noInitializationNeeded() const { return noInitializationNeeded_; }
+ RT_API_ATTRS bool noInitializationNeeded() const {
+ return noInitializationNeeded_;
+ }
RT_API_ATTRS bool noDestructionNeeded() const { return noDestructionNeeded_; }
- RT_API_ATTRS bool noFinalizationNeeded() const { return noFinalizationNeeded_; }
+ RT_API_ATTRS bool noFinalizationNeeded() const {
+ return noFinalizationNeeded_;
+ }
- RT_API_ATTRS std::size_t LenParameters() const { return lenParameterKind().Elements(); }
+ RT_API_ATTRS std::size_t LenParameters() const {
+ return lenParameterKind().Elements();
+ }
const RT_API_ATTRS DerivedType *GetParentType() const;
@@ -229,7 +248,8 @@ public:
const char *name, std::size_t nameLen) const;
// O(1) look-up of special procedure bindings
- const RT_API_ATTRS SpecialBinding *FindSpecialBinding(SpecialBinding::Which which) const {
+ const RT_API_ATTRS SpecialBinding *FindSpecialBinding(
+ SpecialBinding::Which which) const {
auto bitIndex{static_cast<std::uint32_t>(which)};
auto bit{std::uint32_t{1} << bitIndex};
if (specialBitSet_ & bit) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/67489
More information about the flang-commits
mailing list