Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 1 | //===-- TargetInstrInfoImpl.cpp - Target Instruction Information ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the TargetInstrInfoImpl class, it just provides default |
| 11 | // implementations of various methods. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Target/TargetInstrInfo.h" |
| 16 | #include "llvm/CodeGen/MachineInstr.h" |
| 17 | using namespace llvm; |
| 18 | |
| 19 | // commuteInstruction - The default implementation of this method just exchanges |
| 20 | // operand 1 and 2. |
| 21 | MachineInstr *TargetInstrInfoImpl::commuteInstruction(MachineInstr *MI) const { |
| 22 | assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() && |
| 23 | "This only knows how to commute register operands so far"); |
| 24 | unsigned Reg1 = MI->getOperand(1).getReg(); |
| 25 | unsigned Reg2 = MI->getOperand(2).getReg(); |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame^] | 26 | MachineOperand &MO = MI->getOperand(0); |
| 27 | bool UpdateReg0 = MO.isReg() && MO.getReg() == Reg1; |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 28 | bool Reg1IsKill = MI->getOperand(1).isKill(); |
| 29 | bool Reg2IsKill = MI->getOperand(2).isKill(); |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame^] | 30 | if (UpdateReg0) { |
| 31 | // Must be two address instruction! |
| 32 | assert(MI->getDesc().getOperandConstraint(0, TOI::TIED_TO) && |
| 33 | "Expecting a two-address instruction!"); |
| 34 | Reg2IsKill = false; |
| 35 | MI->getOperand(0).setReg(Reg2); |
| 36 | } |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 37 | MI->getOperand(2).setReg(Reg1); |
| 38 | MI->getOperand(1).setReg(Reg2); |
| 39 | MI->getOperand(2).setIsKill(Reg1IsKill); |
| 40 | MI->getOperand(1).setIsKill(Reg2IsKill); |
| 41 | return MI; |
| 42 | } |
| 43 | |
| 44 | bool TargetInstrInfoImpl::PredicateInstruction(MachineInstr *MI, |
| 45 | const std::vector<MachineOperand> &Pred) const { |
| 46 | bool MadeChange = false; |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 47 | const TargetInstrDesc &TID = MI->getDesc(); |
| 48 | if (!TID.isPredicable()) |
| 49 | return false; |
| 50 | |
| 51 | for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 52 | if (TID.OpInfo[i].isPredicate()) { |
| 53 | MachineOperand &MO = MI->getOperand(i); |
| 54 | if (MO.isReg()) { |
| 55 | MO.setReg(Pred[j].getReg()); |
| 56 | MadeChange = true; |
| 57 | } else if (MO.isImm()) { |
| 58 | MO.setImm(Pred[j].getImm()); |
| 59 | MadeChange = true; |
| 60 | } else if (MO.isMBB()) { |
| 61 | MO.setMBB(Pred[j].getMBB()); |
| 62 | MadeChange = true; |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 63 | } |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 64 | ++j; |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | return MadeChange; |
| 68 | } |