cf09734e81b184a977c7caa263a2d344d6d54c35
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9TargetMachine.cpp
1 //***************************************************************************
2 // File:
3 //      Sparc.cpp
4 // 
5 // Purpose:
6 //      
7 // History:
8 //      7/15/01  -  Vikram Adve  -  Created
9 //**************************************************************************/
10
11 #include "llvm/CodeGen/Sparc.h"
12 #include "SparcInternals.h"
13 #include "llvm/Method.h"
14 #include "llvm/CodeGen/InstrScheduling.h"
15 #include "llvm/CodeGen/InstrSelection.h"
16
17
18
19 //---------------------------------------------------------------------------
20 // class UltraSparcInstrInfo 
21 // 
22 // Purpose:
23 //   Information about individual instructions.
24 //   Most information is stored in the SparcMachineInstrDesc array above.
25 //   Other information is computed on demand, and most such functions
26 //   default to member functions in base class MachineInstrInfo. 
27 //---------------------------------------------------------------------------
28
29 /*ctor*/
30 UltraSparcInstrInfo::UltraSparcInstrInfo()
31   : MachineInstrInfo(SparcMachineInstrDesc,
32                      /*descSize = */ NUM_TOTAL_OPCODES,
33                      /*numRealOpCodes = */ NUM_REAL_OPCODES)
34 {
35 }
36
37
38 //---------------------------------------------------------------------------
39 // class UltraSparcSchedInfo 
40 // 
41 // Purpose:
42 //   Scheduling information for the UltraSPARC.
43 //   Primarily just initializes machine-dependent parameters in
44 //   class MachineSchedInfo.
45 //---------------------------------------------------------------------------
46
47 /*ctor*/
48 UltraSparcSchedInfo::UltraSparcSchedInfo(const MachineInstrInfo* mii)
49   : MachineSchedInfo((unsigned int) SPARC_NUM_SCHED_CLASSES,
50                      mii,
51                      SparcRUsageDesc,
52                      SparcInstrUsageDeltas,
53                      SparcInstrIssueDeltas,
54                      sizeof(SparcInstrUsageDeltas)/sizeof(InstrRUsageDelta),
55                      sizeof(SparcInstrIssueDeltas)/sizeof(InstrIssueDelta))
56 {
57   maxNumIssueTotal = 4;
58   longestIssueConflict = 0;             // computed from issuesGaps[]
59   
60   branchMispredictPenalty = 4;          // 4 for SPARC IIi
61   branchTargetUnknownPenalty = 2;       // 2 for SPARC IIi
62   l1DCacheMissPenalty = 8;              // 7 or 9 for SPARC IIi
63   l1ICacheMissPenalty = 8;              // ? for SPARC IIi
64   
65   inOrderLoads = true;                  // true for SPARC IIi
66   inOrderIssue = true;                  // true for SPARC IIi
67   inOrderExec  = false;                 // false for most architectures
68   inOrderRetire= true;                  // true for most architectures
69   
70   // must be called after above parameters are initialized.
71   this->initializeResources();
72 }
73
74 void
75 UltraSparcSchedInfo::initializeResources()
76 {
77   // Compute MachineSchedInfo::instrRUsages and MachineSchedInfo::issueGaps
78   MachineSchedInfo::initializeResources();
79   
80   // Machine-dependent fixups go here.  None for now.
81 }
82
83
84 //---------------------------------------------------------------------------
85 // class UltraSparcMachine 
86 // 
87 // Purpose:
88 //   Primary interface to machine description for the UltraSPARC.
89 //   Primarily just initializes machine-dependent parameters in
90 //   class TargetMachine, and creates machine-dependent subclasses
91 //   for classes such as MachineInstrInfo. 
92 // 
93 //---------------------------------------------------------------------------
94
95 UltraSparc::UltraSparc() : TargetMachine("UltraSparc-Native"),
96                            InstSchedulingInfo(&InstInfo) {
97   optSizeForSubWordData = 4;
98   minMemOpWordSize = 8; 
99   maxAtomicMemOpWordSize = 8;
100   zeroRegNum = 0;                       // %g0 always gives 0 on Sparc
101 }
102
103 bool UltraSparc::compileMethod(Method *M) {
104   if (SelectInstructionsForMethod(M, *this)) {
105     cerr << "Instruction selection failed for method " << M->getName()
106        << "\n\n";
107     return true;
108   }
109   
110   if (ScheduleInstructionsWithSSA(M, *this, InstSchedulingInfo)) {
111     cerr << "Instruction scheduling before allocation failed for method "
112        << M->getName() << "\n\n";
113     return true;
114   }
115   return false;
116 }
117
118 // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
119 // that implements the Sparc backend.
120 //
121 TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }