summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/TargetInfo.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2015-08-31 18:39:22 +0000
committerEric Christopher <echristo@gmail.com>2015-08-31 18:39:22 +0000
commitd40722e26787a6e080e0de30d8980bc15da93ec9 (patch)
tree1986fce43b4b2b38a5dec81a06f81236a5a9799c /clang/lib/Basic/TargetInfo.cpp
parenta8a14c3d884955453f8eb875434f81a1875d7cb1 (diff)
downloadbcm5719-llvm-d40722e26787a6e080e0de30d8980bc15da93ec9.tar.gz
bcm5719-llvm-d40722e26787a6e080e0de30d8980bc15da93ec9.zip
Pull the target attribute parsing out of CGCall and onto TargetInfo.
Also: - Add a typedef to make working with the result easier. - Update callers to use the new function. - Make initFeatureMap out of line. llvm-svn: 246468
Diffstat (limited to 'clang/lib/Basic/TargetInfo.cpp')
-rw-r--r--clang/lib/Basic/TargetInfo.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 30378a5a751..2ee705272dd 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -650,3 +650,50 @@ bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
return true;
}
+
+bool TargetInfo::initFeatureMap(llvm::StringMap<bool> &Features,
+ DiagnosticsEngine &Diags, StringRef CPU,
+ std::vector<std::string> &FeatureVec) const {
+ for (const auto &F : FeatureVec) {
+ const char *Name = F.c_str();
+ // Apply the feature via the target.
+ bool Enabled = Name[0] == '+';
+ setFeatureEnabled(Features, Name + 1, Enabled);
+ }
+ return true;
+}
+
+TargetInfo::ParsedTargetAttr
+TargetInfo::parseTargetAttr(const TargetAttr *TA) const {
+ std::pair<StringRef, std::vector<std::string>> RetPair;
+
+ // Grab the target attribute string.
+ StringRef FeaturesStr = TA->getFeatures();
+ SmallVector<StringRef, 1> AttrFeatures;
+ FeaturesStr.split(AttrFeatures, ",");
+
+ // Grab the various features and prepend a "+" to turn on the feature to
+ // the backend and add them to our existing set of features.
+ for (auto &Feature : AttrFeatures) {
+ // Go ahead and trim whitespace rather than either erroring or
+ // accepting it weirdly.
+ Feature = Feature.trim();
+
+ // While we're here iterating check for a different target cpu.
+ if (Feature.startswith("arch="))
+ RetPair.first = Feature.split("=").second.trim();
+ else if (Feature.startswith("tune="))
+ // We don't support cpu tuning this way currently.
+ ;
+ else if (Feature.startswith("fpmath="))
+ // TODO: Support the fpmath option this way. It will require checking
+ // overall feature validity for the function with the rest of the
+ // attributes on the function.
+ ;
+ else if (Feature.startswith("no-"))
+ RetPair.second.push_back("-" + Feature.split("-").second.str());
+ else
+ RetPair.second.push_back("+" + Feature.str());
+ }
+ return RetPair;
+}
OpenPOWER on IntegriCloud