2008-01-01 21:36:19 +01:00
|
|
|
//===-- lib/CodeGen/MachineInstr.cpp --------------------------------------===//
|
2005-04-22 00:36:52 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:36:52 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-02-13 05:39:32 +01:00
|
|
|
//
|
|
|
|
// Methods common to all machine instructions.
|
|
|
|
//
|
2002-08-09 22:08:06 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 14:41:50 +02:00
|
|
|
|
2001-09-07 19:18:30 +02:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2009-03-23 09:01:15 +01:00
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/InlineAsm.h"
|
2007-12-31 05:13:23 +01:00
|
|
|
#include "llvm/Value.h"
|
2009-09-23 03:33:16 +02:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2004-02-19 17:17:08 +01:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2009-09-25 22:36:54 +02:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2008-01-01 02:12:31 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2008-02-06 23:27:42 +01:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2002-10-30 01:48:05 +01:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-01-31 10:59:15 +01:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2008-01-07 08:42:25 +01:00
|
|
|
#include "llvm/Target/TargetInstrDesc.h"
|
2008-02-10 19:45:23 +01:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2009-10-07 19:38:06 +02:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2009-05-01 01:22:31 +02:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2008-07-18 01:49:46 +02:00
|
|
|
#include "llvm/Support/LeakDetector.h"
|
2008-07-07 22:32:02 +02:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2008-08-24 22:37:32 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-08-20 17:58:01 +02:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2004-02-23 19:38:20 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2007-12-30 22:56:09 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineOperand Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-01-01 02:12:31 +01:00
|
|
|
/// AddRegOperandToRegInfo - Add this register operand to the specified
|
|
|
|
/// MachineRegisterInfo. If it is null, then the next/prev fields should be
|
|
|
|
/// explicitly nulled out.
|
|
|
|
void MachineOperand::AddRegOperandToRegInfo(MachineRegisterInfo *RegInfo) {
|
2008-10-03 17:45:36 +02:00
|
|
|
assert(isReg() && "Can only add reg operand to use lists");
|
2008-01-01 02:12:31 +01:00
|
|
|
|
|
|
|
// If the reginfo pointer is null, just explicitly null out or next/prev
|
|
|
|
// pointers, to ensure they are not garbage.
|
|
|
|
if (RegInfo == 0) {
|
|
|
|
Contents.Reg.Prev = 0;
|
|
|
|
Contents.Reg.Next = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, add this operand to the head of the registers use/def list.
|
2008-01-01 22:08:22 +01:00
|
|
|
MachineOperand **Head = &RegInfo->getRegUseDefListHead(getReg());
|
2008-01-01 02:12:31 +01:00
|
|
|
|
2008-01-01 22:08:22 +01:00
|
|
|
// For SSA values, we prefer to keep the definition at the start of the list.
|
|
|
|
// we do this by skipping over the definition if it is at the head of the
|
|
|
|
// list.
|
|
|
|
if (*Head && (*Head)->isDef())
|
|
|
|
Head = &(*Head)->Contents.Reg.Next;
|
|
|
|
|
|
|
|
Contents.Reg.Next = *Head;
|
2008-01-01 02:12:31 +01:00
|
|
|
if (Contents.Reg.Next) {
|
|
|
|
assert(getReg() == Contents.Reg.Next->getReg() &&
|
|
|
|
"Different regs on the same list!");
|
|
|
|
Contents.Reg.Next->Contents.Reg.Prev = &Contents.Reg.Next;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:08:22 +01:00
|
|
|
Contents.Reg.Prev = Head;
|
|
|
|
*Head = this;
|
2008-01-01 02:12:31 +01:00
|
|
|
}
|
|
|
|
|
2009-04-15 03:17:37 +02:00
|
|
|
/// RemoveRegOperandFromRegInfo - Remove this register operand from the
|
|
|
|
/// MachineRegisterInfo it is linked with.
|
|
|
|
void MachineOperand::RemoveRegOperandFromRegInfo() {
|
|
|
|
assert(isOnRegUseList() && "Reg operand is not on a use list");
|
|
|
|
// Unlink this from the doubly linked list of operands.
|
|
|
|
MachineOperand *NextOp = Contents.Reg.Next;
|
|
|
|
*Contents.Reg.Prev = NextOp;
|
|
|
|
if (NextOp) {
|
|
|
|
assert(NextOp->getReg() == getReg() && "Corrupt reg use/def chain!");
|
|
|
|
NextOp->Contents.Reg.Prev = Contents.Reg.Prev;
|
|
|
|
}
|
|
|
|
Contents.Reg.Prev = 0;
|
|
|
|
Contents.Reg.Next = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-01 02:12:31 +01:00
|
|
|
void MachineOperand::setReg(unsigned Reg) {
|
|
|
|
if (getReg() == Reg) return; // No change.
|
|
|
|
|
|
|
|
// Otherwise, we have to change the register. If this operand is embedded
|
|
|
|
// into a machine function, we need to update the old and new register's
|
|
|
|
// use/def lists.
|
|
|
|
if (MachineInstr *MI = getParent())
|
|
|
|
if (MachineBasicBlock *MBB = MI->getParent())
|
|
|
|
if (MachineFunction *MF = MBB->getParent()) {
|
|
|
|
RemoveRegOperandFromRegInfo();
|
|
|
|
Contents.Reg.RegNo = Reg;
|
|
|
|
AddRegOperandToRegInfo(&MF->getRegInfo());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, just change the register, no problem. :)
|
|
|
|
Contents.Reg.RegNo = Reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ChangeToImmediate - Replace this operand with a new immediate operand of
|
|
|
|
/// the specified value. If an operand is known to be an immediate already,
|
|
|
|
/// the setImm method should be used.
|
|
|
|
void MachineOperand::ChangeToImmediate(int64_t ImmVal) {
|
|
|
|
// If this operand is currently a register operand, and if this is in a
|
|
|
|
// function, deregister the operand from the register's use/def list.
|
2008-10-03 17:45:36 +02:00
|
|
|
if (isReg() && getParent() && getParent()->getParent() &&
|
2008-01-01 02:12:31 +01:00
|
|
|
getParent()->getParent()->getParent())
|
|
|
|
RemoveRegOperandFromRegInfo();
|
|
|
|
|
|
|
|
OpKind = MO_Immediate;
|
|
|
|
Contents.ImmVal = ImmVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ChangeToRegister - Replace this operand with a new register operand of
|
|
|
|
/// the specified value. If an operand is known to be an register already,
|
|
|
|
/// the setReg method should be used.
|
|
|
|
void MachineOperand::ChangeToRegister(unsigned Reg, bool isDef, bool isImp,
|
2009-06-30 10:49:04 +02:00
|
|
|
bool isKill, bool isDead, bool isUndef) {
|
2008-01-01 02:12:31 +01:00
|
|
|
// If this operand is already a register operand, use setReg to update the
|
|
|
|
// register's use/def lists.
|
2008-10-03 17:45:36 +02:00
|
|
|
if (isReg()) {
|
2008-09-14 03:44:36 +02:00
|
|
|
assert(!isEarlyClobber());
|
2008-01-01 02:12:31 +01:00
|
|
|
setReg(Reg);
|
|
|
|
} else {
|
|
|
|
// Otherwise, change this to a register and set the reg#.
|
|
|
|
OpKind = MO_Register;
|
|
|
|
Contents.Reg.RegNo = Reg;
|
|
|
|
|
|
|
|
// If this operand is embedded in a function, add the operand to the
|
|
|
|
// register's use/def list.
|
|
|
|
if (MachineInstr *MI = getParent())
|
|
|
|
if (MachineBasicBlock *MBB = MI->getParent())
|
|
|
|
if (MachineFunction *MF = MBB->getParent())
|
|
|
|
AddRegOperandToRegInfo(&MF->getRegInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
IsDef = isDef;
|
|
|
|
IsImp = isImp;
|
|
|
|
IsKill = isKill;
|
|
|
|
IsDead = isDead;
|
2009-06-30 10:49:04 +02:00
|
|
|
IsUndef = isUndef;
|
2008-09-14 03:44:36 +02:00
|
|
|
IsEarlyClobber = false;
|
2008-01-01 02:12:31 +01:00
|
|
|
SubReg = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:56:09 +01:00
|
|
|
/// isIdenticalTo - Return true if this operand is identical to the specified
|
|
|
|
/// operand.
|
|
|
|
bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
|
2009-06-24 19:54:48 +02:00
|
|
|
if (getType() != Other.getType() ||
|
|
|
|
getTargetFlags() != Other.getTargetFlags())
|
|
|
|
return false;
|
2007-12-30 22:56:09 +01:00
|
|
|
|
|
|
|
switch (getType()) {
|
2009-07-14 18:55:14 +02:00
|
|
|
default: llvm_unreachable("Unrecognized operand type");
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
return getReg() == Other.getReg() && isDef() == Other.isDef() &&
|
|
|
|
getSubReg() == Other.getSubReg();
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return getImm() == Other.getImm();
|
2008-02-14 08:39:30 +01:00
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
return getFPImm() == Other.getFPImm();
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
return getMBB() == Other.getMBB();
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
2007-12-31 00:10:15 +01:00
|
|
|
return getIndex() == Other.getIndex();
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2007-12-31 00:10:15 +01:00
|
|
|
return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2007-12-31 00:10:15 +01:00
|
|
|
return getIndex() == Other.getIndex();
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
return !strcmp(getSymbolName(), Other.getSymbolName()) &&
|
|
|
|
getOffset() == Other.getOffset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// print - Print the specified machine operand.
|
|
|
|
///
|
2008-10-10 03:43:55 +02:00
|
|
|
void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const {
|
2007-12-30 22:56:09 +01:00
|
|
|
switch (getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
2008-02-10 19:45:23 +01:00
|
|
|
if (getReg() == 0 || TargetRegisterInfo::isVirtualRegister(getReg())) {
|
2007-12-30 22:56:09 +01:00
|
|
|
OS << "%reg" << getReg();
|
|
|
|
} else {
|
|
|
|
// If the instruction is embedded into a basic block, we can find the
|
2008-01-01 02:12:31 +01:00
|
|
|
// target info for the instruction.
|
2007-12-30 22:56:09 +01:00
|
|
|
if (TM == 0)
|
|
|
|
if (const MachineInstr *MI = getParent())
|
|
|
|
if (const MachineBasicBlock *MBB = MI->getParent())
|
|
|
|
if (const MachineFunction *MF = MBB->getParent())
|
|
|
|
TM = &MF->getTarget();
|
|
|
|
|
|
|
|
if (TM)
|
2008-02-26 22:47:57 +01:00
|
|
|
OS << "%" << TM->getRegisterInfo()->get(getReg()).Name;
|
2007-12-30 22:56:09 +01:00
|
|
|
else
|
|
|
|
OS << "%mreg" << getReg();
|
|
|
|
}
|
2008-12-18 22:51:27 +01:00
|
|
|
|
2009-06-30 10:49:04 +02:00
|
|
|
if (getSubReg() != 0)
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << ':' << getSubReg();
|
2008-12-18 22:51:27 +01:00
|
|
|
|
2009-06-30 10:49:04 +02:00
|
|
|
if (isDef() || isKill() || isDead() || isImplicit() || isUndef() ||
|
|
|
|
isEarlyClobber()) {
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << '<';
|
2007-12-30 22:56:09 +01:00
|
|
|
bool NeedComma = false;
|
2009-10-15 01:37:31 +02:00
|
|
|
if (isDef()) {
|
2009-06-24 19:54:48 +02:00
|
|
|
if (NeedComma) OS << ',';
|
2008-09-12 19:49:03 +02:00
|
|
|
if (isEarlyClobber())
|
|
|
|
OS << "earlyclobber,";
|
2009-10-15 01:37:31 +02:00
|
|
|
if (isImplicit())
|
|
|
|
OS << "imp-";
|
2007-12-30 22:56:09 +01:00
|
|
|
OS << "def";
|
|
|
|
NeedComma = true;
|
2009-10-21 09:56:02 +02:00
|
|
|
} else if (isImplicit()) {
|
2009-10-15 01:37:31 +02:00
|
|
|
OS << "imp-use";
|
2009-10-21 09:56:02 +02:00
|
|
|
NeedComma = true;
|
|
|
|
}
|
2009-10-15 01:37:31 +02:00
|
|
|
|
2009-06-30 10:49:04 +02:00
|
|
|
if (isKill() || isDead() || isUndef()) {
|
2009-06-24 19:54:48 +02:00
|
|
|
if (NeedComma) OS << ',';
|
2008-02-24 01:56:13 +01:00
|
|
|
if (isKill()) OS << "kill";
|
|
|
|
if (isDead()) OS << "dead";
|
2009-06-30 10:49:04 +02:00
|
|
|
if (isUndef()) {
|
|
|
|
if (isKill() || isDead())
|
|
|
|
OS << ',';
|
|
|
|
OS << "undef";
|
|
|
|
}
|
2007-12-30 22:56:09 +01:00
|
|
|
}
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
OS << getImm();
|
|
|
|
break;
|
2008-02-14 08:39:30 +01:00
|
|
|
case MachineOperand::MO_FPImmediate:
|
2009-10-05 07:54:46 +02:00
|
|
|
if (getFPImm()->getType()->isFloatTy())
|
2008-02-14 08:39:30 +01:00
|
|
|
OS << getFPImm()->getValueAPF().convertToFloat();
|
2009-06-24 19:54:48 +02:00
|
|
|
else
|
2008-02-14 08:39:30 +01:00
|
|
|
OS << getFPImm()->getValueAPF().convertToDouble();
|
|
|
|
break;
|
2007-12-30 22:56:09 +01:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
OS << "mbb<"
|
2007-12-31 00:10:15 +01:00
|
|
|
<< ((Value*)getMBB()->getBasicBlock())->getName()
|
2009-06-24 19:54:48 +02:00
|
|
|
<< "," << (void*)getMBB() << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << "<fi#" << getIndex() << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2007-12-31 00:10:15 +01:00
|
|
|
OS << "<cp#" << getIndex();
|
2007-12-30 22:56:09 +01:00
|
|
|
if (getOffset()) OS << "+" << getOffset();
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << "<jt#" << getIndex() << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
OS << "<ga:" << ((Value*)getGlobal())->getName();
|
|
|
|
if (getOffset()) OS << "+" << getOffset();
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
OS << "<es:" << getSymbolName();
|
|
|
|
if (getOffset()) OS << "+" << getOffset();
|
2009-06-24 19:54:48 +02:00
|
|
|
OS << '>';
|
2007-12-30 22:56:09 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unrecognized operand type");
|
2007-12-30 22:56:09 +01:00
|
|
|
}
|
2009-06-24 19:54:48 +02:00
|
|
|
|
|
|
|
if (unsigned TF = getTargetFlags())
|
|
|
|
OS << "[TF=" << TF << ']';
|
2007-12-30 22:56:09 +01:00
|
|
|
}
|
|
|
|
|
2008-07-07 22:32:02 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineMemOperand Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
MachineMemOperand::MachineMemOperand(const Value *v, unsigned int f,
|
|
|
|
int64_t o, uint64_t s, unsigned int a)
|
|
|
|
: Offset(o), Size(s), V(v),
|
|
|
|
Flags((f & 7) | ((Log2_32(a) + 1) << 3)) {
|
2009-09-21 21:47:04 +02:00
|
|
|
assert(getBaseAlignment() == a && "Alignment is not a power of 2!");
|
2008-07-16 17:56:42 +02:00
|
|
|
assert((isLoad() || isStore()) && "Not a load/store!");
|
2008-07-07 22:32:02 +02:00
|
|
|
}
|
|
|
|
|
2008-08-20 17:58:01 +02:00
|
|
|
/// Profile - Gather unique data for the object.
|
|
|
|
///
|
|
|
|
void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddInteger(Offset);
|
|
|
|
ID.AddInteger(Size);
|
|
|
|
ID.AddPointer(V);
|
|
|
|
ID.AddInteger(Flags);
|
|
|
|
}
|
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
void MachineMemOperand::refineAlignment(const MachineMemOperand *MMO) {
|
|
|
|
// The Value and Offset may differ due to CSE. But the flags and size
|
|
|
|
// should be the same.
|
|
|
|
assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
|
|
|
|
assert(MMO->getSize() == getSize() && "Size mismatch!");
|
|
|
|
|
|
|
|
if (MMO->getBaseAlignment() >= getBaseAlignment()) {
|
|
|
|
// Update the alignment value.
|
|
|
|
Flags = (Flags & 7) | ((Log2_32(MMO->getBaseAlignment()) + 1) << 3);
|
|
|
|
// Also update the base and offset, because the new alignment may
|
|
|
|
// not be applicable with the old ones.
|
|
|
|
V = MMO->getValue();
|
|
|
|
Offset = MMO->getOffset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 01:33:20 +02:00
|
|
|
/// getAlignment - Return the minimum known alignment in bytes of the
|
|
|
|
/// actual memory reference.
|
|
|
|
uint64_t MachineMemOperand::getAlignment() const {
|
|
|
|
return MinAlign(getBaseAlignment(), getOffset());
|
|
|
|
}
|
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MMO) {
|
|
|
|
assert((MMO.isLoad() || MMO.isStore()) &&
|
2009-09-23 03:33:16 +02:00
|
|
|
"SV has to be a load, store or both.");
|
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.isVolatile())
|
2009-09-23 03:33:16 +02:00
|
|
|
OS << "Volatile ";
|
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.isLoad())
|
2009-09-23 03:33:16 +02:00
|
|
|
OS << "LD";
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.isStore())
|
2009-09-23 03:33:16 +02:00
|
|
|
OS << "ST";
|
2009-09-25 22:36:54 +02:00
|
|
|
OS << MMO.getSize();
|
2009-09-23 03:33:16 +02:00
|
|
|
|
|
|
|
// Print the address information.
|
|
|
|
OS << "[";
|
2009-09-25 22:36:54 +02:00
|
|
|
if (!MMO.getValue())
|
2009-09-23 03:33:16 +02:00
|
|
|
OS << "<unknown>";
|
|
|
|
else
|
2009-09-25 22:36:54 +02:00
|
|
|
WriteAsOperand(OS, MMO.getValue(), /*PrintType=*/false);
|
2009-09-23 03:33:16 +02:00
|
|
|
|
|
|
|
// If the alignment of the memory reference itself differs from the alignment
|
|
|
|
// of the base pointer, print the base alignment explicitly, next to the base
|
|
|
|
// pointer.
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.getBaseAlignment() != MMO.getAlignment())
|
|
|
|
OS << "(align=" << MMO.getBaseAlignment() << ")";
|
2009-09-23 03:33:16 +02:00
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.getOffset() != 0)
|
|
|
|
OS << "+" << MMO.getOffset();
|
2009-09-23 03:33:16 +02:00
|
|
|
OS << "]";
|
|
|
|
|
|
|
|
// Print the alignment of the reference.
|
2009-09-25 22:36:54 +02:00
|
|
|
if (MMO.getBaseAlignment() != MMO.getAlignment() ||
|
|
|
|
MMO.getBaseAlignment() != MMO.getSize())
|
|
|
|
OS << "(align=" << MMO.getAlignment() << ")";
|
2009-09-23 03:33:16 +02:00
|
|
|
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:56:09 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineInstr Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-11-28 00:37:22 +01:00
|
|
|
/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
|
2006-11-30 08:08:44 +01:00
|
|
|
/// TID NULL and no operands.
|
2006-11-28 00:37:22 +01:00
|
|
|
MachineInstr::MachineInstr()
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(0), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0),
|
|
|
|
Parent(0), debugLoc(DebugLoc::getUnknownLoc()) {
|
2008-07-18 01:49:46 +02:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-10-28 21:59:49 +01:00
|
|
|
}
|
|
|
|
|
2006-11-30 08:08:44 +01:00
|
|
|
void MachineInstr::addImplicitDefUseOperands() {
|
|
|
|
if (TID->ImplicitDefs)
|
2007-12-30 01:12:25 +01:00
|
|
|
for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
|
2007-12-30 01:41:17 +01:00
|
|
|
addOperand(MachineOperand::CreateReg(*ImpDefs, true, true));
|
2006-11-30 08:08:44 +01:00
|
|
|
if (TID->ImplicitUses)
|
2007-12-30 01:12:25 +01:00
|
|
|
for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
|
2007-12-30 01:41:17 +01:00
|
|
|
addOperand(MachineOperand::CreateReg(*ImpUses, false, true));
|
2006-11-14 00:34:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// MachineInstr ctor - This constructor create a MachineInstr and add the
|
2006-11-28 00:37:22 +01:00
|
|
|
/// implicit operands. It reserves space for number of operands specified by
|
2008-01-07 08:27:27 +01:00
|
|
|
/// TargetInstrDesc or the numOperands if it is not zero. (for
|
2006-11-28 00:37:22 +01:00
|
|
|
/// instructions with variable number of operands).
|
2008-01-07 08:27:27 +01:00
|
|
|
MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), Parent(0),
|
2009-01-28 00:20:29 +01:00
|
|
|
debugLoc(DebugLoc::getUnknownLoc()) {
|
2008-01-07 04:13:06 +01:00
|
|
|
if (!NoImp && TID->getImplicitDefs())
|
|
|
|
for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
|
2006-11-14 00:34:06 +01:00
|
|
|
NumImplicitOps++;
|
2008-01-07 04:13:06 +01:00
|
|
|
if (!NoImp && TID->getImplicitUses())
|
|
|
|
for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
|
2006-11-14 00:34:06 +01:00
|
|
|
NumImplicitOps++;
|
2008-01-07 04:13:06 +01:00
|
|
|
Operands.reserve(NumImplicitOps + TID->getNumOperands());
|
2007-10-13 04:23:01 +02:00
|
|
|
if (!NoImp)
|
|
|
|
addImplicitDefUseOperands();
|
2008-07-18 01:49:46 +02:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2006-11-14 00:34:06 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 00:20:29 +01:00
|
|
|
/// MachineInstr ctor - As above, but with a DebugLoc.
|
|
|
|
MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,
|
|
|
|
bool NoImp)
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0),
|
|
|
|
Parent(0), debugLoc(dl) {
|
2009-01-28 00:20:29 +01:00
|
|
|
if (!NoImp && TID->getImplicitDefs())
|
|
|
|
for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
|
|
|
|
NumImplicitOps++;
|
|
|
|
if (!NoImp && TID->getImplicitUses())
|
|
|
|
for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
|
|
|
|
NumImplicitOps++;
|
|
|
|
Operands.reserve(NumImplicitOps + TID->getNumOperands());
|
|
|
|
if (!NoImp)
|
|
|
|
addImplicitDefUseOperands();
|
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MachineInstr ctor - Work exactly the same as the ctor two above, except
|
|
|
|
/// that the MachineInstr is created and added to the end of the specified
|
|
|
|
/// basic block.
|
|
|
|
///
|
|
|
|
MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), Parent(0),
|
2009-01-28 00:20:29 +01:00
|
|
|
debugLoc(DebugLoc::getUnknownLoc()) {
|
|
|
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
|
|
|
if (TID->ImplicitDefs)
|
|
|
|
for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
|
|
|
|
NumImplicitOps++;
|
|
|
|
if (TID->ImplicitUses)
|
|
|
|
for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
|
|
|
|
NumImplicitOps++;
|
|
|
|
Operands.reserve(NumImplicitOps + TID->getNumOperands());
|
|
|
|
addImplicitDefUseOperands();
|
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
MBB->push_back(this); // Add instruction to end of basic block!
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MachineInstr ctor - As above, but with a DebugLoc.
|
2002-10-30 00:19:00 +01:00
|
|
|
///
|
2009-01-28 00:20:29 +01:00
|
|
|
MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc &tid)
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0),
|
|
|
|
Parent(0), debugLoc(dl) {
|
2002-10-30 00:19:00 +01:00
|
|
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
2006-11-30 08:08:44 +01:00
|
|
|
if (TID->ImplicitDefs)
|
2008-01-07 04:13:06 +01:00
|
|
|
for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
|
2006-11-14 00:34:06 +01:00
|
|
|
NumImplicitOps++;
|
2006-11-30 08:08:44 +01:00
|
|
|
if (TID->ImplicitUses)
|
2008-01-07 04:13:06 +01:00
|
|
|
for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
|
2006-11-14 00:34:06 +01:00
|
|
|
NumImplicitOps++;
|
2008-01-07 04:13:06 +01:00
|
|
|
Operands.reserve(NumImplicitOps + TID->getNumOperands());
|
2006-11-30 08:08:44 +01:00
|
|
|
addImplicitDefUseOperands();
|
2008-07-18 01:49:46 +02:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-10-30 00:19:00 +01:00
|
|
|
MBB->push_back(this); // Add instruction to end of basic block!
|
|
|
|
}
|
|
|
|
|
2004-07-09 16:45:17 +02:00
|
|
|
/// MachineInstr ctor - Copies MachineInstr arg exactly
|
|
|
|
///
|
2008-07-19 02:37:25 +02:00
|
|
|
MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
|
2009-09-25 22:36:54 +02:00
|
|
|
: TID(&MI.getDesc()), NumImplicitOps(0),
|
|
|
|
MemRefs(MI.MemRefs), MemRefsEnd(MI.MemRefsEnd),
|
|
|
|
Parent(0), debugLoc(MI.getDebugLoc()) {
|
2006-05-04 21:14:44 +02:00
|
|
|
Operands.reserve(MI.getNumOperands());
|
2004-05-23 22:58:02 +02:00
|
|
|
|
2004-07-09 16:45:17 +02:00
|
|
|
// Add operands
|
2008-07-19 02:37:25 +02:00
|
|
|
for (unsigned i = 0; i != MI.getNumOperands(); ++i)
|
|
|
|
addOperand(MI.getOperand(i));
|
|
|
|
NumImplicitOps = MI.NumImplicitOps;
|
2004-05-24 05:14:18 +02:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
// Set parent to null.
|
2007-12-31 05:56:33 +01:00
|
|
|
Parent = 0;
|
2008-07-21 20:47:29 +02:00
|
|
|
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2004-05-23 21:35:12 +02:00
|
|
|
}
|
|
|
|
|
2004-07-09 16:45:17 +02:00
|
|
|
MachineInstr::~MachineInstr() {
|
2008-07-18 01:49:46 +02:00
|
|
|
LeakDetector::removeGarbageObject(this);
|
2007-12-30 07:11:04 +01:00
|
|
|
#ifndef NDEBUG
|
2008-01-01 02:12:31 +01:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2007-12-30 07:11:04 +01:00
|
|
|
assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
|
2008-10-03 17:45:36 +02:00
|
|
|
assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
|
2008-01-01 02:12:31 +01:00
|
|
|
"Reg operand def/use list corrupted");
|
|
|
|
}
|
2007-12-30 07:11:04 +01:00
|
|
|
#endif
|
2004-02-16 08:17:43 +01:00
|
|
|
}
|
|
|
|
|
2008-01-01 02:12:31 +01:00
|
|
|
/// getRegInfo - If this instruction is embedded into a MachineFunction,
|
|
|
|
/// return the MachineRegisterInfo object for the current function, otherwise
|
|
|
|
/// return null.
|
|
|
|
MachineRegisterInfo *MachineInstr::getRegInfo() {
|
|
|
|
if (MachineBasicBlock *MBB = getParent())
|
2008-07-09 01:59:09 +02:00
|
|
|
return &MBB->getParent()->getRegInfo();
|
2008-01-01 02:12:31 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
|
|
|
|
/// this instruction from their respective use lists. This requires that the
|
|
|
|
/// operands already be on their use lists.
|
|
|
|
void MachineInstr::RemoveRegOperandsFromUseLists() {
|
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[i].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].RemoveRegOperandFromRegInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AddRegOperandsToUseLists - Add all of the register operands in
|
|
|
|
/// this instruction from their respective use lists. This requires that the
|
|
|
|
/// operands not be on their use lists yet.
|
|
|
|
void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &RegInfo) {
|
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[i].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].AddRegOperandToRegInfo(&RegInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// addOperand - Add the specified operand to the instruction. If it is an
|
|
|
|
/// implicit operand, it is added to the end of the operand list. If it is
|
|
|
|
/// an explicit operand it is added at the end of the explicit operand list
|
|
|
|
/// (before the first implicit operand).
|
|
|
|
void MachineInstr::addOperand(const MachineOperand &Op) {
|
2008-10-03 17:45:36 +02:00
|
|
|
bool isImpReg = Op.isReg() && Op.isImplicit();
|
2008-01-01 02:12:31 +01:00
|
|
|
assert((isImpReg || !OperandsComplete()) &&
|
|
|
|
"Trying to add an operand to a machine instr that is already done!");
|
|
|
|
|
2008-12-09 23:45:08 +01:00
|
|
|
MachineRegisterInfo *RegInfo = getRegInfo();
|
|
|
|
|
2008-01-01 02:12:31 +01:00
|
|
|
// If we are adding the operand to the end of the list, our job is simpler.
|
|
|
|
// This is true most of the time, so this is a reasonable optimization.
|
|
|
|
if (isImpReg || NumImplicitOps == 0) {
|
|
|
|
// We can only do this optimization if we know that the operand list won't
|
|
|
|
// reallocate.
|
|
|
|
if (Operands.empty() || Operands.size()+1 <= Operands.capacity()) {
|
|
|
|
Operands.push_back(Op);
|
|
|
|
|
|
|
|
// Set the parent of the operand.
|
|
|
|
Operands.back().ParentMI = this;
|
|
|
|
|
|
|
|
// If the operand is a register, update the operand's use list.
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Op.isReg())
|
2008-12-09 23:45:08 +01:00
|
|
|
Operands.back().AddRegOperandToRegInfo(RegInfo);
|
2008-01-01 02:12:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we have to insert a real operand before any implicit ones.
|
|
|
|
unsigned OpNo = Operands.size()-NumImplicitOps;
|
|
|
|
|
|
|
|
// If this instruction isn't embedded into a function, then we don't need to
|
|
|
|
// update any operand lists.
|
|
|
|
if (RegInfo == 0) {
|
|
|
|
// Simple insertion, no reginfo update needed for other register operands.
|
|
|
|
Operands.insert(Operands.begin()+OpNo, Op);
|
|
|
|
Operands[OpNo].ParentMI = this;
|
|
|
|
|
|
|
|
// Do explicitly set the reginfo for this operand though, to ensure the
|
|
|
|
// next/prev fields are properly nulled out.
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[OpNo].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[OpNo].AddRegOperandToRegInfo(0);
|
|
|
|
|
|
|
|
} else if (Operands.size()+1 <= Operands.capacity()) {
|
|
|
|
// Otherwise, we have to remove register operands from their register use
|
|
|
|
// list, add the operand, then add the register operands back to their use
|
|
|
|
// list. This also must handle the case when the operand list reallocates
|
|
|
|
// to somewhere else.
|
|
|
|
|
|
|
|
// If insertion of this operand won't cause reallocation of the operand
|
|
|
|
// list, just remove the implicit operands, add the operand, then re-add all
|
|
|
|
// the rest of the operands.
|
|
|
|
for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
assert(Operands[i].isReg() && "Should only be an implicit reg!");
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].RemoveRegOperandFromRegInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the operand. If it is a register, add it to the reg list.
|
|
|
|
Operands.insert(Operands.begin()+OpNo, Op);
|
|
|
|
Operands[OpNo].ParentMI = this;
|
|
|
|
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[OpNo].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[OpNo].AddRegOperandToRegInfo(RegInfo);
|
|
|
|
|
|
|
|
// Re-add all the implicit ops.
|
|
|
|
for (unsigned i = OpNo+1, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
assert(Operands[i].isReg() && "Should only be an implicit reg!");
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].AddRegOperandToRegInfo(RegInfo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, we will be reallocating the operand list. Remove all reg
|
|
|
|
// operands from their list, then readd them after the operand list is
|
|
|
|
// reallocated.
|
|
|
|
RemoveRegOperandsFromUseLists();
|
|
|
|
|
|
|
|
Operands.insert(Operands.begin()+OpNo, Op);
|
|
|
|
Operands[OpNo].ParentMI = this;
|
|
|
|
|
|
|
|
// Re-add all the operands.
|
|
|
|
AddRegOperandsToUseLists(*RegInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RemoveOperand - Erase an operand from an instruction, leaving it with one
|
|
|
|
/// fewer operand than it started with.
|
|
|
|
///
|
|
|
|
void MachineInstr::RemoveOperand(unsigned OpNo) {
|
|
|
|
assert(OpNo < Operands.size() && "Invalid operand number");
|
|
|
|
|
|
|
|
// Special case removing the last one.
|
|
|
|
if (OpNo == Operands.size()-1) {
|
|
|
|
// If needed, remove from the reg def/use list.
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands.back().isReg() && Operands.back().isOnRegUseList())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands.back().RemoveRegOperandFromRegInfo();
|
|
|
|
|
|
|
|
Operands.pop_back();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we are removing an interior operand. If we have reginfo to
|
|
|
|
// update, remove all operands that will be shifted down from their reg lists,
|
|
|
|
// move everything down, then re-add them.
|
|
|
|
MachineRegisterInfo *RegInfo = getRegInfo();
|
|
|
|
if (RegInfo) {
|
|
|
|
for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[i].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].RemoveRegOperandFromRegInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Operands.erase(Operands.begin()+OpNo);
|
|
|
|
|
|
|
|
if (RegInfo) {
|
|
|
|
for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
|
2008-10-03 17:45:36 +02:00
|
|
|
if (Operands[i].isReg())
|
2008-01-01 02:12:31 +01:00
|
|
|
Operands[i].AddRegOperandToRegInfo(RegInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
/// addMemOperand - Add a MachineMemOperand to the machine instruction.
|
|
|
|
/// This function should be used only occasionally. The setMemRefs function
|
|
|
|
/// is the primary method for setting up a MachineInstr's MemRefs list.
|
2008-07-08 01:14:23 +02:00
|
|
|
void MachineInstr::addMemOperand(MachineFunction &MF,
|
2009-09-25 22:36:54 +02:00
|
|
|
MachineMemOperand *MO) {
|
|
|
|
mmo_iterator OldMemRefs = MemRefs;
|
|
|
|
mmo_iterator OldMemRefsEnd = MemRefsEnd;
|
2008-07-08 01:14:23 +02:00
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
size_t NewNum = (MemRefsEnd - MemRefs) + 1;
|
|
|
|
mmo_iterator NewMemRefs = MF.allocateMemRefsArray(NewNum);
|
|
|
|
mmo_iterator NewMemRefsEnd = NewMemRefs + NewNum;
|
2008-07-08 01:14:23 +02:00
|
|
|
|
2009-09-25 22:36:54 +02:00
|
|
|
std::copy(OldMemRefs, OldMemRefsEnd, NewMemRefs);
|
|
|
|
NewMemRefs[NewNum - 1] = MO;
|
|
|
|
|
|
|
|
MemRefs = NewMemRefs;
|
|
|
|
MemRefsEnd = NewMemRefsEnd;
|
|
|
|
}
|
2008-01-01 02:12:31 +01:00
|
|
|
|
2006-04-17 23:35:41 +02:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block, and returns it, but does not delete it.
|
|
|
|
MachineInstr *MachineInstr::removeFromParent() {
|
|
|
|
assert(getParent() && "Not embedded in a basic block!");
|
|
|
|
getParent()->remove(this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block, and deletes it.
|
|
|
|
void MachineInstr::eraseFromParent() {
|
|
|
|
assert(getParent() && "Not embedded in a basic block!");
|
|
|
|
getParent()->erase(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-13 05:39:32 +01:00
|
|
|
/// OperandComplete - Return true if it's illegal to add a new operand
|
|
|
|
///
|
2004-02-12 17:09:53 +01:00
|
|
|
bool MachineInstr::OperandsComplete() const {
|
2008-01-07 04:13:06 +01:00
|
|
|
unsigned short NumOperands = TID->getNumOperands();
|
2008-01-07 06:19:29 +01:00
|
|
|
if (!TID->isVariadic() && getNumOperands()-NumImplicitOps >= NumOperands)
|
2003-05-31 09:39:06 +02:00
|
|
|
return true; // Broken: we have all the operands of this instruction!
|
2002-10-28 21:48:39 +01:00
|
|
|
return false;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
2007-05-15 03:26:09 +02:00
|
|
|
/// getNumExplicitOperands - Returns the number of non-implicit operands.
|
|
|
|
///
|
|
|
|
unsigned MachineInstr::getNumExplicitOperands() const {
|
2008-01-07 04:13:06 +01:00
|
|
|
unsigned NumOperands = TID->getNumOperands();
|
2008-01-07 06:19:29 +01:00
|
|
|
if (!TID->isVariadic())
|
2007-05-15 03:26:09 +02:00
|
|
|
return NumOperands;
|
|
|
|
|
2009-04-15 19:59:11 +02:00
|
|
|
for (unsigned i = NumOperands, e = getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg() || !MO.isImplicit())
|
2007-05-15 03:26:09 +02:00
|
|
|
NumOperands++;
|
|
|
|
}
|
|
|
|
return NumOperands;
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:39:59 +02:00
|
|
|
|
2008-07-01 02:05:16 +02:00
|
|
|
/// isLabel - Returns true if the MachineInstr represents a label.
|
|
|
|
///
|
|
|
|
bool MachineInstr::isLabel() const {
|
|
|
|
return getOpcode() == TargetInstrInfo::DBG_LABEL ||
|
|
|
|
getOpcode() == TargetInstrInfo::EH_LABEL ||
|
|
|
|
getOpcode() == TargetInstrInfo::GC_LABEL;
|
|
|
|
}
|
|
|
|
|
2008-01-31 10:59:15 +01:00
|
|
|
/// isDebugLabel - Returns true if the MachineInstr represents a debug label.
|
|
|
|
///
|
|
|
|
bool MachineInstr::isDebugLabel() const {
|
2008-07-01 02:05:16 +02:00
|
|
|
return getOpcode() == TargetInstrInfo::DBG_LABEL;
|
2008-01-31 10:59:15 +01:00
|
|
|
}
|
|
|
|
|
2007-04-26 21:00:32 +02:00
|
|
|
/// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
|
2009-09-17 19:57:26 +02:00
|
|
|
/// the specific register or -1 if it is not found. It further tightens
|
2007-02-23 02:04:26 +01:00
|
|
|
/// the search criteria to a use that kills the register if isKill is true.
|
2008-03-05 01:59:57 +01:00
|
|
|
int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2006-12-06 09:27:42 +01:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
2007-05-29 20:35:22 +02:00
|
|
|
const MachineOperand &MO = getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg() || !MO.isUse())
|
2008-03-05 01:59:57 +01:00
|
|
|
continue;
|
|
|
|
unsigned MOReg = MO.getReg();
|
|
|
|
if (!MOReg)
|
|
|
|
continue;
|
|
|
|
if (MOReg == Reg ||
|
|
|
|
(TRI &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(MOReg) &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(Reg) &&
|
|
|
|
TRI->isSubRegister(MOReg, Reg)))
|
2007-02-23 02:04:26 +01:00
|
|
|
if (!isKill || MO.isKill())
|
2007-03-27 00:37:45 +02:00
|
|
|
return i;
|
2007-02-19 22:49:54 +01:00
|
|
|
}
|
2007-03-27 00:37:45 +02:00
|
|
|
return -1;
|
2007-02-19 22:49:54 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 01:59:57 +01:00
|
|
|
/// findRegisterDefOperandIdx() - Returns the operand index that is a def of
|
2008-05-06 02:20:10 +02:00
|
|
|
/// the specified register or -1 if it is not found. If isDead is true, defs
|
|
|
|
/// that are not dead are skipped. If TargetRegisterInfo is non-null, then it
|
|
|
|
/// also checks if there is a def of a super-register.
|
2008-03-05 01:59:57 +01:00
|
|
|
int MachineInstr::findRegisterDefOperandIdx(unsigned Reg, bool isDead,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2007-02-19 22:49:54 +01:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
2008-03-05 01:59:57 +01:00
|
|
|
const MachineOperand &MO = getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg() || !MO.isDef())
|
2008-03-05 01:59:57 +01:00
|
|
|
continue;
|
|
|
|
unsigned MOReg = MO.getReg();
|
|
|
|
if (MOReg == Reg ||
|
|
|
|
(TRI &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(MOReg) &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(Reg) &&
|
|
|
|
TRI->isSubRegister(MOReg, Reg)))
|
|
|
|
if (!isDead || MO.isDead())
|
|
|
|
return i;
|
2006-12-06 09:27:42 +01:00
|
|
|
}
|
2008-03-05 01:59:57 +01:00
|
|
|
return -1;
|
2006-12-06 09:27:42 +01:00
|
|
|
}
|
2007-05-15 03:26:09 +02:00
|
|
|
|
2007-05-29 20:35:22 +02:00
|
|
|
/// findFirstPredOperandIdx() - Find the index of the first operand in the
|
|
|
|
/// operand list that is used to represent the predicate. It returns -1 if
|
|
|
|
/// none is found.
|
|
|
|
int MachineInstr::findFirstPredOperandIdx() const {
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc &TID = getDesc();
|
|
|
|
if (TID.isPredicable()) {
|
2007-05-15 03:26:09 +02:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
2008-01-07 08:27:27 +01:00
|
|
|
if (TID.OpInfo[i].isPredicate())
|
2007-05-29 20:35:22 +02:00
|
|
|
return i;
|
2007-05-15 03:26:09 +02:00
|
|
|
}
|
|
|
|
|
2007-05-29 20:35:22 +02:00
|
|
|
return -1;
|
2007-05-15 03:26:09 +02:00
|
|
|
}
|
2006-12-06 09:27:42 +01:00
|
|
|
|
2009-04-09 19:16:43 +02:00
|
|
|
/// isRegTiedToUseOperand - Given the index of a register def operand,
|
|
|
|
/// check if the register def is tied to a source operand, due to either
|
|
|
|
/// two-address elimination or inline assembly constraints. Returns the
|
|
|
|
/// first tied use operand index by reference is UseOpIdx is not null.
|
2009-04-29 22:57:16 +02:00
|
|
|
bool MachineInstr::
|
|
|
|
isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx) const {
|
2009-03-23 09:01:15 +01:00
|
|
|
if (getOpcode() == TargetInstrInfo::INLINEASM) {
|
2009-04-09 19:16:43 +02:00
|
|
|
assert(DefOpIdx >= 2);
|
|
|
|
const MachineOperand &MO = getOperand(DefOpIdx);
|
2009-04-10 01:33:34 +02:00
|
|
|
if (!MO.isReg() || !MO.isDef() || MO.getReg() == 0)
|
2009-03-23 09:01:15 +01:00
|
|
|
return false;
|
2009-06-24 04:05:51 +02:00
|
|
|
// Determine the actual operand index that corresponds to this index.
|
2009-03-23 09:01:15 +01:00
|
|
|
unsigned DefNo = 0;
|
2009-06-24 04:05:51 +02:00
|
|
|
unsigned DefPart = 0;
|
2009-03-23 09:01:15 +01:00
|
|
|
for (unsigned i = 1, e = getNumOperands(); i < e; ) {
|
|
|
|
const MachineOperand &FMO = getOperand(i);
|
2009-07-19 21:09:59 +02:00
|
|
|
// After the normal asm operands there may be additional imp-def regs.
|
|
|
|
if (!FMO.isImm())
|
|
|
|
return false;
|
2009-03-23 09:01:15 +01:00
|
|
|
// Skip over this def.
|
2009-06-24 04:05:51 +02:00
|
|
|
unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm());
|
|
|
|
unsigned PrevDef = i + 1;
|
|
|
|
i = PrevDef + NumOps;
|
|
|
|
if (i > DefOpIdx) {
|
|
|
|
DefPart = DefOpIdx - PrevDef;
|
2009-03-23 09:01:15 +01:00
|
|
|
break;
|
2009-06-24 04:05:51 +02:00
|
|
|
}
|
2009-03-23 09:01:15 +01:00
|
|
|
++DefNo;
|
|
|
|
}
|
2009-06-24 04:05:51 +02:00
|
|
|
for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
|
2009-03-23 09:01:15 +01:00
|
|
|
const MachineOperand &FMO = getOperand(i);
|
|
|
|
if (!FMO.isImm())
|
|
|
|
continue;
|
|
|
|
if (i+1 >= e || !getOperand(i+1).isReg() || !getOperand(i+1).isUse())
|
|
|
|
continue;
|
|
|
|
unsigned Idx;
|
2009-06-24 04:05:51 +02:00
|
|
|
if (InlineAsm::isUseOperandTiedToDef(FMO.getImm(), Idx) &&
|
2009-04-09 19:16:43 +02:00
|
|
|
Idx == DefNo) {
|
|
|
|
if (UseOpIdx)
|
2009-06-24 04:05:51 +02:00
|
|
|
*UseOpIdx = (unsigned)i + 1 + DefPart;
|
2009-03-23 09:01:15 +01:00
|
|
|
return true;
|
2009-04-09 19:16:43 +02:00
|
|
|
}
|
2009-03-23 09:01:15 +01:00
|
|
|
}
|
2009-06-24 04:05:51 +02:00
|
|
|
return false;
|
2009-03-23 09:01:15 +01:00
|
|
|
}
|
|
|
|
|
2009-04-09 19:16:43 +02:00
|
|
|
assert(getOperand(DefOpIdx).isDef() && "DefOpIdx is not a def!");
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc &TID = getDesc();
|
2008-07-10 09:35:43 +02:00
|
|
|
for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = getOperand(i);
|
2008-12-05 06:45:42 +01:00
|
|
|
if (MO.isReg() && MO.isUse() &&
|
2009-04-09 19:16:43 +02:00
|
|
|
TID.getOperandConstraint(i, TOI::TIED_TO) == (int)DefOpIdx) {
|
|
|
|
if (UseOpIdx)
|
|
|
|
*UseOpIdx = (unsigned)i;
|
2008-07-10 09:35:43 +02:00
|
|
|
return true;
|
2009-04-09 19:16:43 +02:00
|
|
|
}
|
2007-10-12 10:50:34 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-19 21:30:06 +01:00
|
|
|
/// isRegTiedToDefOperand - Return true if the operand of the specified index
|
|
|
|
/// is a register use and it is tied to an def operand. It also returns the def
|
|
|
|
/// operand index by reference.
|
2009-04-29 22:57:16 +02:00
|
|
|
bool MachineInstr::
|
|
|
|
isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const {
|
2009-03-23 09:01:15 +01:00
|
|
|
if (getOpcode() == TargetInstrInfo::INLINEASM) {
|
|
|
|
const MachineOperand &MO = getOperand(UseOpIdx);
|
2009-04-09 18:50:43 +02:00
|
|
|
if (!MO.isReg() || !MO.isUse() || MO.getReg() == 0)
|
2009-03-23 09:01:15 +01:00
|
|
|
return false;
|
2009-07-16 22:58:34 +02:00
|
|
|
|
|
|
|
// Find the flag operand corresponding to UseOpIdx
|
|
|
|
unsigned FlagIdx, NumOps=0;
|
|
|
|
for (FlagIdx = 1; FlagIdx < UseOpIdx; FlagIdx += NumOps+1) {
|
|
|
|
const MachineOperand &UFMO = getOperand(FlagIdx);
|
2009-07-19 21:09:59 +02:00
|
|
|
// After the normal asm operands there may be additional imp-def regs.
|
|
|
|
if (!UFMO.isImm())
|
|
|
|
return false;
|
2009-07-16 22:58:34 +02:00
|
|
|
NumOps = InlineAsm::getNumOperandRegisters(UFMO.getImm());
|
|
|
|
assert(NumOps < getNumOperands() && "Invalid inline asm flag");
|
|
|
|
if (UseOpIdx < FlagIdx+NumOps+1)
|
|
|
|
break;
|
2009-06-24 04:05:51 +02:00
|
|
|
}
|
2009-07-16 22:58:34 +02:00
|
|
|
if (FlagIdx >= UseOpIdx)
|
2009-06-24 04:05:51 +02:00
|
|
|
return false;
|
2009-07-16 22:58:34 +02:00
|
|
|
const MachineOperand &UFMO = getOperand(FlagIdx);
|
2009-03-23 09:01:15 +01:00
|
|
|
unsigned DefNo;
|
|
|
|
if (InlineAsm::isUseOperandTiedToDef(UFMO.getImm(), DefNo)) {
|
|
|
|
if (!DefOpIdx)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
unsigned DefIdx = 1;
|
|
|
|
// Remember to adjust the index. First operand is asm string, then there
|
|
|
|
// is a flag for each.
|
|
|
|
while (DefNo) {
|
|
|
|
const MachineOperand &FMO = getOperand(DefIdx);
|
|
|
|
assert(FMO.isImm());
|
|
|
|
// Skip over this def.
|
|
|
|
DefIdx += InlineAsm::getNumOperandRegisters(FMO.getImm()) + 1;
|
|
|
|
--DefNo;
|
|
|
|
}
|
2009-06-24 04:05:51 +02:00
|
|
|
*DefOpIdx = DefIdx + UseOpIdx - FlagIdx;
|
2009-03-23 09:01:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-19 21:30:06 +01:00
|
|
|
const TargetInstrDesc &TID = getDesc();
|
|
|
|
if (UseOpIdx >= TID.getNumOperands())
|
|
|
|
return false;
|
|
|
|
const MachineOperand &MO = getOperand(UseOpIdx);
|
|
|
|
if (!MO.isReg() || !MO.isUse())
|
|
|
|
return false;
|
|
|
|
int DefIdx = TID.getOperandConstraint(UseOpIdx, TOI::TIED_TO);
|
|
|
|
if (DefIdx == -1)
|
|
|
|
return false;
|
|
|
|
if (DefOpIdx)
|
|
|
|
*DefOpIdx = (unsigned)DefIdx;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-12-06 09:27:42 +01:00
|
|
|
/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
|
|
|
|
///
|
|
|
|
void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
|
2006-12-06 09:27:42 +01:00
|
|
|
continue;
|
|
|
|
for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
|
|
|
|
MachineOperand &MOp = getOperand(j);
|
|
|
|
if (!MOp.isIdenticalTo(MO))
|
|
|
|
continue;
|
|
|
|
if (MO.isKill())
|
|
|
|
MOp.setIsKill();
|
|
|
|
else
|
|
|
|
MOp.setIsDead();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-15 03:26:09 +02:00
|
|
|
/// copyPredicates - Copies predicate operand(s) from MI.
|
|
|
|
void MachineInstr::copyPredicates(const MachineInstr *MI) {
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc &TID = MI->getDesc();
|
2008-03-13 01:44:09 +01:00
|
|
|
if (!TID.isPredicable())
|
|
|
|
return;
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
if (TID.OpInfo[i].isPredicate()) {
|
|
|
|
// Predicated operands must be last operands.
|
|
|
|
addOperand(MI->getOperand(i));
|
2007-05-15 03:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 11:09:37 +02:00
|
|
|
/// isSafeToMove - Return true if it is safe to move this instruction. If
|
|
|
|
/// SawStore is set to true, it means that there is a store (or call) between
|
|
|
|
/// the instruction's location and its intended destination.
|
2008-11-18 20:04:29 +01:00
|
|
|
bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII,
|
2009-10-10 01:27:56 +02:00
|
|
|
bool &SawStore,
|
|
|
|
AliasAnalysis *AA) const {
|
2008-03-13 01:44:09 +01:00
|
|
|
// Ignore stuff that we obviously can't move.
|
|
|
|
if (TID->mayStore() || TID->isCall()) {
|
|
|
|
SawStore = true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-23 18:28:50 +01:00
|
|
|
if (TID->isTerminator() || TID->hasUnmodeledSideEffects())
|
2008-03-13 01:44:09 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// See if this instruction does a load. If so, we have to guarantee that the
|
|
|
|
// loaded value doesn't change between the load and the its intended
|
|
|
|
// destination. The check for isInvariantLoad gives the targe the chance to
|
|
|
|
// classify the load as always returning a constant, e.g. a constant pool
|
|
|
|
// load.
|
2009-10-10 01:27:56 +02:00
|
|
|
if (TID->mayLoad() && !isInvariantLoad(AA))
|
2008-03-13 01:44:09 +01:00
|
|
|
// Otherwise, this is a real load. If there is a store between the load and
|
2009-07-28 23:49:18 +02:00
|
|
|
// end of block, or if the load is volatile, we can't move it.
|
2008-10-02 17:04:30 +02:00
|
|
|
return !SawStore && !hasVolatileMemoryRef();
|
2008-09-24 02:06:15 +02:00
|
|
|
|
2008-03-13 01:44:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-27 22:33:50 +02:00
|
|
|
/// isSafeToReMat - Return true if it's safe to rematerialize the specified
|
|
|
|
/// instruction which defined the specified register instead of copying it.
|
2008-11-18 20:04:29 +01:00
|
|
|
bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII,
|
2009-10-10 01:27:56 +02:00
|
|
|
unsigned DstReg,
|
|
|
|
AliasAnalysis *AA) const {
|
2008-08-27 22:33:50 +02:00
|
|
|
bool SawStore = false;
|
2009-10-10 01:27:56 +02:00
|
|
|
if (!TII->isTriviallyReMaterializable(this, AA) ||
|
|
|
|
!isSafeToMove(TII, SawStore, AA))
|
2008-08-27 22:33:50 +02:00
|
|
|
return false;
|
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
2008-11-18 20:49:32 +01:00
|
|
|
const MachineOperand &MO = getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg())
|
2008-08-27 22:33:50 +02:00
|
|
|
continue;
|
|
|
|
// FIXME: For now, do not remat any instruction with register operands.
|
|
|
|
// Later on, we can loosen the restriction is the register operands have
|
|
|
|
// not been modified between the def and use. Note, this is different from
|
2008-08-27 22:58:54 +02:00
|
|
|
// MachineSink because the code is no longer in two-address form (at least
|
2008-08-27 22:33:50 +02:00
|
|
|
// partially).
|
|
|
|
if (MO.isUse())
|
|
|
|
return false;
|
|
|
|
else if (!MO.isDead() && MO.getReg() != DstReg)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-24 02:06:15 +02:00
|
|
|
/// hasVolatileMemoryRef - Return true if this instruction may have a
|
|
|
|
/// volatile memory reference, or if the information describing the
|
|
|
|
/// memory reference is not available. Return false if it is known to
|
|
|
|
/// have no volatile memory references.
|
|
|
|
bool MachineInstr::hasVolatileMemoryRef() const {
|
|
|
|
// An instruction known never to access memory won't have a volatile access.
|
|
|
|
if (!TID->mayStore() &&
|
|
|
|
!TID->mayLoad() &&
|
|
|
|
!TID->isCall() &&
|
|
|
|
!TID->hasUnmodeledSideEffects())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Otherwise, if the instruction has no memory reference information,
|
|
|
|
// conservatively assume it wasn't preserved.
|
|
|
|
if (memoperands_empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check the memory reference information for volatile references.
|
2009-09-25 22:36:54 +02:00
|
|
|
for (mmo_iterator I = memoperands_begin(), E = memoperands_end(); I != E; ++I)
|
|
|
|
if ((*I)->isVolatile())
|
2008-09-24 02:06:15 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:38:06 +02:00
|
|
|
/// isInvariantLoad - Return true if this instruction is loading from a
|
|
|
|
/// location whose value is invariant across the function. For example,
|
|
|
|
/// loading a value from the constant pool or from from the argument area
|
|
|
|
/// of a function if it does not change. This should only return true of
|
|
|
|
/// *all* loads the instruction does are invariant (if it does multiple loads).
|
|
|
|
bool MachineInstr::isInvariantLoad(AliasAnalysis *AA) const {
|
|
|
|
// If the instruction doesn't load at all, it isn't an invariant load.
|
|
|
|
if (!TID->mayLoad())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If the instruction has lost its memoperands, conservatively assume that
|
|
|
|
// it may not be an invariant load.
|
|
|
|
if (memoperands_empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const MachineFrameInfo *MFI = getParent()->getParent()->getFrameInfo();
|
|
|
|
|
|
|
|
for (mmo_iterator I = memoperands_begin(),
|
|
|
|
E = memoperands_end(); I != E; ++I) {
|
|
|
|
if ((*I)->isVolatile()) return false;
|
|
|
|
if ((*I)->isStore()) return false;
|
|
|
|
|
|
|
|
if (const Value *V = (*I)->getValue()) {
|
|
|
|
// A load from a constant PseudoSourceValue is invariant.
|
|
|
|
if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V))
|
|
|
|
if (PSV->isConstant(MFI))
|
|
|
|
continue;
|
|
|
|
// If we have an AliasAnalysis, ask it whether the memory is constant.
|
|
|
|
if (AA && AA->pointsToConstantMemory(V))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise assume conservatively.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Everything checks out.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-02-13 05:39:32 +01:00
|
|
|
void MachineInstr::dump() const {
|
2009-08-23 05:41:05 +02:00
|
|
|
errs() << " " << *this;
|
2008-10-10 03:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {
|
2007-12-30 22:31:53 +01:00
|
|
|
// Specialize printing if op#0 is definition
|
2002-10-30 02:55:38 +01:00
|
|
|
unsigned StartOp = 0;
|
2008-10-03 17:45:36 +02:00
|
|
|
if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
|
2007-12-30 22:56:09 +01:00
|
|
|
getOperand(0).print(OS, TM);
|
2002-10-30 02:55:38 +01:00
|
|
|
OS << " = ";
|
|
|
|
++StartOp; // Don't print this operand again!
|
|
|
|
}
|
2004-06-25 02:13:11 +02:00
|
|
|
|
2008-01-07 08:27:27 +01:00
|
|
|
OS << getDesc().getName();
|
2005-04-22 00:36:52 +02:00
|
|
|
|
2002-10-30 02:55:38 +01:00
|
|
|
for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
|
|
|
|
if (i != StartOp)
|
|
|
|
OS << ",";
|
|
|
|
OS << " ";
|
2007-12-30 22:56:09 +01:00
|
|
|
getOperand(i).print(OS, TM);
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
2005-04-22 00:36:52 +02:00
|
|
|
|
2008-07-08 01:14:23 +02:00
|
|
|
if (!memoperands_empty()) {
|
2008-02-07 17:18:00 +01:00
|
|
|
OS << ", Mem:";
|
2009-09-25 22:36:54 +02:00
|
|
|
for (mmo_iterator i = memoperands_begin(), e = memoperands_end();
|
|
|
|
i != e; ++i) {
|
|
|
|
OS << **i;
|
2009-09-23 03:33:16 +02:00
|
|
|
if (next(i) != e)
|
|
|
|
OS << " ";
|
2008-02-06 23:27:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 22:44:55 +01:00
|
|
|
if (!debugLoc.isUnknown()) {
|
|
|
|
const MachineFunction *MF = getParent()->getParent();
|
|
|
|
DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
|
2009-10-14 01:28:53 +02:00
|
|
|
DICompileUnit CU(DLT.Scope);
|
|
|
|
if (!CU.isNull())
|
|
|
|
OS << " [dbg: "
|
|
|
|
<< CU.getDirectory() << '/' << CU.getFilename() << ","
|
|
|
|
<< DLT.Line << ","
|
|
|
|
<< DLT.Col << "]";
|
2009-02-19 22:44:55 +01:00
|
|
|
}
|
|
|
|
|
2002-10-30 01:48:05 +01:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2008-01-24 02:10:07 +01:00
|
|
|
bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
|
2008-02-10 19:45:23 +01:00
|
|
|
const TargetRegisterInfo *RegInfo,
|
2008-01-24 02:10:07 +01:00
|
|
|
bool AddIfNotFound) {
|
2008-04-16 11:41:59 +02:00
|
|
|
bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
|
2008-07-03 03:18:51 +02:00
|
|
|
bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
|
2008-09-03 17:56:16 +02:00
|
|
|
bool Found = false;
|
2008-04-16 11:41:59 +02:00
|
|
|
SmallVector<unsigned,4> DeadOps;
|
2008-03-03 23:14:33 +01:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = getOperand(i);
|
2009-08-04 22:09:25 +02:00
|
|
|
if (!MO.isReg() || !MO.isUse() || MO.isUndef())
|
2008-04-16 11:41:59 +02:00
|
|
|
continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (!Reg)
|
|
|
|
continue;
|
2008-03-03 23:14:33 +01:00
|
|
|
|
2008-04-16 11:41:59 +02:00
|
|
|
if (Reg == IncomingReg) {
|
2008-09-03 17:56:16 +02:00
|
|
|
if (!Found) {
|
|
|
|
if (MO.isKill())
|
|
|
|
// The register is already marked kill.
|
|
|
|
return true;
|
2009-08-02 21:13:03 +02:00
|
|
|
if (isPhysReg && isRegTiedToDefOperand(i))
|
|
|
|
// Two-address uses of physregs must not be marked kill.
|
|
|
|
return true;
|
2008-09-03 17:56:16 +02:00
|
|
|
MO.setIsKill();
|
|
|
|
Found = true;
|
|
|
|
}
|
|
|
|
} else if (hasAliases && MO.isKill() &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(Reg)) {
|
2008-04-16 11:41:59 +02:00
|
|
|
// A super-register kill already exists.
|
|
|
|
if (RegInfo->isSuperRegister(IncomingReg, Reg))
|
2008-07-03 03:18:51 +02:00
|
|
|
return true;
|
|
|
|
if (RegInfo->isSubRegister(IncomingReg, Reg))
|
2008-04-16 11:41:59 +02:00
|
|
|
DeadOps.push_back(i);
|
2008-01-24 02:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 11:41:59 +02:00
|
|
|
// Trim unneeded kill operands.
|
|
|
|
while (!DeadOps.empty()) {
|
|
|
|
unsigned OpIdx = DeadOps.back();
|
|
|
|
if (getOperand(OpIdx).isImplicit())
|
|
|
|
RemoveOperand(OpIdx);
|
|
|
|
else
|
|
|
|
getOperand(OpIdx).setIsKill(false);
|
|
|
|
DeadOps.pop_back();
|
|
|
|
}
|
|
|
|
|
2008-03-03 23:14:33 +01:00
|
|
|
// If not found, this means an alias of one of the operands is killed. Add a
|
2008-01-24 02:10:07 +01:00
|
|
|
// new implicit operand if required.
|
2008-09-03 17:56:16 +02:00
|
|
|
if (!Found && AddIfNotFound) {
|
2008-03-03 23:14:33 +01:00
|
|
|
addOperand(MachineOperand::CreateReg(IncomingReg,
|
|
|
|
false /*IsDef*/,
|
|
|
|
true /*IsImp*/,
|
|
|
|
true /*IsKill*/));
|
2008-01-24 02:10:07 +01:00
|
|
|
return true;
|
|
|
|
}
|
2008-09-03 17:56:16 +02:00
|
|
|
return Found;
|
2008-01-24 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MachineInstr::addRegisterDead(unsigned IncomingReg,
|
2008-02-10 19:45:23 +01:00
|
|
|
const TargetRegisterInfo *RegInfo,
|
2008-01-24 02:10:07 +01:00
|
|
|
bool AddIfNotFound) {
|
2008-04-16 11:41:59 +02:00
|
|
|
bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
|
2008-06-28 00:11:49 +02:00
|
|
|
bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
|
2008-09-03 17:56:16 +02:00
|
|
|
bool Found = false;
|
2008-04-16 11:41:59 +02:00
|
|
|
SmallVector<unsigned,4> DeadOps;
|
2008-01-24 02:10:07 +01:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = getOperand(i);
|
2008-10-03 17:45:36 +02:00
|
|
|
if (!MO.isReg() || !MO.isDef())
|
2008-04-16 11:41:59 +02:00
|
|
|
continue;
|
|
|
|
unsigned Reg = MO.getReg();
|
2008-09-03 17:56:16 +02:00
|
|
|
if (!Reg)
|
|
|
|
continue;
|
|
|
|
|
2008-04-16 11:41:59 +02:00
|
|
|
if (Reg == IncomingReg) {
|
2008-09-03 17:56:16 +02:00
|
|
|
if (!Found) {
|
|
|
|
if (MO.isDead())
|
|
|
|
// The register is already marked dead.
|
|
|
|
return true;
|
|
|
|
MO.setIsDead();
|
|
|
|
Found = true;
|
|
|
|
}
|
|
|
|
} else if (hasAliases && MO.isDead() &&
|
|
|
|
TargetRegisterInfo::isPhysicalRegister(Reg)) {
|
2008-04-16 11:41:59 +02:00
|
|
|
// There exists a super-register that's marked dead.
|
|
|
|
if (RegInfo->isSuperRegister(IncomingReg, Reg))
|
2008-07-03 03:18:51 +02:00
|
|
|
return true;
|
2008-08-14 20:34:18 +02:00
|
|
|
if (RegInfo->getSubRegisters(IncomingReg) &&
|
|
|
|
RegInfo->getSuperRegisters(Reg) &&
|
|
|
|
RegInfo->isSubRegister(IncomingReg, Reg))
|
2008-04-16 11:41:59 +02:00
|
|
|
DeadOps.push_back(i);
|
2008-01-24 02:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 11:41:59 +02:00
|
|
|
// Trim unneeded dead operands.
|
|
|
|
while (!DeadOps.empty()) {
|
|
|
|
unsigned OpIdx = DeadOps.back();
|
|
|
|
if (getOperand(OpIdx).isImplicit())
|
|
|
|
RemoveOperand(OpIdx);
|
|
|
|
else
|
|
|
|
getOperand(OpIdx).setIsDead(false);
|
|
|
|
DeadOps.pop_back();
|
|
|
|
}
|
|
|
|
|
2008-09-03 17:56:16 +02:00
|
|
|
// If not found, this means an alias of one of the operands is dead. Add a
|
|
|
|
// new implicit operand if required.
|
2009-06-24 19:54:48 +02:00
|
|
|
if (Found || !AddIfNotFound)
|
|
|
|
return Found;
|
|
|
|
|
|
|
|
addOperand(MachineOperand::CreateReg(IncomingReg,
|
|
|
|
true /*IsDef*/,
|
|
|
|
true /*IsImp*/,
|
|
|
|
false /*IsKill*/,
|
|
|
|
true /*IsDead*/));
|
|
|
|
return true;
|
2008-01-24 02:10:07 +01:00
|
|
|
}
|