@@ -128,13 +128,18 @@ static std::optional<unsigned> findOneNVVMAnnotation(const GlobalValue *gv,
128
128
auto &AC = getAnnotationCache ();
129
129
std::lock_guard<sys::Mutex> Guard (AC.Lock );
130
130
const Module *m = gv->getParent ();
131
- if (AC.Cache .find (m) == AC.Cache .end ())
131
+ auto ACIt = AC.Cache .find (m);
132
+ if (ACIt == AC.Cache .end ())
132
133
cacheAnnotationFromMD (m, gv);
133
- else if (AC. Cache [m]. find (gv) == AC. Cache [m] .end ())
134
+ else if (ACIt-> second . find (gv) == ACIt-> second .end ())
134
135
cacheAnnotationFromMD (m, gv);
135
- if (AC.Cache [m][gv].find (prop) == AC.Cache [m][gv].end ())
136
+ // Look up AC.Cache[m][gv] again because cacheAnnotationFromMD may have
137
+ // inserted the entry.
138
+ auto &KVP = AC.Cache [m][gv];
139
+ auto It = KVP.find (prop);
140
+ if (It == KVP.end ())
136
141
return std::nullopt;
137
- return AC. Cache [m][gv][prop] [0 ];
142
+ return It-> second [0 ];
138
143
}
139
144
140
145
static bool findAllNVVMAnnotation (const GlobalValue *gv,
@@ -143,13 +148,18 @@ static bool findAllNVVMAnnotation(const GlobalValue *gv,
143
148
auto &AC = getAnnotationCache ();
144
149
std::lock_guard<sys::Mutex> Guard (AC.Lock );
145
150
const Module *m = gv->getParent ();
146
- if (AC.Cache .find (m) == AC.Cache .end ())
151
+ auto ACIt = AC.Cache .find (m);
152
+ if (ACIt == AC.Cache .end ())
147
153
cacheAnnotationFromMD (m, gv);
148
- else if (AC. Cache [m]. find (gv) == AC. Cache [m] .end ())
154
+ else if (ACIt-> second . find (gv) == ACIt-> second .end ())
149
155
cacheAnnotationFromMD (m, gv);
150
- if (AC.Cache [m][gv].find (prop) == AC.Cache [m][gv].end ())
156
+ // Look up AC.Cache[m][gv] again because cacheAnnotationFromMD may have
157
+ // inserted the entry.
158
+ auto &KVP = AC.Cache [m][gv];
159
+ auto It = KVP.find (prop);
160
+ if (It == KVP.end ())
151
161
return false ;
152
- retval = AC. Cache [m][gv][prop] ;
162
+ retval = It-> second ;
153
163
return true ;
154
164
}
155
165
0 commit comments