Reputation: 3951
I have an LLVM pass that unoptimizes certain part of my programs but I also need to perform some late machine code optimisations. The problem is that normally late machine code optimisations optimise the work my pass does. Anyway to disable specific late machine code optimisations without modifying LLVM?
Upvotes: 0
Views: 533
Reputation: 3341
Not really.
There are specific things you can prevent the late machine code optimizer from doing, but they're fairly intrusive:
But generally speaking, if you want to transform your program in a way that machine optimizations won't disturb, you'll need to transform your program at the machine level. LLVM supports writing very late stage transformation passes that operate on machine code and it is possible to schedule one of those extremely late, after all the machine code optimizations have finished running. However, you now have to deal with machine code rather than a high level and abstract IR.
To give some understanding of why these things are so intrinsically linked, let's consider the register allocator. Most folks don't want to try to do transformations after register allocation has already happened because that is really hard. So this a classic machine optimization that someone would still want to run after their transformations. However, LLVM's register allocator doesn't really work well without the rest of the machine optimizer. It is written assuming that code motion occurs to move code in and out of loops in ways that improves register pressure. It also is written to have a complex coalescing step run, and so on.
Upvotes: 1