//===-- RegAllocSimple.cpp - A simple generic register allocator ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file implements a simple register allocator. *Very* simple: It immediate
// spills every value right after it is computed, and it reloads all used
//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "regalloc"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/SSARegMap.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/Target/MachineInstrInfo.h"
+#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "Support/Debug.h"
#include "Support/Statistic.h"
#include <iostream>
void AllocateBasicBlock(MachineBasicBlock &MBB);
/// getStackSpaceFor - This returns the offset of the specified virtual
- /// register on the stack, allocating space if neccesary.
+ /// register on the stack, allocating space if necessary.
int getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC);
/// Given a virtual register, return a compatible physical register that is
// a preliminary pass that will invalidate any registers that
// are used by the instruction (including implicit uses)
unsigned Opcode = MI->getOpcode();
- const MachineInstrDescriptor &Desc = TM->getInstrInfo().get(Opcode);
- if (const unsigned *Regs = Desc.ImplicitUses)
- while (*Regs)
- RegsUsed[*Regs++] = true;
+ const TargetInstrDescriptor &Desc = TM->getInstrInfo().get(Opcode);
+ const unsigned *Regs = Desc.ImplicitUses;
+ while (*Regs)
+ RegsUsed[*Regs++] = true;
- if (const unsigned *Regs = Desc.ImplicitDefs)
- while (*Regs)
- RegsUsed[*Regs++] = true;
+ Regs = Desc.ImplicitDefs;
+ while (*Regs)
+ RegsUsed[*Regs++] = true;
// Loop over uses, move from memory into registers
for (int i = MI->getNumOperands() - 1; i >= 0; --i) {
// register in any given instruction
unsigned physReg = Virt2PhysRegMap[virtualReg];
if (physReg == 0) {
- if (op.opIsDef()) {
+ if (op.opIsDefOnly() || op.opIsDefAndUse()) {
if (TM->getInstrInfo().isTwoAddrInstr(MI->getOpcode()) && i == 0) {
// must be same register number as the first operand
// This maps a = b + c into b += c, and saves b into a's spot
return true;
}
-Pass *createSimpleRegisterAllocator() {
+FunctionPass *createSimpleRegisterAllocator() {
return new RegAllocSimple();
}