Skip to content

Commit 6b94c1e

Browse files
committed
Add return values to function extract
1 parent b2ebc25 commit 6b94c1e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

mlir/lib/Tools/mlir-query/Query.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ Operation *extractFunction(std::vector<matcher::DynTypedNode> &nodes,
8080
}
8181

8282
auto loc = builder.getUnknownLoc();
83+
84+
if (!hasReturn) {
85+
resultType = slice.back()->getResults().getTypes();
86+
}
87+
8388
func::FuncOp funcOp = func::FuncOp::create(
8489
loc, functionName,
8590
builder.getFunctionType(ValueRange(values), resultType));
@@ -91,8 +96,11 @@ Operation *extractFunction(std::vector<matcher::DynTypedNode> &nodes,
9196
IRMapping mapper;
9297
for (const auto &arg : llvm::enumerate(values))
9398
mapper.map(arg.value(), funcOp.getArgument(arg.index()));
99+
100+
// TODO: FIX assiging lastOp every iteration.
101+
Operation *lastOp;
94102
for (Operation *slicedOp : slice)
95-
builder.clone(*slicedOp, mapper);
103+
lastOp = builder.clone(*slicedOp, mapper);
96104

97105
// Remove func arguments that are not used.
98106
unsigned currentIndex = 0;
@@ -103,8 +111,11 @@ Operation *extractFunction(std::vector<matcher::DynTypedNode> &nodes,
103111
currentIndex++;
104112
}
105113
}
106-
if (!hasReturn)
107-
builder.create<func::ReturnOp>(loc);
114+
115+
// Add an extra return operation with the result of the final operation
116+
if (!hasReturn) {
117+
builder.create<func::ReturnOp>(loc, lastOp->getResults());
118+
}
108119

109120
return funcOp;
110121
}

0 commit comments

Comments
 (0)