MC: Make TargetAsmBackend available to the AsmStreamer.
[oota-llvm.git] / lib / Target / PTX / PTXMFInfoExtract.cpp
1 //===-- PTXMFInfoExtract.cpp - Extract PTX machine function info ----------===//
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 defines an information extractor for PTX machine functions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "ptx-mf-info-extract"
15
16 #include "PTX.h"
17 #include "PTXTargetMachine.h"
18 #include "PTXMachineFunctionInfo.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/MachineRegisterInfo.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/raw_ostream.h"
24
25 namespace llvm {
26   /// PTXMFInfoExtract - PTX specific code to extract of PTX machine
27   /// function information for PTXAsmPrinter
28   ///
29   class PTXMFInfoExtract : public MachineFunctionPass {
30     private:
31       static char ID;
32
33     public:
34       PTXMFInfoExtract(PTXTargetMachine &TM, CodeGenOpt::Level OptLevel)
35         : MachineFunctionPass(ID) {}
36
37       virtual bool runOnMachineFunction(MachineFunction &MF);
38
39       virtual const char *getPassName() const {
40         return "PTX Machine Function Info Extractor";
41       }
42   }; // class PTXMFInfoExtract
43 } // namespace llvm
44
45 using namespace llvm;
46
47 char PTXMFInfoExtract::ID = 0;
48
49 bool PTXMFInfoExtract::runOnMachineFunction(MachineFunction &MF) {
50   PTXMachineFunctionInfo *MFI = MF.getInfo<PTXMachineFunctionInfo>();
51   MachineRegisterInfo &MRI = MF.getRegInfo();
52
53   DEBUG(dbgs() << "****** PTX FUNCTION LOCAL VAR REG DEF ******\n");
54
55   unsigned reg_ret = MFI->retReg();
56
57   // FIXME: This is a slow linear scanning
58   for (unsigned reg = PTX::NoRegister + 1; reg < PTX::NUM_TARGET_REGS; ++reg)
59     if (MRI.isPhysRegUsed(reg) && reg != reg_ret && !MFI->isArgReg(reg))
60       MFI->addLocalVarReg(reg);
61
62   // Notify MachineFunctionInfo that I've done adding local var reg
63   MFI->doneAddLocalVar();
64
65   DEBUG(for (PTXMachineFunctionInfo::reg_iterator
66              i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd();
67              i != e; ++i)
68         dbgs() << "Used Reg: " << *i << "\n";);
69
70   return false;
71 }
72
73 FunctionPass *llvm::createPTXMFInfoExtract(PTXTargetMachine &TM,
74                                            CodeGenOpt::Level OptLevel) {
75   return new PTXMFInfoExtract(TM, OptLevel);
76 }