blob: 26ec6239f498522dcbdef2d1cefe0b096f94454c [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
Benjamin Kramer0861f572011-11-26 23:01:57 +000025using namespace llvm;
26
Che-Liang Chiouad83c1d2011-01-01 10:50:37 +000027// NOTE: PTXMFInfoExtract must after register allocation!
28
Benjamin Kramer0861f572011-11-26 23:01:57 +000029namespace {
Che-Liang Chiou3278c422010-11-08 03:00:52 +000030 /// PTXMFInfoExtract - PTX specific code to extract of PTX machine
31 /// function information for PTXAsmPrinter
32 ///
33 class PTXMFInfoExtract : public MachineFunctionPass {
34 private:
35 static char ID;
36
37 public:
38 PTXMFInfoExtract(PTXTargetMachine &TM, CodeGenOpt::Level OptLevel)
39 : MachineFunctionPass(ID) {}
40
41 virtual bool runOnMachineFunction(MachineFunction &MF);
42
43 virtual const char *getPassName() const {
44 return "PTX Machine Function Info Extractor";
45 }
46 }; // class PTXMFInfoExtract
Benjamin Kramer0861f572011-11-26 23:01:57 +000047} // end anonymous namespace
Che-Liang Chiou3278c422010-11-08 03:00:52 +000048
49using namespace llvm;
50
51char PTXMFInfoExtract::ID = 0;
52
53bool PTXMFInfoExtract::runOnMachineFunction(MachineFunction &MF) {
54 PTXMachineFunctionInfo *MFI = MF.getInfo<PTXMachineFunctionInfo>();
55 MachineRegisterInfo &MRI = MF.getRegInfo();
56
Justin Holewinski297984d2011-09-22 16:45:40 +000057 // Generate list of all virtual registers used in this function
58 for (unsigned i = 0; i < MRI.getNumVirtRegs(); ++i) {
59 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
60 const TargetRegisterClass *TRC = MRI.getRegClass(Reg);
Justin Holewinski4c7ffb62011-12-06 17:39:48 +000061 unsigned RegType;
62 if (TRC == PTX::RegPredRegisterClass)
63 RegType = PTXRegisterType::Pred;
64 else if (TRC == PTX::RegI16RegisterClass)
65 RegType = PTXRegisterType::B16;
66 else if (TRC == PTX::RegI32RegisterClass)
67 RegType = PTXRegisterType::B32;
68 else if (TRC == PTX::RegI64RegisterClass)
69 RegType = PTXRegisterType::B64;
70 else if (TRC == PTX::RegF32RegisterClass)
71 RegType = PTXRegisterType::F32;
72 else if (TRC == PTX::RegF64RegisterClass)
73 RegType = PTXRegisterType::F64;
74 MFI->addRegister(Reg, RegType, PTXRegisterSpace::Reg);
Justin Holewinski297984d2011-09-22 16:45:40 +000075 }
76
Che-Liang Chiou3278c422010-11-08 03:00:52 +000077 return false;
78}
79
80FunctionPass *llvm::createPTXMFInfoExtract(PTXTargetMachine &TM,
81 CodeGenOpt::Level OptLevel) {
82 return new PTXMFInfoExtract(TM, OptLevel);
83}