Skip to content

Commit

Permalink
Lower to unitilalized variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cferry-AMD committed Sep 30, 2024
1 parent 93496a9 commit 4d12bc8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions mlir/lib/Conversion/UBToEmitC/UBToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,15 @@ struct PoisonOpLowering : public OpConversionPattern<ub::PoisonOp> {
if (!convertedType)
return rewriter.notifyMatchFailure(op.getLoc(), "type conversion failed");

Attribute value;
if (emitc::isIntegerIndexOrOpaqueType(convertedType)) {
value = IntegerAttr::get((emitc::isPointerWideType(convertedType)
? IndexType::get(getContext())
: convertedType),
0);
} else if (emitc::isSupportedFloatType(convertedType)) {
value = FloatAttr::get(convertedType, 0);
} else {
if (!(emitc::isIntegerIndexOrOpaqueType(convertedType) ||
emitc::isSupportedFloatType(convertedType))) {
return rewriter.notifyMatchFailure(
op.getLoc(), "only scalar poison values can be lowered");
}

// Any constant will be fine to lower a poison op
rewriter.replaceOpWithNewOp<emitc::VariableOp>(op, convertedType, value);
rewriter.replaceOpWithNewOp<emitc::VariableOp>(
op, convertedType, emitc::OpaqueAttr::get(op->getContext(), ""));
return success();
}
};
Expand Down

0 comments on commit 4d12bc8

Please sign in to comment.