65 Value val,
FuncDefOp computeFunc, OpBuilder &builder, DenseMap<Value, Value> &memo
67 if (
auto it = memo.find(val); it != memo.end()) {
71 if (
auto barg = llvm::dyn_cast<BlockArgument>(val)) {
72 return memo[val] = mapBlockArgumentInCompute(barg, computeFunc);
77 for (Value operand : readOp->getOperands()) {
78 Value rebuiltOperand = mapValueIntoCompute(operand, computeFunc, builder, memo);
79 if (!rebuiltOperand) {
82 mapper.map(operand, rebuiltOperand);
85 Operation *rebuiltOp = builder.clone(*readOp.getOperation(), mapper);
86 assert(rebuiltOp->getNumResults() == 1 &&
"member reads have exactly one result");
87 return memo[val] = rebuiltOp->getResult(0);
90 if (
auto callOp = val.getDefiningOp<
CallOp>()) {
91 if (!callOp.getMapOperands().empty()) {
94 "cannot rebuild affine-instantiated function.call in compute-side auxiliary "
101 SymbolTableCollection tables;
102 FailureOr<SymbolLookupResult<FuncDefOp>> target = callOp.getCalleeTarget(tables);
103 if (failed(target)) {
115 "cannot rebuild function.call in compute-side auxiliary expression: callee "
116 "requires attributes not present on the compute function"
122 SmallVector<Value> rebuiltArgs;
123 rebuiltArgs.reserve(callOp.getArgOperands().size());
124 for (Value arg : callOp.getArgOperands()) {
129 rebuiltArgs.push_back(rebuiltArg);
132 ArrayRef<Attribute> templateParams;
133 if (ArrayAttr params = callOp.getTemplateParamsAttr()) {
134 templateParams = params.getValue();
138 builder, callOp.getLoc(), callOp.getResultTypes(), callOp.getCalleeAttr(), rebuiltArgs,
141 for (
auto [oldResult, newResult] : llvm::zip(callOp.getResults(), rebuilt.getResults())) {
142 memo[oldResult] = newResult;
147 if (val.getType().isIndex()) {
150 Operation *defOp = val.getDefiningOp();
151 assert(defOp &&
"index block arguments should already be mapped");
154 for (Value operand : defOp->getOperands()) {
155 Value rebuiltOperand = mapValueIntoCompute(operand, computeFunc, builder, memo);
156 if (!rebuiltOperand) {
159 mapper.map(operand, rebuiltOperand);
162 Operation *rebuiltOp = builder.clone(*defOp, mapper);
164 rebuiltOp->getNumResults() == defOp->getNumResults() &&
165 "cloned index op should preserve result count"
167 unsigned resultNumber = llvm::cast<OpResult>(val).getResultNumber();
168 return memo[val] = rebuiltOp->getResult(resultNumber);
219 if (Operation *op = val.getDefiningOp()) {
220 op->emitError(
"cannot rebuild unsupported operation in compute-side auxiliary expression")