[cfe-commits] r134296 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/x86_features.c
Eli Friedman
eli.friedman at gmail.com
Fri Jul 1 17:34:19 PDT 2011
Author: efriedma
Date: Fri Jul 1 19:34:19 2011
New Revision: 134296
URL: http://llvm.org/viewvc/llvm-project?rev=134296&view=rev
Log:
Make clang behave in a gcc-compatible way in the presence of multiple flags for the same x86 target feature (e.g. -mno-sse -msse). gcc uses a somewhat unintuitive algorithm here in that the enabled SSE instructions is based on the order of the *last* flag for *each* feature-level, so that "-mno-sse -msse2" only enables SSE2, but "-mno-sse -msse2 -msse" enables all SSE levels.
Issue reported on cfe-dev.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/x86_features.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=134296&r1=134295&r2=134296&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Jul 1 19:34:19 2011
@@ -839,6 +839,14 @@
CmdArgs.push_back(CPUName);
}
+ // The required algorithm here is slightly strange: the options are applied
+ // in order (so -mno-sse -msse2 disables SSE3), but any option that gets
+ // directly overridden later is ignored (so "-mno-sse -msse2 -mno-sse2 -msse"
+ // is equivalent to "-mno-sse2 -msse"). The -cc1 handling deals with the
+ // former correctly, but not the latter; handle directly-overridden
+ // attributes here.
+ llvm::StringMap<unsigned> PrevFeature;
+ std::vector<const char*> Features;
for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group),
ie = Args.filtered_end(); it != ie; ++it) {
llvm::StringRef Name = (*it)->getOption().getName();
@@ -852,8 +860,17 @@
if (IsNegative)
Name = Name.substr(3);
- CmdArgs.push_back("-target-feature");
- CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
+ unsigned& Prev = PrevFeature[Name];
+ if (Prev)
+ Features[Prev - 1] = 0;
+ Prev = Features.size() + 1;
+ Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
+ }
+ for (unsigned i = 0; i < Features.size(); i++) {
+ if (Features[i]) {
+ CmdArgs.push_back("-target-feature");
+ CmdArgs.push_back(Features[i]);
+ }
}
}
Modified: cfe/trunk/test/Driver/x86_features.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/x86_features.c?rev=134296&r1=134295&r2=134296&view=diff
==============================================================================
--- cfe/trunk/test/Driver/x86_features.c (original)
+++ cfe/trunk/test/Driver/x86_features.c Fri Jul 1 19:34:19 2011
@@ -1,3 +1,3 @@
// RUN: %clang -ccc-host-triple i386-unknown-unknown -### -S %s -msse -msse4 -mno-sse -mno-mmx -msse 2> %t
-// RUN: grep '"-target-feature" "+sse" "-target-feature" "+sse4" "-target-feature" "-sse" "-target-feature" "-mmx" "-target-feature" "+sse"' %t
-
+// RUN: grep '"pentium4" "-target-feature" "+sse4" "-target-feature" "-mmx" "-target-feature" "+sse"' %t
+// Note that we filter out all but the last -m(no)sse.
More information about the cfe-commits
mailing list