2009-11-07 22:00:39 +00:00
|
|
|
//===- ARMBaseInstrInfo.h - ARM Base Instruction Information ----*- C++ -*-===//
|
2009-07-08 16:09:28 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the Base ARM implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef ARMBASEINSTRUCTIONINFO_H
|
|
|
|
#define ARMBASEINSTRUCTIONINFO_H
|
|
|
|
|
|
|
|
#include "ARM.h"
|
2009-07-16 23:26:06 +00:00
|
|
|
#include "ARMRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2009-07-08 16:09:28 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// ARMII - This namespace holds all of the target specific flags that
|
|
|
|
/// instruction info tracks.
|
|
|
|
///
|
|
|
|
namespace ARMII {
|
|
|
|
enum {
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Instruction Flags.
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// This four-bit field describes the addressing mode used.
|
|
|
|
|
|
|
|
AddrModeMask = 0xf,
|
|
|
|
AddrModeNone = 0,
|
|
|
|
AddrMode1 = 1,
|
|
|
|
AddrMode2 = 2,
|
|
|
|
AddrMode3 = 3,
|
|
|
|
AddrMode4 = 4,
|
|
|
|
AddrMode5 = 5,
|
|
|
|
AddrMode6 = 6,
|
|
|
|
AddrModeT1_1 = 7,
|
|
|
|
AddrModeT1_2 = 8,
|
|
|
|
AddrModeT1_4 = 9,
|
|
|
|
AddrModeT1_s = 10, // i8 * 4 for pc and sp relative data
|
|
|
|
AddrModeT2_i12 = 11,
|
|
|
|
AddrModeT2_i8 = 12,
|
|
|
|
AddrModeT2_so = 13,
|
|
|
|
AddrModeT2_pc = 14, // +/- i12 for pc relative data
|
|
|
|
AddrModeT2_i8s4 = 15, // i8 * 4
|
|
|
|
|
|
|
|
// Size* - Flags to keep track of the size of an instruction.
|
|
|
|
SizeShift = 4,
|
|
|
|
SizeMask = 7 << SizeShift,
|
|
|
|
SizeSpecial = 1, // 0 byte pseudo or special case.
|
|
|
|
Size8Bytes = 2,
|
|
|
|
Size4Bytes = 3,
|
|
|
|
Size2Bytes = 4,
|
|
|
|
|
|
|
|
// IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
|
|
|
|
// and store ops
|
|
|
|
IndexModeShift = 7,
|
|
|
|
IndexModeMask = 3 << IndexModeShift,
|
|
|
|
IndexModePre = 1,
|
|
|
|
IndexModePost = 2,
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Instruction encoding formats.
|
|
|
|
//
|
|
|
|
FormShift = 9,
|
|
|
|
FormMask = 0x3f << FormShift,
|
|
|
|
|
|
|
|
// Pseudo instructions
|
|
|
|
Pseudo = 0 << FormShift,
|
|
|
|
|
|
|
|
// Multiply instructions
|
|
|
|
MulFrm = 1 << FormShift,
|
|
|
|
|
|
|
|
// Branch instructions
|
|
|
|
BrFrm = 2 << FormShift,
|
|
|
|
BrMiscFrm = 3 << FormShift,
|
|
|
|
|
|
|
|
// Data Processing instructions
|
|
|
|
DPFrm = 4 << FormShift,
|
|
|
|
DPSoRegFrm = 5 << FormShift,
|
|
|
|
|
|
|
|
// Load and Store
|
|
|
|
LdFrm = 6 << FormShift,
|
|
|
|
StFrm = 7 << FormShift,
|
|
|
|
LdMiscFrm = 8 << FormShift,
|
|
|
|
StMiscFrm = 9 << FormShift,
|
|
|
|
LdStMulFrm = 10 << FormShift,
|
|
|
|
|
2009-12-11 01:42:04 +00:00
|
|
|
LdStExFrm = 28 << FormShift,
|
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
// Miscellaneous arithmetic instructions
|
|
|
|
ArithMiscFrm = 11 << FormShift,
|
|
|
|
|
|
|
|
// Extend instructions
|
|
|
|
ExtFrm = 12 << FormShift,
|
|
|
|
|
|
|
|
// VFP formats
|
|
|
|
VFPUnaryFrm = 13 << FormShift,
|
|
|
|
VFPBinaryFrm = 14 << FormShift,
|
|
|
|
VFPConv1Frm = 15 << FormShift,
|
|
|
|
VFPConv2Frm = 16 << FormShift,
|
|
|
|
VFPConv3Frm = 17 << FormShift,
|
|
|
|
VFPConv4Frm = 18 << FormShift,
|
|
|
|
VFPConv5Frm = 19 << FormShift,
|
|
|
|
VFPLdStFrm = 20 << FormShift,
|
|
|
|
VFPLdStMulFrm = 21 << FormShift,
|
|
|
|
VFPMiscFrm = 22 << FormShift,
|
|
|
|
|
|
|
|
// Thumb format
|
|
|
|
ThumbFrm = 23 << FormShift,
|
|
|
|
|
|
|
|
// NEON format
|
|
|
|
NEONFrm = 24 << FormShift,
|
|
|
|
NEONGetLnFrm = 25 << FormShift,
|
|
|
|
NEONSetLnFrm = 26 << FormShift,
|
|
|
|
NEONDupFrm = 27 << FormShift,
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Misc flags.
|
|
|
|
|
|
|
|
// UnaryDP - Indicates this is a unary data processing instruction, i.e.
|
|
|
|
// it doesn't have a Rn operand.
|
|
|
|
UnaryDP = 1 << 15,
|
|
|
|
|
|
|
|
// Xform16Bit - Indicates this Thumb2 instruction may be transformed into
|
|
|
|
// a 16-bit Thumb instruction if certain conditions are met.
|
|
|
|
Xform16Bit = 1 << 16,
|
|
|
|
|
2009-11-02 00:10:38 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Code domain.
|
|
|
|
DomainShift = 17,
|
|
|
|
DomainMask = 3 << DomainShift,
|
|
|
|
DomainGeneral = 0 << DomainShift,
|
|
|
|
DomainVFP = 1 << DomainShift,
|
|
|
|
DomainNEON = 2 << DomainShift,
|
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Field shifts - such shifts are used to set field while generating
|
|
|
|
// machine instructions.
|
|
|
|
M_BitShift = 5,
|
|
|
|
ShiftImmShift = 5,
|
|
|
|
ShiftShift = 7,
|
|
|
|
N_BitShift = 7,
|
|
|
|
ImmHiShift = 8,
|
|
|
|
SoRotImmShift = 8,
|
|
|
|
RegRsShift = 8,
|
|
|
|
ExtRotImmShift = 10,
|
|
|
|
RegRdLoShift = 12,
|
|
|
|
RegRdShift = 12,
|
|
|
|
RegRdHiShift = 16,
|
|
|
|
RegRnShift = 16,
|
|
|
|
S_BitShift = 20,
|
|
|
|
W_BitShift = 21,
|
|
|
|
AM3_I_BitShift = 22,
|
|
|
|
D_BitShift = 22,
|
|
|
|
U_BitShift = 23,
|
|
|
|
P_BitShift = 24,
|
|
|
|
I_BitShift = 25,
|
|
|
|
CondShift = 28
|
|
|
|
};
|
2009-11-24 00:44:37 +00:00
|
|
|
|
|
|
|
/// Target Operand Flag enum.
|
|
|
|
enum TOF {
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// ARM Specific MachineOperand flags.
|
|
|
|
|
|
|
|
MO_NO_FLAG,
|
|
|
|
|
|
|
|
/// MO_LO16 - On a symbol operand, this represents a relocation containing
|
|
|
|
/// lower 16 bit of the address. Used only via movw instruction.
|
|
|
|
MO_LO16,
|
|
|
|
|
|
|
|
/// MO_HI16 - On a symbol operand, this represents a relocation containing
|
|
|
|
/// higher 16 bit of the address. Used only via movt instruction.
|
|
|
|
MO_HI16
|
|
|
|
};
|
2009-07-19 19:16:46 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
class ARMBaseInstrInfo : public TargetInstrInfoImpl {
|
2009-11-02 00:10:38 +00:00
|
|
|
const ARMSubtarget& Subtarget;
|
2009-07-08 16:09:28 +00:00
|
|
|
protected:
|
|
|
|
// Can be only subclassed.
|
2009-11-02 00:10:38 +00:00
|
|
|
explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
|
2009-07-08 16:09:28 +00:00
|
|
|
public:
|
|
|
|
// Return the non-pre/post incrementing version of 'Opc'. Return 0
|
|
|
|
// if there is not such an opcode.
|
|
|
|
virtual unsigned getUnindexedOpcode(unsigned Opc) const =0;
|
|
|
|
|
|
|
|
virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
|
|
|
|
MachineBasicBlock::iterator &MBBI,
|
|
|
|
LiveVariables *LV) const;
|
|
|
|
|
|
|
|
virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0;
|
2009-11-02 00:10:38 +00:00
|
|
|
const ARMSubtarget &getSubtarget() const { return Subtarget; }
|
2009-07-08 16:09:28 +00:00
|
|
|
|
|
|
|
// Branch analysis.
|
|
|
|
virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const;
|
|
|
|
virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
|
|
|
|
virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
|
|
|
|
|
|
|
|
// Predication support.
|
2009-07-10 01:38:27 +00:00
|
|
|
bool isPredicated(const MachineInstr *MI) const {
|
|
|
|
int PIdx = MI->findFirstPredOperandIdx();
|
|
|
|
return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
|
|
|
|
}
|
2009-07-08 16:09:28 +00:00
|
|
|
|
|
|
|
ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
|
|
|
|
int PIdx = MI->findFirstPredOperandIdx();
|
|
|
|
return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
|
|
|
|
: ARMCC::AL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool PredicateInstruction(MachineInstr *MI,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Pred) const;
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Pred2) const;
|
|
|
|
|
|
|
|
virtual bool DefinesPredicate(MachineInstr *MI,
|
|
|
|
std::vector<MachineOperand> &Pred) const;
|
|
|
|
|
2009-11-21 06:21:52 +00:00
|
|
|
virtual bool isPredicable(MachineInstr *MI) const;
|
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
/// GetInstSize - Returns the size of the specified MachineInstr.
|
|
|
|
///
|
|
|
|
virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
|
|
|
|
|
|
|
|
/// Return true if the instruction is a register to register move and return
|
|
|
|
/// the source and dest operands and their sub-register indices by reference.
|
|
|
|
virtual bool isMoveInstr(const MachineInstr &MI,
|
|
|
|
unsigned &SrcReg, unsigned &DstReg,
|
|
|
|
unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
|
|
|
|
|
|
|
|
virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const;
|
|
|
|
virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const;
|
|
|
|
|
|
|
|
virtual bool copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const;
|
2009-07-27 03:14:20 +00:00
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC) const;
|
|
|
|
|
|
|
|
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MBBI,
|
|
|
|
unsigned DestReg, int FrameIndex,
|
|
|
|
const TargetRegisterClass *RC) const;
|
|
|
|
|
|
|
|
virtual bool canFoldMemoryOperand(const MachineInstr *MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops) const;
|
2009-08-11 15:33:49 +00:00
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops,
|
|
|
|
int FrameIndex) const;
|
|
|
|
|
|
|
|
virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
2009-11-06 23:52:48 +00:00
|
|
|
const SmallVectorImpl<unsigned> &Ops,
|
2009-07-08 16:09:28 +00:00
|
|
|
MachineInstr* LoadMI) const;
|
2009-11-07 04:04:34 +00:00
|
|
|
|
2009-11-08 00:15:23 +00:00
|
|
|
virtual void reMaterialize(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, unsigned SubIdx,
|
2009-11-14 02:55:43 +00:00
|
|
|
const MachineInstr *Orig,
|
|
|
|
const TargetRegisterInfo *TRI) const;
|
2009-11-08 00:15:23 +00:00
|
|
|
|
2010-01-06 23:47:07 +00:00
|
|
|
MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
|
|
|
|
|
2009-11-07 04:04:34 +00:00
|
|
|
virtual bool isIdentical(const MachineInstr *MI, const MachineInstr *Other,
|
|
|
|
const MachineRegisterInfo *MRI) const;
|
2009-07-28 05:48:47 +00:00
|
|
|
};
|
2009-07-27 18:20:05 +00:00
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
static inline
|
|
|
|
const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
|
|
|
|
return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
|
|
|
|
}
|
2009-07-27 18:20:05 +00:00
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
static inline
|
|
|
|
const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
|
|
|
|
return MIB.addReg(0);
|
|
|
|
}
|
2009-07-27 18:25:24 +00:00
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
static inline
|
2009-08-10 02:37:24 +00:00
|
|
|
const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB,
|
|
|
|
bool isDead = false) {
|
|
|
|
return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead));
|
2009-07-28 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 07:59:10 +00:00
|
|
|
static inline
|
|
|
|
const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) {
|
|
|
|
return MIB.addReg(0);
|
|
|
|
}
|
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
static inline
|
|
|
|
bool isUncondBranchOpcode(int Opc) {
|
|
|
|
return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B;
|
2009-07-08 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
static inline
|
|
|
|
bool isCondBranchOpcode(int Opc) {
|
|
|
|
return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
bool isJumpTableBranchOpcode(int Opc) {
|
|
|
|
return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd ||
|
|
|
|
Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT;
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:26:41 +00:00
|
|
|
static inline
|
|
|
|
bool isIndirectBranchOpcode(int Opc) {
|
|
|
|
return Opc == ARM::BRIND || Opc == ARM::tBRIND;
|
|
|
|
}
|
|
|
|
|
2009-08-08 03:20:32 +00:00
|
|
|
/// getInstrPredicate - If instruction is predicated, returns its predicate
|
|
|
|
/// condition, otherwise returns AL. It also returns the condition code
|
|
|
|
/// register by reference.
|
2009-09-28 09:14:39 +00:00
|
|
|
ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
|
2009-08-08 03:20:32 +00:00
|
|
|
|
2009-07-28 05:48:47 +00:00
|
|
|
int getMatchingCondBranchOpcode(int Opc);
|
|
|
|
|
|
|
|
/// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of
|
|
|
|
/// instructions to materializea destreg = basereg + immediate in ARM / Thumb2
|
|
|
|
/// code.
|
|
|
|
void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator &MBBI, DebugLoc dl,
|
|
|
|
unsigned DestReg, unsigned BaseReg, int NumBytes,
|
|
|
|
ARMCC::CondCodes Pred, unsigned PredReg,
|
|
|
|
const ARMBaseInstrInfo &TII);
|
|
|
|
|
|
|
|
void emitT2RegPlusImmediate(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator &MBBI, DebugLoc dl,
|
|
|
|
unsigned DestReg, unsigned BaseReg, int NumBytes,
|
|
|
|
ARMCC::CondCodes Pred, unsigned PredReg,
|
|
|
|
const ARMBaseInstrInfo &TII);
|
|
|
|
|
|
|
|
|
2009-08-11 15:33:49 +00:00
|
|
|
/// rewriteARMFrameIndex / rewriteT2FrameIndex -
|
2009-08-27 01:23:50 +00:00
|
|
|
/// Rewrite MI to access 'Offset' bytes from the FP. Return false if the
|
|
|
|
/// offset could not be handled directly in MI, and return the left-over
|
|
|
|
/// portion by reference.
|
|
|
|
bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
|
|
|
|
unsigned FrameReg, int &Offset,
|
|
|
|
const ARMBaseInstrInfo &TII);
|
|
|
|
|
|
|
|
bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
|
|
|
|
unsigned FrameReg, int &Offset,
|
|
|
|
const ARMBaseInstrInfo &TII);
|
2009-07-28 05:48:47 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
2009-07-08 16:09:28 +00:00
|
|
|
#endif
|