OSDN Git Service

radeonsi: initial WIP SI code
[android-x86/external-mesa.git] / src / gallium / drivers / radeon / AMDGPUConvertToISA.cpp
1 //===-- AMDGPUConvertToISA.cpp - Lower AMDIL to HW ISA --------------------===//
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 pass lowers AMDIL machine instructions to the appropriate hardware
11 // instructions. 
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "AMDGPU.h"
16 #include "AMDGPUInstrInfo.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18
19 using namespace llvm;
20
21 namespace {
22   class AMDGPUConvertToISAPass : public MachineFunctionPass {
23
24   private:
25     static char ID;
26     TargetMachine &TM;
27
28     void lowerFLT(MachineInstr &MI);
29
30   public:
31     AMDGPUConvertToISAPass(TargetMachine &tm) :
32       MachineFunctionPass(ID), TM(tm) { }
33
34     virtual bool runOnMachineFunction(MachineFunction &MF);
35
36   };
37 } /* End anonymous namespace */
38
39 char AMDGPUConvertToISAPass::ID = 0;
40
41 FunctionPass *llvm::createAMDGPUConvertToISAPass(TargetMachine &tm) {
42   return new AMDGPUConvertToISAPass(tm);
43 }
44
45 bool AMDGPUConvertToISAPass::runOnMachineFunction(MachineFunction &MF)
46 {
47   const AMDGPUInstrInfo * TII =
48                       static_cast<const AMDGPUInstrInfo*>(TM.getInstrInfo());
49
50   for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
51                                                   BB != BB_E; ++BB) {
52     MachineBasicBlock &MBB = *BB;
53     for (MachineBasicBlock::iterator I = MBB.begin(), Next = llvm::next(I);
54          I != MBB.end(); I = Next, Next = llvm::next(I) ) {
55       MachineInstr &MI = *I;
56       MachineInstr * newInstr = TII->convertToISA(MI, MF, MBB.findDebugLoc(I));
57       if (!newInstr) {
58         continue;
59       }
60       MBB.insert(I, newInstr);
61       MI.eraseFromParent();
62     }
63   }
64   return false;
65 }