1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
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"
22 //===----------------------------------------------------------------------===//
25 // Methods that depend on CodeGen are implemented in
26 // TargetInstrInfoImpl.cpp. Invoking them without linking libCodeGen raises a
28 // ===----------------------------------------------------------------------===//
30 TargetInstrInfo::~TargetInstrInfo() {
33 const TargetRegisterClass*
34 TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum,
35 const TargetRegisterInfo *TRI,
36 const MachineFunction &MF) const {
37 if (OpNum >= MCID.getNumOperands())
40 short RegClass = MCID.OpInfo[OpNum].RegClass;
41 if (MCID.OpInfo[OpNum].isLookupPtrRegClass())
42 return TRI->getPointerRegClass(MF, RegClass);
44 // Instructions like INSERT_SUBREG do not have fixed register classes.
48 // Otherwise just look it up normally.
49 return TRI->getRegClass(RegClass);
52 /// insertNoop - Insert a noop into the instruction stream at the specified
54 void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB,
55 MachineBasicBlock::iterator MI) const {
56 llvm_unreachable("Target didn't implement insertNoop!");
59 /// Measure the specified inline asm to determine an approximation of its
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.
67 unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
68 const MCAsmInfo &MAI) const {
71 // Count the number of instructions in the asm.
72 bool atInsnStart = true;
75 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
76 strlen(MAI.getSeparatorString())) == 0)
78 if (atInsnStart && !std::isspace(*Str)) {
79 Length += MAI.getMaxInstLength();
82 if (atInsnStart && strncmp(Str, MAI.getCommentString(),
83 strlen(MAI.getCommentString())) == 0)