Start TargetRegisterClass indices at 0 instead of 1, so that
[oota-llvm.git] / lib / Target / TargetInstrInfo.cpp
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/MC/MCAsmInfo.h"
16 #include "llvm/Target/TargetRegisterInfo.h"
17 #include "llvm/Support/ErrorHandling.h"
18 using namespace llvm;
19
20 //===----------------------------------------------------------------------===//
21 //  TargetOperandInfo
22 //===----------------------------------------------------------------------===//
23
24 /// getRegClass - Get the register class for the operand, handling resolution
25 /// of "symbolic" pointer register classes etc.  If this is not a register
26 /// operand, this returns null.
27 const TargetRegisterClass *
28 TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
29   if (isLookupPtrRegClass())
30     return TRI->getPointerRegClass(RegClass);
31   // Instructions like INSERT_SUBREG do not have fixed register classes.
32   if (RegClass < 0)
33     return 0;
34   // Otherwise just look it up normally.
35   return TRI->getRegClass(RegClass);
36 }
37
38 //===----------------------------------------------------------------------===//
39 //  TargetInstrInfo
40 //===----------------------------------------------------------------------===//
41
42 TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
43                                  unsigned numOpcodes)
44   : Descriptors(Desc), NumOpcodes(numOpcodes) {
45 }
46
47 TargetInstrInfo::~TargetInstrInfo() {
48 }
49
50 /// insertNoop - Insert a noop into the instruction stream at the specified
51 /// point.
52 void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, 
53                                  MachineBasicBlock::iterator MI) const {
54   llvm_unreachable("Target didn't implement insertNoop!");
55 }
56
57
58 bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
59   const TargetInstrDesc &TID = MI->getDesc();
60   if (!TID.isTerminator()) return false;
61   
62   // Conditional branch is a special case.
63   if (TID.isBranch() && !TID.isBarrier())
64     return true;
65   if (!TID.isPredicable())
66     return true;
67   return !isPredicated(MI);
68 }
69
70
71 /// Measure the specified inline asm to determine an approximation of its
72 /// length.
73 /// Comments (which run till the next SeparatorChar or newline) do not
74 /// count as an instruction.
75 /// Any other non-whitespace text is considered an instruction, with
76 /// multiple instructions separated by SeparatorChar or newlines.
77 /// Variable-length instructions are not handled here; this function
78 /// may be overloaded in the target code to do that.
79 unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
80                                              const MCAsmInfo &MAI) const {
81   
82   
83   // Count the number of instructions in the asm.
84   bool atInsnStart = true;
85   unsigned Length = 0;
86   for (; *Str; ++Str) {
87     if (*Str == '\n' || *Str == MAI.getSeparatorChar())
88       atInsnStart = true;
89     if (atInsnStart && !isspace(*Str)) {
90       Length += MAI.getMaxInstLength();
91       atInsnStart = false;
92     }
93     if (atInsnStart && strncmp(Str, MAI.getCommentString(),
94                                strlen(MAI.getCommentString())) == 0)
95       atInsnStart = false;
96   }
97   
98   return Length;
99 }