2003-01-13 00:21:19 +00:00
|
|
|
//===-- llvm/Target/TargetInstrInfo.h - Instruction Info --------*- C++ -*-===//
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 12:38:31 +00:00
|
|
|
//
|
|
|
|
// This file describes the target machine instructions to the code generator.
|
|
|
|
//
|
2002-12-03 05:41:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
#ifndef LLVM_TARGET_TARGETINSTRINFO_H
|
|
|
|
#define LLVM_TARGET_TARGETINSTRINFO_H
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2004-07-31 08:52:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2002-10-28 23:53:56 +00:00
|
|
|
#include <vector>
|
2003-07-25 17:58:41 +00:00
|
|
|
#include <cassert>
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-10-18 00:02:06 +00:00
|
|
|
class MachineInstr;
|
2002-02-03 07:17:37 +00:00
|
|
|
class TargetMachine;
|
2001-10-18 00:02:06 +00:00
|
|
|
class Value;
|
2003-07-29 20:30:20 +00:00
|
|
|
class Type;
|
2001-10-18 00:02:06 +00:00
|
|
|
class Instruction;
|
2002-10-28 23:53:56 +00:00
|
|
|
class Constant;
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2002-05-19 15:43:31 +00:00
|
|
|
class MachineCodeForInstruction;
|
2005-08-19 16:56:26 +00:00
|
|
|
class TargetRegisterClass;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-02-03 07:17:37 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Data types used to define information about a single machine instruction
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2004-02-12 18:49:07 +00:00
|
|
|
typedef short MachineOpCode;
|
2002-10-28 04:53:18 +00:00
|
|
|
typedef unsigned InstrSchedClass;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2003-01-14 22:00:31 +00:00
|
|
|
// struct TargetInstrDescriptor:
|
2005-04-22 03:46:24 +00:00
|
|
|
// Predefined information about each machine instruction.
|
|
|
|
// Designed to initialized statically.
|
2003-01-14 22:00:31 +00:00
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_BRANCH_FLAG = 1 << 0;
|
|
|
|
const unsigned M_CALL_FLAG = 1 << 1;
|
|
|
|
const unsigned M_RET_FLAG = 1 << 2;
|
|
|
|
const unsigned M_BARRIER_FLAG = 1 << 3;
|
|
|
|
const unsigned M_DELAY_SLOT_FLAG = 1 << 4;
|
|
|
|
const unsigned M_LOAD_FLAG = 1 << 5;
|
|
|
|
const unsigned M_STORE_FLAG = 1 << 6;
|
2005-01-02 02:28:31 +00:00
|
|
|
|
|
|
|
// M_2_ADDR_FLAG - 3-addr instructions which really work like 2-addr ones.
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_2_ADDR_FLAG = 1 << 7;
|
2005-01-02 02:28:31 +00:00
|
|
|
|
|
|
|
// M_CONVERTIBLE_TO_3_ADDR - This is a M_2_ADDR_FLAG instruction which can be
|
|
|
|
// changed into a 3-address instruction if the first two operands cannot be
|
|
|
|
// assigned to the same register. The target must implement the
|
|
|
|
// TargetInstrInfo::convertToThreeAddress method for this instruction.
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_CONVERTIBLE_TO_3_ADDR = 1 << 8;
|
2005-01-02 02:28:31 +00:00
|
|
|
|
|
|
|
// This M_COMMUTABLE - is a 2- or 3-address instruction (of the form X = op Y,
|
|
|
|
// Z), which produces the same result if Y and Z are exchanged.
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_COMMUTABLE = 1 << 9;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-01-13 00:21:19 +00:00
|
|
|
// M_TERMINATOR_FLAG - Is this instruction part of the terminator for a basic
|
|
|
|
// block? Typically this is things like return and branch instructions.
|
|
|
|
// Various passes use this to insert code into the bottom of a basic block, but
|
|
|
|
// before control flow occurs.
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_TERMINATOR_FLAG = 1 << 10;
|
2003-01-13 00:21:19 +00:00
|
|
|
|
2005-08-26 20:31:24 +00:00
|
|
|
// M_USES_CUSTOM_DAG_SCHED_INSERTION - Set if this instruction requires custom
|
|
|
|
// insertion support when the DAG scheduler is inserting it into a machine basic
|
|
|
|
// block.
|
2006-04-20 18:32:02 +00:00
|
|
|
const unsigned M_USES_CUSTOM_DAG_SCHED_INSERTION = 1 << 11;
|
2005-08-26 20:31:24 +00:00
|
|
|
|
2006-06-15 07:22:16 +00:00
|
|
|
// M_VARIABLE_OPS - Set if this instruction can have a variable number of extra
|
|
|
|
// operands in addition to the minimum number operands specified.
|
|
|
|
const unsigned M_VARIABLE_OPS = 1 << 12;
|
|
|
|
|
2006-05-18 20:42:07 +00:00
|
|
|
// Machine operand flags
|
|
|
|
// M_LOOK_UP_PTR_REG_CLASS - Set if this operand is a pointer value and it
|
|
|
|
// requires a callback to look up its register class.
|
|
|
|
const unsigned M_LOOK_UP_PTR_REG_CLASS = 1 << 0;
|
|
|
|
|
2005-08-19 16:56:26 +00:00
|
|
|
/// TargetOperandInfo - This holds information about one operand of a machine
|
|
|
|
/// instruction, indicating the register class for register operands, etc.
|
|
|
|
///
|
|
|
|
class TargetOperandInfo {
|
|
|
|
public:
|
2006-07-21 20:57:35 +00:00
|
|
|
/// RegClass - This specifies the register class enumeration of the operand
|
|
|
|
/// if the operand is a register. If not, this contains 0.
|
|
|
|
unsigned short RegClass;
|
|
|
|
unsigned short Flags;
|
2005-08-19 16:56:26 +00:00
|
|
|
/// Currently no other information.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
class TargetInstrDescriptor {
|
|
|
|
public:
|
2002-10-29 17:35:09 +00:00
|
|
|
const char * Name; // Assembly language mnemonic for the opcode.
|
2006-06-15 07:22:16 +00:00
|
|
|
unsigned numOperands; // Num of args (may be more if variable_ops).
|
2002-10-30 01:06:53 +00:00
|
|
|
InstrSchedClass schedClass; // enum identifying instr sched class
|
|
|
|
unsigned Flags; // flags identifying machine instr class
|
|
|
|
unsigned TSFlags; // Target Specific Flag values
|
2002-12-03 05:41:32 +00:00
|
|
|
const unsigned *ImplicitUses; // Registers implicitly read by this instr
|
|
|
|
const unsigned *ImplicitDefs; // Registers implicitly defined by this instr
|
2005-08-19 16:56:26 +00:00
|
|
|
const TargetOperandInfo *OpInfo; // 'numOperands' entries about operands.
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 20:59:05 +00:00
|
|
|
///
|
2003-01-14 22:00:31 +00:00
|
|
|
/// TargetInstrInfo - Interface to description of machine instructions
|
2005-04-21 20:59:05 +00:00
|
|
|
///
|
2003-01-13 00:21:19 +00:00
|
|
|
class TargetInstrInfo {
|
|
|
|
const TargetInstrDescriptor* desc; // raw array to allow static init'n
|
2004-02-29 06:31:16 +00:00
|
|
|
unsigned NumOpcodes; // number of entries in the desc array
|
2003-01-13 00:21:19 +00:00
|
|
|
unsigned numRealOpCodes; // number of non-dummy op codes
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2003-01-13 00:21:19 +00:00
|
|
|
TargetInstrInfo(const TargetInstrInfo &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const TargetInstrInfo &); // DO NOT IMPLEMENT
|
2001-09-18 12:38:31 +00:00
|
|
|
public:
|
2004-02-29 06:31:16 +00:00
|
|
|
TargetInstrInfo(const TargetInstrDescriptor *desc, unsigned NumOpcodes);
|
2003-01-13 00:21:19 +00:00
|
|
|
virtual ~TargetInstrInfo();
|
2002-12-15 22:16:08 +00:00
|
|
|
|
2006-01-26 23:27:02 +00:00
|
|
|
// Invariant opcodes: All instruction sets have these as their low opcodes.
|
|
|
|
enum {
|
|
|
|
PHI = 0,
|
|
|
|
INLINEASM = 1
|
|
|
|
};
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2004-02-29 06:31:16 +00:00
|
|
|
unsigned getNumOpcodes() const { return NumOpcodes; }
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2002-10-29 17:26:26 +00:00
|
|
|
/// get - Return the machine instruction descriptor that corresponds to the
|
|
|
|
/// specified instruction opcode.
|
|
|
|
///
|
2004-07-31 02:06:48 +00:00
|
|
|
const TargetInstrDescriptor& get(MachineOpCode Opcode) const {
|
|
|
|
assert((unsigned)Opcode < NumOpcodes);
|
|
|
|
return desc[Opcode];
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2002-10-29 17:35:09 +00:00
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
const char *getName(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Name;
|
2002-10-29 17:35:09 +00:00
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
int getNumOperands(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).numOperands;
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2004-02-29 05:57:21 +00:00
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).schedClass;
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2003-06-27 00:00:48 +00:00
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
const unsigned *getImplicitUses(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).ImplicitUses;
|
2003-06-27 00:00:48 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
const unsigned *getImplicitDefs(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).ImplicitDefs;
|
2003-06-27 00:00:48 +00:00
|
|
|
}
|
|
|
|
|
2004-02-29 05:57:21 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
//
|
|
|
|
// Query instruction class flags according to the machine-independent
|
|
|
|
// flags listed above.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2004-07-31 02:06:48 +00:00
|
|
|
bool isReturn(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_RET_FLAG;
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2004-02-29 05:57:21 +00:00
|
|
|
|
2004-07-31 02:06:48 +00:00
|
|
|
bool isTwoAddrInstr(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_2_ADDR_FLAG;
|
2002-12-12 23:19:51 +00:00
|
|
|
}
|
2006-05-12 01:58:24 +00:00
|
|
|
bool isCommutableInstr(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_COMMUTABLE;
|
|
|
|
}
|
2003-01-13 00:21:19 +00:00
|
|
|
bool isTerminatorInstr(unsigned Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_TERMINATOR_FLAG;
|
|
|
|
}
|
2005-09-02 18:16:20 +00:00
|
|
|
|
|
|
|
bool isBranch(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_BRANCH_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isBarrier - Returns true if the specified instruction stops control flow
|
|
|
|
/// from executing the instruction immediately following it. Examples include
|
|
|
|
/// unconditional branches and return instructions.
|
|
|
|
bool isBarrier(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_BARRIER_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCall(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_CALL_FLAG;
|
|
|
|
}
|
|
|
|
bool isLoad(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_LOAD_FLAG;
|
|
|
|
}
|
|
|
|
bool isStore(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_STORE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// usesCustomDAGSchedInsertionHook - Return true if this instruction requires
|
|
|
|
/// custom insertion support when the DAG scheduler is inserting it into a
|
|
|
|
/// machine basic block.
|
|
|
|
bool usesCustomDAGSchedInsertionHook(unsigned Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_USES_CUSTOM_DAG_SCHED_INSERTION;
|
|
|
|
}
|
2002-09-20 00:52:09 +00:00
|
|
|
|
2006-06-15 07:22:16 +00:00
|
|
|
bool hasVariableOperands(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_VARIABLE_OPS;
|
|
|
|
}
|
|
|
|
|
2004-07-31 08:57:27 +00:00
|
|
|
/// Return true if the instruction is a register to register move
|
|
|
|
/// and leave the source and dest operands in the passed parameters.
|
2003-12-28 17:35:08 +00:00
|
|
|
virtual bool isMoveInstr(const MachineInstr& MI,
|
|
|
|
unsigned& sourceReg,
|
|
|
|
unsigned& destReg) const {
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-02 20:11:55 +00:00
|
|
|
|
|
|
|
/// isLoadFromStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// load from a stack slot, return the virtual or physical register number of
|
|
|
|
/// the destination along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than loading from the stack slot.
|
|
|
|
virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isStoreToStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// store to a stack slot, return the virtual or physical register number of
|
|
|
|
/// the source reg along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than storing to the stack slot.
|
|
|
|
virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const {
|
|
|
|
return 0;
|
|
|
|
}
|
2003-12-28 17:35:08 +00:00
|
|
|
|
2005-01-02 02:28:31 +00:00
|
|
|
/// convertToThreeAddress - This method must be implemented by targets that
|
|
|
|
/// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
|
|
|
|
/// may be able to convert a two-address instruction into a true
|
|
|
|
/// three-address instruction on demand. This allows the X86 target (for
|
|
|
|
/// example) to convert ADD and SHL instructions into LEA instructions if they
|
|
|
|
/// would require register copies due to two-addressness.
|
|
|
|
///
|
|
|
|
/// This method returns a null pointer if the transformation cannot be
|
|
|
|
/// performed, otherwise it returns the new instruction.
|
|
|
|
///
|
|
|
|
virtual MachineInstr *convertToThreeAddress(MachineInstr *TA) const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-19 06:53:02 +00:00
|
|
|
/// commuteInstruction - If a target has any instructions that are commutable,
|
|
|
|
/// but require converting to a different instruction or making non-trivial
|
|
|
|
/// changes to commute them, this method can overloaded to do this. The
|
|
|
|
/// default implementation of this method simply swaps the first two operands
|
|
|
|
/// of MI and returns it.
|
|
|
|
///
|
|
|
|
/// If a target wants to make more aggressive changes, they can construct and
|
|
|
|
/// return a new machine instruction. If an instruction cannot commute, it
|
|
|
|
/// can also return null.
|
|
|
|
///
|
|
|
|
virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
|
|
|
|
|
2004-07-31 09:37:52 +00:00
|
|
|
/// Insert a goto (unconditional branch) sequence to TMBB, at the
|
|
|
|
/// end of MBB
|
|
|
|
virtual void insertGoto(MachineBasicBlock& MBB,
|
|
|
|
MachineBasicBlock& TMBB) const {
|
2004-07-31 08:52:30 +00:00
|
|
|
assert(0 && "Target didn't implement insertGoto!");
|
|
|
|
}
|
2004-02-29 05:57:21 +00:00
|
|
|
|
2004-07-31 08:57:27 +00:00
|
|
|
/// Reverses the branch condition of the MachineInstr pointed by
|
|
|
|
/// MI. The instruction is replaced and the new MI is returned.
|
2004-07-31 08:52:30 +00:00
|
|
|
virtual MachineBasicBlock::iterator
|
2004-07-31 08:55:23 +00:00
|
|
|
reverseBranchCondition(MachineBasicBlock::iterator MI) const {
|
2004-07-31 08:52:30 +00:00
|
|
|
assert(0 && "Target didn't implement reverseBranchCondition!");
|
2004-08-01 18:17:36 +00:00
|
|
|
abort();
|
|
|
|
return MI;
|
2004-07-31 08:52:30 +00:00
|
|
|
}
|
2005-09-02 18:16:20 +00:00
|
|
|
|
2006-03-05 23:48:51 +00:00
|
|
|
/// insertNoop - Insert a noop into the instruction stream at the specified
|
|
|
|
/// point.
|
|
|
|
virtual void insertNoop(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI) const {
|
|
|
|
assert(0 && "Target didn't implement insertNoop!");
|
|
|
|
abort();
|
|
|
|
}
|
2006-05-18 20:42:07 +00:00
|
|
|
|
|
|
|
/// getPointerRegClass - Returns a TargetRegisterClass used for pointer
|
|
|
|
/// values.
|
|
|
|
virtual const TargetRegisterClass *getPointerRegClass() const {
|
|
|
|
assert(0 && "Target didn't implement getPointerRegClass!");
|
|
|
|
abort();
|
|
|
|
}
|
2005-09-02 18:16:20 +00:00
|
|
|
|
2004-09-28 18:33:50 +00:00
|
|
|
/// hasDelaySlot - Returns true if the specified instruction has a delay slot
|
|
|
|
/// which must be filled by the code generator.
|
|
|
|
bool hasDelaySlot(unsigned Opcode) const {
|
2004-09-28 18:37:00 +00:00
|
|
|
return get(Opcode).Flags & M_DELAY_SLOT_FLAG;
|
2004-09-28 18:33:50 +00:00
|
|
|
}
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
#endif
|