Added two SubtargetFeatures::AddFeatures methods, which accept a comma-separated string or already parsed command line parameters as input, and some code re-factoring to use these new methods.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89516 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Viktor Kutuzov 2009-11-21 00:00:02 +00:00
parent 00621efb40
commit 054b52c366
3 changed files with 44 additions and 3 deletions

View File

@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/System/DataTypes.h" #include "llvm/System/DataTypes.h"
namespace llvm { namespace llvm {
@ -93,6 +94,12 @@ public:
/// Adding Features. /// Adding Features.
void AddFeature(const std::string &String, bool IsEnabled = true); 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. /// Get feature bits.
uint32_t getBits(const SubtargetFeatureKV *CPUTable, uint32_t getBits(const SubtargetFeatureKV *CPUTable,
size_t CPUTableSize, size_t CPUTableSize,

View File

@ -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. /// Find KV in array using binary search.
template<typename T> const T *Find(const std::string &S, const T *A, size_t L) { 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 // Make the lower bound element we're looking for

View File

@ -304,10 +304,17 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
break; 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 // construct LTModule, hand over ownership of module and target
const std::string FeatureStr = _target = march->createTargetMachine(Triple, features.getString());
SubtargetFeatures::getDefaultSubtargetFeatures(llvm::Triple(Triple));
_target = march->createTargetMachine(Triple, FeatureStr);
} }
return false; return false;
} }