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