Implement MultiPayloadEnum support for projectEnumValue (#30635)

This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
This commit is contained in:
tbkka
2020-03-31 15:12:44 -07:00
committed by GitHub
parent 8d68607681
commit 3c8fde7885
12 changed files with 1110 additions and 554 deletions

View File

@@ -62,21 +62,29 @@ public:
}
/// Attempts to read an integer of the specified size from the given
/// address in the remote process.
/// address in the remote process. Following `storeEnumElement`
/// in EnumImpl.h, this reads arbitrary-size integers by ignoring
/// high-order bits that are outside the range of `IntegerType`.
///
/// Returns false if the operation failed, or the request size is
/// larger than the provided destination.
/// Returns false if the operation failed.
template <typename IntegerType>
bool readInteger(RemoteAddress address, size_t bytes, IntegerType *dest) {
*dest = 0;
if ((bytes > sizeof(IntegerType))
|| !readBytes(address, (uint8_t *)dest, bytes)) {
return false;
}
size_t readSize = std::min(bytes, sizeof(IntegerType));
// FIXME: Assumes host and target have the same endianness.
// TODO: Query DLQ for endianness of target, compare to endianness of host.
#if defined(__BIG_ENDIAN__)
*dest >>= (sizeof(IntegerType) - bytes);
// Read low-order bits of source ...
if (!readBytes(address + (bytes - readSize), (uint8_t *)dest, readSize)) {
return false;
}
// ... align result to low-order bits of *dest
*dest >>= 8 * (sizeof(IntegerType) - readSize);
#else
// Read from low-order bytes of integer
if (!readBytes(address, (uint8_t *)dest, readSize)) {
return false;
}
#endif
return true;
}