-
Notifications
You must be signed in to change notification settings - Fork 141
Add ModArithType folding hooks #3067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| #include "lib/Dialect/RNS/IR/RNSAttributes.h" | ||
|
|
||
| #include "mlir/include/mlir/IR/Attributes.h" // from @llvm-project | ||
| #include "mlir/include/mlir/IR/Diagnostics.h" // from @llvm-project | ||
| #include "mlir/include/mlir/Support/LLVM.h" // from @llvm-project | ||
| #include "lib/Dialect/RNS/IR/RNSOps.h" | ||
| #include "lib/Dialect/RNS/IR/RNSTypes.h" | ||
| #include "mlir/include/mlir/IR/Attributes.h" // from @llvm-project | ||
| #include "mlir/include/mlir/IR/Diagnostics.h" // from @llvm-project | ||
| #include "mlir/include/mlir/IR/DialectImplementation.h" // from @llvm-project | ||
| #include "mlir/include/mlir/IR/OpImplementation.h" // from @llvm-project | ||
| #include "mlir/include/mlir/Support/LLVM.h" // from @llvm-project | ||
|
|
||
| namespace mlir { | ||
| namespace heir { | ||
|
|
@@ -55,6 +59,33 @@ Attribute RNSAttr::parse(AsmParser& parser, Type type) { | |
| parser.getContext(), ArrayRef<Attribute>(attrValues), rnsType); | ||
| } | ||
|
|
||
| // LimbwiseAttrInterface | ||
| ::mlir::Attribute RNSAttr::assembleFromLimbs( | ||
| ::mlir::Type resultAttrType, ::llvm::ArrayRef< ::mlir::Attribute> limbs) { | ||
| auto rnsType = dyn_cast_if_present<RNSType>(resultAttrType); | ||
| if (!rnsType) return {}; | ||
| return get(rnsType, limbs); | ||
| } | ||
|
|
||
| ::mlir::Attribute RNSAttr::extractLimb(unsigned index) const { | ||
| return getValues()[index]; | ||
| } | ||
|
|
||
| ::mlir::Type RNSAttr::getLimbType(unsigned index) const { | ||
| return cast<RNSType>(getType()).getBasisTypes()[index]; | ||
| } | ||
|
|
||
| unsigned RNSAttr::getNumLimbs() const { return getValues().size(); } | ||
|
|
||
| ::mlir::Operation* RNSAttr::materializeConstant(::mlir::OpBuilder& builder, | ||
| ::mlir::Location loc, | ||
| ::mlir::Type type) const { | ||
| auto rnsType = dyn_cast_if_present<RNSType>(type); | ||
| if (!rnsType) return nullptr; | ||
| auto op = rns::ConstantOp::create(builder, loc, rnsType, *this); | ||
| return op.getOperation(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is that different than
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you wrote indeed compiles, but that's because, technically speaking, the tablegen-generated classes like |
||
| } | ||
|
|
||
| } // namespace rns | ||
| } // namespace heir | ||
| } // namespace mlir | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add the modulus here? Is there an assumption somewhere that values should not be negative? c.f. my confusion here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the
urembelow... any other reason?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the urem at the end, I think until ModArithToArith is updated to support anything except standard representatives in [0, q), we will have to maintain that invariant in the folders or else the lowerings may break.