Skip to content

Commit 4155326

Browse files
Huang, Haixinzhczhong
authored andcommitted
fix global_ctors lookup
1 parent b824db2 commit 4155326

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/gc/Transforms/Microkernel/EarlyDispatchMicrokernel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ getOrCreateGlobalKernelHandle(RewriterBase &rewriter, ModuleOp module,
106106
// initialize the gloabl with global_ctors, as the initializer of global
107107
// does not allow side effect
108108
rewriter.setInsertionPointToStart(module.getBody());
109-
LLVM::GlobalCtorsOp global_ctors =
110-
module.lookupSymbol<LLVM::GlobalCtorsOp>(getGlobalCtorsVarName());
109+
LLVM::GlobalCtorsOp global_ctors = nullptr;
110+
for (auto &op : module->getRegion(0).front()) {
111+
auto ctorOp = dyn_cast<LLVM::GlobalCtorsOp>(op);
112+
if (ctorOp) {
113+
global_ctors = ctorOp;
114+
break;
115+
}
116+
}
117+
111118
SmallVector<Attribute> ctorRefs;
112119
SmallVector<Attribute> priorities;
113120
if (global_ctors) {
@@ -117,16 +124,20 @@ getOrCreateGlobalKernelHandle(RewriterBase &rewriter, ModuleOp module,
117124
ctorRefs.push_back(ctor);
118125
priorities.push_back(prior);
119126
}
127+
LLVM_DEBUG(llvm::dbgs()
128+
<< "After append ctors: " << ctorRefs.size() << "\n");
120129
}
121130
ctorRefs.push_back(ctorName);
122131
// Set new ctor's priority to lowest
123132
priorities.push_back(IntegerAttr::get(rewriter.getI32Type(), INT_MAX));
124133
if (global_ctors) {
134+
LLVM_DEBUG(llvm::dbgs() << "Replace existing ctors\n");
125135
// If there's existing ctors
126136
rewriter.replaceOpWithNewOp<LLVM::GlobalCtorsOp>(
127137
global_ctors, rewriter.getArrayAttr(ctorRefs),
128138
rewriter.getArrayAttr(priorities));
129139
} else {
140+
LLVM_DEBUG(llvm::dbgs() << "Create new ctor\n");
130141
rewriter.create<LLVM::GlobalCtorsOp>(module.getLoc(),
131142
rewriter.getArrayAttr(ctorRefs),
132143
rewriter.getArrayAttr(priorities));

0 commit comments

Comments
 (0)