From 1752ee4849f4c37f5e03193e658be92650b0e65a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 24 Aug 2009 09:10:05 +0000 Subject: [PATCH] Switch TargetInfo to store an llvm::Triple. - Primarily to discourage clients form making decisions based on the string. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79901 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 9 +++--- lib/Basic/Targets.cpp | 54 ++++++++++++++++---------------- lib/CodeGen/ModuleBuilder.cpp | 2 +- lib/CodeGen/TargetABIInfo.cpp | 13 +++----- lib/Frontend/PCHReader.cpp | 4 +-- lib/Frontend/PCHWriter.cpp | 5 +-- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index a34b8058c8..000e4f7e4a 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -16,6 +16,7 @@ // FIXME: Daniel isn't smart enough to use a prototype for this. #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/DataTypes.h" #include #include @@ -37,7 +38,7 @@ namespace Builtin { struct Info; } /// TargetInfo - This class exposes information about the current target. /// class TargetInfo { - std::string Triple; + llvm::Triple Triple; protected: // Target values set by the ctor of the actual target implementation. Default // values are specified by the TargetInfo constructor. @@ -287,9 +288,9 @@ public: /// llvm intrinsics. virtual const char *getTargetPrefix() const = 0; - /// getTargetTriple - Return the target triple of the primary target. - const char *getTargetTriple() const { - return Triple.c_str(); + /// getTriple - Return the target triple of the primary target. + const llvm::Triple &getTriple() const { + return Triple; } const char *getTargetDescription() const { diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 49c3ea8c4c..4b8abc457c 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -69,14 +69,14 @@ namespace { template class OSTargetInfo : public TgtInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defines) const=0; public: OSTargetInfo(const std::string& triple) : TgtInfo(triple) {} virtual void getTargetDefines(const LangOptions &Opts, std::vector &Defines) const { TgtInfo::getTargetDefines(Opts, Defines); - getOSDefines(Opts, TgtInfo::getTargetTriple(), Defines); + getOSDefines(Opts, TgtInfo::getTriple(), Defines); } }; @@ -104,14 +104,14 @@ static void getDarwinDefines(std::vector &Defs, const LangOptions &Opts) { Define(Defs, "__DYNAMIC__"); } -static void getDarwinOSXDefines(std::vector &Defs, const char *TripleStr){ - llvm::Triple TheTriple(TripleStr); - if (TheTriple.getOS() != llvm::Triple::Darwin) +static void getDarwinOSXDefines(std::vector &Defs, + const llvm::Triple &Triple) { + if (Triple.getOS() != llvm::Triple::Darwin) return; // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. unsigned Maj, Min, Rev; - TheTriple.getDarwinNumber(Maj, Min, Rev); + Triple.getDarwinNumber(Maj, Min, Rev); char MacOSXStr[] = "1000"; if (Maj >= 4 && Maj <= 13) { // 10.0-10.9 @@ -126,14 +126,13 @@ static void getDarwinOSXDefines(std::vector &Defs, const char *TripleStr){ } static void getDarwinIPhoneOSDefines(std::vector &Defs, - const char *TripleStr) { - llvm::Triple TheTriple(TripleStr); - if (TheTriple.getOS() != llvm::Triple::Darwin) + const llvm::Triple &Triple) { + if (Triple.getOS() != llvm::Triple::Darwin) return; // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. unsigned Maj, Min, Rev; - TheTriple.getDarwinNumber(Maj, Min, Rev); + Triple.getDarwinNumber(Maj, Min, Rev); // When targetting iPhone OS, interpret the minor version and // revision as the iPhone OS version @@ -151,14 +150,13 @@ static void getDarwinIPhoneOSDefines(std::vector &Defs, /// GetDarwinLanguageOptions - Set the default language options for darwin. static void GetDarwinLanguageOptions(LangOptions &Opts, - const char *TripleStr) { + const llvm::Triple &Triple) { Opts.NeXTRuntime = true; - llvm::Triple TheTriple(TripleStr); - if (TheTriple.getOS() != llvm::Triple::Darwin) + if (Triple.getOS() != llvm::Triple::Darwin) return; - unsigned MajorVersion = TheTriple.getDarwinMajorNumber(); + unsigned MajorVersion = Triple.getDarwinMajorNumber(); // Blocks and stack protectors default to on for 10.6 (darwin10) and beyond. if (MajorVersion > 9) { @@ -169,7 +167,7 @@ static void GetDarwinLanguageOptions(LangOptions &Opts, // Non-fragile ABI (in 64-bit mode) default to on for 10.5 (darwin9) and // beyond. if (MajorVersion >= 9 && Opts.ObjC1 && - TheTriple.getArch() == llvm::Triple::x86_64) + Triple.getArch() == llvm::Triple::x86_64) Opts.ObjCNonFragileABI = 1; } @@ -177,7 +175,7 @@ namespace { template class DarwinTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defines) const { getDarwinDefines(Defines, Opts); getDarwinOSXDefines(Defines, Triple); @@ -188,7 +186,7 @@ protected: /// options. virtual void getDefaultLangOptions(LangOptions &Opts) { TargetInfo::getDefaultLangOptions(Opts); - GetDarwinLanguageOptions(Opts, TargetInfo::getTargetTriple()); + GetDarwinLanguageOptions(Opts, TargetInfo::getTriple()); } public: DarwinTargetInfo(const std::string& triple) : @@ -218,7 +216,7 @@ public: template class DragonFlyBSDTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { // DragonFly defines; list based off of gcc output Define(Defs, "__DragonFly__"); @@ -237,11 +235,13 @@ public: template class FreeBSDTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { // FreeBSD defines; list based off of gcc output - const char *FreeBSD = strstr(Triple, "-freebsd"); + // FIXME: Move version number handling to llvm::Triple. + const char *FreeBSD = strstr(Triple.getTriple().c_str(), + "-freebsd"); FreeBSD += strlen("-freebsd"); char release[] = "X"; release[0] = FreeBSD[0]; @@ -265,7 +265,7 @@ public: template class LinuxTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { // Linux defines; list based off of gcc output DefineStd(Defs, "unix", Opts); @@ -284,7 +284,7 @@ public: template class NetBSDTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { // NetBSD defines; list based off of gcc output Define(Defs, "__NetBSD__", "1"); @@ -302,7 +302,7 @@ public: template class OpenBSDTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { // OpenBSD defines; list based off of gcc output @@ -319,7 +319,7 @@ public: template class SolarisTargetInfo : public OSTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defs) const { DefineStd(Defs, "sun", Opts); DefineStd(Defs, "unix", Opts); @@ -339,7 +339,7 @@ public: /// GetWindowsLanguageOptions - Set the default language options for Windows. static void GetWindowsLanguageOptions(LangOptions &Opts, - const char *Triple) { + const llvm::Triple &Triple) { Opts.Microsoft = true; } @@ -923,7 +923,7 @@ public: virtual void getDefaultLangOptions(LangOptions &Opts) { X86_32TargetInfo::getDefaultLangOptions(Opts); - GetWindowsLanguageOptions(Opts, getTargetTriple()); + GetWindowsLanguageOptions(Opts, getTriple()); } }; } // end anonymous namespace @@ -1092,7 +1092,7 @@ namespace { class DarwinARMTargetInfo : public DarwinTargetInfo { protected: - virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, std::vector &Defines) const { getDarwinDefines(Defines, Opts); getDarwinIPhoneOSDefines(Defines, Triple); diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp index 4835454b47..600271f7d8 100644 --- a/lib/CodeGen/ModuleBuilder.cpp +++ b/lib/CodeGen/ModuleBuilder.cpp @@ -54,7 +54,7 @@ namespace { virtual void Initialize(ASTContext &Context) { Ctx = &Context; - M->setTargetTriple(Ctx->Target.getTargetTriple()); + M->setTargetTriple(Ctx->Target.getTriple().getTriple()); M->setDataLayout(Ctx->Target.getTargetDescription()); TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription())); Builder.reset(new CodeGen::CodeGenModule(Context, CompileOpts, diff --git a/lib/CodeGen/TargetABIInfo.cpp b/lib/CodeGen/TargetABIInfo.cpp index a307435fa1..96c70feafe 100644 --- a/lib/CodeGen/TargetABIInfo.cpp +++ b/lib/CodeGen/TargetABIInfo.cpp @@ -1524,18 +1524,16 @@ const ABIInfo &CodeGenTypes::getABIInfo() const { // For now we just cache the ABIInfo in CodeGenTypes and don't free it. - llvm::Triple TargetTriple(getContext().Target.getTargetTriple()); - switch (TargetTriple.getArch()) { + const llvm::Triple &Triple(getContext().Target.getTriple()); + switch (Triple.getArch()) { default: return *(TheABIInfo = new DefaultABIInfo); - case llvm::Triple::x86: { - llvm::Triple::OSType OS = TargetTriple.getOS(); - - if (OS == llvm::Triple::Darwin) + case llvm::Triple::x86: + if (Triple.getOS() == llvm::Triple::Darwin) return *(TheABIInfo = new X86_32ABIInfo(Context, true, true)); - switch (OS) { + switch (Triple.getOS()) { case llvm::Triple::Cygwin: case llvm::Triple::DragonFly: case llvm::Triple::MinGW32: @@ -1547,7 +1545,6 @@ const ABIInfo &CodeGenTypes::getABIInfo() const { default: return *(TheABIInfo = new X86_32ABIInfo(Context, false, false)); } - } case llvm::Triple::x86_64: return *(TheABIInfo = new X86_64ABIInfo()); diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index c025fcd1aa..cb008c0ea2 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -115,9 +115,9 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { } bool PCHValidator::ReadTargetTriple(const std::string &Triple) { - if (Triple != PP.getTargetInfo().getTargetTriple()) { + if (Triple != PP.getTargetInfo().getTriple().getTriple()) { Reader.Diag(diag::warn_pch_target_triple) - << Triple << PP.getTargetInfo().getTargetTriple(); + << Triple << PP.getTargetInfo().getTriple().getTriple(); return true; } return false; diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index dc0ee3575c..ae8a589b60 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -526,8 +526,9 @@ void PCHWriter::WriteMetadata(ASTContext &Context, const char *isysroot) { Record.push_back(CLANG_VERSION_MAJOR); Record.push_back(CLANG_VERSION_MINOR); Record.push_back(isysroot != 0); - const char *Triple = Target.getTargetTriple(); - Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, Triple, strlen(Triple)); + const std::string &TripleStr = Target.getTriple().getTriple(); + Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, + TripleStr.data(), TripleStr.size()); // Original file name SourceManager &SM = Context.getSourceManager(); -- 2.40.0