Add an option to specify the target C++ ABI to the frontend. Use it to

select either the default Itanium ABI or the new, experimental Microsoft ABI.

llvm-svn: 105804
This commit is contained in:
Charles Davis
2010-06-11 01:06:47 +00:00
parent 437416c06b
commit 95a546ee4d
9 changed files with 42 additions and 3 deletions

View File

@@ -66,6 +66,7 @@ def err_target_unknown_triple : Error<
"unknown target triple '%0', please use -triple or -arch">; "unknown target triple '%0', please use -triple or -arch">;
def err_target_unknown_cpu : Error<"unknown target CPU '%0'">; def err_target_unknown_cpu : Error<"unknown target CPU '%0'">;
def err_target_unknown_abi : Error<"unknown target ABI '%0'">; def err_target_unknown_abi : Error<"unknown target ABI '%0'">;
def err_target_unknown_cxxabi : Error<"unknown C++ ABI '%0'">;
def err_target_invalid_feature : Error<"invalid target feature '%0'">; def err_target_invalid_feature : Error<"invalid target feature '%0'">;
// Source manager // Source manager

View File

@@ -58,6 +58,7 @@ protected:
const char *UserLabelPrefix; const char *UserLabelPrefix;
const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat;
unsigned char RegParmMax, SSERegParmMax; unsigned char RegParmMax, SSERegParmMax;
std::string CXXABI;
unsigned HasAlignMac68kSupport : 1; unsigned HasAlignMac68kSupport : 1;
@@ -396,6 +397,11 @@ public:
return ""; return "";
} }
/// getCXXABI - Get the C++ ABI in use.
virtual llvm::StringRef getCXXABI() const {
return CXXABI;
}
/// setCPU - Target the specific CPU. /// setCPU - Target the specific CPU.
/// ///
/// \return - False on error (invalid CPU name). /// \return - False on error (invalid CPU name).
@@ -412,6 +418,16 @@ public:
return false; return false;
} }
/// setCXXABI - Use this specific C++ ABI.
///
/// \return - False on error (invalid ABI name).
virtual bool setCXXABI(const std::string &Name) {
if (Name != "itanium" && Name != "microsoft")
return false;
CXXABI = Name;
return true;
}
/// setFeatureEnabled - Enable or disable a specific target feature, /// setFeatureEnabled - Enable or disable a specific target feature,
/// the feature name must be valid. /// the feature name must be valid.
/// ///

View File

@@ -29,6 +29,10 @@ public:
/// If given, the name of the target ABI to use. /// If given, the name of the target ABI to use.
std::string ABI; std::string ABI;
/// If given, the name of the target C++ ABI to use. If not given, defaults
/// to "itanium".
std::string CXXABI;
/// The list of target specific features to enable or disable -- this should /// The list of target specific features to enable or disable -- this should
/// be a list of strings starting with by '+' or '-'. /// be a list of strings starting with by '+' or '-'.
std::vector<std::string> Features; std::vector<std::string> Features;

View File

@@ -18,6 +18,8 @@ include "OptParser.td"
// Target Options // Target Options
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def cxx_abi : Separate<"-cxx-abi">,
HelpText<"Target a particular C++ ABI type">;
def target_abi : Separate<"-target-abi">, def target_abi : Separate<"-target-abi">,
HelpText<"Target a particular ABI type">; HelpText<"Target a particular ABI type">;
def target_cpu : Separate<"-target-cpu">, def target_cpu : Separate<"-target-cpu">,

View File

@@ -2475,6 +2475,12 @@ TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
return 0; return 0;
} }
// Set the target C++ ABI.
if (!Target->setCXXABI(Opts.CXXABI)) {
Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
return 0;
}
// Compute the default target features, we need the target to handle this // Compute the default target features, we need the target to handle this
// because features may have dependencies on one another. // because features may have dependencies on one another.
llvm::StringMap<bool> Features; llvm::StringMap<bool> Features;

View File

@@ -86,8 +86,10 @@ void CodeGenModule::createObjCRuntime() {
} }
void CodeGenModule::createCXXABI() { void CodeGenModule::createCXXABI() {
// For now, just create an Itanium ABI. if (Context.Target.getCXXABI() == "microsoft")
ABI = CreateItaniumCXXABI(*this); ABI = CreateMicrosoftCXXABI(*this);
else
ABI = CreateItaniumCXXABI(*this);
} }
void CodeGenModule::Release() { void CodeGenModule::Release() {

View File

@@ -124,7 +124,7 @@ void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
assert(false && "Can't yet mangle destructors!"); assert(false && "Can't yet mangle destructors!");
} }
CXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM) { CXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
return new MicrosoftCXXABI(CGM); return new MicrosoftCXXABI(CGM);
} }

View File

@@ -219,6 +219,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
// FIXME: This is broken, we should store the TargetOptions in the PCH. // FIXME: This is broken, we should store the TargetOptions in the PCH.
TargetOptions TargetOpts; TargetOptions TargetOpts;
TargetOpts.ABI = ""; TargetOpts.ABI = "";
TargetOpts.CXXABI = "itanium";
TargetOpts.CPU = ""; TargetOpts.CPU = "";
TargetOpts.Features.clear(); TargetOpts.Features.clear();
TargetOpts.Triple = TargetTriple; TargetOpts.Triple = TargetTriple;

View File

@@ -680,6 +680,8 @@ static void TargetOptsToArgs(const TargetOptions &Opts,
Res.push_back("-target-abi"); Res.push_back("-target-abi");
Res.push_back(Opts.ABI); Res.push_back(Opts.ABI);
} }
Res.push_back("-cxx-abi");
Res.push_back(Opts.CXXABI);
for (unsigned i = 0, e = Opts.Features.size(); i != e; ++i) { for (unsigned i = 0, e = Opts.Features.size(); i != e; ++i) {
Res.push_back("-target-feature"); Res.push_back("-target-feature");
Res.push_back(Opts.Features[i]); Res.push_back(Opts.Features[i]);
@@ -1367,6 +1369,7 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) { static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
using namespace cc1options; using namespace cc1options;
Opts.ABI = Args.getLastArgValue(OPT_target_abi); Opts.ABI = Args.getLastArgValue(OPT_target_abi);
Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi);
Opts.CPU = Args.getLastArgValue(OPT_target_cpu); Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
Opts.Triple = Args.getLastArgValue(OPT_triple); Opts.Triple = Args.getLastArgValue(OPT_triple);
Opts.Features = Args.getAllArgValues(OPT_target_feature); Opts.Features = Args.getAllArgValues(OPT_target_feature);
@@ -1374,6 +1377,10 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
// Use the host triple if unspecified. // Use the host triple if unspecified.
if (Opts.Triple.empty()) if (Opts.Triple.empty())
Opts.Triple = llvm::sys::getHostTriple(); Opts.Triple = llvm::sys::getHostTriple();
// Use the Itanium C++ ABI if unspecified.
if (Opts.CXXABI.empty())
Opts.CXXABI = "itanium";
} }
// //