Skip to content

Commit 15ef84e

Browse files
committed
Crash fix
1 parent d765bb9 commit 15ef84e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/polygeist/Passes/LinalgToKernel.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ FailureOr<StringRef> matchGenericWithDefn(
111111

112112
SmallVector<kernel::DefnOp> defnOps;
113113

114+
//llvm::errs() << "DEBUG: kernel.defn_collection contents:\n";
115+
//llvm::errs() << collectionOp;
116+
//llvm::errs() << collectionOp.getOperation();
117+
//llvm::errs() << "\n";
114118
collectionOp.walk([&](kernel::DefnOp defnOp) {
115119
defnOps.push_back(defnOp);
116120
});
@@ -254,19 +258,19 @@ struct LinalgToKernelPass : public LinalgToKernelBase<LinalgToKernelPass> {
254258
void runOnOperation() override {
255259
ModuleOp module = getOperation();
256260

257-
kernel::DefnCollectionOp collectionOp;
258-
261+
kernel::DefnCollectionOp collectionOp = nullptr;
262+
OwningOpRef<ModuleOp> externalModule;
259263
// Determine which path to use for kernel library
260264
std::string effectiveLibraryPath = externalLibraryPath;
261265
// If no external path was provided via constructor, try the command line option
262266
if (effectiveLibraryPath.empty()) {
263267
effectiveLibraryPath = std::string(kernelLibraryPath);
264268
}
265269

266-
// Debug output
267-
llvm::errs() << "DEBUG: externalLibraryPath = '" << externalLibraryPath << "'\n";
268-
llvm::errs() << "DEBUG: kernelLibraryPath = '" << std::string(kernelLibraryPath) << "'\n";
269-
llvm::errs() << "DEBUG: effectiveLibraryPath = '" << effectiveLibraryPath << "'\n";
270+
//// Debug output
271+
//llvm::errs() << "DEBUG: externalLibraryPath = '" << externalLibraryPath << "'\n";
272+
//llvm::errs() << "DEBUG: kernelLibraryPath = '" << std::string(kernelLibraryPath) << "'\n";
273+
//llvm::errs() << "DEBUG: effectiveLibraryPath = '" << effectiveLibraryPath << "'\n";
270274

271275
// Check if we should load kernel definitions from an external file
272276
if (!effectiveLibraryPath.empty()) {
@@ -284,7 +288,7 @@ struct LinalgToKernelPass : public LinalgToKernelBase<LinalgToKernelPass> {
284288
llvm::SourceMgr sourceMgr;
285289
sourceMgr.AddNewSourceBuffer(std::move(memoryBuffer), llvm::SMLoc());
286290

287-
auto externalModule = mlir::parseSourceFile<ModuleOp>(sourceMgr, &getContext());
291+
externalModule = mlir::parseSourceFile<ModuleOp>(sourceMgr, &getContext());
288292
if (!externalModule) {
289293
module.emitError("Failed to parse kernel library file: ") << effectiveLibraryPath;
290294
return signalPassFailure();
@@ -310,7 +314,8 @@ struct LinalgToKernelPass : public LinalgToKernelBase<LinalgToKernelPass> {
310314

311315
// Debug: Print the found collection
312316
//llvm::errs() << "DEBUG: kernel.defn_collection contents:\n";
313-
//collectionOp.print(llvm::errs());
317+
//llvm::errs() << collectionOp;
318+
//llvm::errs() << collectionOp.getOperation();
314319
//llvm::errs() << "\n";
315320
} else {
316321
// Find the kernel.defn_collection in the current module (original behavior)
@@ -330,6 +335,12 @@ struct LinalgToKernelPass : public LinalgToKernelBase<LinalgToKernelPass> {
330335
// Apply the rewrite pattern
331336
RewritePatternSet patterns(&getContext());
332337
patterns.add<LinalgGenericToKernelPattern>(&getContext(), collectionOp);
338+
339+
//llvm::errs() << "DEBUG: kernel.defn_collection contents:\n";
340+
//llvm::errs() << collectionOp.getOperation();
341+
//llvm::errs() << "\n";
342+
//llvm::errs() << collectionOp;
343+
//llvm::errs() << "\n";
333344

334345
if (failed(applyPatternsAndFoldGreedily(module, std::move(patterns))))
335346
return signalPassFailure();

0 commit comments

Comments
 (0)