File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-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,26 @@ 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
+ auto aliases = analysis.resolveReverse (deallocMemref);
106
+ Value topAllocMemref = allocStack.back ()->getResults ().front ();
107
+ if (aliases.find (topAllocMemref) != aliases.end ()) {
108
+ allocStack.pop_back ();
109
+ } else {
110
+ noTransformOps.insert (op);
111
+ for (int i = allocStack.size () - 1 ; i >= 0 ; --i) {
112
+ Operation *curAlloc = allocStack[i];
113
+ if (aliases.find (curAlloc->getResults ().front ()) !=
114
+ aliases.end ()) {
115
+ noTransformOps.insert (curAlloc);
116
+ allocStack.erase (allocStack.begin () + i);
117
+ }
118
+ }
119
+ }
99
120
}
100
121
});
101
122
});
You can’t perform that action at this time.
0 commit comments