[LLVMdev] Two questions about pass managers and passes

Pedro Artigas
Fri, 16 Nov 2012 18:11:49 -0000

Hello All,

I have two questions, one more of an implementation question, the other more a
design question.

First: I noticed that if one moves the FPPassManager::doInitialization(Module)
call from FPPassManager::runOnModule to MPPassManager::runOnModule (which is the
new location I am aiming for to avoid the need for a
doInitialization/doFinalization outside of the run methods, as preferred by
Chris Lattner) some function passes fail. Notably the Address sanitizer test in
the dump below complains:

FAIL: LLVM ::
Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll (3773 of
6811)
******************** TEST 'LLVM ::
Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll' FAILED
********************
Script:
--
/Users/partigas/Desktop/src/build/Debug+Asserts/bin/opt <
/Users/partigas/Desktop/src/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
-asan -asan-initialization-order -S |
/Users/partigas/Desktop/src/build/Debug+Asserts/bin/FileCheck
/Users/partigas/Desktop/src/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
--
Exit Code: 1
Command Output (stderr):
--
/Users/partigas/Desktop/src/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll:33:10:
error: expected string not found in input
; CHECK: call void @__asan_before_dynamic_init
       ^
<stdin>:20:35: note: scanning from here
define internal void @_GLOBAL__I_a() address_safety section
".text.startup" {
                                ^
<stdin>:33:3: note: possible intended match here
declare void @__asan_report_load1(i64)
^
--

I presume this is either a bug (as the ordering of the
doInitialization/doFinalization per module should not matter as they are just
setting up/clearing up internal state) and/or it is some interaction with the
rest of the code in the main loop of MPPassManager::runOnModule. That is, some
function pass expects to be initialized/finalized before the completion of the
loop in MPPassManager::runOnModule.

If someone has a clue, please let me know. I am investigating more.

Second: Why do we need to use the FunctionPassManager pass manager interface in
clang? it seems we call doInitialization, iterate over the functions and finally
call doFinalization… this seems like it is exactly what a PassManager style pass
manager would do anyways. So why not use that and hide the loop over the
functions in the run method of the PassManager? Does anyone know the reasoning
for that?

Thanks for any info,

Pedro

PS: I am planning on avoiding the need for doInitialization/doFinalization on
the PassManager interface and, after I achieve that, move the
doInitialization/doFinalization methods to the base Pass class, as suggested on
the llvm-commits list.