[PATCH] CodeGen: Emit globals with a constant initializer but no definition as available_externally.
Reid Kleckner
rnk at google.com
Wed Oct 23 14:35:39 PDT 2013
================
Comment at: lib/CodeGen/CodeGenModule.cpp:1244-1247
@@ +1243,6 @@
+bool CodeGenModule::shouldEmitGlobalVariable(const VarDecl *VD) {
+ if (GetLLVMLinkageVarDefinition(VD, /*isConstant=*/true) !=
+ llvm::Function::AvailableExternallyLinkage)
+ return true;
+ return CodeGenOpts.OptimizationLevel != 0;
+}
----------------
This seems more intuitive as:
if (isAvailableExternally)
return CGO.OptLevel != 0;
return true;
Also, how do we know isConstant is true? Can you assert that it is like you do below?
================
Comment at: lib/CodeGen/CodeGenModule.cpp:1846
@@ +1845,3 @@
+ "Variable with init but no definition should be constant!");
+ return llvm::GlobalValue::AvailableExternallyLinkage;
+ }
----------------
What if the variable is thread local, or fits any of the below special cases involving templates? This probably goes towards the end of the if/else chain, not first, considering that it's for an optimization.
http://llvm-reviews.chandlerc.com/D1982
More information about the cfe-commits
mailing list