Make the subregister hashtable output more readable by wrapping the lines,
[oota-llvm.git] / lib / Target / TargetRegisterInfo.cpp
1 //===- TargetRegisterInfo.cpp - Target Register Information Implementation ===//
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 implements the TargetRegisterInfo interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Target/TargetRegisterInfo.h"
16 #include "llvm/Target/TargetFrameInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/ADT/BitVector.h"
20
21 using namespace llvm;
22
23 TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
24                              regclass_iterator RCB, regclass_iterator RCE,
25                              int CFSO, int CFDO,
26                              const unsigned* subregs, const unsigned subregsize)
27   : Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE),
28     SubregHash(subregs), SubregHashSize(subregsize) {
29   assert(NumRegs < FirstVirtualRegister &&
30          "Target has too many physical registers!");
31
32   CallFrameSetupOpcode   = CFSO;
33   CallFrameDestroyOpcode = CFDO;
34 }
35
36 TargetRegisterInfo::~TargetRegisterInfo() {}
37
38 namespace {
39   // Sort according to super- / sub- class relations.
40   // i.e. super- register class < sub- register class.
41   struct RCCompare {
42     bool operator()(const TargetRegisterClass* const &LHS,
43                     const TargetRegisterClass* const &RHS) {
44       return RHS->hasSuperClass(LHS);
45     }
46   };
47 }
48
49 /// getPhysicalRegisterRegClass - Returns the Register Class of a physical
50 /// register of the given type. If type is MVT::Other, then just return any
51 /// register class the register belongs to.
52 const TargetRegisterClass *
53 TargetRegisterInfo::getPhysicalRegisterRegClass(unsigned reg, MVT VT) const {
54   assert(isPhysicalRegister(reg) && "reg must be a physical register");
55
56   // Pick the register class of the right type that contains this physreg.
57   SmallVector<const TargetRegisterClass*, 4> RCs;
58   for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I){
59     if ((VT == MVT::Other || (*I)->hasType(VT)) && (*I)->contains(reg))
60       RCs.push_back(*I);
61   }
62
63   if (RCs.size() == 1)
64     return RCs[0];
65
66   if (RCs.size()) {
67     // Multiple compatible register classes. Get the super- class.
68     std::stable_sort(RCs.begin(), RCs.end(), RCCompare());
69     return RCs[0];
70   }
71
72   assert(false && "Couldn't find the register class");
73   return 0;
74 }
75
76 /// getAllocatableSetForRC - Toggle the bits that represent allocatable
77 /// registers for the specific register class.
78 static void getAllocatableSetForRC(MachineFunction &MF,
79                                    const TargetRegisterClass *RC, BitVector &R){  
80   for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
81          E = RC->allocation_order_end(MF); I != E; ++I)
82     R.set(*I);
83 }
84
85 BitVector TargetRegisterInfo::getAllocatableSet(MachineFunction &MF,
86                                           const TargetRegisterClass *RC) const {
87   BitVector Allocatable(NumRegs);
88   if (RC) {
89     getAllocatableSetForRC(MF, RC, Allocatable);
90     return Allocatable;
91   }
92
93   for (TargetRegisterInfo::regclass_iterator I = regclass_begin(),
94          E = regclass_end(); I != E; ++I)
95     getAllocatableSetForRC(MF, *I, Allocatable);
96   return Allocatable;
97 }
98
99 /// getFrameIndexOffset - Returns the displacement from the frame register to
100 /// the stack frame of the specified index. This is the default implementation
101 /// which is likely incorrect for the target.
102 int TargetRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
103   const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
104   MachineFrameInfo *MFI = MF.getFrameInfo();
105   return MFI->getObjectOffset(FI) + MFI->getStackSize() -
106     TFI.getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
107 }
108
109 /// getInitialFrameState - Returns a list of machine moves that are assumed
110 /// on entry to a function.
111 void
112 TargetRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
113   // Default is to do nothing.
114 }
115