diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-11-26 02:03:36 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-05 13:51:44 -0500 |
commit | a9495fe9dc63bee1166772b6f10e199ef1747892 (patch) | |
tree | f28475b3a79dce2db7a52cb56afc7f3c04a295bd /tools/perf/util | |
parent | 77dfa84a843c0bc935a6c8664f2556573e30845f (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')
-rw-r--r-- | tools/perf/util/c++/clang-test.cpp | 5 | ||||
-rw-r--r-- | tools/perf/util/c++/clang.cpp | 21 | ||||
-rw-r--r-- | tools/perf/util/c++/clang.h | 8 |
3 files changed, 22 insertions, 12 deletions
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp index 3da6bfa4bc54..0f484fbb2b58 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) | |||
16 | perf_clang_scope _scope; | 16 | perf_clang_scope _scope; |
17 | 17 | ||
18 | std::unique_ptr<llvm::Module> M = | 18 | std::unique_ptr<llvm::Module> M = |
19 | perf::getModuleFromSource("perf-test.c", | 19 | perf::getModuleFromSource({"-DRESULT=1"}, |
20 | "int myfunc(void) {return 1;}"); | 20 | "perf-test.c", |
21 | "int myfunc(void) {return RESULT;}"); | ||
21 | 22 | ||
22 | if (!M) | 23 | if (!M) |
23 | return -1; | 24 | return -1; |
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; | |||
29 | using namespace clang; | 29 | using namespace clang; |
30 | 30 | ||
31 | static CompilerInvocation * | 31 | static CompilerInvocation * |
32 | createCompilerInvocation(StringRef& Path, DiagnosticsEngine& Diags) | 32 | createCompilerInvocation(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 | ||
56 | static std::unique_ptr<llvm::Module> | 59 | static std::unique_ptr<llvm::Module> |
57 | getModuleFromSource(StringRef Path, | 60 | getModuleFromSource(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 | ||
76 | std::unique_ptr<llvm::Module> | 80 | std::unique_ptr<llvm::Module> |
77 | getModuleFromSource(StringRef Name, StringRef Content) | 81 | getModuleFromSource(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 | ||
96 | std::unique_ptr<llvm::Module> | 101 | std::unique_ptr<llvm::Module> |
97 | getModuleFromSource(StringRef Path) | 102 | getModuleFromSource(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 | } |
diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h index 90aff0162f1c..b4fc2a96b79d 100644 --- a/tools/perf/util/c++/clang.h +++ b/tools/perf/util/c++/clang.h | |||
@@ -4,16 +4,20 @@ | |||
4 | #include "llvm/ADT/StringRef.h" | 4 | #include "llvm/ADT/StringRef.h" |
5 | #include "llvm/IR/LLVMContext.h" | 5 | #include "llvm/IR/LLVMContext.h" |
6 | #include "llvm/IR/Module.h" | 6 | #include "llvm/IR/Module.h" |
7 | #include "llvm/Option/Option.h" | ||
7 | #include <memory> | 8 | #include <memory> |
9 | |||
8 | namespace perf { | 10 | namespace perf { |
9 | 11 | ||
10 | using namespace llvm; | 12 | using namespace llvm; |
11 | 13 | ||
12 | std::unique_ptr<Module> | 14 | std::unique_ptr<Module> |
13 | getModuleFromSource(StringRef Name, StringRef Content); | 15 | getModuleFromSource(opt::ArgStringList CFlags, |
16 | StringRef Name, StringRef Content); | ||
14 | 17 | ||
15 | std::unique_ptr<Module> | 18 | std::unique_ptr<Module> |
16 | getModuleFromSource(StringRef Path); | 19 | getModuleFromSource(opt::ArgStringList CFlags, |
20 | StringRef Path); | ||
17 | 21 | ||
18 | } | 22 | } |
19 | #endif | 23 | #endif |