blob: 10a5cdb6247a9fb44aa02a660203960c72d6f2e1 [file] [log] [blame]
Chris Lattner08084142003-01-13 00:26:36 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner93fa7052002-10-28 23:55:33 +00009//
Chris Lattner167b10c2005-01-19 06:53:34 +000010// This file implements the TargetInstrInfo class.
Chris Lattner93fa7052002-10-28 23:55:33 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner3501fea2003-01-14 22:00:31 +000014#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000015#include "llvm/Constant.h"
16#include "llvm/DerivedTypes.h"
Chris Lattner167b10c2005-01-19 06:53:34 +000017using namespace llvm;
Chris Lattner93fa7052002-10-28 23:55:33 +000018
Evan Chengcc22a7a2006-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 Lattner749c6f62008-01-07 07:27:27 +000021int TargetInstrDesc::findTiedToSrcOperand(unsigned OpNum) const {
Chris Lattner349c4952008-01-07 03:13:06 +000022 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Chengcc22a7a2006-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 Lattner749c6f62008-01-07 07:27:27 +000032TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
Misha Brukman7847fca2005-04-22 17:54:37 +000033 unsigned numOpcodes)
Chris Lattner749c6f62008-01-07 07:27:27 +000034 : Descriptors(Desc), NumOpcodes(numOpcodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000035}
36
Chris Lattner08084142003-01-13 00:26:36 +000037TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000038}
39
Evan Chengbfd2ec42007-06-08 21:59:56 +000040bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
Chris Lattner749c6f62008-01-07 07:27:27 +000041 const TargetInstrDesc &TID = MI->getDesc();
42 if (!TID.isTerminator()) return false;
Chris Lattner69244302008-01-07 01:56:04 +000043
44 // Conditional branch is a special case.
Chris Lattner749c6f62008-01-07 07:27:27 +000045 if (TID.isBranch() && !TID.isBarrier())
Chris Lattner69244302008-01-07 01:56:04 +000046 return true;
Chris Lattner749c6f62008-01-07 07:27:27 +000047 if (!TID.isPredicable())
Chris Lattner69244302008-01-07 01:56:04 +000048 return true;
49 return !isPredicated(MI);
Evan Chengbfd2ec42007-06-08 21:59:56 +000050}