blob: 4f6c1237e9f8889ab5533a6309543436e756bb85 [file] [log] [blame]
Chris Lattner64105522008-01-01 01:03:04 +00001//===-- 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"
17using namespace llvm;
18
19// commuteInstruction - The default implementation of this method just exchanges
20// operand 1 and 2.
21MachineInstr *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();
26 bool Reg1IsKill = MI->getOperand(1).isKill();
27 bool Reg2IsKill = MI->getOperand(2).isKill();
Evan Cheng9cec00e2008-02-13 09:13:21 +000028 if (MI->getOperand(0).getReg() == Reg1) {
Evan Chenga4d16a12008-02-13 02:46:49 +000029 // Must be two address instruction!
30 assert(MI->getDesc().getOperandConstraint(0, TOI::TIED_TO) &&
31 "Expecting a two-address instruction!");
32 Reg2IsKill = false;
33 MI->getOperand(0).setReg(Reg2);
34 }
Chris Lattner64105522008-01-01 01:03:04 +000035 MI->getOperand(2).setReg(Reg1);
36 MI->getOperand(1).setReg(Reg2);
37 MI->getOperand(2).setIsKill(Reg1IsKill);
38 MI->getOperand(1).setIsKill(Reg2IsKill);
39 return MI;
40}
41
42bool TargetInstrInfoImpl::PredicateInstruction(MachineInstr *MI,
43 const std::vector<MachineOperand> &Pred) const {
44 bool MadeChange = false;
Chris Lattner749c6f62008-01-07 07:27:27 +000045 const TargetInstrDesc &TID = MI->getDesc();
46 if (!TID.isPredicable())
47 return false;
48
49 for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
50 if (TID.OpInfo[i].isPredicate()) {
51 MachineOperand &MO = MI->getOperand(i);
52 if (MO.isReg()) {
53 MO.setReg(Pred[j].getReg());
54 MadeChange = true;
55 } else if (MO.isImm()) {
56 MO.setImm(Pred[j].getImm());
57 MadeChange = true;
58 } else if (MO.isMBB()) {
59 MO.setMBB(Pred[j].getMBB());
60 MadeChange = true;
Chris Lattner64105522008-01-01 01:03:04 +000061 }
Chris Lattner749c6f62008-01-07 07:27:27 +000062 ++j;
Chris Lattner64105522008-01-01 01:03:04 +000063 }
64 }
65 return MadeChange;
66}