-static void
-InsertEpilogCode(Method* method, TargetMachine& target)
-{
- for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I)
- if ((*I)->getTerminator()->getOpcode() == Instruction::Ret)
- {
- BasicBlock* exitBB = *I;
- unsigned N = GetInstructionsForEpilog(exitBB, target, minstrVec);
-
- MachineCodeForBasicBlock& bbMvec = exitBB->getMachineInstrVec();
- MachineCodeForInstruction &termMvec =
- MachineCodeForInstruction::get(exitBB->getTerminator());
-
- // Remove the NOPs in the delay slots of the return instruction
- const MachineInstrInfo &mii = target.getInstrInfo();
- unsigned numNOPs = 0;
- while (termMvec.back()->getOpCode() == NOP)
- {
- assert( termMvec.back() == bbMvec.back());
- termMvec.pop_back();
- bbMvec.pop_back();
- ++numNOPs;
- }
- assert(termMvec.back() == bbMvec.back());
-
- // Check that we found the right number of NOPs and have the right
- // number of instructions to replace them.
- unsigned ndelays = mii.getNumDelaySlots(termMvec.back()->getOpCode());
- assert(numNOPs == ndelays && "Missing NOPs in delay slots?");
- assert(N == ndelays && "Cannot use epilog code for delay slots?");
-
- // Append the epilog code to the end of the basic block.
- bbMvec.push_back(minstrVec[0]);
- }
-}
-
-
-// Insert SAVE/RESTORE instructions for the method
-static void
-InsertPrologEpilog(Method *method, TargetMachine &target)
-{
- MachineCodeForMethod& mcodeInfo = MachineCodeForMethod::get(method);
- if (mcodeInfo.isCompiledAsLeafMethod())
- return; // nothing to do
-
- InsertPrologCode(method, target);
- InsertEpilogCode(method, target);
-}