//
//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "fp"
+#define DEBUG_TYPE "x86-codegen"
#include "X86.h"
#include "X86InstrInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h"
#include <algorithm>
-#include <iostream>
#include <set>
using namespace llvm;
-namespace {
- Statistic<> NumFXCH("x86-codegen", "Number of fxch instructions inserted");
- Statistic<> NumFP ("x86-codegen", "Number of floating point instructions");
+STATISTIC(NumFXCH, "Number of fxch instructions inserted");
+STATISTIC(NumFP , "Number of floating point instructions");
+namespace {
struct VISIBILITY_HIDDEN FPS : public MachineFunctionPass {
virtual bool runOnMachineFunction(MachineFunction &MF);
MachineFunctionPass::getAnalysisUsage(AU);
}
private:
- LiveVariables *LV; // Live variable info for current function...
- MachineBasicBlock *MBB; // Current basic block
- unsigned Stack[8]; // FP<n> Registers in each stack slot...
- unsigned RegMap[8]; // Track which stack slot contains each register
- unsigned StackTop; // The current top of the FP stack.
+ const TargetInstrInfo *TII; // Machine instruction info.
+ LiveVariables *LV; // Live variable info for current function...
+ MachineBasicBlock *MBB; // Current basic block
+ unsigned Stack[8]; // FP<n> Registers in each stack slot...
+ unsigned RegMap[8]; // Track which stack slot contains each register
+ unsigned StackTop; // The current top of the FP stack.
void dumpStack() const {
- std::cerr << "Stack contents:";
+ cerr << "Stack contents:";
for (unsigned i = 0; i != StackTop; ++i) {
- std::cerr << " FP" << Stack[i];
+ cerr << " FP" << Stack[i];
assert(RegMap[Stack[i]] == i && "Stack[] doesn't match RegMap[]!");
}
- std::cerr << "\n";
+ cerr << "\n";
}
private:
// getSlot - Return the stack slot number a particular register number is
bool isAtTop(unsigned RegNo) const { return getSlot(RegNo) == StackTop-1; }
void moveToTop(unsigned RegNo, MachineBasicBlock::iterator &I) {
if (!isAtTop(RegNo)) {
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
-
unsigned STReg = getSTReg(RegNo);
unsigned RegOnTop = getStackEntry(0);
}
void duplicateToTop(unsigned RegNo, unsigned AsReg, MachineInstr *I) {
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
unsigned STReg = getSTReg(RegNo);
pushReg(AsReg); // New register on top of stack
// Early exit.
if (!FPIsUsed) return false;
+ TII = MF.getTarget().getInstrInfo();
LV = &getAnalysis<LiveVariables>();
StackTop = 0;
PrevMI = prior(I);
++NumFP; // Keep track of # of pseudo instrs
- DEBUG(std::cerr << "\nFPInst:\t"; MI->print(std::cerr, &(MF.getTarget())));
+ DOUT << "\nFPInst:\t" << *MI;
// Get dead variables list now because the MI pointer may be deleted as part
// of processing!
for (unsigned i = 0, e = DeadRegs.size(); i != e; ++i) {
unsigned Reg = DeadRegs[i];
if (Reg >= X86::FP0 && Reg <= X86::FP6) {
- DEBUG(std::cerr << "Register FP#" << Reg-X86::FP0 << " is dead!\n");
+ DOUT << "Register FP#" << Reg-X86::FP0 << " is dead!\n";
freeStackSlotAfter(I, Reg-X86::FP0);
}
}
DEBUG(
MachineBasicBlock::iterator PrevI(PrevMI);
if (I == PrevI) {
- std::cerr << "Just deleted pseudo instruction\n";
+ cerr << "Just deleted pseudo instruction\n";
} else {
MachineBasicBlock::iterator Start = I;
// Rewind to first instruction newly inserted.
while (Start != BB.begin() && prior(Start) != PrevI) --Start;
- std::cerr << "Inserted instructions:\n\t";
- Start->print(std::cerr, &MF.getTarget());
+ cerr << "Inserted instructions:\n\t";
+ Start->print(*cerr.stream(), &MF.getTarget());
while (++Start != next(I));
}
dumpStack();
assert(StackTop > 0 && "Cannot pop empty stack!");
RegMap[Stack[--StackTop]] = ~0; // Update state
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
// Check to see if there is a popping version of this instruction...
int Opcode = Lookup(PopTable, ARRAY_SIZE(PopTable), I->getOpcode());
if (Opcode != -1) {
RegMap[TopReg] = OldSlot;
RegMap[FPRegNo] = ~0;
Stack[--StackTop] = ~0;
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
I = BuildMI(*MBB, ++I, TII->get(X86::FSTPrr)).addReg(STReg);
}
///
void FPS::handleZeroArgFP(MachineBasicBlock::iterator &I) {
MachineInstr *MI = I;
- MachineFunction *MF = MI->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
unsigned DestReg = getFPReg(MI->getOperand(0));
// Change from the pseudo instruction to the concrete instruction.
// Convert from the pseudo instruction to the concrete instruction.
MI->RemoveOperand(NumOps-1); // Remove explicit ST(0) operand
- MachineFunction *MF = MI->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
MI->setInstrDescriptor(TII->get(getConcreteOpcode(MI->getOpcode())));
if (MI->getOpcode() == X86::FISTP64m ||
}
// Change from the pseudo instruction to the concrete instruction.
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
MI->RemoveOperand(1); // Drop the source operand.
MI->RemoveOperand(0); // Drop the destination operand.
MI->setInstrDescriptor(TII->get(getConcreteOpcode(MI->getOpcode())));
// Replace the old instruction with a new instruction
MBB->remove(I++);
- MachineFunction *MF = MI->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
I = BuildMI(*MBB, I, TII->get(Opcode)).addReg(getSTReg(NotTOS));
// If both operands are killed, pop one off of the stack in addition to
// anywhere.
moveToTop(Op0, I);
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
// Change from the pseudo instruction to the concrete instruction.
MI->getOperand(0).setReg(getSTReg(Op1));
MI->RemoveOperand(1);
// The first operand *must* be on the top of the stack.
moveToTop(Op0, I);
- MachineFunction *MF = I->getParent()->getParent();
- const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
// Change the second operand to the stack register that the operand is in.
// Change from the pseudo instruction to the concrete instruction.
MI->RemoveOperand(0);