2003-01-13 08:26:36 +08:00
|
|
|
//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-29 07:55:33 +08:00
|
|
|
//
|
2005-01-19 14:53:34 +08:00
|
|
|
// This file implements the TargetInstrInfo class.
|
2002-10-29 07:55:33 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-01-15 06:00:31 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2009-08-02 13:20:37 +08:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2009-05-05 08:30:09 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2009-08-02 12:58:19 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2005-01-19 14:53:34 +08:00
|
|
|
using namespace llvm;
|
2002-10-29 07:55:33 +08:00
|
|
|
|
2009-08-02 13:20:37 +08: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);
|
|
|
|
return TRI->getRegClass(RegClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TargetInstrInfo
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-01-07 15:27:27 +08:00
|
|
|
TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
|
2006-12-09 02:45:48 +08:00
|
|
|
unsigned numOpcodes)
|
2008-01-07 15:27:27 +08:00
|
|
|
: Descriptors(Desc), NumOpcodes(numOpcodes) {
|
2006-12-09 02:45:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetInstrInfo::~TargetInstrInfo() {
|
|
|
|
}
|
|
|
|
|
2009-08-02 12:58:19 +08: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-09 05:59:56 +08:00
|
|
|
bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
|
2008-01-07 15:27:27 +08:00
|
|
|
const TargetInstrDesc &TID = MI->getDesc();
|
|
|
|
if (!TID.isTerminator()) return false;
|
2008-01-07 09:56:04 +08:00
|
|
|
|
|
|
|
// Conditional branch is a special case.
|
2008-01-07 15:27:27 +08:00
|
|
|
if (TID.isBranch() && !TID.isBarrier())
|
2008-01-07 09:56:04 +08:00
|
|
|
return true;
|
2008-01-07 15:27:27 +08:00
|
|
|
if (!TID.isPredicable())
|
2008-01-07 09:56:04 +08:00
|
|
|
return true;
|
|
|
|
return !isPredicated(MI);
|
2007-06-09 05:59:56 +08:00
|
|
|
}
|
2009-05-05 08:30:09 +08:00
|
|
|
|
2009-07-30 05:10:12 +08:00
|
|
|
|
2009-08-02 13:20:37 +08: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,
|
|
|
|
const TargetAsmInfo &TAI) const {
|
|
|
|
|
|
|
|
|
|
|
|
// Count the number of instructions in the asm.
|
|
|
|
bool atInsnStart = true;
|
|
|
|
unsigned Length = 0;
|
|
|
|
for (; *Str; ++Str) {
|
|
|
|
if (*Str == '\n' || *Str == TAI.getSeparatorChar())
|
|
|
|
atInsnStart = true;
|
|
|
|
if (atInsnStart && !isspace(*Str)) {
|
|
|
|
Length += TAI.getMaxInstLength();
|
|
|
|
atInsnStart = false;
|
|
|
|
}
|
|
|
|
if (atInsnStart && strncmp(Str, TAI.getCommentString(),
|
|
|
|
strlen(TAI.getCommentString())) == 0)
|
|
|
|
atInsnStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Length;
|
|
|
|
}
|