@@ -128,13 +128,18 @@ static std::optional<unsigned> findOneNVVMAnnotation(const GlobalValue *gv,
128128 auto &AC = getAnnotationCache ();
129129 std::lock_guard<sys::Mutex> Guard (AC.Lock );
130130 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 ())
132133 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 ())
134135 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 ())
136141 return std::nullopt ;
137- return AC. Cache [m][gv][prop] [0 ];
142+ return It-> second [0 ];
138143}
139144
140145static bool findAllNVVMAnnotation (const GlobalValue *gv,
@@ -143,13 +148,18 @@ static bool findAllNVVMAnnotation(const GlobalValue *gv,
143148 auto &AC = getAnnotationCache ();
144149 std::lock_guard<sys::Mutex> Guard (AC.Lock );
145150 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 ())
147153 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 ())
149155 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 ())
151161 return false ;
152- retval = AC. Cache [m][gv][prop] ;
162+ retval = It-> second ;
153163 return true ;
154164}
155165
0 commit comments