How to migrate PassManager CodeGenPasses for LLVM v6.x?

Hi LLVM developers,

CodeGen had been changed a lot, for example:

* no DataLayoutPass any more ⚙ D7992 Make DataLayout Non-Optional in the Module

* no addAnalysisPasses any more

* new MergeFunctions, BBVectorize (but removed after v5.x), RerollLoops ... for PassManagerBuilder

and I have checked clang-33, clang-39 and clang-svn's EmitAssembly in the lib/CodeGen/BackendUtil.cpp, then migrated the CodeGen related code from:

PerModulePasses->add(new DataLayoutPass());

TheTarget->addAnalysisPasses(*PerModulePasses);

To:

CodeGenPasses->add(
createTargetTransformInfoWrapperPass(TheTarget->getTargetIRAnalysis()));

DragonEgg (as a testcase of GCC and LLVM, migrated to GCC v8.x and LLVM v6.x) is able to generate LLVM IR at present http://lists.llvm.org/pipermail/llvm-dev/2017-August/116705.html but *failed* to generate Assembly File by addPassesToEmitFile(CodeGenPasses, ...) and CodeGenPasses.run(TheModule):

     .file "hello.c"
     .section .rodata
     .type __func__.2269, @object
     .size __func__.2269, 4
__func__.2269:
     .string "foo"
     .comm __gnu_lto_v1,1,1
     .comm __gnu_lto_slim,1,1
     .section .note.GNU-stack,"",@progbits

Please give me some hint about why PerFunctionPasses->run(F) failed to work, thanks a lot!

PS: I also read CodGen's tutorial about Compiling to Object Code https://llvm.org/docs/tutorial/LangImpl08.html it is able to work by addPassesToEmitFile(CodeGenPasses, ...) and CodeGenPasses.run(TheModule)!

NAKAMURA used PassManager instead of FunctionPassManager in CodeGen Use PassManager instead of FunctionPassManager in CodeGen. r210280 ha… · llvm-mirror/dragonegg@76fc0ed · GitHub and clang-33 also use PassManager for CodeGenPasses, I have no idea why use FunctionPassManager for it, and FunctionPassManager for CodeGenPasses is able to work for GCC v4.8 and LLVM v3.3 to generate correct Assembly File.