Fix a problem where lib/Target/TargetInstrInfo.h would include and use

a header file from libcodegen.  This violates a layering order: codegen
depends on target, not the other way around.  The fix to this is to 
split TII into two classes, TII and TargetInstrInfoImpl, which defines
stuff that depends on libcodegen.  It is defined in libcodegen, where 
the base is not.

llvm-svn: 45475
This commit is contained in:
Chris Lattner 2008-01-01 01:03:04 +00:00
parent c23e6351de
commit 25568e4cef
19 changed files with 91 additions and 62 deletions

View File

@ -406,7 +406,7 @@ public:
/// return a new machine instruction. If an instruction cannot commute, it /// return a new machine instruction. If an instruction cannot commute, it
/// can also return null. /// can also return null.
/// ///
virtual MachineInstr *commuteInstruction(MachineInstr *MI) const; virtual MachineInstr *commuteInstruction(MachineInstr *MI) const = 0;
/// AnalyzeBranch - Analyze the branching code at the end of MBB, returning /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
/// true if it cannot be understood (e.g. it's a switch dispatch or isn't /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
@ -504,7 +504,7 @@ public:
/// instruction. It returns true if the operation was successful. /// instruction. It returns true if the operation was successful.
virtual virtual
bool PredicateInstruction(MachineInstr *MI, bool PredicateInstruction(MachineInstr *MI,
const std::vector<MachineOperand> &Pred) const; const std::vector<MachineOperand> &Pred) const = 0;
/// SubsumesPredicate - Returns true if the first specified predicate /// SubsumesPredicate - Returns true if the first specified predicate
/// subsumes the second, e.g. GE subsumes GT. /// subsumes the second, e.g. GE subsumes GT.
@ -531,6 +531,21 @@ public:
} }
}; };
/// TargetInstrInfoImpl - This is the default implementation of
/// TargetInstrInfo, which just provides a couple of default implementations
/// for various methods. This separated out because it is implemented in
/// libcodegen, not in libtarget.
class TargetInstrInfoImpl : public TargetInstrInfo {
protected:
TargetInstrInfoImpl(const TargetInstrDescriptor *desc, unsigned NumOpcodes)
: TargetInstrInfo(desc, NumOpcodes) {}
public:
virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
virtual bool PredicateInstruction(MachineInstr *MI,
const std::vector<MachineOperand> &Pred) const;
};
} // End llvm namespace } // End llvm namespace
#endif #endif

View File

@ -0,0 +1,58 @@
//===-- TargetInstrInfoImpl.cpp - Target Instruction Information ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the TargetInstrInfoImpl class, it just provides default
// implementations of various methods.
//
//===----------------------------------------------------------------------===//
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/CodeGen/MachineInstr.h"
using namespace llvm;
// commuteInstruction - The default implementation of this method just exchanges
// operand 1 and 2.
MachineInstr *TargetInstrInfoImpl::commuteInstruction(MachineInstr *MI) const {
assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() &&
"This only knows how to commute register operands so far");
unsigned Reg1 = MI->getOperand(1).getReg();
unsigned Reg2 = MI->getOperand(2).getReg();
bool Reg1IsKill = MI->getOperand(1).isKill();
bool Reg2IsKill = MI->getOperand(2).isKill();
MI->getOperand(2).setReg(Reg1);
MI->getOperand(1).setReg(Reg2);
MI->getOperand(2).setIsKill(Reg1IsKill);
MI->getOperand(1).setIsKill(Reg2IsKill);
return MI;
}
bool TargetInstrInfoImpl::PredicateInstruction(MachineInstr *MI,
const std::vector<MachineOperand> &Pred) const {
bool MadeChange = false;
const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
if (TID->Flags & M_PREDICABLE) {
for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
MachineOperand &MO = MI->getOperand(i);
if (MO.isReg()) {
MO.setReg(Pred[j].getReg());
MadeChange = true;
} else if (MO.isImm()) {
MO.setImm(Pred[j].getImm());
MadeChange = true;
} else if (MO.isMBB()) {
MO.setMBB(Pred[j].getMBB());
MadeChange = true;
}
++j;
}
}
}
return MadeChange;
}

View File

@ -38,7 +38,7 @@ const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
} }
ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI) ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
: TargetInstrInfo(ARMInsts, array_lengthof(ARMInsts)), : TargetInstrInfoImpl(ARMInsts, array_lengthof(ARMInsts)),
RI(*this, STI) { RI(*this, STI) {
} }

View File

@ -125,7 +125,7 @@ namespace ARMII {
}; };
} }
class ARMInstrInfo : public TargetInstrInfo { class ARMInstrInfo : public TargetInstrInfoImpl {
const ARMRegisterInfo RI; const ARMRegisterInfo RI;
public: public:
ARMInstrInfo(const ARMSubtarget &STI); ARMInstrInfo(const ARMSubtarget &STI);

View File

@ -19,7 +19,7 @@
using namespace llvm; using namespace llvm;
AlphaInstrInfo::AlphaInstrInfo() AlphaInstrInfo::AlphaInstrInfo()
: TargetInstrInfo(AlphaInsts, array_lengthof(AlphaInsts)), : TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
RI(*this) { } RI(*this) { }

View File

@ -19,7 +19,7 @@
namespace llvm { namespace llvm {
class AlphaInstrInfo : public TargetInstrInfo { class AlphaInstrInfo : public TargetInstrInfoImpl {
const AlphaRegisterInfo RI; const AlphaRegisterInfo RI;
public: public:
AlphaInstrInfo(); AlphaInstrInfo();

View File

@ -21,7 +21,7 @@
using namespace llvm; using namespace llvm;
SPUInstrInfo::SPUInstrInfo(SPUTargetMachine &tm) SPUInstrInfo::SPUInstrInfo(SPUTargetMachine &tm)
: TargetInstrInfo(SPUInsts, sizeof(SPUInsts)/sizeof(SPUInsts[0])), : TargetInstrInfoImpl(SPUInsts, sizeof(SPUInsts)/sizeof(SPUInsts[0])),
TM(tm), TM(tm),
RI(*TM.getSubtargetImpl(), *this) RI(*TM.getSubtargetImpl(), *this)
{ {

View File

@ -20,8 +20,7 @@
namespace llvm { namespace llvm {
//! Cell SPU instruction information class //! Cell SPU instruction information class
class SPUInstrInfo : public TargetInstrInfo class SPUInstrInfo : public TargetInstrInfoImpl {
{
SPUTargetMachine &TM; SPUTargetMachine &TM;
const SPURegisterInfo RI; const SPURegisterInfo RI;
public: public:

View File

@ -19,7 +19,7 @@
using namespace llvm; using namespace llvm;
IA64InstrInfo::IA64InstrInfo() IA64InstrInfo::IA64InstrInfo()
: TargetInstrInfo(IA64Insts, sizeof(IA64Insts)/sizeof(IA64Insts[0])), : TargetInstrInfoImpl(IA64Insts, sizeof(IA64Insts)/sizeof(IA64Insts[0])),
RI(*this) { RI(*this) {
} }

View File

@ -19,7 +19,7 @@
namespace llvm { namespace llvm {
class IA64InstrInfo : public TargetInstrInfo { class IA64InstrInfo : public TargetInstrInfoImpl {
const IA64RegisterInfo RI; const IA64RegisterInfo RI;
public: public:
IA64InstrInfo(); IA64InstrInfo();

View File

@ -21,7 +21,7 @@ using namespace llvm;
// TODO: Add the subtarget support on this constructor // TODO: Add the subtarget support on this constructor
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm) MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
: TargetInstrInfo(MipsInsts, array_lengthof(MipsInsts)), : TargetInstrInfoImpl(MipsInsts, array_lengthof(MipsInsts)),
TM(tm), RI(*this) {} TM(tm), RI(*this) {}
static bool isZeroImm(const MachineOperand &op) { static bool isZeroImm(const MachineOperand &op) {

View File

@ -42,8 +42,7 @@ namespace Mips {
} }
class MipsInstrInfo : public TargetInstrInfo class MipsInstrInfo : public TargetInstrInfoImpl {
{
MipsTargetMachine &TM; MipsTargetMachine &TM;
const MipsRegisterInfo RI; const MipsRegisterInfo RI;
public: public:

View File

@ -20,7 +20,7 @@
using namespace llvm; using namespace llvm;
PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm) PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm)
: TargetInstrInfo(PPCInsts, array_lengthof(PPCInsts)), TM(tm), : TargetInstrInfoImpl(PPCInsts, array_lengthof(PPCInsts)), TM(tm),
RI(*TM.getSubtargetImpl(), *this) {} RI(*TM.getSubtargetImpl(), *this) {}
/// getPointerRegClass - Return the register class to use to hold pointers. /// getPointerRegClass - Return the register class to use to hold pointers.

View File

@ -61,7 +61,7 @@ enum PPC970_Unit {
} }
class PPCInstrInfo : public TargetInstrInfo { class PPCInstrInfo : public TargetInstrInfoImpl {
PPCTargetMachine &TM; PPCTargetMachine &TM;
const PPCRegisterInfo RI; const PPCRegisterInfo RI;
public: public:

View File

@ -20,7 +20,7 @@
using namespace llvm; using namespace llvm;
SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST) SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
: TargetInstrInfo(SparcInsts, array_lengthof(SparcInsts)), : TargetInstrInfoImpl(SparcInsts, array_lengthof(SparcInsts)),
RI(ST, *this), Subtarget(ST) { RI(ST, *this), Subtarget(ST) {
} }

View File

@ -31,7 +31,7 @@ namespace SPII {
}; };
} }
class SparcInstrInfo : public TargetInstrInfo { class SparcInstrInfo : public TargetInstrInfoImpl {
const SparcRegisterInfo RI; const SparcRegisterInfo RI;
const SparcSubtarget& Subtarget; const SparcSubtarget& Subtarget;
public: public:

View File

@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetInstrInfo.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Constant.h" #include "llvm/Constant.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
using namespace llvm; using namespace llvm;
@ -38,47 +37,6 @@ TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
TargetInstrInfo::~TargetInstrInfo() { TargetInstrInfo::~TargetInstrInfo() {
} }
// commuteInstruction - The default implementation of this method just exchanges
// operand 1 and 2.
MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const {
assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() &&
"This only knows how to commute register operands so far");
unsigned Reg1 = MI->getOperand(1).getReg();
unsigned Reg2 = MI->getOperand(2).getReg();
bool Reg1IsKill = MI->getOperand(1).isKill();
bool Reg2IsKill = MI->getOperand(2).isKill();
MI->getOperand(2).setReg(Reg1);
MI->getOperand(1).setReg(Reg2);
MI->getOperand(2).setIsKill(Reg1IsKill);
MI->getOperand(1).setIsKill(Reg2IsKill);
return MI;
}
bool TargetInstrInfo::PredicateInstruction(MachineInstr *MI,
const std::vector<MachineOperand> &Pred) const {
bool MadeChange = false;
const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
if (TID->Flags & M_PREDICABLE) {
for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
MachineOperand &MO = MI->getOperand(i);
if (MO.isReg()) {
MO.setReg(Pred[j].getReg());
MadeChange = true;
} else if (MO.isImm()) {
MO.setImm(Pred[j].getImm());
MadeChange = true;
} else if (MO.isMBB()) {
MO.setMBB(Pred[j].getMBB());
MadeChange = true;
}
++j;
}
}
}
return MadeChange;
}
bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const { bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
const TargetInstrDescriptor *TID = MI->getInstrDescriptor(); const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
if (TID->Flags & M_TERMINATOR_FLAG) { if (TID->Flags & M_TERMINATOR_FLAG) {

View File

@ -25,7 +25,7 @@
using namespace llvm; using namespace llvm;
X86InstrInfo::X86InstrInfo(X86TargetMachine &tm) X86InstrInfo::X86InstrInfo(X86TargetMachine &tm)
: TargetInstrInfo(X86Insts, array_lengthof(X86Insts)), : TargetInstrInfoImpl(X86Insts, array_lengthof(X86Insts)),
TM(tm), RI(tm, *this) { TM(tm), RI(tm, *this) {
} }

View File

@ -222,7 +222,7 @@ namespace X86II {
}; };
} }
class X86InstrInfo : public TargetInstrInfo { class X86InstrInfo : public TargetInstrInfoImpl {
X86TargetMachine &TM; X86TargetMachine &TM;
const X86RegisterInfo RI; const X86RegisterInfo RI;
mutable IndexedMap<const MachineInstr*, VirtReg2IndexFunctor> MachineInstrMap; mutable IndexedMap<const MachineInstr*, VirtReg2IndexFunctor> MachineInstrMap;