Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Inserting the prologue-epilogue code


Inserting the prologue-epilogue code involves stack unwinding, finalizing the function layout, saving callee-saved registers and emitting the prologue and epilogue code. It also replaces abstract frame indexes with appropriate references. This pass runs after the register allocation phase.

How to do it…

The skeleton and the important functions defined in the PrologueEpilogueInserter class are as follows:

  • The prologue epilogue inserter pass runs on a machine function, hence it inherits the MachineFunctionPass class. Its constructor initializes the pass:

    class PEI : public MachineFunctionPass {
      public:
        static char ID;
        PEI() : MachineFunctionPass(ID) {
          initializePEIPass(*PassRegistry::getPassRegistry());
        }
  • There are various helper functions defined in this class that help insert the prologue and epilogue code:

        void calculateSets(MachineFunction &Fn);
        void calculateCallsInformation(MachineFunction &Fn);
        void calculateCalleeSavedRegisters...