Suppose, I have a Pass1 implemented as a subclass of Pass, with source code in the directory of llvm source base( transform/analyze ) I can run that pass through opt on the bytecode emitted by gcc frontend through opt tool. However, I want that Pass1 to be the part of the actual GCC compiler. I want to know how I can position Pass1 among other passes /optimizations/ code generations. e.g if I want to run Pass1 before register allocation, then..? So when I run llvmgcc , among other transformations, my Pass1 also runs on the code.
On Wed, Dec 17, 2003 at 06:50:48PM +0000, Umar Janjua wrote:> Suppose, I have a Pass1 implemented as a subclass of Pass, with source > code in the directory of llvm source base( transform/analyze ) > > I can run that pass through opt on the bytecode emitted by gcc frontend > through opt tool. However, I want that Pass1 to be the part of the actual GCC > compiler. I want to know how I can position Pass1 among other passes > /optimizations/ code generations.[snip]> So when I run llvmgcc , among other transformations, my Pass1 also > runs on the code.llvm-gcc produces text LLVM assembly, which is then assembled and run through the gccas tool. If you take a look at llvm/tools/gccas/gccas.cpp, you will find a list of passes and the order in which they are run. You can add your pass within the list of passes you see there.> e.g if I want to run Pass1 before register allocation, then..?llvm-gcc does not run the register allocator, as that is machine-specific, and is only done at code-generation time. This means you are ALREADY running your pass before register allocation if you use opt, for example: % llvm-gcc program.c -o program # you now have 'program' which is a shell script and 'program.bc' which # is LLVM bytecode. NO register allocation has taken place % opt -load=/path/to/opt < program.bc > program-transformed.bc # You now have run your optimization on the code % llc program-transformed.bc -o program-transformed.s # You now have run register allocation FYI, the flow is like this (simplified): C, C++, etc. => llvm-gcc => gccas (some transformations) => gccld (links bytecode files together) => opt (optional, some more transformations) => llc (native assembly) Or substitute the jit for llc to get dynamic execution. HTH. -- Misha Brukman :: http://misha.brukman.net
> I can run that pass through opt on the bytecode emitted by gcc frontend > through opt tool. However, I want that Pass1 to be the part of the > actual GCC compiler. I want to know how I can position Pass1 among > other passes /optimizations/ code generations.I had a similar question and Chris recommended that I edit the addPassesToEmitAssembly method. Quoting him: " Basically, if you want to work on the code generator, this is what you should do: Add your pass to the addPassesToEmitAssembly method for the target of your choice, and in your pass implement the getPassName() method to provide a nice user-friendly name. " You can explicitly specify where (w.r.t other passes) your pass will execute in the addPassesToEmitAssembly method. -Anshu
Anshu Dasgupta wrote:>> I can run that pass through opt on the bytecode emitted by gcc frontend >> through opt tool. However, I want that Pass1 to be the part of the >> actual GCC compiler. I want to know how I can position Pass1 among >> other passes /optimizations/ code generations. >Another thing to note is that gccld, as well as gccas, also performs optimizations on the bytecode. Since gccld links together all of the translation units, it can do interprocedural optimizations on the entire program (whereas gccas can only optimize one bytecode file at a time). Your optimization pass may be better added to gccld, depending on what it does.> > I had a similar question and Chris recommended that I edit the > addPassesToEmitAssembly method. Quoting him: > > " Basically, if you want to work on the code generator, this is what you > should do: Add your pass to the addPassesToEmitAssembly method for the > target of your choice, and in your pass implement the getPassName() > method to provide a nice user-friendly name. " > > You can explicitly specify where (w.r.t other passes) your pass will > execute in the addPassesToEmitAssembly method.My understanding of this is not complete, but from what I understand, Anshu's issue revolves around the fact that his pass deals specifically with code generation in llc. Regular optimization and analysis passes can be coded as a separate project and loaded into opt or analyze dynamically at run time (or they can be hard-coded into gccas and gccld). I believe only passes that directly deal with machine code generation (i.e. passes added to llc) need to use addPassesToEmitAssembly(). So, for Umar's work, the addPassesToEmitAssembly() should not be necessary. Corrections to my comments welcome.> > -Anshu > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdevRegards, John T. Criswell -- ********************************************************************* * John T. Criswell Email: criswell at uiuc.edu * * Research Programmer * * University of Illinois at Urbana-Champaign * * * * "It's today!" said Piglet. "My favorite day," said Pooh. * *********************************************************************