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"
|
2009-05-05 00:30:09 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2010-10-06 06:27:31 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2011-06-29 01:14:12 +00:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2009-08-02 04:58:19 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-12-19 20:43:38 +00:00
|
|
|
#include <cctype>
|
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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TargetInstrInfo
|
2012-06-08 17:23:27 +00:00
|
|
|
//
|
|
|
|
// Methods that depend on CodeGen are implemented in
|
|
|
|
// TargetInstrInfoImpl.cpp. Invoking them without linking libCodeGen raises a
|
|
|
|
// link error.
|
|
|
|
// ===----------------------------------------------------------------------===//
|
2009-08-02 05:20:37 +00:00
|
|
|
|
2006-12-08 18:45:48 +00:00
|
|
|
TargetInstrInfo::~TargetInstrInfo() {
|
|
|
|
}
|
|
|
|
|
2011-06-27 21:26:13 +00:00
|
|
|
const TargetRegisterClass*
|
2011-06-28 19:10:37 +00:00
|
|
|
TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum,
|
2012-05-07 22:10:26 +00:00
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
const MachineFunction &MF) const {
|
2011-06-28 19:10:37 +00:00
|
|
|
if (OpNum >= MCID.getNumOperands())
|
2011-06-27 21:26:13 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
short RegClass = MCID.OpInfo[OpNum].RegClass;
|
|
|
|
if (MCID.OpInfo[OpNum].isLookupPtrRegClass())
|
2012-05-07 22:10:26 +00:00
|
|
|
return TRI->getPointerRegClass(MF, RegClass);
|
2011-06-27 21:26:13 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2009-08-02 04:58:19 +00:00
|
|
|
/// insertNoop - Insert a noop into the instruction stream at the specified
|
|
|
|
/// point.
|
2010-12-24 04:28:06 +00:00
|
|
|
void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
|
2009-08-02 04:58:19 +00:00
|
|
|
MachineBasicBlock::iterator MI) const {
|
|
|
|
llvm_unreachable("Target didn't implement insertNoop!");
|
|
|
|
}
|
|
|
|
|
2009-08-02 05:20:37 +00:00
|
|
|
/// Measure the specified inline asm to determine an approximation of its
|
|
|
|
/// length.
|
2011-03-24 18:46:34 +00:00
|
|
|
/// Comments (which run till the next SeparatorString or newline) do not
|
2009-08-02 05:20:37 +00:00
|
|
|
/// count as an instruction.
|
|
|
|
/// Any other non-whitespace text is considered an instruction, with
|
2011-03-24 18:46:34 +00:00
|
|
|
/// multiple instructions separated by SeparatorString or newlines.
|
2009-08-02 05:20:37 +00: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 21:43:10 +00:00
|
|
|
const MCAsmInfo &MAI) const {
|
2010-12-24 04:28:06 +00:00
|
|
|
|
|
|
|
|
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) {
|
2011-03-24 18:46:34 +00:00
|
|
|
if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
|
|
|
|
strlen(MAI.getSeparatorString())) == 0)
|
2009-08-02 05:20:37 +00:00
|
|
|
atInsnStart = true;
|
2010-12-19 20:42:43 +00:00
|
|
|
if (atInsnStart && !std::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;
|
|
|
|
}
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2009-08-02 05:20:37 +00:00
|
|
|
return Length;
|
|
|
|
}
|