[cfe-commits] [PATCH] [4/6] Hexagon TC: Add/improve support for small data, threshold, pic, pie

Matthew Curtis mcurtis at codeaurora.org
Fri Nov 16 11:06:02 PST 2012


Refreshing patch against current trunk.

Matthew Curtis.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

-------------- next part --------------
>From 2101cd593a2a71a909099040e96555fc84236b8a Mon Sep 17 00:00:00 2001
From: Matthew Curtis <mcurtis at codeaurora.org>
Date: Fri, 14 Sep 2012 12:18:25 -0500
Subject: [PATCH 4/6] Hexagon TC: Add/improve support for small data
 threshold, pic, pie

---
 include/clang/Driver/Options.td |    3 +-
 lib/Driver/Tools.cpp            |   46 ++++++++++++++++++---
 test/Driver/hexagon-toolchain.c |   85 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+), 7 deletions(-)

diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 5dca961..a4abbfa 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -152,7 +152,8 @@ def E : Flag<["-"], "E">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>,
   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>;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 36b5191..fde84a4 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1223,6 +1223,28 @@ void Clang::AddX86TargetArgs(const ArgList &Args,
   }
 }
 
+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();
@@ -1236,13 +1258,11 @@ void Clang::AddHexagonTargetArgs(const ArgList &Args,
   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))
@@ -3451,6 +3471,10 @@ void hexagon::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
     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
@@ -3508,6 +3532,7 @@ void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA,
   //----------------------------------------------------------------------------
   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);
@@ -3543,6 +3568,15 @@ void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA,
   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));
+  }
+
   //----------------------------------------------------------------------------
   //
   //----------------------------------------------------------------------------
diff --git a/test/Driver/hexagon-toolchain.c b/test/Driver/hexagon-toolchain.c
index cd9a78b..0940b7b 100644
--- a/test/Driver/hexagon-toolchain.c
+++ b/test/Driver/hexagon-toolchain.c
@@ -433,3 +433,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"
-- 
1.7.8.3



More information about the cfe-commits mailing list