2003-09-30 20:37:50 +02:00
|
|
|
//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-03 08:11:59 +01:00
|
|
|
//
|
|
|
|
// This file contains the declaration of the MachineInstr class, which is the
|
2003-08-22 00:14:26 +02:00
|
|
|
// basic representation for all target dependent machine instructions used by
|
2002-02-03 08:11:59 +01:00
|
|
|
// the back end.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 14:39:03 +02:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEINSTR_H
|
|
|
|
|
2007-12-30 05:40:25 +01:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2008-04-07 21:35:22 +02:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2008-05-29 21:52:31 +02:00
|
|
|
#include <vector>
|
2003-06-11 16:01:36 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2008-01-07 08:27:27 +01:00
|
|
|
class TargetInstrDesc;
|
2008-03-13 01:44:09 +01:00
|
|
|
class TargetInstrInfo;
|
2008-02-10 19:45:23 +01:00
|
|
|
class TargetRegisterInfo;
|
2002-10-28 03:29:46 +01:00
|
|
|
|
2004-10-27 18:14:51 +02:00
|
|
|
template <typename T> struct ilist_traits;
|
|
|
|
template <typename T> struct ilist;
|
2004-02-12 03:27:10 +01:00
|
|
|
|
2003-06-03 17:42:53 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-05-04 20:16:01 +02:00
|
|
|
/// MachineInstr - Representation of each machine instruction.
|
|
|
|
///
|
2003-06-03 00:07:37 +02:00
|
|
|
class MachineInstr {
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc *TID; // Instruction descriptor.
|
2006-11-28 00:37:22 +01:00
|
|
|
unsigned short NumImplicitOps; // Number of implicit operands (which
|
2006-11-15 21:48:17 +01:00
|
|
|
// are determined at construction time).
|
|
|
|
|
2006-05-04 21:14:44 +02:00
|
|
|
std::vector<MachineOperand> Operands; // the operands
|
2008-04-07 21:35:22 +02:00
|
|
|
std::vector<MachineMemOperand> MemOperands;// information on memory references
|
2007-12-31 05:56:33 +01:00
|
|
|
MachineInstr *Prev, *Next; // Links for MBB's intrusive list.
|
|
|
|
MachineBasicBlock *Parent; // Pointer to the owning basic block.
|
2004-03-03 20:07:27 +01:00
|
|
|
|
2002-10-28 21:48:39 +01:00
|
|
|
// OperandComplete - Return true if it's illegal to add a new operand
|
|
|
|
bool OperandsComplete() const;
|
2002-10-29 20:41:18 +01:00
|
|
|
|
2004-05-23 21:35:12 +02:00
|
|
|
MachineInstr(const MachineInstr&);
|
2003-06-03 00:07:37 +02:00
|
|
|
void operator=(const MachineInstr&); // DO NOT IMPLEMENT
|
2004-02-12 03:27:10 +01:00
|
|
|
|
|
|
|
// Intrusive list support
|
2004-10-27 18:14:51 +02:00
|
|
|
friend struct ilist_traits<MachineInstr>;
|
2008-01-01 02:12:31 +01:00
|
|
|
friend struct ilist_traits<MachineBasicBlock>;
|
2007-12-31 05:56:33 +01:00
|
|
|
void setParent(MachineBasicBlock *P) { Parent = P; }
|
2001-07-21 14:39:03 +02:00
|
|
|
public:
|
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();
|
2002-09-20 02:47:49 +02:00
|
|
|
|
2006-11-14 00:34:06 +01:00
|
|
|
/// MachineInstr ctor - This constructor create a MachineInstr and add the
|
2007-12-30 01:12:25 +01:00
|
|
|
/// implicit operands. It reserves space for number of operands specified by
|
2008-01-07 08:27:27 +01:00
|
|
|
/// TargetInstrDesc.
|
|
|
|
explicit MachineInstr(const TargetInstrDesc &TID, bool NoImp = false);
|
2006-11-14 00:34:06 +01:00
|
|
|
|
2002-10-30 00:18:23 +01: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 08:27:27 +01:00
|
|
|
MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &TID);
|
2005-04-21 22:39:54 +02:00
|
|
|
|
2004-02-16 08:17:43 +01:00
|
|
|
~MachineInstr();
|
|
|
|
|
2007-12-31 05:56:33 +01:00
|
|
|
const MachineBasicBlock* getParent() const { return Parent; }
|
|
|
|
MachineBasicBlock* getParent() { return Parent; }
|
2006-11-30 08:08:44 +01:00
|
|
|
|
2008-01-07 02:56:04 +01:00
|
|
|
/// getDesc - Returns the target instruction descriptor of this
|
2006-11-30 08:08:44 +01:00
|
|
|
/// MachineInstr.
|
2008-01-07 08:27:27 +01:00
|
|
|
const TargetInstrDesc &getDesc() const { return *TID; }
|
2004-02-12 19:49:07 +01:00
|
|
|
|
2004-03-03 20:07:27 +01:00
|
|
|
/// getOpcode - Returns the opcode of this MachineInstr.
|
2004-02-12 02:34:03 +01:00
|
|
|
///
|
2007-09-14 22:08:19 +02:00
|
|
|
int getOpcode() const;
|
2003-05-31 09:43:01 +02:00
|
|
|
|
2004-02-12 02:34:03 +01:00
|
|
|
/// Access to explicit operands of the instruction.
|
|
|
|
///
|
2008-05-05 20:30:58 +02:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2005-04-21 22:39:54 +02:00
|
|
|
|
2002-10-28 05:24:49 +01:00
|
|
|
const MachineOperand& getOperand(unsigned i) const {
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 21:14:44 +02:00
|
|
|
return Operands[i];
|
2002-10-28 05:24:49 +01:00
|
|
|
}
|
|
|
|
MachineOperand& getOperand(unsigned i) {
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
2006-05-04 21:14:44 +02:00
|
|
|
return Operands[i];
|
2002-10-28 05:24:49 +01:00
|
|
|
}
|
2002-10-28 05:30:20 +01:00
|
|
|
|
2007-05-15 03:26:09 +02:00
|
|
|
/// getNumExplicitOperands - Returns the number of non-implicit operands.
|
|
|
|
///
|
|
|
|
unsigned getNumExplicitOperands() const;
|
2006-10-21 00:39:36 +02:00
|
|
|
|
2008-02-06 23:27:42 +01:00
|
|
|
/// Access to memory operands of the instruction
|
2008-05-05 20:30:58 +02:00
|
|
|
unsigned getNumMemOperands() const { return (unsigned)MemOperands.size(); }
|
2008-02-06 23:27:42 +01:00
|
|
|
|
2008-04-07 21:35:22 +02:00
|
|
|
const MachineMemOperand& getMemOperand(unsigned i) const {
|
2008-02-06 23:27:42 +01:00
|
|
|
assert(i < getNumMemOperands() && "getMemOperand() out of range!");
|
|
|
|
return MemOperands[i];
|
|
|
|
}
|
2008-04-07 21:35:22 +02:00
|
|
|
MachineMemOperand& getMemOperand(unsigned i) {
|
2008-02-06 23:27:42 +01:00
|
|
|
assert(i < getNumMemOperands() && "getMemOperand() out of range!");
|
|
|
|
return MemOperands[i];
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:39:36 +02: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-21 00:44:45 +02:00
|
|
|
Other->getNumOperands() != getNumOperands())
|
2006-10-21 00:39:36 +02: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 20:41:18 +01:00
|
|
|
|
2004-05-23 22:58:02 +02: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 21:14:44 +02:00
|
|
|
MachineInstr* clone() const { return new MachineInstr(*this); }
|
2006-04-17 23:35:08 +02: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 21:35:12 +02:00
|
|
|
|
2008-01-31 10:59:15 +01:00
|
|
|
/// isDebugLabel - Returns true if the MachineInstr represents a debug label.
|
|
|
|
///
|
|
|
|
bool isDebugLabel() const;
|
|
|
|
|
2008-03-05 01:59:57 +01: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 21:00:32 +02:00
|
|
|
/// findRegisterUseOperandIdx() - Returns the operand index that is a use of
|
2007-03-27 00:37:45 +02:00
|
|
|
/// the specific register or -1 if it is not found. It further tightening
|
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 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 02:04:05 +01:00
|
|
|
MachineOperand *findRegisterUseOperand(unsigned Reg, bool isKill = false,
|
2008-03-05 01:59:57 +01:00
|
|
|
const TargetRegisterInfo *TRI = NULL) {
|
|
|
|
int Idx = findRegisterUseOperandIdx(Reg, isKill, TRI);
|
|
|
|
return (Idx == -1) ? NULL : &getOperand(Idx);
|
|
|
|
}
|
2006-12-06 09:27:42 +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 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 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 findFirstPredOperandIdx() const;
|
2007-02-19 22:49:54 +01:00
|
|
|
|
2007-10-12 10:50:34 +02:00
|
|
|
/// isRegReDefinedByTwoAddr - Returns true if the Reg re-definition is due
|
|
|
|
/// to two addr elimination.
|
|
|
|
bool isRegReDefinedByTwoAddr(unsigned Reg) const;
|
|
|
|
|
2006-11-15 21:48:17 +01:00
|
|
|
/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
|
|
|
|
///
|
2006-12-06 09:27:42 +01:00
|
|
|
void copyKillDeadInfo(const MachineInstr *MI);
|
2006-11-15 21:48:17 +01:00
|
|
|
|
2007-05-15 03:26:09 +02:00
|
|
|
/// copyPredicates - Copies predicate operand(s) from MI.
|
|
|
|
void copyPredicates(const MachineInstr *MI);
|
|
|
|
|
2008-01-24 02:10:07 +01: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 19:45:23 +01:00
|
|
|
bool addRegisterKilled(unsigned IncomingReg,
|
|
|
|
const TargetRegisterInfo *RegInfo,
|
2008-01-24 02:10:07 +01: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 19:45:23 +01:00
|
|
|
bool addRegisterDead(unsigned IncomingReg, const TargetRegisterInfo *RegInfo,
|
2008-01-24 02:10:07 +01:00
|
|
|
bool AddIfNotFound = false);
|
|
|
|
|
2008-03-13 01:44:09 +01:00
|
|
|
/// copyKillDeadInfo - Copies killed/dead information from one instr to another
|
2008-01-24 02:10:07 +01:00
|
|
|
void copyKillDeadInfo(MachineInstr *OldMI,
|
2008-02-10 19:45:23 +01:00
|
|
|
const TargetRegisterInfo *RegInfo);
|
2008-01-24 02:10:07 +01:00
|
|
|
|
2008-03-13 01:44:09 +01: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 06:23:19 +02:00
|
|
|
//
|
|
|
|
// Debugging support
|
2002-10-30 01:46:48 +01:00
|
|
|
//
|
2006-12-17 06:15:13 +01:00
|
|
|
void print(std::ostream *OS, const TargetMachine *TM) const {
|
|
|
|
if (OS) print(*OS, TM);
|
2006-11-28 23:21:29 +01:00
|
|
|
}
|
2007-12-30 22:31:53 +01:00
|
|
|
void print(std::ostream &OS, const TargetMachine *TM = 0) const;
|
2006-12-17 06:15:13 +01:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2002-10-28 05:24:49 +01:00
|
|
|
void dump() const;
|
2002-02-05 07:02:59 +01:00
|
|
|
|
2002-10-28 21:48:39 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
2008-01-01 02:12:31 +01:00
|
|
|
// Accessors used to build up machine instructions.
|
2002-12-28 21:05:44 +01:00
|
|
|
|
2008-01-01 02:12:31 +01: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 19:10:50 +01:00
|
|
|
/// setDesc - Replace the instruction descriptor (thus opcode) of
|
2006-11-30 08:08:44 +01:00
|
|
|
/// the current instruction with a new one.
|
2003-01-13 01:18:17 +01:00
|
|
|
///
|
2008-01-11 19:10:50 +01:00
|
|
|
void setDesc(const TargetInstrDesc &tid) { TID = &tid; }
|
2003-01-13 01:18:17 +01:00
|
|
|
|
|
|
|
/// RemoveOperand - Erase an operand from an instruction, leaving it with one
|
|
|
|
/// fewer operand than it started with.
|
|
|
|
///
|
2008-01-01 02:12:31 +01:00
|
|
|
void RemoveOperand(unsigned i);
|
|
|
|
|
2008-04-07 21:35:22 +02:00
|
|
|
/// addMemOperand - Add a MachineMemOperand to the machine instruction,
|
|
|
|
/// referencing arbitrary storage.
|
|
|
|
void addMemOperand(const MachineMemOperand &MO) {
|
2008-02-06 23:27:42 +01:00
|
|
|
MemOperands.push_back(MO);
|
|
|
|
}
|
|
|
|
|
2006-05-04 21:14:44 +02:00
|
|
|
private:
|
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 *getRegInfo();
|
2006-11-14 00:34:06 +01:00
|
|
|
|
|
|
|
/// addImplicitDefUseOperands - Add all implicit def and use operands to
|
|
|
|
/// this instruction.
|
2006-11-30 08:08:44 +01:00
|
|
|
void addImplicitDefUseOperands();
|
2008-01-01 02:12:31 +01: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 06:23:19 +02:00
|
|
|
};
|
2001-07-21 14:39:03 +02:00
|
|
|
|
2003-06-03 17:42:53 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-10 22:50:20 +02:00
|
|
|
// Debugging Support
|
|
|
|
|
2007-12-30 22:31:53 +01:00
|
|
|
inline std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI) {
|
|
|
|
MI.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2001-08-29 01:11:46 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-07-21 14:39:03 +02:00
|
|
|
#endif
|