Skip to content

Global variables as type descriptors#173

Merged
ahueck merged 35 commits intodevelfrom
feat/global-types
Nov 13, 2025
Merged

Global variables as type descriptors#173
ahueck merged 35 commits intodevelfrom
feat/global-types

Conversation

@ahueck
Copy link
Copy Markdown
Contributor

@ahueck ahueck commented Nov 7, 2025

  • Type description/type id system for parallel compilation of target codes:
    • file: place user-defined type descriptor in central yaml file (serial compilation needed)
    • hybrid: place type descriptors as globals for user-defined types in each module.
    • inline: also for all (supported) built-in types

Type descriptors

  • Types descriptors are placed inside a module as a r/w global. For startup registration with runtime constructor functions are used. Format, 48 bytes per type + members:
struct GlobalTypeInfo {
  std::int32_t type_id;
  const std::uint32_t extent;
  const std::uint16_t num_members;
  const std::uint16_t flag;
  const char* name;
  const std::uint16_t* offsets;
  const std::uint16_t* array_sizes;
  const GlobalTypeInfo** member_types;
};
  • Callback:
void __typeart_register_type(const void* type_ptr);
  • Globals are parsed at runtime during startup, and the actual type-id is computed and set for each of these globals:
void GlobalTypeTranslator::register_type(const void* type) {
  const auto* info_struct = reinterpret_cast<const GlobalTypeInfo*>(type);
  const auto type_id      = pImpl->register_t(info_struct);
  const_cast<GlobalTypeInfo*>(info_struct)->type_id = type_id;
}

Misc

  • Update CI: clang-format-18 on github action runner has bug, use LLVM repo
  • Abseil's hashmap clashes with ASan: use std::unordered_map when using ASan and Abseil

ToDos ?

  • Save some space by defining the type as, e.g.:
struct GlobalTypeInfo {
  std::int32_t type_id;
  const std::uint32_t extent;
  const std::uint16_t flag;
  const char* name;
  const MemberTypeInfo* info;
};
struct MemberTypeInfo {
  const std::uint16_t num_members;
  const std::uint16_t* offsets;
  const std::uint16_t* array_sizes;
  const GlobalTypeInfo** member_types;
}

ahueck added 30 commits October 24, 2025 13:07
* LLVM 14: disregard inline/hybrid type serialization mode.
* Non-opaque LLVM: always emit type file, also see above
* Type handling: Arrays of MPI type handles (pointer to opaque struct) are treated as pointers
* Runtime: check if hash map has type entry
* Type descriptor member was NULL due to a fwd decl variable being extern, see 'runtime/22_threads_stack.cpp':
  * Fwd decl '_ZTSNSt6thread6_StateE' contained in '_ZTSNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFvvEEEEEEE'
* Global type variable contained whitespaces, replace with '_'.
* Always normalize global variable names during type serialization
* Search type db during registration for duplicate names, remove hash map
* lulesh inline mode: 4250 vs. 3698 bytes
@ahueck ahueck force-pushed the feat/global-types branch from 67781d7 to a179308 Compare November 7, 2025 15:28
@ahueck ahueck force-pushed the feat/global-types branch from a179308 to e9694af Compare November 7, 2025 15:40
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Nov 7, 2025

Pull Request Test Coverage Report for Build 19192146139

Details

  • 597 of 629 (94.91%) changed or added relevant lines in 25 files are covered.
  • 3 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+1.4%) to 90.318%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/runtime/TypeResolution.cpp 15 16 93.75%
lib/passes/TypeARTPass.cpp 26 28 92.86%
lib/runtime/GlobalTypeDefCallbacks.h 4 6 66.67%
lib/typelib/TypeDB.cpp 4 6 66.67%
lib/runtime/GlobalTypeDefCallbacks.cpp 60 64 93.75%
lib/passes/instrumentation/TypeARTFunctions.cpp 100 106 94.34%
lib/runtime/AllocationTracking.cpp 41 56 73.21%
Files with Coverage Reduction New Missed Lines %
lib/runtime/AllocationTracking.cpp 1 91.62%
lib/typelib/TypeDB.cpp 1 89.69%
lib/typelib/TypeDB.h 1 94.74%
Totals Coverage Status
Change from base Build 15098967331: 1.4%
Covered Lines: 4767
Relevant Lines: 5278

💛 - Coveralls

@ahueck ahueck force-pushed the feat/global-types branch from e6d559e to 52fe99c Compare November 8, 2025 09:42
@ahueck ahueck force-pushed the feat/global-types branch from 52fe99c to cc5657d Compare November 8, 2025 11:03
@ahueck ahueck merged commit acf5c0e into devel Nov 13, 2025
53 checks passed
@ahueck ahueck deleted the feat/global-types branch November 13, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants