blob: 98c013100855fe21b0de0187efb62e853594f8c7 [file] [log] [blame]
Chris Lattner1d21f3e2002-04-09 05:21:26 +00001//===-- 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//===----------------------------------------------------------------------===//
Vikram S. Adve9db43182001-10-22 13:44:23 +00007
Chris Lattner20b1ea02001-09-14 03:47:57 +00008#include "SparcInternals.h"
Vikram S. Adve9db43182001-10-22 13:44:23 +00009#include "llvm/Target/Sparc.h"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000010#include "llvm/Function.h"
Chris Lattner221d6882002-02-12 21:07:25 +000011#include "llvm/BasicBlock.h"
Vikram S. Advee1f72802002-09-16 15:39:26 +000012#include "llvm/CodeGen/MachineCodeForMethod.h"
Chris Lattner697954c2002-01-20 22:54:45 +000013#include <iostream>
14using std::cerr;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +000015
Chris Lattner9a3d63b2001-09-19 15:56:23 +000016// Build the MachineInstruction Description Array...
17const 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};
Vikram S. Adve0fb49802001-09-18 13:01:29 +000024
25//----------------------------------------------------------------------------
Chris Lattner46cbff62001-09-14 16:56:32 +000026// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
27// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
Vikram S. Adve0fb49802001-09-18 13:01:29 +000028//----------------------------------------------------------------------------
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +000029
Chris Lattner46cbff62001-09-14 16:56:32 +000030TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
Chris Lattner20b1ea02001-09-14 03:47:57 +000031
32
Vikram S. Adve9db43182001-10-22 13:44:23 +000033
Vikram S. Adve9db43182001-10-22 13:44:23 +000034//---------------------------------------------------------------------------
35// class UltraSparcFrameInfo
36//
37// Purpose:
38// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +000039// Starting offsets for each area of the stack frame are aligned at
40// a multiple of getStackFrameSizeAlignment().
Vikram S. Adve9db43182001-10-22 13:44:23 +000041//---------------------------------------------------------------------------
42
43int
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000044UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineCodeForMethod& ,
45 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000046{
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000047 pos = false; // static stack area grows downwards
48 return StaticAreaOffsetFromFP;
Vikram S. Adve9db43182001-10-22 13:44:23 +000049}
50
51int
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000052UltraSparcFrameInfo::getRegSpillAreaOffset(MachineCodeForMethod& mcInfo,
53 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000054{
Vikram S. Adve0bc05162002-04-25 04:43:45 +000055 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
56
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000057 pos = false; // static stack area grows downwards
58 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
Vikram S. Adve00521d72001-11-12 23:26:35 +000059 return StaticAreaOffsetFromFP - autoVarsSize;
Vikram S. Adve9db43182001-10-22 13:44:23 +000060}
61
62int
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000063UltraSparcFrameInfo::getTmpAreaOffset(MachineCodeForMethod& mcInfo,
64 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000065{
Vikram S. Adve0bc05162002-04-25 04:43:45 +000066 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
67 mcInfo.freezeSpillsArea(); // ensure no more spill slots are added
68
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000069 pos = false; // static stack area grows downwards
70 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
71 unsigned int spillAreaSize = mcInfo.getRegSpillsSize();
Vikram S. Adve00521d72001-11-12 23:26:35 +000072 int offset = autoVarsSize + spillAreaSize;
Vikram S. Adve00521d72001-11-12 23:26:35 +000073 return StaticAreaOffsetFromFP - offset;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000074}
75
76int
77UltraSparcFrameInfo::getDynamicAreaOffset(MachineCodeForMethod& mcInfo,
78 bool& pos) const
79{
Vikram S. Advee6d2c412002-03-18 03:08:07 +000080 // 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;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000085 unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize();
Vikram S. Advee1f72802002-09-16 15:39:26 +000086 if (int extra = optArgsSize % getStackFrameSizeAlignment())
87 optArgsSize += (getStackFrameSizeAlignment() - extra);
Vikram S. Adve00521d72001-11-12 23:26:35 +000088 int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
Vikram S. Advee6d2c412002-03-18 03:08:07 +000089 assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
Vikram S. Adve00521d72001-11-12 23:26:35 +000090 return offset;
Vikram S. Adve9db43182001-10-22 13:44:23 +000091}
92
Ruchira Sasankae38bd5332001-09-15 00:30:44 +000093
Chris Lattner20b1ea02001-09-14 03:47:57 +000094//---------------------------------------------------------------------------
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
Vikram S. Adve0fb49802001-09-18 13:01:29 +0000105UltraSparc::UltraSparc()
106 : TargetMachine("UltraSparc-Native"),
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000107 instrInfo(*this),
108 schedInfo(*this),
109 regInfo(*this),
Vikram S. Adveb7048402001-11-09 02:16:04 +0000110 frameInfo(*this),
111 cacheInfo(*this)
Vikram S. Adve0fb49802001-09-18 13:01:29 +0000112{
Chris Lattner20b1ea02001-09-14 03:47:57 +0000113 optSizeForSubWordData = 4;
114 minMemOpWordSize = 8;
115 maxAtomicMemOpWordSize = 8;
Chris Lattner20b1ea02001-09-14 03:47:57 +0000116}
117