1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetInstrInfo.h"
15 #include "llvm/CodeGen/MachineInstr.h"
16 #include "llvm/Constant.h"
17 #include "llvm/DerivedTypes.h"
20 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
22 : desc(Desc), NumOpcodes(numOpcodes) {
25 TargetInstrInfo::~TargetInstrInfo() {
28 /// findTiedToSrcOperand - Returns the operand that is tied to the specified
29 /// dest operand. Returns -1 if there isn't one.
31 TargetInstrInfo::findTiedToSrcOperand(MachineOpCode Opc, unsigned OpNum) const {
32 for (unsigned i = 0, e = getNumOperands(Opc); i != e; ++i) {
35 int ti = getOperandConstraint(Opc, i, TIED_TO);
43 // commuteInstruction - The default implementation of this method just exchanges
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);
55 MI->getOperand(2).setIsKill();
57 MI->getOperand(2).unsetIsKill();
59 MI->getOperand(1).setIsKill();
61 MI->getOperand(1).unsetIsKill();