remove useless MaterializeHostConstantsPass.cpp and fix lowering before instead
Validate Operations / validate-operations (push) Has been cancelled
Validate Operations / validate-operations (push) Has been cancelled
avoid spammy pim codegen diagnostics
This commit is contained in:
@@ -375,6 +375,57 @@ static void cloneHelperChain(Value sourceValue,
|
||||
}
|
||||
}
|
||||
|
||||
static bool isHostStaticReturnValue(Value value) {
|
||||
llvm::SmallPtrSet<Operation*, 8> visited;
|
||||
while (Operation* definingOp = value.getDefiningOp()) {
|
||||
if (!visited.insert(definingOp).second)
|
||||
return false;
|
||||
if (isa<arith::ConstantOp>(definingOp) || definingOp->hasTrait<OpTrait::ConstantLike>())
|
||||
return true;
|
||||
if (!isReturnHelperChainOp(definingOp) || definingOp->getNumOperands() != 1)
|
||||
return false;
|
||||
value = definingOp->getOperand(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static FailureOr<Value>
|
||||
materializeHostStaticReturnValue(IRRewriter& rewriter, Value value, OperationFolder& constantFolder) {
|
||||
llvm::SmallVector<Operation*> chain;
|
||||
llvm::SmallPtrSet<Operation*, 8> visited;
|
||||
while (Operation* definingOp = value.getDefiningOp()) {
|
||||
if (!visited.insert(definingOp).second)
|
||||
return failure();
|
||||
chain.push_back(definingOp);
|
||||
if (isa<arith::ConstantOp>(definingOp) || definingOp->hasTrait<OpTrait::ConstantLike>())
|
||||
break;
|
||||
if (!isReturnHelperChainOp(definingOp) || definingOp->getNumOperands() != 1)
|
||||
return failure();
|
||||
value = definingOp->getOperand(0);
|
||||
}
|
||||
|
||||
if (chain.empty())
|
||||
return failure();
|
||||
|
||||
IRMapping mapping;
|
||||
Value clonedValue;
|
||||
for (Operation* op : llvm::reverse(chain)) {
|
||||
if (auto constantOp = dyn_cast<arith::ConstantOp>(op)) {
|
||||
clonedValue = getOrCreateConstantLike(constantFolder, constantOp);
|
||||
mapping.map(op->getResult(0), clonedValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
Operation* clonedOp = rewriter.clone(*op, mapping);
|
||||
for (auto [originalResult, newResult] : llvm::zip(op->getResults(), clonedOp->getResults()))
|
||||
mapping.map(originalResult, newResult);
|
||||
clonedValue = clonedOp->getResult(0);
|
||||
rewriter.setInsertionPointAfter(clonedOp);
|
||||
}
|
||||
|
||||
return clonedValue;
|
||||
}
|
||||
|
||||
static FailureOr<Value> emitHostCopy(IRRewriter& rewriter,
|
||||
Location loc,
|
||||
Value outputTensor,
|
||||
@@ -444,7 +495,30 @@ raptor::SpatialToPimPass::ReturnPathLoweringResult raptor::SpatialToPimPass::low
|
||||
OperationFolder constantFolder(producerOp->getContext());
|
||||
auto storedTensorType = cast<TensorType>(storedValue.getType());
|
||||
|
||||
auto materializeDirectHostReturn = [&](size_t returnIndex,
|
||||
Value sourceValue,
|
||||
ArrayRef<Operation*> helperChain) -> ReturnPathLoweringResult {
|
||||
rewriter.setInsertionPointAfter(producerOp);
|
||||
auto hostStaticValue = materializeHostStaticReturnValue(rewriter, sourceValue, constantFolder);
|
||||
if (failed(hostStaticValue))
|
||||
return ReturnPathLoweringResult::Failure;
|
||||
|
||||
Value hostReturnValue = *hostStaticValue;
|
||||
if (!helperChain.empty())
|
||||
cloneHelperChain(hostReturnValue, helperChain, rewriter, constantFolder, hostReturnValue);
|
||||
|
||||
outputTensors[returnIndex] =
|
||||
[hostReturnValue](IRRewriter& rewriter, Location loc) -> Value { return hostReturnValue; };
|
||||
return ReturnPathLoweringResult::Handled;
|
||||
};
|
||||
|
||||
if (auto returnUse = analyzeReturnUse(producedValue)) {
|
||||
if (isHostStaticReturnValue(storedValue)) {
|
||||
for (Operation* op : returnUse->helperChain)
|
||||
markOpToRemove(op);
|
||||
return materializeDirectHostReturn(returnUse->returnIndex, storedValue, returnUse->helperChain);
|
||||
}
|
||||
|
||||
Value currentStoredValue = storedValue;
|
||||
cloneHelperChain(storedValue, returnUse->helperChain, rewriter, constantFolder, currentStoredValue);
|
||||
for (Operation* op : returnUse->helperChain)
|
||||
@@ -470,6 +544,8 @@ raptor::SpatialToPimPass::ReturnPathLoweringResult raptor::SpatialToPimPass::low
|
||||
|
||||
if (isa<func::ReturnOp>(resultUser)) {
|
||||
size_t resultIndexInReturn = resultUse.getOperandNumber();
|
||||
if (isHostStaticReturnValue(storedValue))
|
||||
return materializeDirectHostReturn(resultIndexInReturn, storedValue, {});
|
||||
auto byteSize =
|
||||
pim::getCheckedShapedTypeSizeInBytes(storedTensorType, producerOp, "return-path host copy byte size");
|
||||
if (failed(byteSize))
|
||||
|
||||
Reference in New Issue
Block a user