Extract out a function onto CodeGenModule for getting the map of

features for a particular function, then use it to clean up some
code.

llvm-svn: 252819
This commit is contained in:
Eric Christopher
2015-11-11 23:05:08 +00:00
parent cc9030b60a
commit 2b90a64e31
5 changed files with 47 additions and 44 deletions

View File

@@ -3875,3 +3875,32 @@ llvm::MDTuple *CodeGenModule::CreateVTableBitSetEntry(
llvm::ConstantInt::get(Int64Ty, Offset.getQuantity()))};
return llvm::MDTuple::get(getLLVMContext(), BitsetOps);
}
// Fills in the supplied string map with the set of target features for the
// passed in function.
void CodeGenModule::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
const FunctionDecl *FD) {
StringRef TargetCPU = Target.getTargetOpts().CPU;
if (const auto *TD = FD->getAttr<TargetAttr>()) {
// If we have a TargetAttr build up the feature map based on that.
TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
// Make a copy of the features as passed on the command line into the
// beginning of the additional features from the function to override.
ParsedAttr.first.insert(ParsedAttr.first.begin(),
Target.getTargetOpts().FeaturesAsWritten.begin(),
Target.getTargetOpts().FeaturesAsWritten.end());
if (ParsedAttr.second != "")
TargetCPU = ParsedAttr.second;
// Now populate the feature map, first with the TargetCPU which is either
// the default or a new one from the target attribute string. Then we'll use
// the passed in features (FeaturesAsWritten) along with the new ones from
// the attribute.
Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU, ParsedAttr.first);
} else {
Target.initFeatureMap(FeatureMap, getDiags(), TargetCPU,
Target.getTargetOpts().Features);
}
}