From patchwork Fri Sep 23 12:49:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 76856 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp552988qgf; Fri, 23 Sep 2016 05:52:31 -0700 (PDT) X-Received: by 10.66.155.137 with SMTP id vw9mr12233175pab.154.1474635151034; Fri, 23 Sep 2016 05:52:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zc1si7813457pac.259.2016.09.23.05.52.30; Fri, 23 Sep 2016 05:52:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034333AbcIWMw2 (ORCPT + 27 others); Fri, 23 Sep 2016 08:52:28 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:18968 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965416AbcIWMvA (ORCPT ); Fri, 23 Sep 2016 08:51:00 -0400 Received: from 172.24.1.136 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.136]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRL70274; Fri, 23 Sep 2016 20:50:23 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Fri, 23 Sep 2016 20:50:12 +0800 From: Wang Nan To: , CC: , , , Wang Nan , Arnaldo Carvalho de Melo , He Kuang , Jiri Olsa Subject: [PATCH 08/14] perf clang: Allow passing CFLAGS to builtin clang Date: Fri, 23 Sep 2016 12:49:55 +0000 Message-ID: <1474635001-153850-9-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1474635001-153850-1-git-send-email-wangnan0@huawei.com> References: <1474635001-153850-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.57E5250F.01EB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 66a88533e50794f3a19d051e7fc060c6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Improve getModuleFromSource() API to accept a cflags list. This feature will be used to pass LINUX_VERSION_CODE and -I flags. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa --- tools/perf/util/c++/clang-test.cpp | 5 +++-- tools/perf/util/c++/clang.cpp | 21 +++++++++++++-------- tools/perf/util/c++/clang.h | 8 ++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) -- 1.8.3.4 diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp index 3da6bfa..0f484fb 100644 --- a/tools/perf/util/c++/clang-test.cpp +++ b/tools/perf/util/c++/clang-test.cpp @@ -16,8 +16,9 @@ int test__clang_to_IR(void) perf_clang_scope _scope; std::unique_ptr M = - perf::getModuleFromSource("perf-test.c", - "int myfunc(void) {return 1;}"); + perf::getModuleFromSource({"-DRESULT=1"}, + "perf-test.c", + "int myfunc(void) {return RESULT;}"); if (!M) return -1; diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp index f032ea8..f6f6a8c 100644 --- a/tools/perf/util/c++/clang.cpp +++ b/tools/perf/util/c++/clang.cpp @@ -27,7 +27,8 @@ static std::unique_ptr LLVMCtx; using namespace clang; static CompilerInvocation * -createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags) +createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path, + DiagnosticsEngine& Diags) { llvm::opt::ArgStringList CCArgs { "-cc1", @@ -43,6 +44,8 @@ createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags) "-Wno-unused-value", "-Wno-pointer-sign", "-x", "c"}; + + CCArgs.append(CFlags.begin(), CFlags.end()); CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs); FrontendOptions& Opts = CI->getFrontendOpts(); @@ -52,8 +55,8 @@ createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags) } static std::unique_ptr -getModuleFromSource(StringRef Path, - IntrusiveRefCntPtr VFS) +getModuleFromSource(llvm::opt::ArgStringList CFlags, + StringRef Path, IntrusiveRefCntPtr VFS) { CompilerInstance Clang; Clang.createDiagnostics(); @@ -61,7 +64,8 @@ getModuleFromSource(StringRef Path, Clang.setVirtualFileSystem(&*VFS); IntrusiveRefCntPtr CI = - createCompilerInvocation(Path, Clang.getDiagnostics()); + createCompilerInvocation(std::move(CFlags), Path, + Clang.getDiagnostics()); Clang.setInvocation(&*CI); std::unique_ptr Act(new EmitLLVMOnlyAction(&*LLVMCtx)); @@ -72,7 +76,8 @@ getModuleFromSource(StringRef Path, } std::unique_ptr -getModuleFromSource(StringRef Name, StringRef Content) +getModuleFromSource(llvm::opt::ArgStringList CFlags, + StringRef Name, StringRef Content) { using namespace vfs; @@ -88,14 +93,14 @@ getModuleFromSource(StringRef Name, StringRef Content) OverlayFS->pushOverlay(MemFS); MemFS->addFile(Twine(Name), 0, llvm::MemoryBuffer::getMemBuffer(Content)); - return getModuleFromSource(Name, OverlayFS); + return getModuleFromSource(std::move(CFlags), Name, OverlayFS); } std::unique_ptr -getModuleFromSource(StringRef Path) +getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path) { IntrusiveRefCntPtr VFS(vfs::getRealFileSystem()); - return getModuleFromSource(Path, VFS); + return getModuleFromSource(std::move(CFlags), Path, VFS); } } diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h index 90aff01..b4fc2a9 100644 --- a/tools/perf/util/c++/clang.h +++ b/tools/perf/util/c++/clang.h @@ -4,16 +4,20 @@ #include "llvm/ADT/StringRef.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/Option/Option.h" #include + namespace perf { using namespace llvm; std::unique_ptr -getModuleFromSource(StringRef Name, StringRef Content); +getModuleFromSource(opt::ArgStringList CFlags, + StringRef Name, StringRef Content); std::unique_ptr -getModuleFromSource(StringRef Path); +getModuleFromSource(opt::ArgStringList CFlags, + StringRef Path); } #endif