-static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR];
-
-static void
-InsertPrologCode(Method* method, TargetMachine& target)
-{
- BasicBlock* entryBB = method->getEntryNode();
- unsigned N = GetInstructionsForProlog(entryBB, target, minstrVec);
- assert(N <= MAX_INSTR_PER_VMINSTR);
- if (N > 0)
- {
- MachineCodeForBasicBlock& bbMvec = entryBB->getMachineInstrVec();
- bbMvec.insert(bbMvec.begin(), minstrVec, minstrVec+N);
- }
-}
-
-
-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();
- MachineCodeForVMInstr& termMvec =
- exitBB->getTerminator()->getMachineInstrVec();
-
- // 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]);
- }
-}
-