1 //===- PTXInstrInfo.cpp - PTX Instruction Information ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the PTX implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
15 #include "PTXInstrInfo.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "PTXGenInstrInfo.inc"
22 PTXInstrInfo::PTXInstrInfo(PTXTargetMachine
&_TM
)
23 : TargetInstrInfoImpl(PTXInsts
, array_lengthof(PTXInsts
)),
24 RI(_TM
, *this), TM(_TM
) {}
26 static const struct map_entry
{
27 const TargetRegisterClass
*cls
;
30 { &PTX::RRegs32RegClass
, PTX::MOVrr
},
31 { &PTX::PredsRegClass
, PTX::MOVpp
}
34 void PTXInstrInfo::copyPhysReg(MachineBasicBlock
&MBB
,
35 MachineBasicBlock::iterator I
, DebugLoc DL
,
36 unsigned DstReg
, unsigned SrcReg
,
38 for (int i
= 0, e
= sizeof(map
)/sizeof(map
[0]); i
!= e
; ++ i
)
39 if (PTX::RRegs32RegClass
.contains(DstReg
, SrcReg
)) {
41 get(PTX::MOVrr
), DstReg
).addReg(SrcReg
, getKillRegState(KillSrc
));
45 llvm_unreachable("Impossible reg-to-reg copy");
48 bool PTXInstrInfo::copyRegToReg(MachineBasicBlock
&MBB
,
49 MachineBasicBlock::iterator I
,
50 unsigned DstReg
, unsigned SrcReg
,
51 const TargetRegisterClass
*DstRC
,
52 const TargetRegisterClass
*SrcRC
,
57 for (int i
= 0, e
= sizeof(map
)/sizeof(map
[0]); i
!= e
; ++ i
)
58 if (DstRC
== map
[i
].cls
) {
59 MachineInstr
*MI
= BuildMI(MBB
, I
, DL
, get(map
[i
].opcode
),
60 DstReg
).addReg(SrcReg
);
61 if (MI
->findFirstPredOperandIdx() == -1) {
62 MI
->addOperand(MachineOperand::CreateReg(0, false));
63 MI
->addOperand(MachineOperand::CreateImm(/*IsInv=*/0));
71 bool PTXInstrInfo::isMoveInstr(const MachineInstr
& MI
,
72 unsigned &SrcReg
, unsigned &DstReg
,
73 unsigned &SrcSubIdx
, unsigned &DstSubIdx
) const {
74 switch (MI
.getOpcode()) {
79 assert(MI
.getNumOperands() >= 2 &&
80 MI
.getOperand(0).isReg() && MI
.getOperand(1).isReg() &&
81 "Invalid register-register move instruction");
82 SrcSubIdx
= DstSubIdx
= 0; // No sub-registers
83 DstReg
= MI
.getOperand(0).getReg();
84 SrcReg
= MI
.getOperand(1).getReg();