Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions mlir/include/mlir/Conversion/SolToStandard/EVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ unsigned getCallDataHeadSize(Type ty);
/// the element type size.
int64_t getMallocSize(Type ty);

/// MLIR version of solidity ast's Type::storageSize().
unsigned getStorageSlotCount(Type ty);

/// Returns true if the type can be packed within a storage slot.
/// Packable types (scalars) need {slot, offset} representation.
/// Non-packable types (arrays, structs, mappings) are slot-aligned and only
/// need slot.
bool canBePacked(mlir::Type ty);

/// Returns the byte size of a packable type in storage.
unsigned getStorageByteSize(mlir::Type ty);

/// IR Builder for EVM specific lowering.
class Builder {
// It's possible to provide a mlirgen::BuilderHelper member with same default
Expand Down Expand Up @@ -180,6 +168,12 @@ class Builder {
sol::DataLocation dataLoc = sol::DataLocation::Storage,
std::optional<Location> locArg = std::nullopt);

/// Cleans up a packed storage value to match Solidity storage-load semantics
/// for the given element type.
Value
genCleanupPackedStorageValue(Type eltTy, Value value,
std::optional<Location> locArg = std::nullopt);

/// Inserts integer value (<=32 bytes) to the slot value:
/// or(and(slot, holeMask), shiftedVal), where
/// holeMask = not(ones(numBits) << offset * 8),
Expand Down
12 changes: 12 additions & 0 deletions mlir/include/mlir/Dialect/Sol/Sol.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ bool isRevertStringsEnabled(ModuleOp mod);
/// Return true if the type is address-like (i.e. address or contract type).
bool isAddressLikeType(Type ty);

/// MLIR version of solidity ast's Type::storageSize().
unsigned getStorageSlotCount(Type ty);

/// Returns true if the type can be packed within a storage slot.
/// Packable types (scalars) need {slot, offset} representation.
/// Non-packable types (arrays, structs, mappings) are slot-aligned and only
/// need slot.
bool canBePacked(mlir::Type ty);

/// Returns the byte size of a packable type in storage.
unsigned getStorageByteSize(mlir::Type ty);

///
/// The following functions are used to query the capabilities of the specified
/// evm in the module.
Expand Down
29 changes: 28 additions & 1 deletion mlir/include/mlir/Dialect/Sol/SolBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,34 @@ def Sol_ArrayType : Sol_Type<"Array", "array"> {

def Sol_StructType : Sol_Type<"Struct", "struct"> {
let parameters = (ins ArrayRefParameter<"Type">:$memberTypes,
Sol_DataLocation:$dataLocation);
Sol_DataLocation:$dataLocation,
ArrayRefParameter<"uint64_t">:$memberSlotOffsets,
ArrayRefParameter<"uint64_t">:$memberByteOffsets,
"uint64_t":$storageSlotCount);
let skipDefaultBuilders = 1;
let builders = [
TypeBuilder<(ins "ArrayRef<Type>":$memberTypes,
"DataLocation":$dataLocation), [{
::llvm::SmallVector<uint64_t, 8> memberSlotOffsets;
::llvm::SmallVector<uint64_t, 8> memberByteOffsets;
uint64_t storageSlotCount = 0;
if (dataLocation == DataLocation::Storage)
computeStructStorageMemberOffsets(memberTypes, memberSlotOffsets,
memberByteOffsets,
storageSlotCount);

return $_get($_ctxt, memberTypes, dataLocation, memberSlotOffsets,
memberByteOffsets, storageSlotCount);
}]>
];
let extraClassDeclaration = [{
struct StorageMemberOffset {
uint64_t slotOffset;
uint64_t byteOffset;
};

StorageMemberOffset getStorageMemberOffset(uint64_t memberIdx) const;
}];

let hasCustomAssemblyFormat = 1;
}
Expand Down
Loading
Loading