[cfe-commits] r79901 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/Targets.cpp lib/CodeGen/ModuleBuilder.cpp lib/CodeGen/TargetABIInfo.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp

Daniel Dunbar daniel at zuster.org
Mon Aug 24 02:10:06 PDT 2009


Author: ddunbar
Date: Mon Aug 24 04:10:05 2009
New Revision: 79901

URL: http://llvm.org/viewvc/llvm-project?rev=79901&view=rev
Log:
Switch TargetInfo to store an llvm::Triple.
 - Primarily to discourage clients form making decisions based on the string.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
    cfe/trunk/lib/CodeGen/TargetABIInfo.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Aug 24 04:10:05 2009
@@ -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 <cassert>
 #include <vector>
@@ -37,7 +38,7 @@
 /// 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 @@
   /// 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 {

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Aug 24 04:10:05 2009
@@ -69,14 +69,14 @@
 template<typename TgtInfo>
 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<char> &Defines) const=0;
 public:
   OSTargetInfo(const std::string& triple) : TgtInfo(triple) {}
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     TgtInfo::getTargetDefines(Opts, Defines);
-    getOSDefines(Opts, TgtInfo::getTargetTriple(), Defines);
+    getOSDefines(Opts, TgtInfo::getTriple(), Defines);
   }
 
 };
@@ -104,14 +104,14 @@
     Define(Defs, "__DYNAMIC__");
 }
 
-static void getDarwinOSXDefines(std::vector<char> &Defs, const char *TripleStr){
-  llvm::Triple TheTriple(TripleStr);
-  if (TheTriple.getOS() != llvm::Triple::Darwin)
+static void getDarwinOSXDefines(std::vector<char> &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 getDarwinIPhoneOSDefines(std::vector<char> &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 @@
 
 /// 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 @@
   // 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 @@
 template<typename Target>
 class DarwinTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &Defines) const {
     getDarwinDefines(Defines, Opts);
     getDarwinOSXDefines(Defines, Triple);
@@ -188,7 +186,7 @@
   /// 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 @@
 template<typename Target>
 class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &Defs) const {
     // DragonFly defines; list based off of gcc output
     Define(Defs, "__DragonFly__");
@@ -237,11 +235,13 @@
 template<typename Target>
 class FreeBSDTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &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 @@
 template<typename Target>
 class LinuxTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                            std::vector<char> &Defs) const {
     // Linux defines; list based off of gcc output
     DefineStd(Defs, "unix", Opts);
@@ -284,7 +284,7 @@
 template<typename Target>
 class NetBSDTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &Defs) const {
     // NetBSD defines; list based off of gcc output
     Define(Defs, "__NetBSD__", "1");
@@ -302,7 +302,7 @@
 template<typename Target>
 class OpenBSDTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &Defs) const {
     // OpenBSD defines; list based off of gcc output
 
@@ -319,7 +319,7 @@
 template<typename Target>
 class SolarisTargetInfo : public OSTargetInfo<Target> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                                 std::vector<char> &Defs) const {
     DefineStd(Defs, "sun", Opts);
     DefineStd(Defs, "unix", Opts);
@@ -339,7 +339,7 @@
 
 /// 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 @@
 
   virtual void getDefaultLangOptions(LangOptions &Opts) {
     X86_32TargetInfo::getDefaultLangOptions(Opts);
-    GetWindowsLanguageOptions(Opts, getTargetTriple());
+    GetWindowsLanguageOptions(Opts, getTriple());
   }
 };
 } // end anonymous namespace
@@ -1092,7 +1092,7 @@
 class DarwinARMTargetInfo : 
   public DarwinTargetInfo<ARMTargetInfo> {
 protected:
-  virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
+  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     std::vector<char> &Defines) const {
     getDarwinDefines(Defines, Opts);
     getDarwinIPhoneOSDefines(Defines, Triple);

Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Mon Aug 24 04:10:05 2009
@@ -54,7 +54,7 @@
     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,

Modified: cfe/trunk/lib/CodeGen/TargetABIInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetABIInfo.cpp?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/TargetABIInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetABIInfo.cpp Mon Aug 24 04:10:05 2009
@@ -1524,18 +1524,16 @@
 
   // 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 @@
     default:
       return *(TheABIInfo = new X86_32ABIInfo(Context, false, false));
     }
-  }
 
   case llvm::Triple::x86_64:
     return *(TheABIInfo = new X86_64ABIInfo());

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Aug 24 04:10:05 2009
@@ -115,9 +115,9 @@
 }
 
 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;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=79901&r1=79900&r2=79901&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Aug 24 04:10:05 2009
@@ -526,8 +526,9 @@
   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();





More information about the cfe-commits mailing list