Commit 86e5d883 by Nicolas Capens Committed by Nicolas Capens

Ensure NoDefinitions gets initialized only at first use.

As a global, NoDefinitions could get initialized at program startup, which happens specifically with Visual Studio. This causes the progam to abort because its initialization depends on a TLS variable to be (manually) initialized first. Since there's only one use of NoDefinitions, it can be moved to that location and since it's at function scope it only gets constructed at first use. BUG=swiftshader:7 Change-Id: I30801ad0d0ab380ead33069f174bb78dc1b230ab Reviewed-on: https://chromium-review.googlesource.com/379955Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarJim Stichnoth <stichnot@chromium.org>
parent 0e137b2e
...@@ -509,8 +509,17 @@ const Inst *VariablesMetadata::getFirstDefinition(const Variable *Var) const { ...@@ -509,8 +509,17 @@ const Inst *VariablesMetadata::getFirstDefinition(const Variable *Var) const {
const InstDefList & const InstDefList &
VariablesMetadata::getLatterDefinitions(const Variable *Var) const { VariablesMetadata::getLatterDefinitions(const Variable *Var) const {
assert(Kind == VMK_All); assert(Kind == VMK_All);
if (!isTracked(Var)) if (!isTracked(Var)) {
return NoDefinitions; // NoDefinitions has to be initialized after we've had a chance to set the
// CfgAllocator, so it can't be a static global object. Also, while C++11
// guarantees the initialization of static local objects to be thread-safe,
// we use a pointer to it so we can avoid frequent mutex locking overhead.
if (NoDefinitions == nullptr) {
static const InstDefList NoDefinitionsInstance;
NoDefinitions = &NoDefinitionsInstance;
}
return *NoDefinitions;
}
SizeT VarNum = Var->getIndex(); SizeT VarNum = Var->getIndex();
return Metadata[VarNum].getLatterDefinitions(); return Metadata[VarNum].getLatterDefinitions();
} }
...@@ -529,7 +538,7 @@ RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const { ...@@ -529,7 +538,7 @@ RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const {
return Metadata[VarNum].getUseWeight(); return Metadata[VarNum].getUseWeight();
} }
const InstDefList VariablesMetadata::NoDefinitions; const InstDefList *VariablesMetadata::NoDefinitions = nullptr;
// ======================== dump routines ======================== // // ======================== dump routines ======================== //
......
...@@ -1075,7 +1075,7 @@ private: ...@@ -1075,7 +1075,7 @@ private:
const Cfg *Func; const Cfg *Func;
MetadataKind Kind; MetadataKind Kind;
CfgVector<VariableTracking> Metadata; CfgVector<VariableTracking> Metadata;
const static InstDefList NoDefinitions; static const InstDefList *NoDefinitions;
}; };
/// BooleanVariable represents a variable that was the zero-extended result of a /// BooleanVariable represents a variable that was the zero-extended result of a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment