2003-01-13 01:26:36 +01:00
|
|
|
//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-29 00:55:33 +01:00
|
|
|
//
|
2005-01-19 07:53:34 +01:00
|
|
|
// This file implements the TargetInstrInfo class.
|
2002-10-29 00:55:33 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-01-14 23:00:31 +01:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2009-05-05 02:30:09 +02:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2010-10-06 08:27:31 +02:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2011-06-29 03:14:12 +02:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2009-08-02 06:58:19 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-12-19 21:43:38 +01:00
|
|
|
#include <cctype>
|
2005-01-19 07:53:34 +01:00
|
|
|
using namespace llvm;
|
2002-10-29 00:55:33 +01:00
|
|
|
|
2009-08-02 07:20:37 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TargetInstrInfo
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-08 19:45:48 +01:00
|
|
|
TargetInstrInfo::~TargetInstrInfo() {
|
|
|
|
}
|
|
|
|
|
2011-06-27 23:26:13 +02:00
|
|
|
const TargetRegisterClass*
|
2011-06-28 21:10:37 +02:00
|
|
|
TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum,
|
2011-06-27 23:26:13 +02:00
|
|
|
const TargetRegisterInfo *TRI) const {
|
2011-06-28 21:10:37 +02:00
|
|
|
if (OpNum >= MCID.getNumOperands())
|
2011-06-27 23:26:13 +02:00
|
|
|
return 0;
|
|
|
|
|
2011-06-28 21:10:37 +02:00
|
|
|
short RegClass = MCID.OpInfo[OpNum].RegClass;
|
|
|
|
if (MCID.OpInfo[OpNum].isLookupPtrRegClass())
|
2011-06-27 23:26:13 +02:00
|
|
|
return TRI->getPointerRegClass(RegClass);
|
|
|
|
|
|
|
|
// Instructions like INSERT_SUBREG do not have fixed register classes.
|
|
|
|
if (RegClass < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Otherwise just look it up normally.
|
|
|
|
return TRI->getRegClass(RegClass);
|
|
|
|
}
|
|
|
|
|
2010-09-09 20:18:55 +02:00
|
|
|
unsigned
|
2010-11-03 01:45:17 +01:00
|
|
|
TargetInstrInfo::getNumMicroOps(const InstrItineraryData *ItinData,
|
|
|
|
const MachineInstr *MI) const {
|
2010-09-10 03:29:16 +02:00
|
|
|
if (!ItinData || ItinData->isEmpty())
|
2010-09-09 20:18:55 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
unsigned Class = MI->getDesc().getSchedClass();
|
2010-09-15 18:28:21 +02:00
|
|
|
unsigned UOps = ItinData->Itineraries[Class].NumMicroOps;
|
2010-09-09 20:18:55 +02: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 08:27:31 +02: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);
|
|
|
|
}
|
|
|
|
|
2010-11-03 01:45:17 +01:00
|
|
|
int TargetInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
|
|
|
|
const MachineInstr *MI,
|
|
|
|
unsigned *PredCost) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return ItinData->getStageLatency(MI->getDesc().getSchedClass());
|
|
|
|
}
|
|
|
|
|
|
|
|
int TargetInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
|
|
|
|
SDNode *N) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!N->isMachineOpcode())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return ItinData->getStageLatency(get(N->getMachineOpcode()).getSchedClass());
|
|
|
|
}
|
|
|
|
|
2010-10-26 04:08:50 +02:00
|
|
|
bool TargetInstrInfo::hasLowDefLatency(const InstrItineraryData *ItinData,
|
|
|
|
const MachineInstr *DefMI,
|
|
|
|
unsigned DefIdx) const {
|
|
|
|
if (!ItinData || ItinData->isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned DefClass = DefMI->getDesc().getSchedClass();
|
|
|
|
int DefCycle = ItinData->getOperandCycle(DefClass, DefIdx);
|
|
|
|
return (DefCycle != -1 && DefCycle <= 1);
|
|
|
|
}
|
2010-10-06 08:27:31 +02:00
|
|
|
|
2009-08-02 06:58:19 +02:00
|
|
|
/// insertNoop - Insert a noop into the instruction stream at the specified
|
|
|
|
/// point.
|
2010-12-24 05:28:06 +01:00
|
|
|
void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
|
2009-08-02 06:58:19 +02:00
|
|
|
MachineBasicBlock::iterator MI) const {
|
|
|
|
llvm_unreachable("Target didn't implement insertNoop!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-08 23:59:56 +02:00
|
|
|
bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
|
2011-06-28 21:10:37 +02:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
if (!MCID.isTerminator()) return false;
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2008-01-07 02:56:04 +01:00
|
|
|
// Conditional branch is a special case.
|
2011-06-28 21:10:37 +02:00
|
|
|
if (MCID.isBranch() && !MCID.isBarrier())
|
2008-01-07 02:56:04 +01:00
|
|
|
return true;
|
2011-06-28 21:10:37 +02:00
|
|
|
if (!MCID.isPredicable())
|
2008-01-07 02:56:04 +01:00
|
|
|
return true;
|
|
|
|
return !isPredicated(MI);
|
2007-06-08 23:59:56 +02:00
|
|
|
}
|
2009-05-05 02:30:09 +02:00
|
|
|
|
2009-07-29 23:10:12 +02:00
|
|
|
|
2009-08-02 07:20:37 +02:00
|
|
|
/// Measure the specified inline asm to determine an approximation of its
|
|
|
|
/// length.
|
2011-03-24 19:46:34 +01:00
|
|
|
/// Comments (which run till the next SeparatorString or newline) do not
|
2009-08-02 07:20:37 +02:00
|
|
|
/// count as an instruction.
|
|
|
|
/// Any other non-whitespace text is considered an instruction, with
|
2011-03-24 19:46:34 +01:00
|
|
|
/// multiple instructions separated by SeparatorString or newlines.
|
2009-08-02 07:20:37 +02:00
|
|
|
/// 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 23:43:10 +02:00
|
|
|
const MCAsmInfo &MAI) const {
|
2010-12-24 05:28:06 +01:00
|
|
|
|
|
|
|
|
2009-08-02 07:20:37 +02:00
|
|
|
// Count the number of instructions in the asm.
|
|
|
|
bool atInsnStart = true;
|
|
|
|
unsigned Length = 0;
|
|
|
|
for (; *Str; ++Str) {
|
2011-03-24 19:46:34 +01:00
|
|
|
if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
|
|
|
|
strlen(MAI.getSeparatorString())) == 0)
|
2009-08-02 07:20:37 +02:00
|
|
|
atInsnStart = true;
|
2010-12-19 21:42:43 +01:00
|
|
|
if (atInsnStart && !std::isspace(*Str)) {
|
2009-08-22 23:43:10 +02:00
|
|
|
Length += MAI.getMaxInstLength();
|
2009-08-02 07:20:37 +02:00
|
|
|
atInsnStart = false;
|
|
|
|
}
|
2009-08-22 23:43:10 +02:00
|
|
|
if (atInsnStart && strncmp(Str, MAI.getCommentString(),
|
|
|
|
strlen(MAI.getCommentString())) == 0)
|
2009-08-02 07:20:37 +02:00
|
|
|
atInsnStart = false;
|
|
|
|
}
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2009-08-02 07:20:37 +02:00
|
|
|
return Length;
|
|
|
|
}
|