]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/PTX/PTXMFInfoExtract.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / 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 // NOTE: PTXMFInfoExtract must after register allocation!
26
27 namespace llvm {
28   /// PTXMFInfoExtract - PTX specific code to extract of PTX machine
29   /// function information for PTXAsmPrinter
30   ///
31   class PTXMFInfoExtract : public MachineFunctionPass {
32     private:
33       static char ID;
34
35     public:
36       PTXMFInfoExtract(PTXTargetMachine &TM, CodeGenOpt::Level OptLevel)
37         : MachineFunctionPass(ID) {}
38
39       virtual bool runOnMachineFunction(MachineFunction &MF);
40
41       virtual const char *getPassName() const {
42         return "PTX Machine Function Info Extractor";
43       }
44   }; // class PTXMFInfoExtract
45 } // namespace llvm
46
47 using namespace llvm;
48
49 char PTXMFInfoExtract::ID = 0;
50
51 bool PTXMFInfoExtract::runOnMachineFunction(MachineFunction &MF) {
52   PTXMachineFunctionInfo *MFI = MF.getInfo<PTXMachineFunctionInfo>();
53   MachineRegisterInfo &MRI = MF.getRegInfo();
54
55   DEBUG(dbgs() << "******** PTX FUNCTION LOCAL VAR REG DEF ********\n");
56
57   DEBUG(dbgs()
58         << "PTX::NoRegister == " << PTX::NoRegister << "\n"
59         << "PTX::NUM_TARGET_REGS == " << PTX::NUM_TARGET_REGS << "\n");
60
61   DEBUG(for (unsigned reg = PTX::NoRegister + 1;
62              reg < PTX::NUM_TARGET_REGS; ++reg)
63           if (MRI.isPhysRegUsed(reg))
64             dbgs() << "Used Reg: " << reg << "\n";);
65
66   // FIXME: This is a slow linear scanning
67   for (unsigned reg = PTX::NoRegister + 1; reg < PTX::NUM_TARGET_REGS; ++reg)
68     if (MRI.isPhysRegUsed(reg) &&
69         !MFI->isRetReg(reg) &&
70         (MFI->isKernel() || !MFI->isArgReg(reg)))
71       MFI->addLocalVarReg(reg);
72
73   // Notify MachineFunctionInfo that I've done adding local var reg
74   MFI->doneAddLocalVar();
75
76   DEBUG(for (PTXMachineFunctionInfo::reg_iterator
77              i = MFI->argRegBegin(), e = MFI->argRegEnd();
78              i != e; ++i)
79         dbgs() << "Arg Reg: " << *i << "\n";);
80
81   DEBUG(for (PTXMachineFunctionInfo::reg_iterator
82              i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd();
83              i != e; ++i)
84         dbgs() << "Local Var Reg: " << *i << "\n";);
85
86   return false;
87 }
88
89 FunctionPass *llvm::createPTXMFInfoExtract(PTXTargetMachine &TM,
90                                            CodeGenOpt::Level OptLevel) {
91   return new PTXMFInfoExtract(TM, OptLevel);
92 }