Hi.
I’m trying to write a lowering pass that converts an op returning a single value to multiple ops. The result of the original op will need to be replaced by all the new values.
Here is an example:
%1 = foo() : MultipleIntegersType
%2 = bar(%1)
Should get lowered to:
%1 = constant 42 : Integer
%2 = constant 56 : Integer
%3 = addi(%1, %2) : Integer
Notice that the operation “foo” with custom type “MultipleIntegersType” got lowered to multiple ops.
I wrote a custom type conversion:
typeConverter.addConversion(
[](MultipleIntegersType t, SmallVectorImpl<Type>& result) -> llvm::Optional<LogicalResult> {
// omitted: place correct number of integers into result here
return success();
});
Also in pseudo-code, here is how I wrote the lowering pattern for foo
:
auto intOne = rewriter.create<IntegerOp>(...);
auto intTwo = rewriter.create<IntegerOp>(...);
rewriter.replaceOp(originalOp, ValueRange{intOne, intTwo});
However, this doesn’t seem to work: I always get some variation of “wrong number of results” on the rewriter.replaceOp
line. This seems counter-intuitive to me - why hasn’t the type converter been applied, which would result in the result type being multiple integers?
Is there any way to achieve what I want? I realise I could just pack the values into a struct and lower the MultipleIntegersType into a single struct, but I’d like to avoid that if possible.