}
explicit FuncBuilder(Function &func) : FuncBuilder(&func) {}
+ virtual ~FuncBuilder();
/// Create a function builder and set insertion point to the given
/// operation, which will cause subsequent insertions to go right before it.
Block *getBlock() const { return block; }
/// Creates an operation given the fields represented as an OperationState.
- Operation *createOperation(const OperationState &state);
+ virtual Operation *createOperation(const OperationState &state);
/// Create operation of specific op type at the current insertion point.
template <typename OpTy, typename... Args>
/// to apply patterns and observe their effects (e.g. to keep worklists or
/// other data structures up to date).
///
-class PatternRewriter : public Builder {
+class PatternRewriter : public FuncBuilder {
public:
/// Create operation of specific op type at the current insertion point
/// without verifying to see if it is valid.
ArrayRef<Value *> valuesToRemoveIfDead = {});
protected:
- PatternRewriter(MLIRContext *context) : Builder(context) {}
+ PatternRewriter(Function *fn) : FuncBuilder(fn) {}
virtual ~PatternRewriter();
// These are the callback methods that subclasses can choose to implement if
// Operations.
//===----------------------------------------------------------------------===//
+FuncBuilder::~FuncBuilder() {}
+
/// Add new block and set the insertion point to the end of it. If an
/// 'insertBefore' block is passed, the block will be placed before the
/// specified block. If not, the block will be appended to the end of the
public:
explicit GreedyPatternRewriteDriver(Function &fn,
OwningRewritePatternList &&patterns)
- : PatternRewriter(fn.getContext()), matcher(std::move(patterns), *this),
- builder(&fn) {
+ : PatternRewriter(&fn), matcher(std::move(patterns), *this) {
worklist.reserve(64);
}
// Implement the hook for creating operations, and make sure that newly
// created ops are added to the worklist for processing.
Operation *createOperation(const OperationState &state) override {
- auto *result = builder.createOperation(state);
+ auto *result = FuncBuilder::createOperation(state);
addToWorklist(result);
return result;
}
/// The low-level pattern matcher.
RewritePatternMatcher matcher;
- /// This builder is used to create new operations.
- FuncBuilder builder;
-
/// The worklist for this transformation keeps track of the operations that
/// need to be revisited, plus their index in the worklist. This allows us to
/// efficiently remove operations from the worklist when they are erased from
/// Perform the rewrites.
bool GreedyPatternRewriteDriver::simplifyFunction(int maxIterations) {
- Function *fn = builder.getFunction();
+ Function *fn = getFunction();
FoldHelper helper(fn);
bool changed = false;
}
// Make sure that any new operations are inserted at this point.
- builder.setInsertionPoint(op);
+ setInsertionPoint(op);
// Try to match one of the canonicalization patterns. The rewriter is
// automatically notified of any necessary changes, so there is nothing