-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `qualified` to the type assembly format This is because I noticed the assembly format was printing <10> for polynomials instead of the fully qualified type name. After this commit it will print the whole type See https://mlir.llvm.org/docs/DefiningDialects/Operations/#declarative-assembly-format for more details. * Add SameOperandsAndResultType This removes the flexibility of having mixed poly + tensor ops for the binary operations, but demonstrates how the type inference engine enables a more succinct textual IR. If you were to simplify the assembly format without doing this, you'd get a compile-time error complaining that it can't infer the type of the operands or argument. * add AllTypesMatch to EvalOp * add a custom verifier for evalop * add verifier via trait
- Loading branch information
Showing
12 changed files
with
84 additions
and
31 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,28 @@ | ||
#ifndef LIB_DIALECT_POLY_POLYTRAITS_H_ | ||
#define LIB_DIALECT_POLY_POLYTRAITS_H_ | ||
|
||
#include "mlir/include/mlir/IR/OpDefinition.h" | ||
|
||
namespace mlir::tutorial::poly { | ||
|
||
template <typename ConcreteType> | ||
class Has32BitArguments : public OpTrait::TraitBase<ConcreteType, Has32BitArguments> { | ||
public: | ||
static LogicalResult verifyTrait(Operation *op) { | ||
for (auto type : op->getOperandTypes()) { | ||
// OK to skip non-integer operand types | ||
if (!type.isIntOrIndex()) continue; | ||
|
||
if (!type.isInteger(32)) { | ||
return op->emitOpError() | ||
<< "requires each numeric operand to be a 32-bit integer"; | ||
} | ||
} | ||
|
||
return success(); | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif // LIB_DIALECT_POLY_POLYTRAITS_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
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,10 @@ | ||
// RUN: tutorial-opt %s 2>%t; FileCheck %s < %t | ||
|
||
func.func @test_invalid_evalop(%arg0: !poly.poly<10>, %cst: i64) -> i64 { | ||
// This is a little brittle, since it matches both the error message | ||
// emitted by Has32BitArguments as well as that of EvalOp::verify. | ||
// I manually tested that they both fire when the input is as below. | ||
// CHECK: to be a 32-bit integer | ||
%0 = poly.eval %arg0, %cst : (!poly.poly<10>, i64) -> i64 | ||
return %0 : i64 | ||
} |
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