Changed `MachineCodeForMethod' to `MachineFunction'.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9TargetMachine.cpp
1 //===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
2 //
3 // This file contains the code for the Sparc Target that does not fit in any of
4 // the other files in this directory.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "SparcInternals.h"
9 #include "llvm/Target/Sparc.h"
10 #include "llvm/Function.h"
11 #include "llvm/CodeGen/MachineFunction.h"
12 using std::cerr;
13
14 // Build the MachineInstruction Description Array...
15 const MachineInstrDescriptor SparcMachineInstrDesc[] = {
16 #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
17           NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS)             \
18   { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE,             \
19           NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS },
20 #include "SparcInstr.def"
21 };
22
23 //----------------------------------------------------------------------------
24 // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
25 // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
26 //----------------------------------------------------------------------------
27
28 TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
29
30
31
32 //---------------------------------------------------------------------------
33 // class UltraSparcFrameInfo 
34 // 
35 // Purpose:
36 //   Interface to stack frame layout info for the UltraSPARC.
37 //   Starting offsets for each area of the stack frame are aligned at
38 //   a multiple of getStackFrameSizeAlignment().
39 //---------------------------------------------------------------------------
40
41 int
42 UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& ,
43                                                 bool& pos) const
44 {
45   pos = false;                          // static stack area grows downwards
46   return StaticAreaOffsetFromFP;
47 }
48
49 int
50 UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo,
51                                            bool& pos) const
52 {
53   mcInfo.freezeAutomaticVarsArea();     // ensure no more auto vars are added
54   
55   pos = false;                          // static stack area grows downwards
56   unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
57   return StaticAreaOffsetFromFP - autoVarsSize; 
58 }
59
60 int
61 UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo,
62                                       bool& pos) const
63 {
64   mcInfo.freezeAutomaticVarsArea();     // ensure no more auto vars are added
65   mcInfo.freezeSpillsArea();            // ensure no more spill slots are added
66   
67   pos = false;                          // static stack area grows downwards
68   unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
69   unsigned int spillAreaSize = mcInfo.getRegSpillsSize();
70   int offset = autoVarsSize + spillAreaSize;
71   return StaticAreaOffsetFromFP - offset;
72 }
73
74 int
75 UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
76                                           bool& pos) const
77 {
78   // Dynamic stack area grows downwards starting at top of opt-args area.
79   // The opt-args, required-args, and register-save areas are empty except
80   // during calls and traps, so they are shifted downwards on each
81   // dynamic-size alloca.
82   pos = false;
83   unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize();
84   if (int extra = optArgsSize % getStackFrameSizeAlignment())
85     optArgsSize += (getStackFrameSizeAlignment() - extra);
86   int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
87   assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
88   return offset;
89 }
90
91
92 //---------------------------------------------------------------------------
93 // class UltraSparcMachine 
94 // 
95 // Purpose:
96 //   Primary interface to machine description for the UltraSPARC.
97 //   Primarily just initializes machine-dependent parameters in
98 //   class TargetMachine, and creates machine-dependent subclasses
99 //   for classes such as MachineInstrInfo. 
100 // 
101 //---------------------------------------------------------------------------
102
103 UltraSparc::UltraSparc()
104   : TargetMachine("UltraSparc-Native"),
105     instrInfo(*this),
106     schedInfo(*this),
107     regInfo(*this),
108     frameInfo(*this),
109     cacheInfo(*this),
110     optInfo(*this)
111 {
112   optSizeForSubWordData = 4;
113   minMemOpWordSize = 8; 
114   maxAtomicMemOpWordSize = 8;
115 }
116