1//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the TargetInstrInfo class. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Target/TargetInstrInfo.h" 15#include "llvm/Target/TargetRegisterInfo.h" 16#include "llvm/MC/MCAsmInfo.h" 17#include "llvm/MC/MCInstrItineraries.h" 18#include "llvm/Support/ErrorHandling.h" 19#include <cctype> 20using namespace llvm; 21 22//===----------------------------------------------------------------------===// 23// TargetInstrInfo 24// 25// Methods that depend on CodeGen are implemented in 26// TargetInstrInfoImpl.cpp. Invoking them without linking libCodeGen raises a 27// link error. 28// ===----------------------------------------------------------------------===// 29 30TargetInstrInfo::~TargetInstrInfo() { 31} 32 33const TargetRegisterClass* 34TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum, 35 const TargetRegisterInfo *TRI, 36 const MachineFunction &MF) const { 37 if (OpNum >= MCID.getNumOperands()) 38 return 0; 39 40 short RegClass = MCID.OpInfo[OpNum].RegClass; 41 if (MCID.OpInfo[OpNum].isLookupPtrRegClass()) 42 return TRI->getPointerRegClass(MF, RegClass); 43 44 // Instructions like INSERT_SUBREG do not have fixed register classes. 45 if (RegClass < 0) 46 return 0; 47 48 // Otherwise just look it up normally. 49 return TRI->getRegClass(RegClass); 50} 51 52/// insertNoop - Insert a noop into the instruction stream at the specified 53/// point. 54void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, 55 MachineBasicBlock::iterator MI) const { 56 llvm_unreachable("Target didn't implement insertNoop!"); 57} 58 59/// Measure the specified inline asm to determine an approximation of its 60/// length. 61/// Comments (which run till the next SeparatorString or newline) do not 62/// count as an instruction. 63/// Any other non-whitespace text is considered an instruction, with 64/// multiple instructions separated by SeparatorString or newlines. 65/// Variable-length instructions are not handled here; this function 66/// may be overloaded in the target code to do that. 67unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, 68 const MCAsmInfo &MAI) const { 69 70 71 // Count the number of instructions in the asm. 72 bool atInsnStart = true; 73 unsigned Length = 0; 74 for (; *Str; ++Str) { 75 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), 76 strlen(MAI.getSeparatorString())) == 0) 77 atInsnStart = true; 78 if (atInsnStart && !std::isspace(*Str)) { 79 Length += MAI.getMaxInstLength(); 80 atInsnStart = false; 81 } 82 if (atInsnStart && strncmp(Str, MAI.getCommentString(), 83 strlen(MAI.getCommentString())) == 0) 84 atInsnStart = false; 85 } 86 87 return Length; 88} 89