blob: 0e79baac7c919891b44a5305ad61fe2636f5d940 [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//
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.
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 Lattnera187ed92002-11-17 22:53:03 +000015#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000016#include "llvm/Constant.h"
17#include "llvm/DerivedTypes.h"
Chris Lattner167b10c2005-01-19 06:53:34 +000018using namespace llvm;
Chris Lattner93fa7052002-10-28 23:55:33 +000019
Chris Lattner08084142003-01-13 00:26:36 +000020TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
Misha Brukman7847fca2005-04-22 17:54:37 +000021 unsigned numOpcodes)
Chris Lattnerdce363d2004-02-29 06:31:44 +000022 : desc(Desc), NumOpcodes(numOpcodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000023}
24
Chris Lattner08084142003-01-13 00:26:36 +000025TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000026}
27
Evan Chenge6ae14e2006-11-01 23:18:32 +000028/// findTiedToSrcOperand - Returns the operand that is tied to the specified
29/// dest operand. Returns -1 if there isn't one.
Evan Cheng3cc38162006-12-08 07:57:56 +000030int TargetInstrInfo::findTiedToSrcOperand(const TargetInstrDescriptor *TID,
31 unsigned OpNum) const {
32 for (unsigned i = 0, e = TID->numOperands; i != e; ++i) {
Evan Cheng981b5bd2006-11-01 23:00:31 +000033 if (i == OpNum)
34 continue;
Evan Cheng3cc38162006-12-08 07:57:56 +000035 if (TID->getOperandConstraint(i, TOI::TIED_TO) == (int)OpNum)
Evan Cheng981b5bd2006-11-01 23:00:31 +000036 return i;
37 }
38 return -1;
39}
40
Chris Lattner93fa7052002-10-28 23:55:33 +000041
Chris Lattner167b10c2005-01-19 06:53:34 +000042// commuteInstruction - The default implementation of this method just exchanges
43// operand 1 and 2.
44MachineInstr *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();
Evan Cheng31ff1ff2006-05-12 01:46:26 +000048 unsigned Reg2 = MI->getOperand(2).getReg();
Evan Chengff608a72006-11-15 20:56:03 +000049 bool Reg1IsKill = MI->getOperand(1).isKill();
50 bool Reg2IsKill = MI->getOperand(2).isKill();
Chris Lattnere53f4a02006-05-04 17:52:23 +000051 MI->getOperand(2).setReg(Reg1);
52 MI->getOperand(1).setReg(Reg2);
Evan Chengff608a72006-11-15 20:56:03 +000053 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();
Chris Lattner167b10c2005-01-19 06:53:34 +000061 return MI;
62}