PTX: Fix a couple of lint violations
[oota-llvm.git] / lib / Target / PTX / PTXInstrInfo.cpp
1 //===- PTXInstrInfo.cpp - PTX 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 contains the PTX implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PTX.h"
15 #include "PTXInstrInfo.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17
18 using namespace llvm;
19
20 #include "PTXGenInstrInfo.inc"
21
22 PTXInstrInfo::PTXInstrInfo(PTXTargetMachine &_TM)
23   : TargetInstrInfoImpl(PTXInsts, array_lengthof(PTXInsts)),
24     RI(_TM, *this), TM(_TM) {}
25
26 static const struct map_entry {
27   const TargetRegisterClass *cls;
28   const int opcode;
29 } map[] = {
30   { &PTX::RRegu16RegClass, PTX::MOVU16rr },
31   { &PTX::RRegu32RegClass, PTX::MOVU32rr },
32   { &PTX::RRegu64RegClass, PTX::MOVU64rr },
33   { &PTX::RRegf32RegClass, PTX::MOVF32rr },
34   { &PTX::RRegf64RegClass, PTX::MOVF64rr },
35   { &PTX::PredsRegClass,   PTX::MOVPREDrr }
36 };
37
38 void PTXInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
39                                MachineBasicBlock::iterator I, DebugLoc DL,
40                                unsigned DstReg, unsigned SrcReg,
41                                bool KillSrc) const {
42   for (int i = 0, e = sizeof(map)/sizeof(map[0]); i != e; ++ i) {
43     if (map[i].cls->contains(DstReg, SrcReg)) {
44       BuildMI(MBB, I, DL,
45               get(map[i].opcode), DstReg).addReg(SrcReg,
46                                                  Getkillregstate(KillSrc));
47       return;
48     }
49   }
50
51   llvm_unreachable("Impossible reg-to-reg copy");
52 }
53
54 bool PTXInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
55                                 MachineBasicBlock::iterator I,
56                                 unsigned DstReg, unsigned SrcReg,
57                                 const TargetRegisterClass *DstRC,
58                                 const TargetRegisterClass *SrcRC,
59                                 DebugLoc DL) const {
60   if (DstRC != SrcRC)
61     return false;
62
63   for (int i = 0, e = sizeof(map)/sizeof(map[0]); i != e; ++ i)
64     if (DstRC == map[i].cls) {
65       MachineInstr *MI = BuildMI(MBB, I, DL, get(map[i].opcode),
66                                  DstReg).addReg(SrcReg);
67       if (MI->findFirstPredOperandIdx() == -1) {
68         MI->addOperand(MachineOperand::CreateReg(0, false));
69         MI->addOperand(MachineOperand::CreateImm(/*IsInv=*/0));
70       }
71       return true;
72     }
73
74   return false;
75 }
76
77 bool PTXInstrInfo::isMoveInstr(const MachineInstr& MI,
78                                unsigned &SrcReg, unsigned &DstReg,
79                                unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
80   switch (MI.getOpcode()) {
81     default:
82       return false;
83     case PTX::MOVU16rr:
84     case PTX::MOVU32rr:
85     case PTX::MOVU64rr:
86     case PTX::MOVF32rr:
87     case PTX::MOVF64rr:
88     case PTX::MOVPREDrr:
89       assert(MI.getNumOperands() >= 2 &&
90              MI.getOperand(0).isReg() && MI.getOperand(1).isReg() &&
91              "Invalid register-register move instruction");
92       SrcSubIdx = DstSubIdx = 0; // No sub-registers
93       DstReg = MI.getOperand(0).getReg();
94       SrcReg = MI.getOperand(1).getReg();
95       return true;
96   }
97 }