3c1f0635a0c411447ca91774c4b97c58926b07f8
[oota-llvm.git] / lib / Target / AMDGPU / AMDGPUInstrInfo.cpp
1 //===-- AMDGPUInstrInfo.cpp - Base class for AMD GPU InstrInfo ------------===//
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 implementation of the TargetInstrInfo class that is
11 // common to all AMD GPUs.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "AMDGPUInstrInfo.h"
16 #include "AMDGPURegisterInfo.h"
17 #include "AMDGPUTargetMachine.h"
18 #include "AMDIL.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
20
21 using namespace llvm;
22
23 AMDGPUInstrInfo::AMDGPUInstrInfo(AMDGPUTargetMachine &tm)
24   : AMDILInstrInfo(tm) { }
25
26 void AMDGPUInstrInfo::convertToISA(MachineInstr & MI, MachineFunction &MF,
27     DebugLoc DL) const
28 {
29   MachineRegisterInfo &MRI = MF.getRegInfo();
30   const AMDGPURegisterInfo & RI = getRegisterInfo();
31
32   for (unsigned i = 0; i < MI.getNumOperands(); i++) {
33     MachineOperand &MO = MI.getOperand(i);
34     // Convert dst regclass to one that is supported by the ISA
35     if (MO.isReg() && MO.isDef()) {
36       if (TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
37         const TargetRegisterClass * oldRegClass = MRI.getRegClass(MO.getReg());
38         const TargetRegisterClass * newRegClass = RI.getISARegClass(oldRegClass);
39
40         assert(newRegClass);
41
42         MRI.setRegClass(MO.getReg(), newRegClass);
43       }
44     }
45   }
46 }