Set default llvm Pass to Opt and Clang

1.1k views Asked by At

Currently I'm trying to set a default Pass to Opt/Clang. It will be called implicitly when I use commands like:

clang -c -emit-llvm code.ll

and with

opt code.ll

The problem is that the modification should be done directly on the llvm source code, that is, I shouldn't use environment variables, symbolic links and aliases.

I did a lot of search on the internet and on the llvm source code but I didn't find a solution and I don't have any idea how solve this problem.

1

There are 1 answers

0
hailinzeng On

Add your pass to PassManager.

diff --git a/llvm-3.8.0/tools/opt/opt.cpp b/llvm-3.8.0/tools/opt/opt.cpp

@@ -446,6 +446,8 @@ int main(int argc, char **argv) {
   if (DisableSimplifyLibCalls)
     TLII.disableAllFunctions();
   Passes.add(new TargetLibraryInfoWrapperPass(TLII));
+  Passes.add(createxxxPass());

Also, have a look at these functions.

PassManagerBuilder::populateFunctionPassManager
PassManagerBuilder::populateModulePassManager
PassManagerBuilder::addLTOOptimizationPasses
PassManagerBuilder::populateLTOPassManager