afbadbfc63eb81feb59d9470bb61f32d456e0c0d
[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/Target/TargetRegisterInfo.h"
16 #include "llvm/Constant.h"
17 #include "llvm/DerivedTypes.h"
18 using namespace llvm;
19
20 TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
21                                  unsigned numOpcodes)
22   : Descriptors(Desc), NumOpcodes(numOpcodes) {
23 }
24
25 TargetInstrInfo::~TargetInstrInfo() {
26 }
27
28 bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
29   const TargetInstrDesc &TID = MI->getDesc();
30   if (!TID.isTerminator()) return false;
31   
32   // Conditional branch is a special case.
33   if (TID.isBranch() && !TID.isBarrier())
34     return true;
35   if (!TID.isPredicable())
36     return true;
37   return !isPredicated(MI);
38 }
39
40 /// getRegClass - Get the register class for the operand, handling resolution
41 /// of "symbolic" pointer register classes etc.  If this is not a register
42 /// operand, this returns null.
43 const TargetRegisterClass *
44 TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
45   if (isLookupPtrRegClass())
46     return TRI->getPointerRegClass(RegClass);
47   return TRI->getRegClass(RegClass);
48 }
49
50 /// getInstrOperandRegClass - Return register class of the operand of an
51 /// instruction of the specified TargetInstrDesc.
52 const TargetRegisterClass*
53 llvm::getInstrOperandRegClass(const TargetRegisterInfo *TRI,
54                               const TargetInstrDesc &II, unsigned Op) {
55   // FIXME: Should be an assert!
56   if (Op >= II.getNumOperands())
57     return NULL;
58   return II.OpInfo[Op].getRegClass(TRI);
59 }