@@ -2307,34 +2307,6 @@ void CGBuilderInserter::InsertHelper(
2307
2307
CGF->InsertHelper (I, Name, BB, InsertPt);
2308
2308
}
2309
2309
2310
- static bool hasRequiredFeatures (const SmallVectorImpl<StringRef> &ReqFeatures,
2311
- CodeGenModule &CGM, const FunctionDecl *FD,
2312
- std::string &FirstMissing) {
2313
- // If there aren't any required features listed then go ahead and return.
2314
- if (ReqFeatures.empty ())
2315
- return false ;
2316
-
2317
- // Now build up the set of caller features and verify that all the required
2318
- // features are there.
2319
- llvm::StringMap<bool > CallerFeatureMap;
2320
- CGM.getContext ().getFunctionFeatureMap (CallerFeatureMap, FD);
2321
-
2322
- // If we have at least one of the features in the feature list return
2323
- // true, otherwise return false.
2324
- return std::all_of (
2325
- ReqFeatures.begin (), ReqFeatures.end (), [&](StringRef Feature) {
2326
- SmallVector<StringRef, 1 > OrFeatures;
2327
- Feature.split (OrFeatures, ' |' );
2328
- return llvm::any_of (OrFeatures, [&](StringRef Feature) {
2329
- if (!CallerFeatureMap.lookup (Feature)) {
2330
- FirstMissing = Feature.str ();
2331
- return false ;
2332
- }
2333
- return true ;
2334
- });
2335
- });
2336
- }
2337
-
2338
2310
// Emits an error if we don't have a valid set of target features for the
2339
2311
// called function.
2340
2312
void CodeGenFunction::checkTargetFeatures (const CallExpr *E,
@@ -2361,19 +2333,20 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
2361
2333
// listed cpu and any listed features.
2362
2334
unsigned BuiltinID = TargetDecl->getBuiltinID ();
2363
2335
std::string MissingFeature;
2336
+ llvm::StringMap<bool > CallerFeatureMap;
2337
+ CGM.getContext ().getFunctionFeatureMap (CallerFeatureMap, FD);
2364
2338
if (BuiltinID) {
2365
- SmallVector<StringRef, 1 > ReqFeatures;
2366
- const char *FeatureList =
2367
- CGM.getContext ().BuiltinInfo .getRequiredFeatures (BuiltinID);
2339
+ StringRef FeatureList (
2340
+ CGM.getContext ().BuiltinInfo .getRequiredFeatures (BuiltinID));
2368
2341
// Return if the builtin doesn't have any required features.
2369
- if (! FeatureList || StringRef (FeatureList) == " " )
2342
+ if (FeatureList. empty () )
2370
2343
return ;
2371
- StringRef (FeatureList).split (ReqFeatures, ' ,' );
2372
- if (!hasRequiredFeatures (ReqFeatures, CGM, FD, MissingFeature))
2344
+ assert (FeatureList.find (' ' ) == StringRef::npos &&
2345
+ " Space in feature list" );
2346
+ TargetFeatures TF (CallerFeatureMap);
2347
+ if (!TF.hasRequiredFeatures (FeatureList))
2373
2348
CGM.getDiags ().Report (Loc, diag::err_builtin_needs_feature)
2374
- << TargetDecl->getDeclName ()
2375
- << CGM.getContext ().BuiltinInfo .getRequiredFeatures (BuiltinID);
2376
-
2349
+ << TargetDecl->getDeclName () << FeatureList;
2377
2350
} else if (!TargetDecl->isMultiVersion () &&
2378
2351
TargetDecl->hasAttr <TargetAttr>()) {
2379
2352
// Get the required features for the callee.
@@ -2396,7 +2369,13 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
2396
2369
if (F.getValue ())
2397
2370
ReqFeatures.push_back (F.getKey ());
2398
2371
}
2399
- if (!hasRequiredFeatures (ReqFeatures, CGM, FD, MissingFeature))
2372
+ if (!llvm::all_of (ReqFeatures, [&](StringRef Feature) {
2373
+ if (!CallerFeatureMap.lookup (Feature)) {
2374
+ MissingFeature = Feature.str ();
2375
+ return false ;
2376
+ }
2377
+ return true ;
2378
+ }))
2400
2379
CGM.getDiags ().Report (Loc, diag::err_function_needs_feature)
2401
2380
<< FD->getDeclName () << TargetDecl->getDeclName () << MissingFeature;
2402
2381
}
0 commit comments