-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for struct type & corresponding operations (#53)
We are likely missing something like `struct_inject` for assigning a field for struct values, but this could be done later. Lots of small fixes and refactorings while there. --------- Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
- Loading branch information
Showing
17 changed files
with
1,105 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_H | ||
#define P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_H | ||
|
||
#include "mlir/IR/Types.h" | ||
|
||
namespace P4::P4MLIR::P4HIR { | ||
namespace FieldIdImpl { | ||
unsigned getMaxFieldID(::mlir::Type); | ||
|
||
std::pair<::mlir::Type, unsigned> getSubTypeByFieldID(::mlir::Type, unsigned fieldID); | ||
|
||
::mlir::Type getFinalTypeByFieldID(::mlir::Type type, unsigned fieldID); | ||
|
||
std::pair<unsigned, bool> projectToChildFieldID(::mlir::Type, unsigned fieldID, unsigned index); | ||
|
||
std::pair<unsigned, unsigned> getIndexAndSubfieldID(::mlir::Type type, unsigned fieldID); | ||
|
||
unsigned getFieldID(::mlir::Type type, unsigned index); | ||
|
||
unsigned getIndexForFieldID(::mlir::Type type, unsigned fieldID); | ||
|
||
} // namespace FieldIdImpl | ||
} // namespace P4::P4MLIR::P4HIR | ||
|
||
#include "p4mlir/Dialect/P4HIR/P4HIR_TypeInterfaces.h.inc" | ||
|
||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_TD | ||
#define P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_TD | ||
|
||
include "mlir/IR/OpBase.td" | ||
|
||
def FieldIDTypeInterface : TypeInterface<"FieldIDTypeInterface"> { | ||
let description = [{ | ||
Common methods for types which can be indexed by a FieldID. | ||
FieldID is a depth-first numbering of the elements of a type. For example: | ||
``` | ||
struct a /* 0 */ { | ||
int b; /* 1 */ | ||
struct c /* 2 */ { | ||
int d; /* 3 */ | ||
} | ||
} | ||
|
||
int e; /* 0 */ | ||
``` | ||
}]; | ||
|
||
let methods = [ | ||
InterfaceMethod<"Get the maximum field ID for this type", | ||
"unsigned", "getMaxFieldID">, | ||
|
||
InterfaceMethod<[{ | ||
Get the sub-type of a type for a field ID, and the subfield's ID. Strip | ||
off a single layer of this type and return the sub-type and a field ID | ||
targeting the same field, but rebased on the sub-type. | ||
|
||
The resultant type *may* not be a FieldIDTypeInterface if the resulting | ||
fieldID is zero. This means that leaf types may be ground without | ||
implementing an interface. An empty aggregate will also appear as a | ||
zero. | ||
}], | ||
"std::pair<::mlir::Type, unsigned>", "getSubTypeByFieldID", (ins "unsigned":$fieldID)>, | ||
|
||
InterfaceMethod<[{ | ||
Returns the effective field id when treating the index field as the | ||
root of the type. Essentially maps a fieldID to a fieldID after a | ||
subfield op. Returns the new id and whether the id is in the given | ||
child. | ||
}], | ||
"std::pair<unsigned, bool>", "projectToChildFieldID", (ins "unsigned":$fieldID, "unsigned":$index)>, | ||
|
||
InterfaceMethod<[{ | ||
Returns the index (e.g. struct or vector element) for a given FieldID. | ||
This returns the containing index in the case that the fieldID points to a | ||
child field of a field. | ||
}], | ||
"unsigned", "getIndexForFieldID", (ins "unsigned":$fieldID)>, | ||
|
||
InterfaceMethod<[{ | ||
Return the fieldID of a given index (e.g. struct or vector element). | ||
Field IDs start at 1, and are assigned | ||
to each field in a recursive depth-first walk of all | ||
elements. A field ID of 0 is used to reference the type itself. | ||
}], | ||
"unsigned", "getFieldID", (ins "unsigned":$index)>, | ||
|
||
InterfaceMethod<[{ | ||
Find the index of the element that contains the given fieldID. | ||
As well, rebase the fieldID to the element. | ||
}], | ||
"std::pair<unsigned, unsigned>", "getIndexAndSubfieldID", (ins "unsigned":$fieldID)>, | ||
|
||
]; | ||
|
||
let cppNamespace = "::P4::P4MLIR::P4HIR"; | ||
} | ||
|
||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_TYPEINTERFACES_TD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.