File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ struct ConvertMemRefToCPURuntime
77
77
auto *ctx = &getContext ();
78
78
// Create a local set to store operations that should not be transformed.
79
79
llvm::SmallSet<Operation *, 16 > noTransformOps;
80
+ llvm::SmallVector<Operation *, 16 > allocStack;
80
81
81
82
// Walk through the module to find func::FuncOp instances.
82
83
getOperation ()->walk ([&](func::FuncOp funcOp) {
@@ -96,6 +97,24 @@ struct ConvertMemRefToCPURuntime
96
97
}
97
98
}
98
99
}
100
+ } else if (isa<memref::AllocOp>(op)) {
101
+ allocStack.push_back (op);
102
+ } else if (isa<memref::DeallocOp>(op)) {
103
+ // fallback alloc / dealloc not in FILO fashion
104
+ Value deallocMemref = op->getOperands ().front ();
105
+ Value topAllocMemref = allocStack.back ()->getResults ().front ();
106
+ if (deallocMemref == topAllocMemref) {
107
+ allocStack.pop_back ();
108
+ } else {
109
+ noTransformOps.insert (op);
110
+ for (int i = allocStack.size () - 1 ; i >= 0 ; --i) {
111
+ Operation *curAlloc = allocStack[i];
112
+ if (deallocMemref == curAlloc->getResults ().front ()) {
113
+ noTransformOps.insert (curAlloc);
114
+ allocStack.erase (allocStack.begin () + i);
115
+ }
116
+ }
117
+ }
99
118
}
100
119
});
101
120
});
You can’t perform that action at this time.
0 commit comments