-
Notifications
You must be signed in to change notification settings - Fork 305
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
[RTG][Elaboration] Add support for arith constants #7890
Draft
maerhart
wants to merge
1
commit into
maerhart-rtg-elaboration-debug-printing
Choose a base branch
from
maerhart-rtg-elaboration-arith
base: maerhart-rtg-elaboration-debug-printing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−19
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//===- ArithVisitors.h - Arith Dialect Visitors -----------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines visitors that make it easier to work with Arith Ops. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_DIALECT_RTG_IR_ARITHVISITORS_H | ||
#define CIRCT_DIALECT_RTG_IR_ARITHVISITORS_H | ||
|
||
#include "mlir/Dialect/Arith/IR/Arith.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
namespace mlir { | ||
namespace arith { | ||
|
||
/// This helps visit TypeOp nodes. | ||
template <typename ConcreteType, typename ResultType = void, | ||
typename... ExtraArgs> | ||
class ArithOpVisitor { | ||
public: | ||
ResultType dispatchOpVisitor(Operation *op, ExtraArgs... args) { | ||
auto *thisCast = static_cast<ConcreteType *>(this); | ||
return TypeSwitch<Operation *, ResultType>(op) | ||
.template Case<ConstantOp, AddIOp, AddUIExtendedOp, SubIOp, MulIOp, | ||
MulSIExtendedOp, MulUIExtendedOp, DivUIOp, DivSIOp, | ||
CeilDivUIOp, CeilDivSIOp, FloorDivSIOp, RemUIOp, RemSIOp, | ||
AndIOp, OrIOp, XOrIOp, ShLIOp, ShRUIOp, ShRSIOp, NegFOp, | ||
AddFOp, SubFOp, MaximumFOp, MaxNumFOp, MaxSIOp, MaxUIOp, | ||
MinimumFOp, MinNumFOp, MinSIOp, MinUIOp, MulFOp, DivFOp, | ||
RemFOp, ExtUIOp, ExtSIOp, ExtFOp, TruncIOp, TruncFOp, | ||
UIToFPOp, SIToFPOp, FPToUIOp, FPToSIOp, IndexCastOp, | ||
IndexCastUIOp, BitcastOp, CmpIOp, CmpFOp, SelectOp>( | ||
[&](auto expr) -> ResultType { | ||
return thisCast->visitOp(expr, args...); | ||
}) | ||
.Default([&](auto expr) -> ResultType { | ||
if (op->getDialect() == | ||
op->getContext()->getLoadedDialect<ArithDialect>()) { | ||
return visitInvalidTypeOp(op, args...); | ||
} | ||
return thisCast->visitExternalOp(op, args...); | ||
}); | ||
} | ||
|
||
/// This callback is invoked on any RTG operations not handled properly by the | ||
/// TypeSwitch. | ||
ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) { | ||
op->emitOpError("Unknown Arith operation: ") << op->getName(); | ||
abort(); | ||
} | ||
|
||
/// This callback is invoked on any operations that are not | ||
/// handled by the concrete visitor. | ||
ResultType visitUnhandledOp(Operation *op, ExtraArgs... args); | ||
|
||
ResultType visitExternalOp(Operation *op, ExtraArgs... args) { | ||
return ResultType(); | ||
} | ||
|
||
#define HANDLE(OPTYPE, OPKIND) \ | ||
ResultType visitOp(OPTYPE op, ExtraArgs... args) { \ | ||
return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \ | ||
} | ||
|
||
HANDLE(ConstantOp, Unhandled); | ||
HANDLE(AddIOp, Unhandled); | ||
HANDLE(AddUIExtendedOp, Unhandled); | ||
HANDLE(SubIOp, Unhandled); | ||
HANDLE(MulIOp, Unhandled); | ||
HANDLE(MulSIExtendedOp, Unhandled); | ||
HANDLE(MulUIExtendedOp, Unhandled); | ||
HANDLE(DivUIOp, Unhandled); | ||
HANDLE(DivSIOp, Unhandled); | ||
HANDLE(CeilDivUIOp, Unhandled); | ||
HANDLE(CeilDivSIOp, Unhandled); | ||
HANDLE(FloorDivSIOp, Unhandled); | ||
HANDLE(RemUIOp, Unhandled); | ||
HANDLE(RemSIOp, Unhandled); | ||
HANDLE(AndIOp, Unhandled); | ||
HANDLE(OrIOp, Unhandled); | ||
HANDLE(XOrIOp, Unhandled); | ||
HANDLE(ShLIOp, Unhandled); | ||
HANDLE(ShRUIOp, Unhandled); | ||
HANDLE(ShRSIOp, Unhandled); | ||
HANDLE(NegFOp, Unhandled); | ||
HANDLE(AddFOp, Unhandled); | ||
HANDLE(SubFOp, Unhandled); | ||
HANDLE(MaximumFOp, Unhandled); | ||
HANDLE(MaxNumFOp, Unhandled); | ||
HANDLE(MaxSIOp, Unhandled); | ||
HANDLE(MaxUIOp, Unhandled); | ||
HANDLE(MinimumFOp, Unhandled); | ||
HANDLE(MinNumFOp, Unhandled); | ||
HANDLE(MinSIOp, Unhandled); | ||
HANDLE(MinUIOp, Unhandled); | ||
HANDLE(MulFOp, Unhandled); | ||
HANDLE(DivFOp, Unhandled); | ||
HANDLE(RemFOp, Unhandled); | ||
HANDLE(ExtUIOp, Unhandled); | ||
HANDLE(ExtSIOp, Unhandled); | ||
HANDLE(ExtFOp, Unhandled); | ||
HANDLE(TruncIOp, Unhandled); | ||
HANDLE(TruncFOp, Unhandled); | ||
HANDLE(UIToFPOp, Unhandled); | ||
HANDLE(SIToFPOp, Unhandled); | ||
HANDLE(FPToUIOp, Unhandled); | ||
HANDLE(FPToSIOp, Unhandled); | ||
HANDLE(IndexCastOp, Unhandled); | ||
HANDLE(IndexCastUIOp, Unhandled); | ||
HANDLE(BitcastOp, Unhandled); | ||
HANDLE(CmpIOp, Unhandled); | ||
HANDLE(CmpFOp, Unhandled); | ||
HANDLE(SelectOp, Unhandled); | ||
#undef HANDLE | ||
}; | ||
|
||
} // namespace arith | ||
} // namespace mlir | ||
|
||
#endif // CIRCT_DIALECT_RTG_IR_ARITHVISITORS_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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sigh. I don't suppose we can get around this.