2003-01-13 00:26:36 +00:00
|
|
|
//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-28 23:55:33 +00:00
|
|
|
//
|
2005-01-19 06:53:34 +00:00
|
|
|
// This file implements the TargetInstrInfo class.
|
2002-10-28 23:55:33 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2010-09-09 18:18:55 +00:00
|
|
|
#include "llvm/Target/TargetInstrItineraries.h"
|
2009-05-05 00:30:09 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2010-10-06 06:27:31 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-02 04:58:19 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2005-01-19 06:53:34 +00:00
|
|
|
using namespace llvm;
|
2002-10-28 23:55:33 +00:00
|
|
|
|
2009-08-02 05:20:37 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TargetOperandInfo
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getRegClass - Get the register class for the operand, handling resolution
|
|
|
|
/// of "symbolic" pointer register classes etc. If this is not a register
|
|
|
|
/// operand, this returns null.
|
|
|
|
const TargetRegisterClass *
|
|
|
|
TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
|
|
|
|
if (isLookupPtrRegClass())
|
|
|
|
return TRI->getPointerRegClass(RegClass);
|
2010-06-18 18:13:55 +00:00
|
|
|
// Instructions like INSERT_SUBREG do not have fixed register classes.
|
|
|
|
if (RegClass < 0)
|
|
|
|
return 0;
|
|
|
|
// Otherwise just look it up normally.
|
2009-08-02 05:20:37 +00:00
|
|
|
return TRI->getRegClass(RegClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TargetInstrInfo
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-01-07 07:27:27 +00:00
|
|
|
TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
|
2006-12-08 18:45:48 +00:00
|
|
|
unsigned numOpcodes)
|
2008-01-07 07:27:27 +00:00
|
|
|
: Descriptors(Desc), NumOpcodes(numOpcodes) {
|
2006-12-08 18:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetInstrInfo::~TargetInstrInfo() {
|
|
|
|
}
|
|
|
|
|
2010-09-09 18:18:55 +00:00
|
|
|
unsigned
|
|
|
|
TargetInstrInfo::getNumMicroOps(const MachineInstr *MI,
|
2010-09-10 01:29:16 +00:00
|
|
|
const InstrItineraryData *ItinData) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
2010-09-09 18:18:55 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
unsigned Class = MI->getDesc().getSchedClass();
|
2010-09-15 16:28:21 +00:00
|
|
|
unsigned UOps = ItinData->Itineraries[Class].NumMicroOps;
|
2010-09-09 18:18:55 +00:00
|
|
|
if (UOps)
|
|
|
|
return UOps;
|
|
|
|
|
|
|
|
// The # of u-ops is dynamically determined. The specific target should
|
|
|
|
// override this function to return the right number.
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-06 06:27:31 +00:00
|
|
|
int
|
|
|
|
TargetInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
|
|
|
|
const MachineInstr *DefMI, unsigned DefIdx,
|
|
|
|
const MachineInstr *UseMI, unsigned UseIdx) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
unsigned DefClass = DefMI->getDesc().getSchedClass();
|
|
|
|
unsigned UseClass = UseMI->getDesc().getSchedClass();
|
|
|
|
return ItinData->getOperandLatency(DefClass, DefIdx, UseClass, UseIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
TargetInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
|
|
|
|
SDNode *DefNode, unsigned DefIdx,
|
|
|
|
SDNode *UseNode, unsigned UseIdx) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!DefNode->isMachineOpcode())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
unsigned DefClass = get(DefNode->getMachineOpcode()).getSchedClass();
|
|
|
|
if (!UseNode->isMachineOpcode())
|
|
|
|
return ItinData->getOperandCycle(DefClass, DefIdx);
|
|
|
|
unsigned UseClass = get(UseNode->getMachineOpcode()).getSchedClass();
|
|
|
|
return ItinData->getOperandLatency(DefClass, DefIdx, UseClass, UseIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-02 04:58:19 +00:00
|
|
|
/// insertNoop - Insert a noop into the instruction stream at the specified
|
|
|
|
/// point.
|
|
|
|
void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI) const {
|
|
|
|
llvm_unreachable("Target didn't implement insertNoop!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-08 21:59:56 +00:00
|
|
|
bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
|
2008-01-07 07:27:27 +00:00
|
|
|
const TargetInstrDesc &TID = MI->getDesc();
|
|
|
|
if (!TID.isTerminator()) return false;
|
2008-01-07 01:56:04 +00:00
|
|
|
|
|
|
|
// Conditional branch is a special case.
|
2008-01-07 07:27:27 +00:00
|
|
|
if (TID.isBranch() && !TID.isBarrier())
|
2008-01-07 01:56:04 +00:00
|
|
|
return true;
|
2008-01-07 07:27:27 +00:00
|
|
|
if (!TID.isPredicable())
|
2008-01-07 01:56:04 +00:00
|
|
|
return true;
|
|
|
|
return !isPredicated(MI);
|
2007-06-08 21:59:56 +00:00
|
|
|
}
|
2009-05-05 00:30:09 +00:00
|
|
|
|
2009-07-29 21:10:12 +00:00
|
|
|
|
2009-08-02 05:20:37 +00:00
|
|
|
/// Measure the specified inline asm to determine an approximation of its
|
|
|
|
/// length.
|
|
|
|
/// Comments (which run till the next SeparatorChar or newline) do not
|
|
|
|
/// count as an instruction.
|
|
|
|
/// Any other non-whitespace text is considered an instruction, with
|
|
|
|
/// multiple instructions separated by SeparatorChar or newlines.
|
|
|
|
/// Variable-length instructions are not handled here; this function
|
|
|
|
/// may be overloaded in the target code to do that.
|
|
|
|
unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
|
2009-08-22 21:43:10 +00:00
|
|
|
const MCAsmInfo &MAI) const {
|
2009-08-02 05:20:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Count the number of instructions in the asm.
|
|
|
|
bool atInsnStart = true;
|
|
|
|
unsigned Length = 0;
|
|
|
|
for (; *Str; ++Str) {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (*Str == '\n' || *Str == MAI.getSeparatorChar())
|
2009-08-02 05:20:37 +00:00
|
|
|
atInsnStart = true;
|
|
|
|
if (atInsnStart && !isspace(*Str)) {
|
2009-08-22 21:43:10 +00:00
|
|
|
Length += MAI.getMaxInstLength();
|
2009-08-02 05:20:37 +00:00
|
|
|
atInsnStart = false;
|
|
|
|
}
|
2009-08-22 21:43:10 +00:00
|
|
|
if (atInsnStart && strncmp(Str, MAI.getCommentString(),
|
|
|
|
strlen(MAI.getCommentString())) == 0)
|
2009-08-02 05:20:37 +00:00
|
|
|
atInsnStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Length;
|
|
|
|
}
|