blob: 10a5cdb6247a9fb44aa02a660203960c72d6f2e1 [file] [log] [blame]
Chris Lattner0d5644b2003-01-13 00:26:36 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner910b82f2002-10-28 23:55:33 +00009//
Chris Lattnerf6932b72005-01-19 06:53:34 +000010// This file implements the TargetInstrInfo class.
Chris Lattner910b82f2002-10-28 23:55:33 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerb4d58d72003-01-14 22:00:31 +000014#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner910b82f2002-10-28 23:55:33 +000015#include "llvm/Constant.h"
16#include "llvm/DerivedTypes.h"
Chris Lattnerf6932b72005-01-19 06:53:34 +000017using namespace llvm;
Chris Lattner910b82f2002-10-28 23:55:33 +000018
Evan Cheng78cb08d2006-12-08 18:45:48 +000019/// findTiedToSrcOperand - Returns the operand that is tied to the specified
20/// dest operand. Returns -1 if there isn't one.
Chris Lattner03ad8852008-01-07 07:27:27 +000021int TargetInstrDesc::findTiedToSrcOperand(unsigned OpNum) const {
Chris Lattnerb0d06b42008-01-07 03:13:06 +000022 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Cheng78cb08d2006-12-08 18:45:48 +000023 if (i == OpNum)
24 continue;
25 if (getOperandConstraint(i, TOI::TIED_TO) == (int)OpNum)
26 return i;
27 }
28 return -1;
29}
30
31
Chris Lattner03ad8852008-01-07 07:27:27 +000032TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Misha Brukmane73e76d2005-04-22 17:54:37 +000033 unsigned numOpcodes)
Chris Lattner03ad8852008-01-07 07:27:27 +000034 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Chris Lattner910b82f2002-10-28 23:55:33 +000035}
36
Chris Lattner0d5644b2003-01-13 00:26:36 +000037TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner910b82f2002-10-28 23:55:33 +000038}
39
Evan Cheng5514bbe2007-06-08 21:59:56 +000040bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner03ad8852008-01-07 07:27:27 +000041 const TargetInstrDesc &TID = MI->getDesc();
42 if (!TID.isTerminator()) return false;
Chris Lattnera98c6792008-01-07 01:56:04 +000043
44 // Conditional branch is a special case.
Chris Lattner03ad8852008-01-07 07:27:27 +000045 if (TID.isBranch() && !TID.isBarrier())
Chris Lattnera98c6792008-01-07 01:56:04 +000046 return true;
Chris Lattner03ad8852008-01-07 07:27:27 +000047 if (!TID.isPredicable())
Chris Lattnera98c6792008-01-07 01:56:04 +000048 return true;
49 return !isPredicated(MI);
Evan Cheng5514bbe2007-06-08 21:59:56 +000050}