forked from OSchip/llvm-project
llvmc: First stab at better -march handling.
llvm-svn: 120230
This commit is contained in:
parent
7283b8d18c
commit
c5d7ae4d64
|
@ -46,8 +46,8 @@ def OptList : OptionList<[
|
||||||
(help "Choose linker (possible values: gcc, g++)")),
|
(help "Choose linker (possible values: gcc, g++)")),
|
||||||
(parameter_option "mtune",
|
(parameter_option "mtune",
|
||||||
(help "Target a specific CPU type"), (forward_not_split)),
|
(help "Target a specific CPU type"), (forward_not_split)),
|
||||||
(parameter_option "march",
|
(parameter_list_option "march",
|
||||||
(help "Architecture to generate code for"), (forward_not_split)),
|
(help "Generate code for the specified machine type")),
|
||||||
(parameter_option "mcpu",
|
(parameter_option "mcpu",
|
||||||
(help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
|
(help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
|
||||||
(switch_option "mfix-and-continue",
|
(switch_option "mfix-and-continue",
|
||||||
|
@ -295,7 +295,8 @@ def llc : Tool<
|
||||||
(switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
|
(switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
|
||||||
(switch_on "mdynamic-no-pic"),
|
(switch_on "mdynamic-no-pic"),
|
||||||
(append_cmd "-relocation-model=dynamic-no-pic"),
|
(append_cmd "-relocation-model=dynamic-no-pic"),
|
||||||
(not_empty "march"), (forward "march"),
|
(not_empty "march"), (forward_transformed_value
|
||||||
|
"march", "ConvertMArchToMAttr"),
|
||||||
(not_empty "mcpu"), (forward "mcpu"),
|
(not_empty "mcpu"), (forward "mcpu"),
|
||||||
(and (not_empty "mtune"), (empty "mcpu")),
|
(and (not_empty "mtune"), (empty "mcpu")),
|
||||||
(forward_as "mtune", "-mcpu"),
|
(forward_as "mtune", "-mcpu"),
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace hooks {
|
namespace hooks {
|
||||||
typedef std::vector<std::string> StrVec;
|
typedef std::vector<std::string> StrVec;
|
||||||
|
typedef llvm::StringMap<const char*> ArgMap;
|
||||||
|
|
||||||
/// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-*
|
/// ConvertToMAttrImpl - Common implementation of ConvertMArchToMAttr and
|
||||||
std::string ConvertToMAttr(const StrVec& Opts) {
|
/// ConvertToMAttr. The optional Args parameter contains information about how
|
||||||
|
/// to transform special-cased values (for example, '-march=armv6' must be
|
||||||
|
/// forwarded as '-mattr=+v6').
|
||||||
|
std::string ConvertToMAttrImpl(const StrVec& Opts, const ArgMap* Args = 0) {
|
||||||
std::string out("-mattr=");
|
std::string out("-mattr=");
|
||||||
|
|
||||||
bool firstIter = true;
|
bool firstIter = true;
|
||||||
|
|
||||||
for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
|
for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
|
||||||
const std::string& Arg = *B;
|
const std::string& Arg = *B;
|
||||||
|
|
||||||
|
@ -17,10 +23,23 @@ std::string ConvertToMAttr(const StrVec& Opts) {
|
||||||
else
|
else
|
||||||
out += ",";
|
out += ",";
|
||||||
|
|
||||||
|
// Check if the argument is a special case.
|
||||||
|
if (Args != 0) {
|
||||||
|
ArgMap::const_iterator I = Args->find(Arg);
|
||||||
|
|
||||||
|
if (I != Args->end()) {
|
||||||
|
out += '+';
|
||||||
|
out += I->getValue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert 'no-foo' to '-foo'.
|
||||||
if (Arg.find("no-") == 0 && Arg[3] != 0) {
|
if (Arg.find("no-") == 0 && Arg[3] != 0) {
|
||||||
out += '-';
|
out += '-';
|
||||||
out += Arg.c_str() + 3;
|
out += Arg.c_str() + 3;
|
||||||
}
|
}
|
||||||
|
// Convert 'foo' to '+foo'.
|
||||||
else {
|
else {
|
||||||
out += '+';
|
out += '+';
|
||||||
out += Arg;
|
out += Arg;
|
||||||
|
@ -30,4 +49,36 @@ std::string ConvertToMAttr(const StrVec& Opts) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Values needed to be special-cased by ConvertMArchToMAttr.
|
||||||
|
const char* MArchMapKeys[] = { "armv6" };
|
||||||
|
const char* MArchMapValues[] = { "v6" };
|
||||||
|
const unsigned NumMArchMapKeys = sizeof(MArchMapKeys) / sizeof(const char*);
|
||||||
|
|
||||||
|
void InitializeMArchMap(ArgMap& Args) {
|
||||||
|
for (unsigned i = 0; i < NumMArchMapKeys; ++i) {
|
||||||
|
// Explicit cast to StringRef here is necessary to pick up the right
|
||||||
|
// overload.
|
||||||
|
Args.GetOrCreateValue(llvm::StringRef(MArchMapKeys[i]), MArchMapValues[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ConvertMArchToMAttr - Try to convert -march from the gcc dialect to
|
||||||
|
/// something llc can understand.
|
||||||
|
std::string ConvertMArchToMAttr(const StrVec& Opts) {
|
||||||
|
static ArgMap MArchMap(NumMArchMapKeys);
|
||||||
|
static bool MArchMapInitialized = false;
|
||||||
|
|
||||||
|
if (!MArchMapInitialized) {
|
||||||
|
InitializeMArchMap(MArchMap);
|
||||||
|
MArchMapInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertToMAttrImpl(Opts, &MArchMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ConvertToMAttr - Convert '-mfoo' and '-mno-bar' to '-mattr=+foo,-bar'.
|
||||||
|
std::string ConvertToMAttr(const StrVec& Opts) {
|
||||||
|
return ConvertToMAttrImpl(Opts);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue