Repository navigation
Description
Summary
With --compile-ir-cache-dir, a .ll file given as input is parsed from its text by the run that fills the cache, and from the bitcode of its cache entry by the runs that read it. That bitcode is written without the order of each value's uses. The bitcode reader then rebuilds the use lists its own way, and the two modules can list the users of a value in another order.
The analyses walk these lists. Some walks keep the first match, stop on a budget or report in the order of the walk: #274 lists them. A .ll input can therefore be walked one way from an empty cache and another way from a filled one.
No diagnostic was seen to change. This is about the order of the lists, found while reviewing #274.
Reproduction
callers.ll, where @callee is declared after its two callers, as Clang prints declarations:
define i32 @first(i32 %x) {
%r = call i32 @callee(i32 %x)
ret i32 %r
}
define i32 @second(i32 %x) {
%r = call i32 @callee(i32 %x)
ret i32 %r
}
declare i32 @callee(i32)- Load it with a compile IR cache directory: the module is parsed from the text, and an entry is written.
- Load it again: the module is parsed from the entry's bitcode.
- Compare the users of
@calleein the two modules.
Observed: the two modules list the two calls in another order.
Expected: the module read from the cache lists each value's uses in the order the module parsed from the text does.
The command line prints no use list, so the comparison needs a unit test, or a build that compares the module of a load with the module parsed from its bitcode.
Cause
In loadModuleForAnalysis (src/analysis/InputPipeline.cpp), the .ll input path writes the entry with llvm::WriteBitcodeToFile(*result.module, bitcodeStream), which leaves ShouldPreserveUseListOrder at false. A run that finds the entry parses that bitcode before the entry's text.
The text parser meets the uses of @callee before its declaration. A bitcode reader knows every function before it reads a body. Without the order in the bitcode, each ends with its own.
Scope
Counted with a build that compares the module parsed from the text with the module parsed from its bitcode, value by value: the users of every global variable, function, argument, block and instruction, with the operand of each use.
.ll files |
Values with several uses | Lists in another order | With the order in the bitcode |
|---|---|---|---|
callers.ll above |
1 | 1 | 0 |
Lua 5.4.6, 34 files printed by Clang 20 at -O0 -g |
18,640 | 898: 883 functions, 15 global variables | 0 |
The 12 .ll files of test/ |
32 | 0 | 0 |
- Only a
.llinput, with the compile IR cache. For a C or C++ source, the run that fills the cache and the runs that read it parse the same bitcode in thebcformat, and the same text in thellformat. - No diagnostic was seen to change. On the 34 Lua files, the reports from an empty cache and from a filled one hold the same 1008 diagnostics and 2170 functions, over three rounds. The order of Lua's diagnostics varies from run to run, with or without the cache.
- Where the order differs here, the lists are those of functions and global variables. Of the walks perf(input): take each module from compileToModule in the bitcode format #274 lists, one can start from a global variable, and none from a function.
Activity
fix(input): move the compile IR cache to schema v5
test(unit): check that a .ll entry of the previous cache schema is no…
docs(changelog): note that the cache is filled again once