mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 18:06:32 +00:00

In `SourceManager::getFileID()`, Clang performs binary search over its buffer of `SLocEntries`. For modules, this binary search fully deserializes the entire `SLocEntry` block for each visited entry. For some entries, that includes decompressing the associated buffer (e.g. the predefines buffer, macro expansion buffers, contents of volatile files), which shows up in profiles of the dependency scanner. This patch moves the binary search over loaded entries into `ASTReader`, which can perform cheaper partial deserialization during the binary search, reducing the wall time of dependency scans by ~3%. This also reduces the number of retired instructions by ~1.4% on regular (implicit) modules compilation. Note that this patch drops the optimizations based on the last lookup ID (pruning the search space and performing linear search before resorting to the full binary search). Instead, it reduces the search space by asking `ASTReader::GlobalSLocOffsetMap` for the containing `ModuleFile` and only does binary search over entries of single module file.
61 lines
3.1 KiB
C++
61 lines
3.1 KiB
C++
// RUN: rm -rf %t
|
|
// RUN: mkdir %t
|
|
// RUN: echo 'extern int a; template<typename T> int a2 = T::error;' > %t/a.h
|
|
// RUN: echo 'extern int b;' > %t/b.h
|
|
// RUN: echo 'extern int c = 0;' > %t/c.h
|
|
// RUN: echo 'module a { module aa { header "a.h" header "b.h" header "c.h" } }' > %t/modulemap
|
|
// RUN: echo 'module other {}' > %t/other.modulemap
|
|
|
|
// We lazily check that the files referenced by an explicitly-specified .pcm
|
|
// file exist. Test this by removing files and ensuring that the compilation
|
|
// still succeeds.
|
|
//
|
|
// RUN: %clang_cc1 -fmodules -I %t -emit-module -fmodule-name=a -x c++ %t/modulemap -o %t/a.pcm \
|
|
// RUN: -fmodule-map-file=%t/other.modulemap \
|
|
// RUN: -fmodules-embed-file=%t/modulemap -fmodules-embed-file=%t/other.modulemap
|
|
// RUN: %clang_cc1 -fmodules -I %t -emit-module -fmodule-name=a -x c++ %t/modulemap -o %t/b.pcm \
|
|
// RUN: -fmodule-map-file=%t/other.modulemap \
|
|
// RUN: -fmodules-embed-all-files
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -DERRORS 2>&1 | FileCheck %s
|
|
// RUN: mv %t/modulemap %t/modulemap.moved
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -DERRORS 2>&1 | FileCheck %s
|
|
// RUN: rm %t/other.modulemap
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -DERRORS 2>&1 | FileCheck %s
|
|
// RUN: sleep 1
|
|
// RUN: touch %t/a.h
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -DERRORS 2>&1 | FileCheck %s
|
|
// RUN: rm %t/b.h
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/b.pcm %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -DERRORS 2>&1 | FileCheck %s --check-prefix=MISSING-B
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm -fmodule-map-file=%t/modulemap.moved %s
|
|
// RUN: not %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm -fmodule-map-file=%t/modulemap.moved -std=c++1z %s
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm -fmodule-map-file=%t/modulemap.moved -std=c++1z -Wno-module-file-config-mismatch %s -Db=a
|
|
// RUN: rm %t/a.h
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/a.pcm %s -verify
|
|
// RUN: %clang_cc1 -fmodules -I %t -fmodule-file=%t/b.pcm %s -verify
|
|
|
|
// Oftentimes on Windows there are open handles, and deletion will fail.
|
|
// REQUIRES: can-remove-opened-file
|
|
|
|
#include "a.h" // expected-error {{file not found}}
|
|
int x = b;
|
|
|
|
#ifdef ERRORS
|
|
int y = a2<int>;
|
|
// CHECK: In module 'a':
|
|
// CHECK-NEXT: a.h:1:45: error:
|
|
|
|
int z = b<int>;
|
|
// MISSING-B: could not find file '{{.*}}b.h'
|
|
// MISSING-B-NOT: please delete the module cache
|
|
#endif
|
|
|
|
// RUN: not %clang_cc1 -fmodules -I %t -emit-module -fmodule-name=a -x c++ /dev/null -o %t/c.pcm \
|
|
// RUN: -fmodules-embed-file=%t/does-not-exist 2>&1 | FileCheck %s --check-prefix=MISSING-EMBED
|
|
// MISSING-EMBED: fatal error: file '{{.*}}does-not-exist' specified by '-fmodules-embed-file=' not found
|