aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/c++/clang.cpp
diff options
context:
space:
mode:
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}