blob: b33a273dc93d6ec0b6302eaca555af26284f7a49 [file] [log] [blame]
Che-Liang Chiou3278c422010-11-08 03:00:52 +00001//===-- 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
Che-Liang Chiouad83c1d2011-01-01 10:50:37 +000025// NOTE: PTXMFInfoExtract must after register allocation!
26
Che-Liang Chiou3278c422010-11-08 03:00:52 +000027namespace 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
47using namespace llvm;
48
49char PTXMFInfoExtract::ID = 0;
50
51bool PTXMFInfoExtract::runOnMachineFunction(MachineFunction &MF) {
52 PTXMachineFunctionInfo *MFI = MF.getInfo<PTXMachineFunctionInfo>();
53 MachineRegisterInfo &MRI = MF.getRegInfo();
54
Justin Holewinski297984d2011-09-22 16:45:40 +000055 // Generate list of all virtual registers used in this function
56 for (unsigned i = 0; i < MRI.getNumVirtRegs(); ++i) {
57 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
58 const TargetRegisterClass *TRC = MRI.getRegClass(Reg);
59 MFI->addVirtualRegister(TRC, Reg);
60 }
61
Che-Liang Chiou3278c422010-11-08 03:00:52 +000062 return false;
63}
64
65FunctionPass *llvm::createPTXMFInfoExtract(PTXTargetMachine &TM,
66 CodeGenOpt::Level OptLevel) {
67 return new PTXMFInfoExtract(TM, OptLevel);
68}