blob: f2e5e4c110268367666b66d4612210759ff94945 [file] [log] [blame]
Eric Christopher50880d02010-09-18 18:52:28 +00001//===- 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
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000014#include "PTX.h"
Eric Christopher50880d02010-09-18 18:52:28 +000015#include "PTXInstrInfo.h"
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
Eric Christopher50880d02010-09-18 18:52:28 +000017
18using namespace llvm;
19
20#include "PTXGenInstrInfo.inc"
21
22PTXInstrInfo::PTXInstrInfo(PTXTargetMachine &_TM)
23 : TargetInstrInfoImpl(PTXInsts, array_lengthof(PTXInsts)),
24 RI(_TM, *this), TM(_TM) {}
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000025
26static const struct map_entry {
27 const TargetRegisterClass *cls;
28 const int opcode;
29} map[] = {
30 { &PTX::RRegs32RegClass, PTX::MOVrr },
Che-Liang Chiouf7172022011-02-28 06:34:09 +000031 { &PTX::RRegf32RegClass, PTX::MOVrr },
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000032 { &PTX::PredsRegClass, PTX::MOVpp }
33};
34
35void PTXInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
36 MachineBasicBlock::iterator I, DebugLoc DL,
37 unsigned DstReg, unsigned SrcReg,
38 bool KillSrc) const {
Che-Liang Chiouf7172022011-02-28 06:34:09 +000039 for (int i = 0, e = sizeof(map)/sizeof(map[0]); i != e; ++ i) {
40 if (map[i].cls->contains(DstReg, SrcReg)) {
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000041 BuildMI(MBB, I, DL,
Che-Liang Chiouf7172022011-02-28 06:34:09 +000042 get(map[i].opcode), DstReg).addReg(SrcReg, getKillRegState(KillSrc));
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000043 return;
44 }
Che-Liang Chiouf7172022011-02-28 06:34:09 +000045 }
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000046
47 llvm_unreachable("Impossible reg-to-reg copy");
48}
49
50bool PTXInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
51 MachineBasicBlock::iterator I,
52 unsigned DstReg, unsigned SrcReg,
53 const TargetRegisterClass *DstRC,
54 const TargetRegisterClass *SrcRC,
55 DebugLoc DL) const {
56 if (DstRC != SrcRC)
57 return false;
58
59 for (int i = 0, e = sizeof(map)/sizeof(map[0]); i != e; ++ i)
60 if (DstRC == map[i].cls) {
61 MachineInstr *MI = BuildMI(MBB, I, DL, get(map[i].opcode),
62 DstReg).addReg(SrcReg);
63 if (MI->findFirstPredOperandIdx() == -1) {
64 MI->addOperand(MachineOperand::CreateReg(0, false));
65 MI->addOperand(MachineOperand::CreateImm(/*IsInv=*/0));
66 }
67 return true;
68 }
69
70 return false;
71}
72
73bool PTXInstrInfo::isMoveInstr(const MachineInstr& MI,
74 unsigned &SrcReg, unsigned &DstReg,
75 unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
76 switch (MI.getOpcode()) {
77 default:
78 return false;
79 case PTX::MOVpp:
80 case PTX::MOVrr:
81 assert(MI.getNumOperands() >= 2 &&
82 MI.getOperand(0).isReg() && MI.getOperand(1).isReg() &&
83 "Invalid register-register move instruction");
84 SrcSubIdx = DstSubIdx = 0; // No sub-registers
85 DstReg = MI.getOperand(0).getReg();
86 SrcReg = MI.getOperand(1).getReg();
87 return true;
88 }
89}