[cfe-commits] r169517 - in /cfe/trunk: include/clang/Driver/Options.td lib/Driver/Tools.cpp test/Driver/hexagon-toolchain.c

Matthew Curtis mcurtis at codeaurora.org
Thu Dec 6 09:49:04 PST 2012


Author: mcurtis
Date: Thu Dec  6 11:49:03 2012
New Revision: 169517

URL: http://llvm.org/viewvc/llvm-project?rev=169517&view=rev
Log:
Hexagon TC: Add/improve support for small data
 threshold, pic, pie


Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/hexagon-toolchain.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=169517&r1=169516&r2=169517&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Dec  6 11:49:03 2012
@@ -152,7 +152,8 @@
   HelpText<"Only run the preprocessor">;
 def F : JoinedOrSeparate<["-"], "F">, Flags<[RenderJoined,CC1Option]>,
     HelpText<"Add directory to framework include search path">;
-def G : Separate<["-"], "G">, Flags<[DriverOption]>;
+def G : JoinedOrSeparate<["-"], "G">, Flags<[DriverOption]>;
+def G_EQ : Joined<["-"], "G=">, Flags<[DriverOption]>;
 def H : Flag<["-"], "H">, Flags<[CC1Option]>,
     HelpText<"Show header includes and nesting depth">;
 def I_ : Flag<["-"], "I-">, Group<I_Group>;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=169517&r1=169516&r2=169517&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec  6 11:49:03 2012
@@ -1227,6 +1227,28 @@
   }
 }
 
+static inline bool HasPICArg(const ArgList &Args) {
+  return Args.hasArg(options::OPT_fPIC)
+    || Args.hasArg(options::OPT_fpic);
+}
+
+static Arg *GetLastSmallDataThresholdArg(const ArgList &Args) {
+  return Args.getLastArg(options::OPT_G,
+                         options::OPT_G_EQ,
+                         options::OPT_msmall_data_threshold_EQ);
+}
+
+static std::string GetHexagonSmallDataThresholdValue(const ArgList &Args) {
+  std::string value;
+  if (HasPICArg(Args))
+    value = "0";
+  else if (Arg *A = GetLastSmallDataThresholdArg(Args)) {
+    value = A->getValue();
+    A->claim();
+  }
+  return value;
+}
+
 void Clang::AddHexagonTargetArgs(const ArgList &Args,
                                  ArgStringList &CmdArgs) const {
   llvm::Triple Triple = getToolChain().getTriple();
@@ -1240,13 +1262,11 @@
   if (Args.hasArg(options::OPT_mqdsp6_compat))
     CmdArgs.push_back("-mqdsp6-compat");
 
-  if (Arg *A = Args.getLastArg(options::OPT_G,
-                               options::OPT_msmall_data_threshold_EQ)) {
-    std::string SmallDataThreshold="-small-data-threshold=";
-    SmallDataThreshold += A->getValue();
+  std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
+  if (!SmallDataThreshold.empty()) {
     CmdArgs.push_back ("-mllvm");
-    CmdArgs.push_back(Args.MakeArgString(SmallDataThreshold));
-    A->claim();
+    CmdArgs.push_back(Args.MakeArgString(
+                        "-hexagon-small-data-threshold=" + SmallDataThreshold));
   }
 
   if (!Args.hasArg(options::OPT_fno_short_enums))
@@ -3482,6 +3502,10 @@
     CmdArgs.push_back("-fsyntax-only");
   }
 
+  std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
+  if (!SmallDataThreshold.empty())
+    CmdArgs.push_back(
+      Args.MakeArgString(std::string("-G") + SmallDataThreshold));
 
   // Only pass -x if gcc will understand it; otherwise hope gcc
   // understands the suffix correctly. The main use case this would go
@@ -3539,6 +3563,7 @@
   //----------------------------------------------------------------------------
   bool hasStaticArg = Args.hasArg(options::OPT_static);
   bool buildingLib = Args.hasArg(options::OPT_shared);
+  bool buildPIE = Args.hasArg(options::OPT_pie);
   bool incStdLib = !Args.hasArg(options::OPT_nostdlib);
   bool incStartFiles = !Args.hasArg(options::OPT_nostartfiles);
   bool incDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
@@ -3574,6 +3599,15 @@
   if (hasStaticArg)
     CmdArgs.push_back("-static");
 
+  if (buildPIE && !buildingLib)
+    CmdArgs.push_back("-pie");
+
+  std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
+  if (!SmallDataThreshold.empty()) {
+    CmdArgs.push_back(
+      Args.MakeArgString(std::string("-G") + SmallDataThreshold));
+  }
+
   //----------------------------------------------------------------------------
   //
   //----------------------------------------------------------------------------

Modified: cfe/trunk/test/Driver/hexagon-toolchain.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/hexagon-toolchain.c?rev=169517&r1=169516&r2=169517&view=diff
==============================================================================
--- cfe/trunk/test/Driver/hexagon-toolchain.c (original)
+++ cfe/trunk/test/Driver/hexagon-toolchain.c Thu Dec  6 11:49:03 2012
@@ -3,9 +3,6 @@
 // Tests disabled for now in non-Unix-like systems where we can't seem to find hexagon-as
 // XFAIL: mingw32,win32
 
-// Temporarily 
-// XFAIL
-
 // -----------------------------------------------------------------------------
 // Test standard include paths
 // -----------------------------------------------------------------------------
@@ -439,3 +436,88 @@
 // CHECK022: "-lstdc++" "-lm"
 // CHECK022: "--start-group" "-lstandalone" "-lc" "-lgcc" "--end-group"
 // CHECK022: "[[GNU_DIR]]/hexagon/lib/v4/fini.o"
+
+// -----------------------------------------------------------------------------
+// pic, small data threshold
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK023 %s
+// CHECK023:      "{{.*}}clang{{.*}}" "-cc1"
+// CHECK023:        "-mrelocation-model" "static"
+// CHECK023-NEXT: "[[GNU_DIR:.*]]/bin/hexagon-as"
+// CHECK023-NOT:    "-G{{[0-9]+}}"
+// CHECK023-NEXT: "[[GNU_DIR]]/bin/hexagon-ld"
+// CHECK023-NOT:    "-G{{[0-9]+}}"
+
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -fpic \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK024 %s
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -fPIC \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK024 %s
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -fPIC \
+// RUN:   -msmall_data_threshold=8 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK024 %s
+// CHECK024:      "{{.*}}clang{{.*}}" "-cc1"
+// CHECK024-NOT:    "-mrelocation-model" "static"
+// CHECK024:        "-pic-level" "{{[12]}}"
+// CHECK024:        "-mllvm" "-hexagon-small-data-threshold=0"
+// CHECK024-NEXT: "[[GNU_DIR:.*]]/bin/hexagon-as"
+// CHECK024:        "-G0"
+// CHECK024-NEXT: "[[GNU_DIR]]/bin/hexagon-ld"
+// CHECK024:        "-G0"
+
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -G=8 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK025 %s
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -G 8 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK025 %s
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -msmall-data-threshold=8 \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK025 %s
+// CHECK025:      "{{.*}}clang{{.*}}" "-cc1"
+// CHECK025:        "-mrelocation-model" "static"
+// CHECK025:        "-mllvm" "-hexagon-small-data-threshold=8"
+// CHECK025-NEXT: "[[GNU_DIR:.*]]/bin/hexagon-as"
+// CHECK025:        "-G8"
+// CHECK025-NEXT: "[[GNU_DIR]]/bin/hexagon-ld"
+// CHECK025:        "-G8"
+
+// -----------------------------------------------------------------------------
+// pie
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -pie \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK026 %s
+// CHECK026:      "{{.*}}clang{{.*}}" "-cc1"
+// CHECK026-NEXT: "[[GNU_DIR:.*]]/bin/hexagon-as"
+// CHECK026-NEXT: "[[GNU_DIR]]/bin/hexagon-ld"
+// CHECK026:        "-pie"
+
+// RUN: %clang -### -target hexagon-unknown-linux     \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \
+// RUN:   -pie -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK027 %s
+// CHECK027:      "{{.*}}clang{{.*}}" "-cc1"
+// CHECK027-NEXT: "[[GNU_DIR:.*]]/bin/hexagon-as"
+// CHECK027-NEXT: "[[GNU_DIR]]/bin/hexagon-ld"
+// CHECK027-NOT:    "-pie"





More information about the cfe-commits mailing list