summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-06-30 18:12:25 +0000
committerJustin Lebar <jlebar@google.com>2016-06-30 18:12:25 +0000
commit909f14ac45a043ba03cd95a119d7521573fb219a (patch)
tree8af7bdd97dfb5a1fbc8fb7ded8272f59546296be /unittests
parent007ae0afb873fe3bba2bf5a9db77fae267679f92 (diff)
Don't instantiate a full host toolchain in ASTMatchersTest.
Summary: This test was stat()'ing large swaths of /usr/lib hundreds of times, as every invocation of matchesConditionally*() created a new Linux toolchain. In addition to being slow, perf indicated this was causing substantial contention in the kernel. Something is...interesting in the kernel, as without this patch I sometimes see ~11m spent in the kernel, and sometimes ~5m. This corresponds to bimodal ninja check-clang times of ~30s and ~20s. It's not clear to me exactly what causes the bimodality. In any case, this change makes this test run in 2.5s, down from 17s, and it seems to cause us to get the 20s ninja check-clang time unconditionally. Reviewers: chandlerc Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D21810 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274257 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h
index 7f4d38c48b..4b3387c0ba 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/unittests/ASTMatchers/ASTMatchersTest.h
@@ -73,12 +73,16 @@ testing::AssertionResult matchesConditionally(
return testing::AssertionFailure() << "Could not add dynamic matcher";
std::unique_ptr<FrontendActionFactory> Factory(
newFrontendActionFactory(&Finder));
- // Some tests use typeof, which is a gnu extension.
- std::vector<std::string> Args;
- Args.push_back(CompileArg);
- // Some tests need rtti/exceptions on
- Args.push_back("-frtti");
- Args.push_back("-fexceptions");
+ // Some tests need rtti/exceptions on. Use an unknown-unknown triple so we
+ // don't instantiate the full system toolchain. On Linux, instantiating the
+ // toolchain involves stat'ing large portions of /usr/lib, and this slows down
+ // not only this test, but all other tests, via contention in the kernel.
+ //
+ // FIXME: This is a hack to work around the fact that there's no way to do the
+ // equivalent of runToolOnCodeWithArgs without instantiating a full Driver.
+ // We should consider having a function, at least for tests, that invokes cc1.
+ std::vector<std::string> Args = {CompileArg, "-frtti", "-fexceptions",
+ "-target", "i386-unknown-unknown"};
if (!runToolOnCodeWithArgs(
Factory->create(), Code, Args, Filename, "clang-tool",
std::make_shared<PCHContainerOperations>(), VirtualMappedFiles)) {
@@ -180,13 +184,12 @@ testing::AssertionResult matchesConditionallyWithCuda(
return testing::AssertionFailure() << "Could not add dynamic matcher";
std::unique_ptr<FrontendActionFactory> Factory(
newFrontendActionFactory(&Finder));
- // Some tests use typeof, which is a gnu extension.
- std::vector<std::string> Args;
- Args.push_back("-xcuda");
- Args.push_back("-fno-ms-extensions");
- Args.push_back("--cuda-host-only");
- Args.push_back("-nocudainc");
- Args.push_back(CompileArg);
+ // Some tests use typeof, which is a gnu extension. Using an explicit
+ // unknown-unknown triple is good for a large speedup, because it lets us
+ // avoid constructing a full system triple.
+ std::vector<std::string> Args = {
+ "-xcuda", "-fno-ms-extensions", "--cuda-host-only", "-nocudainc",
+ "-target", "nvptx64-unknown-unknown", CompileArg};
if (!runToolOnCodeWithArgs(Factory->create(),
CudaHeader + Code, Args)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
@@ -230,8 +233,11 @@ matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
Finder.addMatcher(AMatcher, &VerifyVerifiedResult);
std::unique_ptr<FrontendActionFactory> Factory(
newFrontendActionFactory(&Finder));
- // Some tests use typeof, which is a gnu extension.
- std::vector<std::string> Args(1, "-std=gnu++98");
+ // Some tests use typeof, which is a gnu extension. Using an explicit
+ // unknown-unknown triple is good for a large speedup, because it lets us
+ // avoid constructing a full system triple.
+ std::vector<std::string> Args = {"-std=gnu++98", "-target",
+ "i386-unknown-unknown"};
if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}