Remove the ugly SPARCV9 TargetInstrDescriptors hack.
[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
31 TargetInstrInfo::findTiedToSrcOperand(MachineOpCode Opc, unsigned OpNum) const {
32   for (unsigned i = 0, e = getNumOperands(Opc); i != e; ++i) {
33     if (i == OpNum)
34       continue;
35     int ti = getOperandConstraint(Opc, i, TIED_TO);
36     if (ti == (int)OpNum)
37       return i;
38   }
39   return -1;
40 }
41
42
43 // commuteInstruction - The default implementation of this method just exchanges
44 // operand 1 and 2.
45 MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const {
46   assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() &&
47          "This only knows how to commute register operands so far");
48   unsigned Reg1 = MI->getOperand(1).getReg();
49   unsigned Reg2 = MI->getOperand(2).getReg();
50   bool Reg1IsKill = MI->getOperand(1).isKill();
51   bool Reg2IsKill = MI->getOperand(2).isKill();
52   MI->getOperand(2).setReg(Reg1);
53   MI->getOperand(1).setReg(Reg2);
54   if (Reg1IsKill)
55     MI->getOperand(2).setIsKill();
56   else
57     MI->getOperand(2).unsetIsKill();
58   if (Reg2IsKill)
59     MI->getOperand(1).setIsKill();
60   else
61     MI->getOperand(1).unsetIsKill();
62   return MI;
63 }