Skip to content

Commit

Permalink
[EmitC] Fix API usage in dialect conversion (#18411)
Browse files Browse the repository at this point in the history
This should fix a bug triggered by
llvm/llvm-project#106760.

Signed-off-by: Simon Camphausen <[email protected]>
  • Loading branch information
simon-camp committed Sep 2, 2024
1 parent f28dae9 commit 573929a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1485,19 +1485,6 @@ ResultOpTy lookupSymbolRef(Operation *accessOp, StringRef attrName) {
return globalOp;
}

void updateResultUses(Operation *op, ConversionPatternRewriter &rewriter,
SmallVector<Value> &resultOperands) {
for (auto [result, resultOperand] :
llvm::zip(op->getResults(), resultOperands)) {
if (!llvm::isa<IREE::VM::RefType>(result.getType())) {
auto operand = cast<TypedValue<emitc::LValueType>>(resultOperand);
auto operandRValue =
emitc_builders::asRValue(rewriter, op->getLoc(), operand);
result.replaceAllUsesWith(operandRValue);
}
}
}

template <typename OpTy>
class EmitCConversionPattern : public OpConversionPattern<OpTy> {
public:
Expand Down Expand Up @@ -2647,9 +2634,8 @@ class CallOpConversion : public EmitCConversionPattern<OpTy> {
/*rewriter=*/rewriter, /*location=*/loc, /*callee=*/funcOp,
/*operands=*/updatedOperands, this->getModuleAnalysis());

updateResultUses(op, rewriter, resultOperands);

rewriter.eraseOp(op);
emitc_builders::asRValues(rewriter, loc, resultOperands);
rewriter.replaceOp(op, resultOperands);

return success();
}
Expand Down Expand Up @@ -2714,9 +2700,8 @@ class CallOpConversion : public EmitCConversionPattern<OpTy> {
returnIfError(rewriter, loc, callee, updatedOperands,
this->getModuleAnalysis());

updateResultUses(op, rewriter, resultOperands);

rewriter.eraseOp(op);
emitc_builders::asRValues(rewriter, loc, resultOperands);
rewriter.replaceOp(op, resultOperands);

return success();
}
Expand Down Expand Up @@ -3833,9 +3818,8 @@ class ContainerOpConversion : public EmitCConversionPattern<OpTy> {
/*operands=*/ArrayRef<Value>(unwrappedOperands),
this->getModuleAnalysis());

updateResultUses(op.getOperation(), rewriter, resultOperands);

rewriter.eraseOp(op);
emitc_builders::asRValues(rewriter, loc, resultOperands);
rewriter.replaceOp(op, resultOperands);
} else {
rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
/*op=*/op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ Value asRValue(OpBuilder builder, Location loc,
value);
}

void asRValues(OpBuilder builder, Location location,
SmallVector<Value> &values) {
for (auto &value : values) {
if (auto lvalue = llvm::dyn_cast<TypedValue<emitc::LValueType>>(value)) {
value = emitc_builders::asRValue(builder, location, lvalue);
}
}
}

TypedValue<emitc::PointerType>
addressOf(OpBuilder builder, Location location,
TypedValue<emitc::LValueType> operand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ TypedValue<emitc::LValueType> asLValue(OpBuilder builder, Location loc,
Value asRValue(OpBuilder builder, Location loc,
TypedValue<emitc::LValueType> value);

/// Replace values of lvalue type with rvalues.
void asRValues(OpBuilder builder, Location location,
SmallVector<Value> &values);

TypedValue<emitc::PointerType> addressOf(OpBuilder builder, Location location,
TypedValue<emitc::LValueType> operand);

Expand Down

0 comments on commit 573929a

Please sign in to comment.