================ @@ -269,6 +269,40 @@ mlir::Operation *CIRGenModule::getGlobalValue(StringRef name) { return mlir::SymbolTable::lookupSymbolIn(theModule, name); } +cir::GlobalOp CIRGenModule::createGlobalOp(CIRGenModule &cgm, + mlir::Location loc, StringRef name, + mlir::Type t, + mlir::Operation *insertPoint) { + cir::GlobalOp g; + CIRGenBuilderTy &builder = cgm.getBuilder(); + + { + mlir::OpBuilder::InsertionGuard guard(builder); + + // Some global emissions are triggered while emitting a function, e.g. + // void s() { const char *s = "yolo"; ... } + // + // Be sure to insert global before the current function + CIRGenFunction *curCGF = cgm.curCGF; + if (curCGF) + builder.setInsertionPoint(curCGF->curFn); + + g = builder.create<cir::GlobalOp>(loc, name, t); + if (!curCGF) { + if (insertPoint) + cgm.getModule().insert(insertPoint, g); ---------------- erichkeane wrote:
It would be kind of neat here if a null-insertion point to 'insert' just got interpreted as the 'end' instead, to avoid us from having to do this. https://github.com/llvm/llvm-project/pull/138222 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits