Skip to content

Commit

Permalink
[OM] Add OpInterface for IntegerBinaryArithmeticOp. (#6703)
Browse files Browse the repository at this point in the history
As we start adding integer binary arithmetic expressions, this will
allow us to abstract over these ops in the evaluator. The interfaces
defines accessors for each operand and the result, which can be
trivially implemented by a shared helper in ODS. The interface also
defines one method to be used in the evaluator, which is to actually
evaluate the integer arithmetic operation. APSInts for each operand
are passed to the interface method, and an APSInt representing the
result or a failure must be returned.
  • Loading branch information
mikeurbach committed Feb 15, 2024
1 parent 6e1db86 commit 9e2c380
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/circt/Dialect/OM/OMOpInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define CIRCT_DIALECT_OM_OMOPINTERFACES_H

#include "mlir/IR/OpDefinition.h"
#include "llvm/ADT/APSInt.h"

#include "circt/Dialect/OM/OMOpInterfaces.h.inc"

Expand Down
16 changes: 16 additions & 0 deletions include/circt/Dialect/OM/OMOpInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ def ClassFieldLike : OpInterface<"ClassFieldLike"> {
];
}

def IntegerBinaryArithmeticInterface : OpInterface<"IntegerBinaryArithmeticOp"> {
let cppNamespace = "circt::om";
let description = "Common interface for integer binary arithmetic ops.";
let methods = [
InterfaceMethod<"Get the lhs Value",
"mlir::Value", "getLhs", (ins)>,
InterfaceMethod<"Get the rhs Value",
"mlir::Value", "getRhs", (ins)>,
InterfaceMethod<"Get the result Value",
"mlir::Value", "getResult", (ins)>,
InterfaceMethod<"Evaluate the integer binary arithmetic operation",
"mlir::FailureOr<llvm::APSInt>", "evaluateIntegerOperation",
(ins "llvm::APSInt":$lhs, "llvm::APSInt":$rhs)>
];
}

#endif // CIRCT_DIALECT_OM_OMOPINTERFACES_TD

0 comments on commit 9e2c380

Please sign in to comment.