2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-03 07:11:59 +00:00
|
|
|
//
|
|
|
|
// This file contains the declaration of the MachineInstr class, which is the
|
2003-08-21 22:14:26 +00:00
|
|
|
// basic representation for all target dependent machine instructions used by
|
2002-02-03 07:11:59 +00:00
|
|
|
// the back end.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2008-04-07 19:35:22 +00:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2003-06-11 14:01:36 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2008-01-07 07:27:27 +00:00
|
|
|
class TargetInstrDesc;
|
2008-03-13 00:44:09 +00:00
|
|
|
class TargetInstrInfo;
|
2008-02-10 18:45:23 +00:00
|
|
|
class TargetRegisterInfo;
|
2002-10-28 02:29:46 +00:00
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
template <typename T> struct ilist_traits;
|
|
|
|
template <typename T> struct ilist;
|
2004-02-12 02:27:10 +00:00
|
|
|
|
2003-06-03 15:42:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-05-04 18:16:01 +00:00
|
|
|
/// MachineInstr - Representation of each machine instruction.
|
|
|
|
///
|
2003-06-02 22:07:37 +00:00
|
|
|
class MachineInstr {
|
2008-01-07 07:27:27 +00:00
|
|
|
const TargetInstrDesc *TID; // Instruction descriptor.
|
2006-11-27 23:37:22 +00:00
|
|
|
unsigned short NumImplicitOps; // Number of implicit operands (which
|
2006-11-15 20:48:17 +00:00
|
|
|
// are determined at construction time).
|
|
|
|
|
2006-05-04 19:14:44 +00:00
|
|
|
std::vector<MachineOperand> Operands; // the operands
|
2008-04-07 19:35:22 +00:00
|
|
|
std::vector<MachineMemOperand> MemOperands;// information on memory references
|
2007-12-31 04:56:33 +00:00
|
|
|
MachineInstr *Prev, *Next; // Links for MBB's intrusive list.
|
|
|
|
MachineBasicBlock *Parent; // Pointer to the owning basic block.
|
2004-03-03 19:07:27 +00:00
|
|
|
|
2002-10-28 20:48:39 +00:00
|
|
|
// OperandComplete - Return true if it's illegal to add a new operand
|
|
|
|
bool OperandsComplete() const;
|
2002-10-29 19:41:18 +00:00
|
|
|
|
2004-05-23 19:35:12 +00:00
|
|
|
MachineInstr(const MachineInstr&);
|
2003-06-02 22:07:37 +00:00
|
|
|
void operator=(const MachineInstr&); // DO NOT IMPLEMENT
|
2004-02-12 02:27:10 +00:00
|
|
|
|
|
|
|
// Intrusive list support
|
2004-10-27 16:14:51 +00:00
|
|
|
friend struct ilist_traits<MachineInstr>;
|
2008-01-01 01:12:31 +00:00
|
|
|
friend struct ilist_traits<MachineBasicBlock>;
|
2007-12-31 04:56:33 +00:00
|
|
|
void setParent(MachineBasicBlock *P) { Parent = P; }
|
2001-07-21 12:39:03 +00:00
|
|
|
public:
|
2006-11-27 23:37:22 +00:00
|
|
|
/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
|
2006-11-30 07:08:44 +00:00
|
|
|
/// TID NULL and no operands.
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr();
|
2002-09-20 00:47:49 +00:00
|
|
|
|
2006-11-13 23:34:06 +00:00
|
|
|
/// MachineInstr ctor - This constructor create a MachineInstr and add the
|
2007-12-30 00:12:25 +00:00
|
|
|
/// implicit operands. It reserves space for number of operands specified by
|
2008-01-07 07:27:27 +00:00
|
|
|
/// TargetInstrDesc.
|
|
|
|
explicit MachineInstr(const TargetInstrDesc &TID, bool NoImp = false);
|
2006-11-13 23:34:06 +00:00
|
|
|
|
2002-10-29 23:18:23 +00:00
|
|
|
/// MachineInstr ctor - Work exactly the same as the ctor above, except that
|
|
|
|
/// the MachineInstr is created and added to the end of the specified basic
|
|
|
|
/// block.
|
|
|
|
///
|
2008-01-07 07:27:27 +00:00
|
|
|
MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &TID);
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2004-02-16 07:17:43 +00:00
|
|
|
~MachineInstr();
|
|
|
|
|
2007-12-31 04:56:33 +00:00
|
|
|
const MachineBasicBlock* getParent() const { return Parent; }
|
|
|
|
MachineBasicBlock* getParent() { return Parent; }
|
2006-11-30 07:08:44 +00:00
|
|
|
|
2008-01-07 01:56:04 +00:00
|
|
|
/// getDesc - Returns the target instruction descriptor of this
|
2006-11-30 07:08:44 +00:00
|
|
|
/// MachineInstr.
|
2008-01-07 07:27:27 +00:00
|
|
|
const TargetInstrDesc &getDesc() const { return *TID; }
|
2004-02-12 18:49:07 +00:00
|
|
|
|
2004-03-03 19:07:27 +00:00
|
|
|
/// getOpcode - Returns the opcode of this MachineInstr.
|
2004-02-12 01:34:03 +00:00
|
|
|
///
|
2007-09-14 20:08:19 +00:00
|
|
|
int getOpcode() const;
|
2003-05-31 07:43:01 +00:00
|
|
|
|
2004-02-12 01:34:03 +00:00
|
|
|
/// Access to explicit operands of the instruction.
|
|
|
|
///
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2002-10-28 04:24:49 +00:00
|
|
|
const MachineOperand& getOperand(unsigned i) const {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 19:14:44 +00:00
|
|
|
return Operands[i];
|
2002-10-28 04:24:49 +00:00
|
|
|
}
|
|
|
|
MachineOperand& getOperand(unsigned i) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 19:14:44 +00:00
|
|
|
return Operands[i];
|
2002-10-28 04:24:49 +00:00
|
|
|
}
|
2002-10-28 04:30:20 +00:00
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// getNumExplicitOperands - Returns the number of non-implicit operands.
|
|
|
|
///
|
|
|
|
unsigned getNumExplicitOperands() const;
|
2006-10-20 22:39:36 +00:00
|
|
|
|
2008-02-06 22:27:42 +00:00
|
|
|
/// Access to memory operands of the instruction
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumMemOperands() const { return (unsigned)MemOperands.size(); }
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-04-07 19:35:22 +00:00
|
|
|
const MachineMemOperand& getMemOperand(unsigned i) const {
|
2008-02-06 22:27:42 +00:00
|
|
|
assert(i < getNumMemOperands() && "getMemOperand() out of range!");
|
|
|
|
return MemOperands[i];
|
|
|
|
}
|
2008-04-07 19:35:22 +00:00
|
|
|
MachineMemOperand& getMemOperand(unsigned i) {
|
2008-02-06 22:27:42 +00:00
|
|
|
assert(i < getNumMemOperands() && "getMemOperand() out of range!");
|
|
|
|
return MemOperands[i];
|
|
|
|
}
|
|
|
|
|
2006-10-20 22:39:36 +00:00
|
|
|
/// isIdenticalTo - Return true if this instruction is identical to (same
|
|
|
|
/// opcode and same operands as) the specified instruction.
|
|
|
|
bool isIdenticalTo(const MachineInstr *Other) const {
|
|
|
|
if (Other->getOpcode() != getOpcode() ||
|
2006-10-20 22:44:45 +00:00
|
|
|
Other->getNumOperands() != getNumOperands())
|
2006-10-20 22:39:36 +00:00
|
|
|
return false;
|
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
if (!getOperand(i).isIdenticalTo(Other->getOperand(i)))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2002-10-29 19:41:18 +00:00
|
|
|
|
2004-05-23 20:58:02 +00:00
|
|
|
/// clone - Create a copy of 'this' instruction that is identical in
|
|
|
|
/// all ways except the the instruction has no parent, prev, or next.
|
2006-05-04 19:14:44 +00:00
|
|
|
MachineInstr* clone() const { return new MachineInstr(*this); }
|
2006-04-17 21:35:08 +00:00
|
|
|
|
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block, and returns it, but does not delete it.
|
|
|
|
MachineInstr *removeFromParent();
|
|
|
|
|
|
|
|
/// eraseFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block and deletes it.
|
|
|
|
void eraseFromParent() {
|
|
|
|
delete removeFromParent();
|
|
|
|
}
|
2004-05-23 19:35:12 +00:00
|
|
|
|
2008-01-31 09:59:15 +00:00
|
|
|
/// isDebugLabel - Returns true if the MachineInstr represents a debug label.
|
|
|
|
///
|
|
|
|
bool isDebugLabel() const;
|
|
|
|
|
2008-03-05 00:59:57 +00:00
|
|
|
/// readsRegister - Return true if the MachineInstr reads the specified
|
|
|
|
/// register. If TargetRegisterInfo is passed, then it also checks if there
|
|
|
|
/// is a read of a super-register.
|
|
|
|
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
|
|
|
|
return findRegisterUseOperandIdx(Reg, false, TRI) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// killsRegister - Return true if the MachineInstr kills the specified
|
|
|
|
/// register. If TargetRegisterInfo is passed, then it also checks if there is
|
|
|
|
/// a kill of a super-register.
|
|
|
|
bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI = NULL) const {
|
|
|
|
return findRegisterUseOperandIdx(Reg, true, TRI) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// modifiesRegister - Return true if the MachineInstr modifies the
|
|
|
|
/// specified register. If TargetRegisterInfo is passed, then it also checks
|
|
|
|
/// if there is a def of a super-register.
|
|
|
|
bool modifiesRegister(unsigned Reg,
|
|
|
|
const TargetRegisterInfo *TRI = NULL) const {
|
|
|
|
return findRegisterDefOperandIdx(Reg, false, TRI) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// registerDefIsDead - Returns true if the register is dead in this machine
|
|
|
|
/// instruction. If TargetRegisterInfo is passed, then it also checks
|
|
|
|
/// if there is a dead def of a super-register.
|
|
|
|
bool registerDefIsDead(unsigned Reg,
|
|
|
|
const TargetRegisterInfo *TRI = NULL) const {
|
|
|
|
return findRegisterDefOperandIdx(Reg, true, TRI) != -1;
|
|
|
|
}
|
|
|
|
|
2007-04-26 19:00:32 +00:00
|
|
|
/// findRegisterUseOperandIdx() - Returns the operand index that is a use of
|
2007-03-26 22:37:45 +00:00
|
|
|
/// the specific register or -1 if it is not found. It further tightening
|
2007-02-23 01:04:26 +00:00
|
|
|
/// the search criteria to a use that kills the register if isKill is true.
|
2008-03-05 00:59:57 +00:00
|
|
|
int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
|
|
|
|
const TargetRegisterInfo *TRI = NULL) const;
|
|
|
|
|
|
|
|
/// findRegisterUseOperand - Wrapper for findRegisterUseOperandIdx, it returns
|
|
|
|
/// a pointer to the MachineOperand rather than an index.
|
2008-03-29 01:04:05 +00:00
|
|
|
MachineOperand *findRegisterUseOperand(unsigned Reg, bool isKill = false,
|
2008-03-05 00:59:57 +00:00
|
|
|
const TargetRegisterInfo *TRI = NULL) {
|
|
|
|
int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
|
|
|
|
return (Idx == -1) ? NULL : &getOperand(Idx);
|
|
|
|
}
|
2006-12-06 08:27:42 +00:00
|
|
|
|
2008-03-05 00:59:57 +00:00
|
|
|
/// findRegisterDefOperandIdx() - Returns the operand index that is a def of
|
2008-05-06 00:20:10 +00: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 00:59:57 +00:00
|
|
|
int findRegisterDefOperandIdx(unsigned Reg, bool isDead = false,
|
|
|
|
const TargetRegisterInfo *TRI = NULL) const;
|
|
|
|
|
|
|
|
/// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
|
|
|
|
/// a pointer to the MachineOperand rather than an index.
|
|
|
|
MachineOperand *findRegisterDefOperand(unsigned Reg,bool isDead = false,
|
|
|
|
const TargetRegisterInfo *TRI = NULL) {
|
|
|
|
int Idx = findRegisterDefOperandIdx(Reg, isDead, TRI);
|
|
|
|
return (Idx == -1) ? NULL : &getOperand(Idx);
|
|
|
|
}
|
2007-05-15 01:26:09 +00:00
|
|
|
|
2007-05-29 18:35:22 +00: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 findFirstPredOperandIdx() const;
|
2007-02-19 21:49:54 +00:00
|
|
|
|
2007-10-12 08:50:34 +00:00
|
|
|
/// isRegReDefinedByTwoAddr - Returns true if the Reg re-definition is due
|
|
|
|
/// to two addr elimination.
|
|
|
|
bool isRegReDefinedByTwoAddr(unsigned Reg) const;
|
|
|
|
|
2006-11-15 20:48:17 +00:00
|
|
|
/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
|
|
|
|
///
|
2006-12-06 08:27:42 +00:00
|
|
|
void copyKillDeadInfo(const MachineInstr *MI);
|
2006-11-15 20:48:17 +00:00
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// copyPredicates - Copies predicate operand(s) from MI.
|
|
|
|
void copyPredicates(const MachineInstr *MI);
|
|
|
|
|
2008-01-24 01:10:07 +00:00
|
|
|
/// addRegisterKilled - We have determined MI kills a register. Look for the
|
|
|
|
/// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
|
|
|
|
/// add a implicit operand if it's not found. Returns true if the operand
|
|
|
|
/// exists / is added.
|
2008-02-10 18:45:23 +00:00
|
|
|
bool addRegisterKilled(unsigned IncomingReg,
|
|
|
|
const TargetRegisterInfo *RegInfo,
|
2008-01-24 01:10:07 +00:00
|
|
|
bool AddIfNotFound = false);
|
|
|
|
|
|
|
|
/// addRegisterDead - We have determined MI defined a register without a use.
|
|
|
|
/// Look for the operand that defines it and mark it as IsDead. If
|
|
|
|
/// AddIfNotFound is true, add a implicit operand if it's not found. Returns
|
|
|
|
/// true if the operand exists / is added.
|
2008-02-10 18:45:23 +00:00
|
|
|
bool addRegisterDead(unsigned IncomingReg, const TargetRegisterInfo *RegInfo,
|
2008-01-24 01:10:07 +00:00
|
|
|
bool AddIfNotFound = false);
|
|
|
|
|
2008-03-13 00:44:09 +00:00
|
|
|
/// copyKillDeadInfo - Copies killed/dead information from one instr to another
|
2008-01-24 01:10:07 +00:00
|
|
|
void copyKillDeadInfo(MachineInstr *OldMI,
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo *RegInfo);
|
2008-01-24 01:10:07 +00:00
|
|
|
|
2008-03-13 00:44:09 +00:00
|
|
|
/// isSafeToMove - Return true if it is safe to this instruction. If SawStore
|
|
|
|
/// true, it means there is a store (or call) between the instruction the
|
|
|
|
/// localtion and its intended destination.
|
|
|
|
bool isSafeToMove(const TargetInstrInfo *TII, bool &SawStore);
|
|
|
|
|
2001-10-11 04:23:19 +00:00
|
|
|
//
|
|
|
|
// Debugging support
|
2002-10-30 00:46:48 +00:00
|
|
|
//
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS, const TargetMachine *TM) const {
|
|
|
|
if (OS) print(*OS, TM);
|
2006-11-28 22:21:29 +00:00
|
|
|
}
|
2007-12-30 21:31:53 +00:00
|
|
|
void print(std::ostream &OS, const TargetMachine *TM = 0) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2002-10-28 04:24:49 +00:00
|
|
|
void dump() const;
|
2002-02-05 06:02:59 +00:00
|
|
|
|
2002-10-28 20:48:39 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2008-01-01 01:12:31 +00:00
|
|
|
// Accessors used to build up machine instructions.
|
2002-12-28 20:05:44 +00:00
|
|
|
|
2008-01-01 01:12:31 +00:00
|
|
|
/// 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 addOperand(const MachineOperand &Op);
|
|
|
|
|
2008-01-11 18:10:50 +00:00
|
|
|
/// setDesc - Replace the instruction descriptor (thus opcode) of
|
2006-11-30 07:08:44 +00:00
|
|
|
/// the current instruction with a new one.
|
2003-01-13 00:18:17 +00:00
|
|
|
///
|
2008-01-11 18:10:50 +00:00
|
|
|
void setDesc(const TargetInstrDesc &tid) { TID = &tid; }
|
2003-01-13 00:18:17 +00:00
|
|
|
|
|
|
|
/// RemoveOperand - Erase an operand from an instruction, leaving it with one
|
|
|
|
/// fewer operand than it started with.
|
|
|
|
///
|
2008-01-01 01:12:31 +00:00
|
|
|
void RemoveOperand(unsigned i);
|
|
|
|
|
2008-04-07 19:35:22 +00:00
|
|
|
/// addMemOperand - Add a MachineMemOperand to the machine instruction,
|
|
|
|
/// referencing arbitrary storage.
|
|
|
|
void addMemOperand(const MachineMemOperand &MO) {
|
2008-02-06 22:27:42 +00:00
|
|
|
MemOperands.push_back(MO);
|
|
|
|
}
|
|
|
|
|
2006-05-04 19:14:44 +00:00
|
|
|
private:
|
2008-01-01 01:12:31 +00:00
|
|
|
/// getRegInfo - If this instruction is embedded into a MachineFunction,
|
|
|
|
/// return the MachineRegisterInfo object for the current function, otherwise
|
|
|
|
/// return null.
|
|
|
|
MachineRegisterInfo *getRegInfo();
|
2006-11-13 23:34:06 +00:00
|
|
|
|
|
|
|
/// addImplicitDefUseOperands - Add all implicit def and use operands to
|
|
|
|
/// this instruction.
|
2006-11-30 07:08:44 +00:00
|
|
|
void addImplicitDefUseOperands();
|
2008-01-01 01:12:31 +00:00
|
|
|
|
|
|
|
/// 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 RemoveRegOperandsFromUseLists();
|
|
|
|
|
|
|
|
/// 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 AddRegOperandsToUseLists(MachineRegisterInfo &RegInfo);
|
2001-10-11 04:23:19 +00:00
|
|
|
};
|
2001-07-21 12:39:03 +00:00
|
|
|
|
2003-06-03 15:42:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-10 20:50:20 +00:00
|
|
|
// Debugging Support
|
|
|
|
|
2007-12-30 21:31:53 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI) {
|
|
|
|
MI.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2001-08-28 23:11:46 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-07-21 12:39:03 +00:00
|
|
|
#endif
|