diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e60c47..de8c685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ include_directories(${LLVM_INCLUDE_DIRS}) include_directories(${MLIR_INCLUDE_DIRS}) include_directories(${P4MLIR_SOURCE_DIR}/include) include_directories(${P4MLIR_BINARY_DIR}/include) - +set(LLVM_RUNTIME_OUTPUT_INTDIR "${P4MLIR_BINARY_DIR}/bin") add_subdirectory(include) add_subdirectory(lib) add_subdirectory(test) diff --git a/include/p4mlir/Dialect/P4HIR/CMakeLists.txt b/include/p4mlir/Dialect/P4HIR/CMakeLists.txt index fb84482..d144dde 100644 --- a/include/p4mlir/Dialect/P4HIR/CMakeLists.txt +++ b/include/p4mlir/Dialect/P4HIR/CMakeLists.txt @@ -5,5 +5,8 @@ mlir_tablegen(P4HIR_Ops.h.inc -gen-op-decls) mlir_tablegen(P4HIR_Ops.cpp.inc -gen-op-defs) mlir_tablegen(P4HIR_Types.h.inc -gen-typedef-decls -typedefs-dialect=p4hir) mlir_tablegen(P4HIR_Types.cpp.inc -gen-typedef-defs -typedefs-dialect=p4hir) +mlir_tablegen(P4HIR_Attrs.h.inc -gen-attrdef-decls -attrdefs-dialect=p4hir) +mlir_tablegen(P4HIR_Attrs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=p4hir) + add_public_tablegen_target(P4MLIR_P4HIR_IncGen) add_dependencies(mlir-headers P4MLIR_P4HIR_IncGen) diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.h b/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.h new file mode 100644 index 0000000..ced757e --- /dev/null +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.h @@ -0,0 +1,10 @@ +#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H +#define P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H + +#include "mlir/IR/BuiltinAttributes.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" + +#define GET_ATTRDEF_CLASSES +#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.h.inc" + +#endif // P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.td b/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.td new file mode 100644 index 0000000..f036eb9 --- /dev/null +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Attrs.td @@ -0,0 +1,62 @@ +#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD +#define P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD + +include "mlir/IR/BuiltinAttributeInterfaces.td" +include "mlir/IR/EnumAttr.td" + +include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.td" + +class P4HIR_Attr traits = []> + : AttrDef { + let mnemonic = attrMnemonic; +} + +//===----------------------------------------------------------------------===// +// BoolAttr +//===----------------------------------------------------------------------===// + +def P4_BoolAttr : P4HIR_Attr<"Bool", "bool", [TypedAttrInterface]> { + let summary = "Represent true/false for !p4hir.bool types"; + let description = [{ + The BoolAttr represents a 'true' or 'false' value. + }]; + + let parameters = (ins AttributeSelfTypeParameter<"", "BoolType">:$type, + "bool":$value); + + let assemblyFormat = [{ + `<` $value `>` + }]; +} + +//===----------------------------------------------------------------------===// +// IntegerAttr +//===----------------------------------------------------------------------===// + +def IntAttr : P4HIR_Attr<"Int", "int", [TypedAttrInterface]> { + let summary = "An Attribute containing a integer value"; + let description = [{ + An integer attribute is a literal attribute that represents an integral + value of the specified integer type. + }]; + let parameters = (ins AttributeSelfTypeParameter<"">:$type, "llvm::APInt":$value); + let builders = [ + AttrBuilderWithInferredContext<(ins "mlir::Type":$type, "const llvm::APInt &":$value), [{ + return $_get(type.getContext(), type, value); + }]>, + AttrBuilderWithInferredContext<(ins "mlir::Type":$type, "int64_t":$value), [{ + BitsType intType = mlir::cast(type); + mlir::APInt apValue(intType.getWidth(), value, intType.isSigned()); + return $_get(intType.getContext(), intType, apValue); + }]>, + ]; + let extraClassDeclaration = [{ + int64_t getSInt() const { return getValue().getSExtValue(); } + uint64_t getUInt() const { return getValue().getZExtValue(); } + bool isNullValue() const { return getValue() == 0; } + }]; + let genVerifyDecl = 1; + let hasCustomAssemblyFormat = 1; +} + +#endif // P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.h b/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.h index 7acf56f..dfeedf4 100644 --- a/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.h +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.h @@ -1,9 +1,13 @@ #ifndef P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H #define P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H +// We explicitly do not use push / pop for diagnostic in +// order to propagate pragma further on +#pragma GCC diagnostic ignored "-Wunused-parameter" + #include "mlir/Bytecode/BytecodeOpInterface.h" #include "mlir/IR/Dialect.h" #include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h.inc" -#endif // P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H +#endif // P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.td b/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.td index 1752a41..0b39baa 100644 --- a/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.td +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Dialect.td @@ -16,7 +16,16 @@ def P4HIR_Dialect : Dialect { }]; let cppNamespace = "::P4::P4MLIR::P4HIR"; - let useDefaultTypePrinterParser = 1; + let useDefaultTypePrinterParser = 0; + let useDefaultAttributePrinterParser = 1; + + let extraClassDeclaration = [{ + mlir::Type parseType(mlir::DialectAsmParser &parser) const override; + void printType(mlir::Type type, mlir::DialectAsmPrinter &printer) const override; + + void registerAttributes(); + void registerTypes(); + }]; } #endif // P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_TD diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.h b/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.h index 4b968ec..13266f5 100644 --- a/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.h +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.h @@ -1,6 +1,10 @@ #ifndef P4MLIR_DIALECT_P4HIR_P4HIR_OPS_H #define P4MLIR_DIALECT_P4HIR_P4HIR_OPS_H +// We explicitly do not use push / pop for diagnostic in +// order to propagate pragma further on +#pragma GCC diagnostic ignored "-Wunused-parameter" + #include "mlir/Bytecode/BytecodeOpInterface.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.td b/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.td index 8534e06..7b96039 100644 --- a/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.td +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Ops.td @@ -8,6 +8,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td" include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.td" include "p4mlir/Dialect/P4HIR/P4HIR_Types.td" +include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.td" //===----------------------------------------------------------------------===// // Base P4HIR operation definition. @@ -20,31 +21,30 @@ class P4HIR_Op traits = []> : // P4HIR operation definitions. //===----------------------------------------------------------------------===// -def P4HIR_ConstOp : P4HIR_Op<"const", [Pure]> { - let summary = "const operation"; +def P4HIR_ConstOp : P4HIR_Op<"const", + [ConstantLike, Pure, AllTypesMatch<["value", "res"]>]> { + let summary = "Defines a P4 constant"; let description = [{ - The `p4hir.const` operation turns a literal into an SSA value. It + The `p4hir.const` operation turns a literal into an SSA value. + The data is attached to the operation as an attribute. It represents a constant declaration in P4. Example: ```mlir - %0 = p4hir.const 42 : ui32 -> !p4hir.bit<32> + %0 = p4hir.const p4hir.int<-128> : !p4hir.int<8> ``` + }]; - Corresponding P4 code: + // The constant operation takes an attribute as the only input. + let arguments = (ins TypedAttrInterface:$value); - ```p4 - const bit<32> a = 42; - ``` - }]; + // The constant operation returns a single value of AnyP4Type. + let results = (outs AnyP4Type:$res); - let arguments = (ins APIntAttr:$value); - let results = (outs P4HIR_P4Type:$result); + let assemblyFormat = "attr-dict $value"; - let assemblyFormat = [{ - $value attr-dict `->` qualified(type($result)) - }]; + let hasVerifier = 1; } #endif // P4MLIR_DIALECT_P4HIR_P4HIR_OPS_TD diff --git a/include/p4mlir/Dialect/P4HIR/P4HIR_Types.td b/include/p4mlir/Dialect/P4HIR/P4HIR_Types.td index 3a1504d..f4fa866 100644 --- a/include/p4mlir/Dialect/P4HIR/P4HIR_Types.td +++ b/include/p4mlir/Dialect/P4HIR/P4HIR_Types.td @@ -14,21 +14,80 @@ class P4HIR_Type traits = []> let mnemonic = typeMnemonic; } -def P4HIR_BitType : P4HIR_Type<"BitType", "bit"> { - let summary = "fixed width unsigned integer type"; +class P4HIR_TypeNoMnemonic traits = []> + : TypeDef { + string typeName = dialect.name # "." # typeMnemonic; +} + +//===----------------------------------------------------------------------===// +// Integer types: signed (int) and unsigned (bit) +def P4HIR_BitsType : P4HIR_TypeNoMnemonic<"Bits", "bits"> { + let summary = "fixed width integer type"; let description = [{ - The `p4hir.bit` type represents a P4 `bit` type. + The `p4hir.bit` / `p4hir.int` type represents a P4 `bit` or `int` type. + + For example, `p4hir.bit<32>` represents `bit<32>` in P4 and + `p4hir.int<42>` is `int<42>` in P4. + }]; + let parameters = (ins "unsigned":$width, "bool":$isSigned); + let extraClassDeclaration = [{ + /// Return true if this is a signed integer type. + bool isSigned() const { return getIsSigned(); } + /// Return true if this is an unsigned integer type. + bool isUnsigned() const { return !getIsSigned(); } + + static mlir::Type parse(mlir::AsmParser &parser, bool isSigned); + void print(mlir::AsmPrinter &printer) const; + }]; +} - For example, `p4hir.bit<32>` represents `bit<32>` in P4. +// Unsigned integer type of a specific width (bits). +class P4HIR_Bit + : Type($_self)">, + CPred<"::mlir::cast<::p4hir::BitsType>($_self).isUnsigned()">, + CPred<"::mlir::cast<::p4hir::BitsType>($_self).getWidth() == " # width> + ]>, width # "-bit unsigned integer", "::p4hir::BitsType">, + BuildableType< + "p4hir::BitsType::get($_builder.getContext(), " + # width # ", /*isSigned=*/false)"> { + int bitwidth = width; +} + +// Signed integer type of a specific width (int). +class P4HIR_Int + : Type($_self)">, + CPred<"::mlir::cast<::p4hir::IntType>($_self).isSigned()">, + CPred<"::mlir::cast<::p4hir::IntType>($_self).getWidth() == " # width> + ]>, width # "-bit signed integer", "::p4hir::BitsType">, + BuildableType< + "p4hir::BitsType::get($_builder.getContext(), " + # width # ", /*isSigned=*/true)"> { + int bitwidth = width; +} + +//===----------------------------------------------------------------------===// +// BoolType +// +// An alternative here is to represent bool as mlir::i1, but let's be more +// generic. +// +//===----------------------------------------------------------------------===// + +def P4HIR_BooleanType : P4HIR_Type<"Bool", "bool"> { + let summary = "boolean type"; + let description = [{ + `p4hir.bool` represents a P4 `bool` type. }]; - let parameters = (ins "uint64_t":$width); - let assemblyFormat = "`<` $width `>`"; + + let hasCustomAssemblyFormat = 1; } //===----------------------------------------------------------------------===// // P4HIR type constraints. //===----------------------------------------------------------------------===// -def P4HIR_P4Type : AnyTypeOf<[P4HIR_BitType]> {} +def AnyP4Type : AnyTypeOf<[P4HIR_BitsType, P4HIR_BooleanType]> {} #endif // P4MLIR_DIALECT_P4HIR_P4HIR_TYPES_TD diff --git a/lib/Dialect/P4HIR/CMakeLists.txt b/lib/Dialect/P4HIR/CMakeLists.txt index 0850a8f..cb38ee5 100644 --- a/lib/Dialect/P4HIR/CMakeLists.txt +++ b/lib/Dialect/P4HIR/CMakeLists.txt @@ -1,5 +1,7 @@ add_mlir_dialect_library(P4MLIR_P4HIR - P4HIR.cpp + P4HIR_Ops.cpp + P4HIR_Types.cpp + P4HIR_Attrs.cpp ADDITIONAL_HEADER_DIRS ${PROJECT_SOURCE_DIR}/include/p4mlir/Dialect/P4HIR diff --git a/lib/Dialect/P4HIR/P4HIR.cpp b/lib/Dialect/P4HIR/P4HIR.cpp deleted file mode 100644 index 68638c0..0000000 --- a/lib/Dialect/P4HIR/P4HIR.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h" -#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.h" -#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" - -#include "mlir/IR/Builders.h" -#include "mlir/IR/DialectImplementation.h" -#include "llvm/ADT/TypeSwitch.h" - -#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.cpp.inc" -#define GET_OP_CLASSES -#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.cpp.inc" -#define GET_TYPEDEF_CLASSES -#include "p4mlir/Dialect/P4HIR/P4HIR_Types.cpp.inc" - -namespace P4::P4MLIR::P4HIR { - -void P4HIRDialect::initialize() { - addOperations< -#define GET_OP_LIST -#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.cpp.inc" - >(); - addTypes< -#define GET_TYPEDEF_LIST -#include "p4mlir/Dialect/P4HIR/P4HIR_Types.cpp.inc" - >(); -} - -} // namespace P4::P4MLIR::P4HIR diff --git a/lib/Dialect/P4HIR/P4HIR_Attrs.cpp b/lib/Dialect/P4HIR/P4HIR_Attrs.cpp new file mode 100644 index 0000000..e25d294 --- /dev/null +++ b/lib/Dialect/P4HIR/P4HIR_Attrs.cpp @@ -0,0 +1,85 @@ +#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.h" + +#include "llvm/ADT/TypeSwitch.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/DialectImplementation.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" + +#define GET_ATTRDEF_CLASSES +#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.cpp.inc" + +using namespace mlir; +using namespace P4::P4MLIR::P4HIR; + +Type BoolType::parse(mlir::AsmParser &parser) { return get(parser.getContext()); } + +void BoolType::print(mlir::AsmPrinter &printer) const {} + +Attribute IntAttr::parse(AsmParser &parser, Type odsType) { + mlir::APInt APValue; + + if (!mlir::isa(odsType)) return {}; + auto type = mlir::cast(odsType); + + // Consume the '<' symbol. + if (parser.parseLess()) return {}; + + // Fetch arbitrary precision integer value. + if (type.isSigned()) { + int64_t value; + if (parser.parseInteger(value)) + parser.emitError(parser.getCurrentLocation(), "expected integer value"); + APValue = mlir::APInt(type.getWidth(), value, type.isSigned()); + if (APValue.getSExtValue() != value) + parser.emitError(parser.getCurrentLocation(), + "integer value too large for the given type"); + } else { + uint64_t value; + if (parser.parseInteger(value)) + parser.emitError(parser.getCurrentLocation(), "expected integer value"); + APValue = mlir::APInt(type.getWidth(), value, type.isSigned()); + if (APValue.getZExtValue() != value) + parser.emitError(parser.getCurrentLocation(), + "integer value too large for the given type"); + } + + // Consume the '>' symbol. + if (parser.parseGreater()) return {}; + + return IntAttr::get(type, APValue); +} + +void IntAttr::print(AsmPrinter &printer) const { + auto type = mlir::cast(getType()); + printer << '<'; + if (type.isSigned()) + printer << getSInt(); + else + printer << getUInt(); + printer << '>'; +} + +LogicalResult IntAttr::verify(function_ref emitError, Type type, + APInt value) { + if (!mlir::isa(type)) { + emitError() << "expected 'simple.int' type"; + return failure(); + } + + auto intType = mlir::cast(type); + if (value.getBitWidth() != intType.getWidth()) { + emitError() << "type and value bitwidth mismatch: " << intType.getWidth() + << " != " << value.getBitWidth(); + return failure(); + } + + return success(); +} + +void P4HIRDialect::registerAttributes() { + addAttributes< +#define GET_ATTRDEF_LIST +#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.cpp.inc" // NOLINT + >(); +} diff --git a/lib/Dialect/P4HIR/P4HIR_Ops.cpp b/lib/Dialect/P4HIR/P4HIR_Ops.cpp new file mode 100644 index 0000000..6932347 --- /dev/null +++ b/lib/Dialect/P4HIR/P4HIR_Ops.cpp @@ -0,0 +1,57 @@ +#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.h" + +#include "mlir/IR/Builders.h" +#include "mlir/IR/DialectImplementation.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" + +#define GET_OP_CLASSES +#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.cpp.inc" +#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.cpp.inc" + +using namespace mlir; +using namespace P4::P4MLIR; + +//===----------------------------------------------------------------------===// +// ConstantOp +//===----------------------------------------------------------------------===// + +static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType, + mlir::Attribute attrType) { + if (mlir::isa(attrType)) { + if (!mlir::isa(opType)) + return op->emitOpError("result type (") + << opType << ") must be '!p4hir.bool' for '" << attrType << "'"; + return success(); + } + + if (mlir::isa(attrType)) { + if (!mlir::isa(opType)) + return op->emitOpError("result type (") + << opType << ") does not match value type (" << attrType << ")"; + return success(); + } + + if (mlir::isa(attrType)) return success(); + + assert(isa(attrType) && "expected typed attribute"); + return op->emitOpError("constant with type ") + << cast(attrType).getType() << " not supported"; +} + +LogicalResult P4HIR::ConstOp::verify() { + // ODS already generates checks to make sure the result type is valid. We just + // need to additionally check that the value's attribute type is consistent + // with the result type. + return checkConstantTypes(getOperation(), getType(), getValue()); +} + +void P4HIR::P4HIRDialect::initialize() { + registerTypes(); + registerAttributes(); + addOperations< +#define GET_OP_LIST +#include "p4mlir/Dialect/P4HIR/P4HIR_Ops.cpp.inc" // NOLINT + >(); +} diff --git a/lib/Dialect/P4HIR/P4HIR_Types.cpp b/lib/Dialect/P4HIR/P4HIR_Types.cpp new file mode 100644 index 0000000..7d9561c --- /dev/null +++ b/lib/Dialect/P4HIR/P4HIR_Types.cpp @@ -0,0 +1,70 @@ +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" + +#include "llvm/ADT/TypeSwitch.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/DialectImplementation.h" +#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h" + +#define GET_TYPEDEF_CLASSES +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.cpp.inc" + +using namespace mlir; +using namespace P4::P4MLIR::P4HIR; + +void BitsType::print(mlir::AsmPrinter &printer) const { + printer << (isSigned() ? "int" : "bit") << '<' << getWidth() << '>'; +} + +Type BitsType::parse(mlir::AsmParser &parser, bool isSigned) { + auto *context = parser.getBuilder().getContext(); + + if (parser.parseLess()) return {}; + + // Fetch integer size. + unsigned width; + if (parser.parseInteger(width)) return {}; + + if (parser.parseGreater()) return {}; + + return BitsType::get(context, width, isSigned); +} + +Type BoolType::parse(mlir::AsmParser &parser) { return get(parser.getContext()); } + +void BoolType::print(mlir::AsmPrinter &printer) const {} + +Type P4HIRDialect::parseType(DialectAsmParser &parser) const { + llvm::SMLoc typeLoc = parser.getCurrentLocation(); + llvm::StringRef mnemonic; + Type genType; + + // Try to parse as a tablegen'd type. + OptionalParseResult parseResult = generatedTypeParser(parser, &mnemonic, genType); + if (parseResult.has_value()) return genType; + + // Type is not tablegen'd: try to parse as a raw C++ type. + return StringSwitch>(mnemonic) + .Case("int", [&] { return BitsType::parse(parser, /* isSigned */ true); }) + .Case("bit", [&] { return BitsType::parse(parser, /* isSigned */ false); }) + .Default([&] { + parser.emitError(typeLoc) << "unknown P4HIR type: " << mnemonic; + return Type(); + })(); +} + +void P4HIRDialect::printType(Type type, DialectAsmPrinter &os) const { + // Try to print as a tablegen'd type. + if (generatedTypePrinter(type, os).succeeded()) return; + + // Add some special handling for certain types + TypeSwitch(type).Case([&](BitsType type) { type.print(os); }).Default([](Type) { + llvm::report_fatal_error("printer is missing a handler for this type"); + }); +} + +void P4HIRDialect::registerTypes() { + addTypes< +#define GET_TYPEDEF_LIST +#include "p4mlir/Dialect/P4HIR/P4HIR_Types.cpp.inc" // NOLINT + >(); +} diff --git a/test/Dialect/P4HIR/bits.mlir b/test/Dialect/P4HIR/bits.mlir new file mode 100644 index 0000000..0c7b6ce --- /dev/null +++ b/test/Dialect/P4HIR/bits.mlir @@ -0,0 +1,30 @@ +// RUN: p4mlir-opt %s | FileCheck %s + +!s8i = !p4hir.int<8> +!s16i = !p4hir.int<16> +!s32i = !p4hir.int<32> +!s64i = !p4hir.int<64> + +!u8i = !p4hir.bit<8> +!u16i = !p4hir.bit<16> +!u32i = !p4hir.bit<32> +!u64i = !p4hir.bit<64> + +// No need to check stuff. If it parses, it's fine. +// CHECK: module +module { + %1 = p4hir.const #p4hir.int<-128> : !p4hir.int<8> + %2 = p4hir.const #p4hir.int<127> : !p4hir.int<8> + %3 = p4hir.const #p4hir.int<255> : !p4hir.bit<8> + + %4 = p4hir.const #p4hir.int<-32768> : !p4hir.int<16> + %5 = p4hir.const #p4hir.int<32767> : !p4hir.int<16> + %6 = p4hir.const #p4hir.int<65535> : !p4hir.bit<16> + + %7 = p4hir.const #p4hir.int<-2147483648> : !p4hir.int<32> + %8 = p4hir.const #p4hir.int<2147483647> : !p4hir.int<32> + %9 = p4hir.const #p4hir.int<4294967295> : !p4hir.bit<32> + + %10 = p4hir.const #p4hir.int<9223372036854775807> : !p4hir.int<72> + %11 = p4hir.const #p4hir.int<18446744073709551615> : !p4hir.bit<72> +} diff --git a/test/Dialect/P4HIR/bool.mlir b/test/Dialect/P4HIR/bool.mlir new file mode 100644 index 0000000..0e3f37b --- /dev/null +++ b/test/Dialect/P4HIR/bool.mlir @@ -0,0 +1,10 @@ +// RUN: p4mlir-opt %s | FileCheck %s + +#true = #p4hir.bool : !p4hir.bool + +// No need to check stuff. If it parses, it's fine. +// CHECK: module +module { + %0 = p4hir.const #true + %1 = p4hir.const #p4hir.bool : !p4hir.bool +} diff --git a/test/Dialect/P4HIR/p4hir_syntax.mlir b/test/Dialect/P4HIR/p4hir_syntax.mlir deleted file mode 100644 index bb4f592..0000000 --- a/test/Dialect/P4HIR/p4hir_syntax.mlir +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: p4mlir-opt %s | FileCheck %s -// Check for P4HIR syntax. - -// CHECK-LABEL: test -module @test { - - %0 = p4hir.const 42 : ui32 -> !p4hir.bit<32> - -} diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 5f43278..788ad22 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -20,3 +20,5 @@ set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV}) set(MLIR_INCLUDE_DIRS "${llvm_SOURCE_DIR}/../mlir/include;${llvm_BINARY_DIR}/tools/mlir/include" PARENT_SCOPE) set(LLVM_INCLUDE_DIRS "${llvm_SOURCE_DIR}/include;${llvm_BINARY_DIR}/include" PARENT_SCOPE) +set(LLVM_EXTERNAL_LIT "${llvm_BINARY_DIR}/bin/llvm-lit" PARENT_SCOPE) +set(LLVM_TOOLS_BINARY_DIR "${llvm_BINARY_DIR}/bin" PARENT_SCOPE)