13 #include "llvm/Support/Debug.h"
20 "Expected a C expression");
23 assert(op->
getNumResults() == 1 &&
"Expected exactly one result");
29 auto expressionOp = builder.
create<emitc::ExpressionOp>(loc, resultType);
35 Region ®ion = expressionOp.getRegion();
38 auto yieldOp = builder.
create<emitc::YieldOp>(loc, result);
56 LogicalResult matchAndRewrite(ExpressionOp expressionOp,
58 bool anythingFolded =
false;
59 for (
Operation &op : llvm::make_early_inc_range(
60 expressionOp.getBody()->without_terminator())) {
62 auto applyOp = dyn_cast<emitc::ApplyOp>(op);
63 if (applyOp && applyOp.getApplicableOperator() ==
"&")
66 for (
Value operand : op.getOperands()) {
68 dyn_cast_if_present<ExpressionOp>(operand.getDefiningOp());
75 if (!usedExpression.getResult().hasOneUse())
79 if (usedExpression.hasSideEffects())
88 usedExpression.getBody()->without_terminator()) {
93 Operation *expressionRoot = usedExpression.getRootOp();
95 assert(clonedExpressionRootOp &&
96 "Expected cloned expression root to be in mapper");
98 "Expected cloned root to have a single result");
100 rewriter.
replaceOp(usedExpression, clonedExpressionRootOp);
101 anythingFolded =
true;
104 return anythingFolded ? success() : failure();
Block represents an ordered list of Operations.
This is a utility class for mapping one set of IR entities to another.
auto lookup(T from) const
Lookup a mapped value within the map.
void map(Value from, Value to)
Inserts a new mapping for 'from' to 'to'.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation * clone(Operation &op, IRMapping &mapper)
Creates a deep copy of the specified operation, remapping any operands that use values outside of the...
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
void setInsertionPointToEnd(Block *block)
Sets the insertion point to the end of the specified block.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Location getLoc()
The source location the operation was defined or derived from.
void moveBefore(Operation *existingOp)
Unlink this operation from its current block and insert it right before existingOp which may be in th...
unsigned getNumResults()
Return the number of results held by this operation.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
void replaceAllUsesWith(Value newValue)
Replace all uses of 'this' value with the new value, updating anything in the IR that uses 'this' to ...
void populateExpressionPatterns(RewritePatternSet &patterns)
Populates patterns with expression-related patterns.
ExpressionOp createExpression(Operation *op, OpBuilder &builder)
Include the generated interface declarations.
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...