From: Daniel Dunbar Date: Sat, 19 Dec 2009 03:30:57 +0000 (+0000) Subject: Targets: Allow CreateTargetInfo to mutate the target features. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b93292ab7f2b3d43a9e0ad6421f572d1f5a323b4;p=clang Targets: Allow CreateTargetInfo to mutate the target features. - In particular, it can claim features for itself instead of always passing them on to LLVM. - This allows using the target features as a generic mechanism for passing target specific options to the TargetInfo instance, which may need them for initializing preprocessor defines, etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91753 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 1dd01c7338..0d95e6a603 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -61,8 +61,11 @@ protected: public: /// CreateTargetInfo - Construct a target for the given options. - static TargetInfo* CreateTargetInfo(Diagnostic &Diags, - const TargetOptions &Opts); + /// + /// \param Opts - The options to use to initialize the target. The target may + /// modify the options to canonicalize the target feature information to match + /// what the backend expects. + static TargetInfo* CreateTargetInfo(Diagnostic &Diags, TargetOptions &Opts); virtual ~TargetInfo(); @@ -389,7 +392,10 @@ public: /// HandleTargetOptions - Perform initialization based on the user configured /// set of features (e.g., +sse4). The list is guaranteed to have at most one /// entry per feature. - virtual void HandleTargetFeatures(const std::vector &Features) { + /// + /// The target may modify the features list, to change which options are + /// passed onwards to the backend. + virtual void HandleTargetFeatures(std::vector &Features) { } // getRegParmMax - Returns maximal number of args passed in registers. diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 059d4d3023..7cc9f73b6c 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -688,7 +688,7 @@ public: bool Enabled) const; virtual void getDefaultFeatures(const std::string &CPU, llvm::StringMap &Features) const; - virtual void HandleTargetFeatures(const std::vector &Features); + virtual void HandleTargetFeatures(std::vector &Features); }; void X86TargetInfo::getDefaultFeatures(const std::string &CPU, @@ -805,8 +805,7 @@ bool X86TargetInfo::setFeatureEnabled(llvm::StringMap &Features, /// HandleTargetOptions - Perform initialization based on the user /// configured set of features. -void -X86TargetInfo::HandleTargetFeatures(const std::vector &Features) { +void X86TargetInfo::HandleTargetFeatures(std::vector &Features) { // Remember the maximum enabled sselevel. for (unsigned i = 0, e = Features.size(); i !=e; ++i) { // Ignore disabled features. @@ -2112,7 +2111,7 @@ static TargetInfo *AllocateTarget(const std::string &T) { /// CreateTargetInfo - Return the target info object for the specified target /// triple. TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, - const TargetOptions &Opts) { + TargetOptions &Opts) { llvm::Triple Triple(Opts.Triple); // Construct the target @@ -2156,11 +2155,11 @@ TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, // // FIXME: If we are completely confident that we have the right set, we only // need to pass the minuses. - std::vector StrFeatures; + Opts.Features.clear(); for (llvm::StringMap::const_iterator it = Features.begin(), ie = Features.end(); it != ie; ++it) - StrFeatures.push_back(std::string(it->second ? "+" : "-") + it->first()); - Target->HandleTargetFeatures(StrFeatures); + Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first()); + Target->HandleTargetFeatures(Opts.Features); return Target.take(); }