Use MI's TargetInstrDescriptor.
[oota-llvm.git] / lib / Target / TargetInstrInfo.cpp
1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/CodeGen/MachineInstr.h"
16 #include "llvm/Constant.h"
17 #include "llvm/DerivedTypes.h"
18 using namespace llvm;
19
20 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
21                                  unsigned numOpcodes)
22   : desc(Desc), NumOpcodes(numOpcodes) {
23 }
24
25 TargetInstrInfo::~TargetInstrInfo() {
26 }
27
28 /// findTiedToSrcOperand - Returns the operand that is tied to the specified
29 /// dest operand. Returns -1 if there isn't one.
30 int TargetInstrInfo::findTiedToSrcOperand(const TargetInstrDescriptor *TID,
31                                           unsigned OpNum) const {
32   for (unsigned i = 0, e = TID->numOperands; i != e; ++i) {
33     if (i == OpNum)
34       continue;
35     if (TID->getOperandConstraint(i, TOI::TIED_TO) == (int)OpNum)
36       return i;
37   }
38   return -1;
39 }
40
41
42 // commuteInstruction - The default implementation of this method just exchanges
43 // operand 1 and 2.
44 MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const {
45   assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() &&
46          "This only knows how to commute register operands so far");
47   unsigned Reg1 = MI->getOperand(1).getReg();
48   unsigned Reg2 = MI->getOperand(2).getReg();
49   bool Reg1IsKill = MI->getOperand(1).isKill();
50   bool Reg2IsKill = MI->getOperand(2).isKill();
51   MI->getOperand(2).setReg(Reg1);
52   MI->getOperand(1).setReg(Reg2);
53   if (Reg1IsKill)
54     MI->getOperand(2).setIsKill();
55   else
56     MI->getOperand(2).unsetIsKill();
57   if (Reg2IsKill)
58     MI->getOperand(1).setIsKill();
59   else
60     MI->getOperand(1).unsetIsKill();
61   return MI;
62 }