MCPcopy Create free account
hub / github.com/MegEngine/MegCC / Reshape>

Method Reshape>

compiler/lib/Dialect/Kernel/Transforms/MemoryForwarding.cpp:93–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92template <>
93LogicalResult onMemoryForwardFailure<Kernel::Reshape>(
94 Kernel::Reshape op, PatternRewriter& rewriter) {
95 Value input = op->getOperand(0), output = op->getResult(0);
96 MemRefType outputType = output.getType().dyn_cast<MemRefType>();
97 Value newOutput = rewriter.create<memref::AllocOp>(
98 op->getLoc(),
99 MemRefType::get(outputType.getShape(), outputType.getElementType()));
100 MemRefType inputType = input.getType().dyn_cast<MemRefType>();
101 Value newOutputReshaped = rewriter.create<Kernel::Reshape>(
102 op->getLoc(),
103 MemRefType::get(inputType.getShape(), inputType.getElementType()),
104 newOutput, true);
105 rewriter.create<Kernel::RelayoutKernel>(op->getLoc(), input, newOutputReshaped);
106 rewriter.replaceOp(op, newOutput);
107 return success();
108}
109
110template <typename OpTy>
111class MemFwdOpConversion final : public OpRewritePattern<OpTy> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected