Skip to content

Resource summary cache: the key depends on where the IR comes from #192

Open

Description

@SizzleUnrlsd

The resource summary cache keys change when a module's IR comes from the compile IR cache instead of a fresh compile. The summaries of an unchanged file are then computed and written twice: once after the compile, and again on the next run, which reads the IR from the cache.

Example

alias.c, caller.c and model.txt are any inputs with the resource model loaded, for example:

// alias.c
static int storage;
void *create_impl(void) { return &storage; }
void *wrapper(void) { return create_impl(); }
// caller.c
void *wrapper(void);
void release_handle(void *);
void consumer(void) { release_handle(wrapper()); }
acquire_ret create_impl Handle
release_arg release_handle 0 Handle

With the analyzer built from main 112ffcf, run twice with the same caches:

stack_usage_analyzer alias.c caller.c --jobs=1 --timing --resource-model=model.txt \
  --resource-summary-cache-dir=rc --compile-ir-cache-dir=irc --dump-ir=d1/
stack_usage_analyzer alias.c caller.c --jobs=1 --timing --resource-model=model.txt \
  --resource-summary-cache-dir=rc --compile-ir-cache-dir=irc --dump-ir=d2/
Run IR Resource summaries Files in rc
1 compiled 4 module analyses 4
2 compile IR cache (2 hits) 4 module analyses 8
3 compile IR cache 0 module analyses 8

The IR of the two first runs differs in one line:

$ diff d1/alias.c.ll d2/alias.c.ll
1c1
< ; ModuleID = 'compiled_bc'
---
> ; ModuleID = 'cached_ir_bc'

Why

ResourceSummaryOperations::cacheKey (src/app/AnalyzerApp.cpp) hashes hashModuleIR, the module printed in full, ModuleID included. InputPipeline names the module's buffer compiled_bc after a compile and cached_ir_bc after reading the compile IR cache, so the same IR gets two keys.

Expected

The same IR gives the same key whatever its origin: run 2 above reads the summaries run 1 wrote (0 module analyses). For example, the key could leave out the module identifier, or both origins could give the module the same identifier.

The cost is an extra computation of the summaries, not a wrong result. CI runs the test suite with a compile IR cache. In #190, a check that compares two runs fills that cache first, so both runs read their IR from it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions