summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Target/SubtargetFeature.h7
-rw-r--r--lib/Target/SubtargetFeature.cpp27
-rw-r--r--tools/lto/LTOCodeGenerator.cpp13
3 files changed, 44 insertions, 3 deletions
diff --git a/include/llvm/Target/SubtargetFeature.h b/include/llvm/Target/SubtargetFeature.h
index 38a3cc2fef..fb5dba1f6d 100644
--- a/include/llvm/Target/SubtargetFeature.h
+++ b/include/llvm/Target/SubtargetFeature.h
@@ -22,6 +22,7 @@
#include <vector>
#include <cstring>
#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/System/DataTypes.h"
namespace llvm {
@@ -93,6 +94,12 @@ public:
/// Adding Features.
void AddFeature(const std::string &String, bool IsEnabled = true);
+ /// Add a set of features from the comma-separated string.
+ void AddFeatures(const std::string &String);
+
+ /// Add a set of features from the parsed command line parameters.
+ void AddFeatures(const cl::list<std::string> &List);
+
/// Get feature bits.
uint32_t getBits(const SubtargetFeatureKV *CPUTable,
size_t CPUTableSize,
diff --git a/lib/Target/SubtargetFeature.cpp b/lib/Target/SubtargetFeature.cpp
index 590574ef39..1085668a76 100644
--- a/lib/Target/SubtargetFeature.cpp
+++ b/lib/Target/SubtargetFeature.cpp
@@ -110,6 +110,33 @@ void SubtargetFeatures::AddFeature(const std::string &String,
}
}
+/// Add a set of features from the comma-separated string.
+void SubtargetFeatures::AddFeatures(const std::string &String)
+{
+ std::vector<std::string> _Features;
+
+ Split(_Features, String);
+ // Nothing is specified.
+ if (_Features.size() == 0)
+ return;
+
+ for (std::vector<std::string>::iterator it = _Features.begin(),
+ end = _Features.end(); it != end; ++it) {
+ // AddFeature will take care of feature string normalization.
+ AddFeature(*it);
+ }
+}
+
+/// Add a set of features from the parsed command line parameters.
+void SubtargetFeatures::AddFeatures(const cl::list<std::string> &List)
+{
+ for (cl::list<std::string>::const_iterator it = List.begin(),
+ end = List.end(); it != end; ++it) {
+ // AddFeature will take care of feature string normalization.
+ AddFeature(*it);
+ }
+}
+
/// Find KV in array using binary search.
template<typename T> const T *Find(const std::string &S, const T *A, size_t L) {
// Make the lower bound element we're looking for
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 0b9cb2952e..f079c2e360 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -304,10 +304,17 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
break;
}
+ // Prepare subtarget feature set for the given command line options.
+ SubtargetFeatures features;
+
+ // Set the rest of features by default.
+ // Note: Please keep this after all explict feature settings to make sure
+ // defaults will not override explicitly set options.
+ features.AddFeatures(
+ SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple)));
+
// construct LTModule, hand over ownership of module and target
- const std::string FeatureStr =
- SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple));
- _target = march->createTargetMachine(Triple, FeatureStr);
+ _target = march->createTargetMachine(Triple, features.getString());
}
return false;
}