-
Notifications
You must be signed in to change notification settings - Fork 188
[CIR] Implement static local variable initialization with guard variables #2046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh/lanza/20/base
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -636,8 +636,9 @@ CIRGenFunction::addInitializerToStaticVarDecl(const VarDecl &varDecl, | |
| else { | ||
| // Since we have a static initializer, this global variable can't | ||
| // be constant. | ||
| llvm_unreachable("C++ guarded init it NYI"); | ||
| globalOp.setConstant(false); | ||
| emitCXXGuardedInit(varDecl, globalOp, /*performInit*/ true); | ||
| getGlobalOp.setStaticLocal(true); | ||
| } | ||
| return globalOp; | ||
| } | ||
|
|
@@ -660,13 +661,34 @@ CIRGenFunction::addInitializerToStaticVarDecl(const VarDecl &varDecl, | |
| if (globalOp.getSymType() != typedInit.getType()) { | ||
| globalOp.setSymType(typedInit.getType()); | ||
|
|
||
| cir::GlobalOp oldGlobalOp = globalOp; | ||
| globalOp = | ||
| builder.createGlobal(CGM.getModule(), getLoc(varDecl.getSourceRange()), | ||
| oldGlobalOp.getName(), typedInit.getType(), | ||
| oldGlobalOp.getConstant(), globalOp.getLinkage()); | ||
| // FIXME(cir): OG codegen inserts new GV before old one, we probably don't | ||
| // need that? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LLVM translation usually put them out in the proper order, because of the way MLIR handles this I don't think it should be a problem for us. |
||
| globalOp.setVisibility(oldGlobalOp.getVisibility()); | ||
| globalOp.setGlobalVisibilityAttr(oldGlobalOp.getGlobalVisibilityAttr()); | ||
| globalOp.setInitialValueAttr(typedInit); | ||
| globalOp.setTlsModelAttr(oldGlobalOp.getTlsModelAttr()); | ||
| globalOp.setDSOLocal(oldGlobalOp.getDsoLocal()); | ||
| assert(!cir::MissingFeatures::setComdat()); | ||
| assert(!cir::MissingFeatures::addressSpaceInGlobalVar()); | ||
|
|
||
| // Normally this should be done with a call to CGM.replaceGlobal(OldGV, GV), | ||
| // but since at this point the current block hasn't been really attached, | ||
| // there's no visibility into the GetGlobalOp corresponding to this Global. | ||
| // Given those constraints, thread in the GetGlobalOp and update it | ||
| // directly. | ||
| getGlobalOp.getAddr().setType(getBuilder().getPointerTo( | ||
| typedInit.getType(), globalOp.getAddrSpaceAttr())); | ||
|
|
||
| // Replace all uses of the old global with the new global | ||
| oldGlobalOp->replaceAllUsesWith(globalOp); | ||
|
|
||
| // Erase the old global, since it is no longer used. | ||
| oldGlobalOp->erase(); | ||
| } | ||
|
|
||
| bool needsDtor = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2243,6 +2243,19 @@ class CIRGenFunction : public CIRGenTypeCache { | |
|
|
||
| void emitInvariantStart(CharUnits Size); | ||
|
|
||
| /// Emit code in this function to perform a guarded variable | ||
| /// initialization. Guarded initializations are used when it's not | ||
| /// possible to prove that an initialization will be done exactly | ||
| /// once, e.g. with a static local variable or a static data member | ||
| /// of a class template. | ||
| void emitCXXGuardedInit(const VarDecl &varDecl, cir::GlobalOp globalOp, | ||
| bool performInit); | ||
|
|
||
| /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
| /// variable with global storage. | ||
| void emitCXXGlobalVarDeclInit(const VarDecl &varDecl, cir::GlobalOp globalOp, | ||
| bool performInit); | ||
|
|
||
| mlir::LogicalResult emitLabel(const clang::LabelDecl *D); | ||
| mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &S); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.