]> granicus.if.org Git - clang/commitdiff
Add -plugin-opt=sample-profile for thinLTO build.
authorDehao Chen <dehao@google.com>
Wed, 4 Jan 2017 00:33:23 +0000 (00:33 +0000)
committerDehao Chen <dehao@google.com>
Wed, 4 Jan 2017 00:33:23 +0000 (00:33 +0000)
Summary: ThinLTO needs to pass down the sample profile file path to linker.

Reviewers: tejohnson, davidxl, mehdi_amini

Subscribers: bruno, cfe-commits

Differential Revision: https://reviews.llvm.org/D27832

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290919 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/gold-lto-samplepgo.c [new file with mode: 0644]

index 2a367bb29aa5fe4fc81a9e85d9db3bd034b26a56..01a17dbf517114010611e2fdd0adb6b76ffe9887 100644 (file)
@@ -2235,6 +2235,15 @@ static void AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
                    UseSeparateSections)) {
     CmdArgs.push_back("-plugin-opt=-data-sections");
   }
+
+  if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) {
+    StringRef FName = A->getValue();
+    if (!llvm::sys::fs::exists(FName))
+      D.Diag(diag::err_drv_no_such_file) << FName;
+    else
+      CmdArgs.push_back(
+          Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + FName));
+  }
 }
 
 /// This is a helper function for validating the optional refinement step
diff --git a/test/Driver/gold-lto-samplepgo.c b/test/Driver/gold-lto-samplepgo.c
new file mode 100644 (file)
index 0000000..ee4b51c
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \
+// RUN:     -Wl,-plugin-opt=foo -O3 \
+// RUN:     -fprofile-sample-use=%s \
+// RUN:     | FileCheck %s
+// CHECK: -plugin-opt=sample-profile=