summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2015-11-11 23:05:08 +0000
committerEric Christopher <echristo@gmail.com>2015-11-11 23:05:08 +0000
commit2b90a64e319be87760ca2b4323362b1b0e403182 (patch)
treec96388aa8f24b4bb46e9d39f0255a15a30f74709 /clang/lib/CodeGen
parentcc9030b60a4b84e3057836eaef2e2fc39b2712c8 (diff)
downloadbcm5719-llvm-2b90a64e319be87760ca2b4323362b1b0e403182.tar.gz
bcm5719-llvm-2b90a64e319be87760ca2b4323362b1b0e403182.zip
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
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp29
-rw-r--r--clang/lib/CodeGen/CGCall.cpp26
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h2
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp29
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h5
5 files changed, 47 insertions, 44 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 16969918794..f82302bd74a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -353,7 +353,8 @@ bool CodeGenFunction::checkBuiltinTargetFeatures(
// Get the current enclosing function if it exists. If it doesn't
// we can't check the target features anyhow.
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl);
- if (!FD) return true;
+ if (!FD)
+ return true;
unsigned BuiltinID = TargetDecl->getBuiltinID();
const char *FeatureList =
@@ -362,32 +363,8 @@ bool CodeGenFunction::checkBuiltinTargetFeatures(
if (!FeatureList || StringRef(FeatureList) == "")
return true;
- StringRef TargetCPU = Target.getTargetOpts().CPU;
llvm::StringMap<bool> FeatureMap;
-
- 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, CGM.getDiags(), TargetCPU,
- ParsedAttr.first);
- } else {
- Target.initFeatureMap(FeatureMap, CGM.getDiags(), TargetCPU,
- Target.getTargetOpts().Features);
- }
+ CGM.getFunctionFeatureMap(FeatureMap, FD);
// If we have at least one of the features in the feature list return
// true, otherwise return false.
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 99a093223d1..430184d4398 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1506,24 +1506,7 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
if (FD && FD->hasAttr<TargetAttr>()) {
llvm::StringMap<bool> FeatureMap;
- const auto *TD = FD->getAttr<TargetAttr>();
- 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(),
- getTarget().getTargetOpts().FeaturesAsWritten.begin(),
- getTarget().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.
- getTarget().initFeatureMap(FeatureMap, Diags, TargetCPU, ParsedAttr.first);
+ getFunctionFeatureMap(FeatureMap, FD);
// Produce the canonical string for this set of features.
std::vector<std::string> Features;
@@ -1533,6 +1516,13 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
Features.push_back((it->second ? "+" : "-") + it->first().str());
// Now add the target-cpu and target-features to the function.
+ // While we populated the feature map above, we still need to
+ // get and parse the target attribute so we can get the cpu for
+ // the function.
+ const auto *TD = FD->getAttr<TargetAttr>();
+ TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
+ if (ParsedAttr.second != "")
+ TargetCPU = ParsedAttr.second;
if (TargetCPU != "")
FuncAttrs.addAttribute("target-cpu", TargetCPU);
if (!Features.empty()) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 4b0c4905351..1aab00e10d2 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2638,6 +2638,8 @@ public:
RValue EmitCallExpr(const CallExpr *E,
ReturnValueSlot ReturnValue = ReturnValueSlot());
+ void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
+ const FunctionDecl *FD);
bool checkBuiltinTargetFeatures(const FunctionDecl *TargetDecl);
llvm::CallInst *EmitRuntimeCall(llvm::Value *callee,
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d36a85df54c..5f4de74014f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -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);
+ }
+}
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index d3f6e515ad1..b9a5c8d2e6a 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -979,6 +979,11 @@ public:
unsigned &CallingConv,
bool AttrOnCallSite);
+ // Fills in the supplied string map with the set of target features for the
+ // passed in function.
+ void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
+ const FunctionDecl *FD);
+
StringRef getMangledName(GlobalDecl GD);
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
OpenPOWER on IntegriCloud