blob: afbadbfc63eb81feb59d9470bb61f32d456e0c0d [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng8058d702009-05-05 00:30:09 +000015#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016#include "llvm/Constant.h"
17#include "llvm/DerivedTypes.h"
18using namespace llvm;
19
Chris Lattner5b930372008-01-07 07:27:27 +000020TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021 unsigned numOpcodes)
Chris Lattner5b930372008-01-07 07:27:27 +000022 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023}
24
25TargetInstrInfo::~TargetInstrInfo() {
26}
27
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner5b930372008-01-07 07:27:27 +000029 const TargetInstrDesc &TID = MI->getDesc();
30 if (!TID.isTerminator()) return false;
Chris Lattner62327602008-01-07 01:56:04 +000031
32 // Conditional branch is a special case.
Chris Lattner5b930372008-01-07 07:27:27 +000033 if (TID.isBranch() && !TID.isBarrier())
Chris Lattner62327602008-01-07 01:56:04 +000034 return true;
Chris Lattner5b930372008-01-07 07:27:27 +000035 if (!TID.isPredicable())
Chris Lattner62327602008-01-07 01:56:04 +000036 return true;
37 return !isPredicated(MI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038}
Evan Cheng8058d702009-05-05 00:30:09 +000039
Chris Lattner6a66b292009-07-29 21:10:12 +000040/// 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.
43const TargetRegisterClass *
44TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
45 if (isLookupPtrRegClass())
46 return TRI->getPointerRegClass(RegClass);
47 return TRI->getRegClass(RegClass);
48}
49
Evan Cheng8058d702009-05-05 00:30:09 +000050/// getInstrOperandRegClass - Return register class of the operand of an
51/// instruction of the specified TargetInstrDesc.
52const TargetRegisterClass*
53llvm::getInstrOperandRegClass(const TargetRegisterInfo *TRI,
Chris Lattner6a66b292009-07-29 21:10:12 +000054 const TargetInstrDesc &II, unsigned Op) {
55 // FIXME: Should be an assert!
Evan Cheng8058d702009-05-05 00:30:09 +000056 if (Op >= II.getNumOperands())
57 return NULL;
Chris Lattner6a66b292009-07-29 21:10:12 +000058 return II.OpInfo[Op].getRegClass(TRI);
Evan Cheng8058d702009-05-05 00:30:09 +000059}