[all-commits] [llvm/llvm-project] 2e30c8: [Flang][NFCI] Use abstraction for binary scalar da...

Michael Kruse via All-commits all-commits at lists.llvm.org
Mon Sep 7 03:28:33 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2e30c8e267256e3a2b43985d9be68831c412a1b5
      https://github.com/llvm/llvm-project/commit/2e30c8e267256e3a2b43985d9be68831c412a1b5
  Author: Michael Kruse <llvm-project at meinersbur.de>
  Date:   2026-09-07 (Mon, 07 Sep 2026)

  Changed paths:
    A flang/include/flang/Evaluate/char.h
    M flang/include/flang/Evaluate/complex.h
    M flang/include/flang/Evaluate/initial-image.h
    M flang/include/flang/Evaluate/integer.h
    M flang/include/flang/Evaluate/logical.h
    M flang/include/flang/Evaluate/real.h
    M flang/lib/Evaluate/host.h
    M flang/lib/Evaluate/initial-image.cpp

  Log Message:
  -----------
  [Flang][NFCI] Use abstraction for binary scalar data (#212956)

There is currently the assumption that the binary representation of the
scalar data classes (Integer, Real, Complex, Logical) is identical to
the binary representation of native types. For instance `Integer<64>`
can be reinterpret-casted to a `int64_t` or serialized using `memcpy`.
This will not be the case anymore with #206907. This first PR introduces
`LoadRawBytes` and `StoreRawBytes` abstractions that can be adapted when
the binary data layout of the scalar data classes change. No functional
change intended.

The binary representation is assumed for these uses:

1. Data serialization in initial-image.h/.cpp

2. Calling native math functions to constant-fold functions such as
`sin` in intrinsics-library.cpp. An abstraction layer has been created
in host.h/host.cpp to convert between host-native types and the scalar
data classes.


Some implementation notes:
* I originally used `CharacterUtils` but it is in a private header file.
Instead I created `CharacterValue` which similar to what #216960 will
introduce to allow a consistent interface between the scalar value
classes (such as `kind()` returning the current runtime kind)
* `bytesStored` is another such common interface. It it meant to
resemble `llvm::DataLayout::getTypeStoreSize` (there is also
`getTypeAllocSize`, `llvm::Type::getPrimitiveSizeInBits()`,
`llvm::Type::getScalarSizeInBits()`) and must match
`common::TypeSizeInBytes`.
* `Real<10>` uses 16-byte alignment regardless what the host compiler
thinks what `long double` should be. The padding is unitialized data in
`X87IntegerContainer`. Even though x87 is the classic example where
"allocation size" and "store size" would be different, Flang does not
differentiate between them and treats all bytes also as stored bytes,
see `common::TypeSizeInBytes`. As a consequence, `Complex<10>` is 32
bytes. initial-image.h/.cpp will even load/store/compare that
uninitialized data. host.h/host.cpp instead reads/writes the floats
separately to translate to whatever the host compiler does.
* initial-image.cpp/.h is inconsistent when it uses number of bytes and
when it uses number of characters
* For the case the image does not have sufficient bytes to read, I did
not want to insert checks whether another byte can be read into every
ReadRawBytes function, and instead add zero-padding explicitly when
necessary.

Assisted-by: AI



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list