2003-01-13 01:21:19 +01:00
|
|
|
//===-- llvm/Target/TargetInstrInfo.h - Instruction Info --------*- C++ -*-===//
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02: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 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
|
|
|
// This file describes the target machine instructions to the code generator.
|
|
|
|
//
|
2002-12-03 06:41:32 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2003-01-14 23:00:31 +01:00
|
|
|
#ifndef LLVM_TARGET_TARGETINSTRINFO_H
|
|
|
|
#define LLVM_TARGET_TARGETINSTRINFO_H
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2004-07-31 10:52:30 +02:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2002-10-29 00:53:56 +01:00
|
|
|
#include <vector>
|
2003-07-25 19:58:41 +02:00
|
|
|
#include <cassert>
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-10-18 02:02:06 +02:00
|
|
|
class MachineInstr;
|
2002-02-03 08:17:37 +01:00
|
|
|
class TargetMachine;
|
2001-10-18 02:02:06 +02:00
|
|
|
class Value;
|
2003-07-29 22:30:20 +02:00
|
|
|
class Type;
|
2001-10-18 02:02:06 +02:00
|
|
|
class Instruction;
|
2002-10-29 00:53:56 +01:00
|
|
|
class Constant;
|
2002-03-23 23:51:58 +01:00
|
|
|
class Function;
|
2002-05-19 17:43:31 +02:00
|
|
|
class MachineCodeForInstruction;
|
2005-08-19 18:56:26 +02:00
|
|
|
class TargetRegisterClass;
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2002-02-03 08:17:37 +01:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Data types used to define information about a single machine instruction
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2004-02-12 19:49:07 +01:00
|
|
|
typedef short MachineOpCode;
|
2002-10-28 05:53:18 +01:00
|
|
|
typedef unsigned InstrSchedClass;
|
2001-09-18 14:38:31 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2003-01-14 23:00:31 +01:00
|
|
|
// struct TargetInstrDescriptor:
|
2005-04-22 05:46:24 +02:00
|
|
|
// Predefined information about each machine instruction.
|
|
|
|
// Designed to initialized statically.
|
2003-01-14 23:00:31 +01:00
|
|
|
//
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2006-04-20 20:32:02 +02: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 03:28:31 +01:00
|
|
|
|
|
|
|
// M_2_ADDR_FLAG - 3-addr instructions which really work like 2-addr ones.
|
2006-04-20 20:32:02 +02:00
|
|
|
const unsigned M_2_ADDR_FLAG = 1 << 7;
|
2005-01-02 03:28:31 +01: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 20:32:02 +02:00
|
|
|
const unsigned M_CONVERTIBLE_TO_3_ADDR = 1 << 8;
|
2005-01-02 03:28:31 +01: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 20:32:02 +02:00
|
|
|
const unsigned M_COMMUTABLE = 1 << 9;
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2003-01-13 01:21:19 +01: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 20:32:02 +02:00
|
|
|
const unsigned M_TERMINATOR_FLAG = 1 << 10;
|
2003-01-13 01:21:19 +01:00
|
|
|
|
2005-08-26 22:31:24 +02: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 20:32:02 +02:00
|
|
|
const unsigned M_USES_CUSTOM_DAG_SCHED_INSERTION = 1 << 11;
|
2005-08-26 22:31:24 +02:00
|
|
|
|
2006-06-15 09:22:16 +02: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 22:42:07 +02: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 18:56:26 +02: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 22:57:35 +02: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 18:56:26 +02:00
|
|
|
/// Currently no other information.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-10-27 18:14:51 +02:00
|
|
|
class TargetInstrDescriptor {
|
|
|
|
public:
|
2002-10-29 18:35:09 +01:00
|
|
|
const char * Name; // Assembly language mnemonic for the opcode.
|
2006-06-15 09:22:16 +02:00
|
|
|
unsigned numOperands; // Num of args (may be more if variable_ops).
|
2002-10-30 02:06:53 +01:00
|
|
|
InstrSchedClass schedClass; // enum identifying instr sched class
|
|
|
|
unsigned Flags; // flags identifying machine instr class
|
|
|
|
unsigned TSFlags; // Target Specific Flag values
|
2002-12-03 06:41:32 +01:00
|
|
|
const unsigned *ImplicitUses; // Registers implicitly read by this instr
|
|
|
|
const unsigned *ImplicitDefs; // Registers implicitly defined by this instr
|
2005-08-19 18:56:26 +02:00
|
|
|
const TargetOperandInfo *OpInfo; // 'numOperands' entries about operands.
|
2001-09-18 14:38:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-14 23:00:31 +01:00
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 22:59:05 +02:00
|
|
|
///
|
2003-01-14 23:00:31 +01:00
|
|
|
/// TargetInstrInfo - Interface to description of machine instructions
|
2005-04-21 22:59:05 +02:00
|
|
|
///
|
2003-01-13 01:21:19 +01:00
|
|
|
class TargetInstrInfo {
|
|
|
|
const TargetInstrDescriptor* desc; // raw array to allow static init'n
|
2004-02-29 07:31:16 +01:00
|
|
|
unsigned NumOpcodes; // number of entries in the desc array
|
2003-01-13 01:21:19 +01:00
|
|
|
unsigned numRealOpCodes; // number of non-dummy op codes
|
2005-04-21 22:59:05 +02:00
|
|
|
|
2003-01-13 01:21:19 +01:00
|
|
|
TargetInstrInfo(const TargetInstrInfo &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const TargetInstrInfo &); // DO NOT IMPLEMENT
|
2001-09-18 14:38:31 +02:00
|
|
|
public:
|
2004-02-29 07:31:16 +01:00
|
|
|
TargetInstrInfo(const TargetInstrDescriptor *desc, unsigned NumOpcodes);
|
2003-01-13 01:21:19 +01:00
|
|
|
virtual ~TargetInstrInfo();
|
2002-12-15 23:16:08 +01:00
|
|
|
|
2006-01-27 00:27:02 +01:00
|
|
|
// Invariant opcodes: All instruction sets have these as their low opcodes.
|
|
|
|
enum {
|
|
|
|
PHI = 0,
|
|
|
|
INLINEASM = 1
|
|
|
|
};
|
2005-04-21 22:59:05 +02:00
|
|
|
|
2004-02-29 07:31:16 +01:00
|
|
|
unsigned getNumOpcodes() const { return NumOpcodes; }
|
2005-04-21 22:59:05 +02:00
|
|
|
|
2002-10-29 18:26:26 +01:00
|
|
|
/// get - Return the machine instruction descriptor that corresponds to the
|
|
|
|
/// specified instruction opcode.
|
|
|
|
///
|
2004-07-31 04:06:48 +02:00
|
|
|
const TargetInstrDescriptor& get(MachineOpCode Opcode) const {
|
|
|
|
assert((unsigned)Opcode < NumOpcodes);
|
|
|
|
return desc[Opcode];
|
2001-09-18 14:38:31 +02:00
|
|
|
}
|
2002-10-29 18:35:09 +01:00
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
const char *getName(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Name;
|
2002-10-29 18:35:09 +01:00
|
|
|
}
|
2005-04-21 22:59:05 +02:00
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
int getNumOperands(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).numOperands;
|
2001-09-18 14:38:31 +02:00
|
|
|
}
|
2004-02-29 06:57:21 +01:00
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).schedClass;
|
2001-09-18 14:38:31 +02:00
|
|
|
}
|
2003-06-27 02:00:48 +02:00
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
const unsigned *getImplicitUses(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).ImplicitUses;
|
2003-06-27 02:00:48 +02:00
|
|
|
}
|
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
const unsigned *getImplicitDefs(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).ImplicitDefs;
|
2003-06-27 02:00:48 +02:00
|
|
|
}
|
|
|
|
|
2004-02-29 06:57:21 +01:00
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
|
|
|
// Query instruction class flags according to the machine-independent
|
|
|
|
// flags listed above.
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2004-07-31 04:06:48 +02:00
|
|
|
bool isReturn(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_RET_FLAG;
|
2001-09-18 14:38:31 +02:00
|
|
|
}
|
2004-02-29 06:57:21 +01:00
|
|
|
|
2004-07-31 04:06:48 +02:00
|
|
|
bool isTwoAddrInstr(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_2_ADDR_FLAG;
|
2002-12-13 00:19:51 +01:00
|
|
|
}
|
2006-05-12 03:58:24 +02:00
|
|
|
bool isCommutableInstr(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_COMMUTABLE;
|
|
|
|
}
|
2003-01-13 01:21:19 +01:00
|
|
|
bool isTerminatorInstr(unsigned Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_TERMINATOR_FLAG;
|
|
|
|
}
|
2005-09-02 20:16:20 +02: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 02:52:09 +02:00
|
|
|
|
2006-06-15 09:22:16 +02:00
|
|
|
bool hasVariableOperands(MachineOpCode Opcode) const {
|
|
|
|
return get(Opcode).Flags & M_VARIABLE_OPS;
|
|
|
|
}
|
|
|
|
|
2004-07-31 10:57:27 +02: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 18:35:08 +01:00
|
|
|
virtual bool isMoveInstr(const MachineInstr& MI,
|
|
|
|
unsigned& sourceReg,
|
|
|
|
unsigned& destReg) const {
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-02 21:11:55 +01: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 18:35:08 +01:00
|
|
|
|
2005-01-02 03:28:31 +01: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 07:53:02 +01: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 11:37:52 +02: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 10:52:30 +02:00
|
|
|
assert(0 && "Target didn't implement insertGoto!");
|
|
|
|
}
|
2004-02-29 06:57:21 +01:00
|
|
|
|
2004-07-31 10:57:27 +02:00
|
|
|
/// Reverses the branch condition of the MachineInstr pointed by
|
|
|
|
/// MI. The instruction is replaced and the new MI is returned.
|
2004-07-31 10:52:30 +02:00
|
|
|
virtual MachineBasicBlock::iterator
|
2004-07-31 10:55:23 +02:00
|
|
|
reverseBranchCondition(MachineBasicBlock::iterator MI) const {
|
2004-07-31 10:52:30 +02:00
|
|
|
assert(0 && "Target didn't implement reverseBranchCondition!");
|
2004-08-01 20:17:36 +02:00
|
|
|
abort();
|
|
|
|
return MI;
|
2004-07-31 10:52:30 +02:00
|
|
|
}
|
2005-09-02 20:16:20 +02:00
|
|
|
|
2006-03-06 00:48:51 +01: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 22:42:07 +02: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 20:16:20 +02:00
|
|
|
|
2004-09-28 20:33:50 +02: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 20:37:00 +02:00
|
|
|
return get(Opcode).Flags & M_DELAY_SLOT_FLAG;
|
2004-09-28 20:33:50 +02:00
|
|
|
}
|
2001-09-18 14:38:31 +02:00
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
#endif
|