r246128 - Pass in a cpu to initDefaultFeatures so that we can share this code

Eric Christopher via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 17:05:52 PDT 2015


Author: echristo
Date: Wed Aug 26 19:05:52 2015
New Revision: 246128

URL: http://llvm.org/viewvc/llvm-project?rev=246128&view=rev
Log:
Pass in a cpu to initDefaultFeatures so that we can share this code
with multiple uses of feature map construction.

Note: We could make this a static function on TargetInfo if we
fix the x86 port needing to check the triple in an isolated case.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=246128&r1=246127&r2=246128&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Aug 26 19:05:52 2015
@@ -741,10 +741,9 @@ public:
   virtual void adjust(const LangOptions &Opts);
 
   /// \brief Initialize the map with the default set of target features for the
-  /// CPU, ABI, and FPMath options - these should have already been set prior
-  /// to calling this function; this should include all legal feature strings on
-  /// the target.
-  virtual void initDefaultFeatures(llvm::StringMap<bool> &Features) const {}
+  /// CPU this should include all legal feature strings on the target.
+  virtual void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                                   StringRef CPU) const {}
 
   /// \brief Get the ABI currently in use.
   virtual StringRef getABI() const { return StringRef(); }

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246128&r1=246127&r2=246128&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Aug 26 19:05:52 2015
@@ -863,7 +863,8 @@ public:
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override;
 
-  void initDefaultFeatures(llvm::StringMap<bool> &Features) const override;
+  void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                           StringRef CPU) const override;
 
   bool handleTargetFeatures(std::vector<std::string> &Features,
                             DiagnosticsEngine &Diags) override;
@@ -1262,7 +1263,8 @@ void PPCTargetInfo::getTargetDefines(con
   //   __NO_FPRS__
 }
 
-void PPCTargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features) const {
+void PPCTargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features,
+                                        StringRef CPU) const {
   Features["altivec"] = llvm::StringSwitch<bool>(CPU)
     .Case("7400", true)
     .Case("g4", true)
@@ -2372,7 +2374,8 @@ public:
   // initDefaultFeatures which calls this repeatedly.
   static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
                                     StringRef Name, bool Enabled);
-  void initDefaultFeatures(llvm::StringMap<bool> &Features) const override;
+  void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                           StringRef CPU) const override;
   bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector<std::string> &Features,
                             DiagnosticsEngine &Diags) override;
@@ -2498,14 +2501,15 @@ bool X86TargetInfo::setFPMath(StringRef
   return false;
 }
 
-void X86TargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features) const {
+void X86TargetInfo::initDefaultFeatures(llvm::StringMap<bool> &Features,
+                                        StringRef CPU) const {
   // FIXME: This *really* should not be here.
 
   // X86_64 always has SSE2.
   if (getTriple().getArch() == llvm::Triple::x86_64)
     setFeatureEnabledImpl(Features, "sse2", true);
 
-  switch (CPU) {
+  switch (getCPUKind(CPU)) {
   case CK_Generic:
   case CK_i386:
   case CK_i486:
@@ -4375,7 +4379,8 @@ public:
   }
 
   // FIXME: This should be based on Arch attributes, not CPU names.
-  void initDefaultFeatures(llvm::StringMap<bool> &Features) const override {
+  void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                           StringRef CPU) const override {
     if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
       Features["vfp2"] = true;
     else if (CPU == "cortex-a8" || CPU == "cortex-a9") {
@@ -5818,7 +5823,8 @@ public:
 
     return CPUKnown;
   }
-  void initDefaultFeatures(llvm::StringMap<bool> &Features) const override {
+  void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                           StringRef CPU) const override {
     if (CPU == "zEC12")
       Features["transactional-execution"] = true;
     if (CPU == "z13") {
@@ -6185,7 +6191,8 @@ public:
         .Default(false);
   }
   const std::string& getCPU() const { return CPU; }
-  void initDefaultFeatures(llvm::StringMap<bool> &Features) const override {
+  void initDefaultFeatures(llvm::StringMap<bool> &Features,
+                           StringRef CPU) const override {
     if (CPU == "octeon")
       Features["mips64r2"] = Features["cnmips"] = true;
     else
@@ -7475,7 +7482,7 @@ TargetInfo::CreateTargetInfo(Diagnostics
   // Compute the default target features, we need the target to handle this
   // because features may have dependencies on one another.
   llvm::StringMap<bool> Features;
-  Target->initDefaultFeatures(Features);
+  Target->initDefaultFeatures(Features, Opts->CPU);
 
   // Apply the user specified deltas.
   if (!Target->handleUserFeatures(Features, Opts->FeaturesAsWritten, Diags))




More information about the cfe-commits mailing list