aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/c++/clang.cpp
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-11-26 02:03:36 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-12-05 13:51:44 -0500
commita9495fe9dc63bee1166772b6f10e199ef1747892 (patch)
treef28475b3a79dce2db7a52cb56afc7f3c04a295bd /tools/perf/util/c++/clang.cpp
parent77dfa84a843c0bc935a6c8664f2556573e30845f (diff)
perf clang: Allow passing CFLAGS to builtin clang
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 <wangnan0@huawei.com> Cc: Alexei Starovoitov <ast@fb.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Joe Stringer <joe@ovn.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-13-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/c++/clang.cpp')
-rw-r--r--tools/perf/util/c++/clang.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index cf96199b4b6f..715ca0a3dee0 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -29,7 +29,8 @@ static std::unique_ptr<llvm::LLVMContext> LLVMCtx;
29using namespace clang; 29using namespace clang;
30 30
31static CompilerInvocation * 31static CompilerInvocation *
32createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags) 32createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
33 DiagnosticsEngine& Diags)
33{ 34{
34 llvm::opt::ArgStringList CCArgs { 35 llvm::opt::ArgStringList CCArgs {
35 "-cc1", 36 "-cc1",
@@ -45,6 +46,8 @@ createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags)
45 "-Wno-unused-value", 46 "-Wno-unused-value",
46 "-Wno-pointer-sign", 47 "-Wno-pointer-sign",
47 "-x", "c"}; 48 "-x", "c"};
49
50 CCArgs.append(CFlags.begin(), CFlags.end());
48 CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs); 51 CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs);
49 52
50 FrontendOptions& Opts = CI->getFrontendOpts(); 53 FrontendOptions& Opts = CI->getFrontendOpts();
@@ -54,8 +57,8 @@ createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags)
54} 57}
55 58
56static std::unique_ptr<llvm::Module> 59static std::unique_ptr<llvm::Module>
57getModuleFromSource(StringRef Path, 60getModuleFromSource(llvm::opt::ArgStringList CFlags,
58 IntrusiveRefCntPtr<vfs::FileSystem> VFS) 61 StringRef Path, IntrusiveRefCntPtr<vfs::FileSystem> VFS)
59{ 62{
60 CompilerInstance Clang; 63 CompilerInstance Clang;
61 Clang.createDiagnostics(); 64 Clang.createDiagnostics();
@@ -63,7 +66,8 @@ getModuleFromSource(StringRef Path,
63 Clang.setVirtualFileSystem(&*VFS); 66 Clang.setVirtualFileSystem(&*VFS);
64 67
65 IntrusiveRefCntPtr<CompilerInvocation> CI = 68 IntrusiveRefCntPtr<CompilerInvocation> CI =
66 createCompilerInvocation(Path, Clang.getDiagnostics()); 69 createCompilerInvocation(std::move(CFlags), Path,
70 Clang.getDiagnostics());
67 Clang.setInvocation(&*CI); 71 Clang.setInvocation(&*CI);
68 72
69 std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx)); 73 std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx));
@@ -74,7 +78,8 @@ getModuleFromSource(StringRef Path,
74} 78}
75 79
76std::unique_ptr<llvm::Module> 80std::unique_ptr<llvm::Module>
77getModuleFromSource(StringRef Name, StringRef Content) 81getModuleFromSource(llvm::opt::ArgStringList CFlags,
82 StringRef Name, StringRef Content)
78{ 83{
79 using namespace vfs; 84 using namespace vfs;
80 85
@@ -90,14 +95,14 @@ getModuleFromSource(StringRef Name, StringRef Content)
90 OverlayFS->pushOverlay(MemFS); 95 OverlayFS->pushOverlay(MemFS);
91 MemFS->addFile(Twine(Name), 0, llvm::MemoryBuffer::getMemBuffer(Content)); 96 MemFS->addFile(Twine(Name), 0, llvm::MemoryBuffer::getMemBuffer(Content));
92 97
93 return getModuleFromSource(Name, OverlayFS); 98 return getModuleFromSource(std::move(CFlags), Name, OverlayFS);
94} 99}
95 100
96std::unique_ptr<llvm::Module> 101std::unique_ptr<llvm::Module>
97getModuleFromSource(StringRef Path) 102getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path)
98{ 103{
99 IntrusiveRefCntPtr<vfs::FileSystem> VFS(vfs::getRealFileSystem()); 104 IntrusiveRefCntPtr<vfs::FileSystem> VFS(vfs::getRealFileSystem());
100 return getModuleFromSource(Path, VFS); 105 return getModuleFromSource(std::move(CFlags), Path, VFS);
101} 106}
102 107
103} 108}