blob: 2484acebf24616344b2bc7072d43df4c7e61ffae [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"
Misha Brukmanfce11432002-10-28 00:28:31 +000011#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner697954c2002-01-20 22:54:45 +000012using std::cerr;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +000013
Chris Lattner9a3d63b2001-09-19 15:56:23 +000014// Build the MachineInstruction Description Array...
15const 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};
Vikram S. Adve0fb49802001-09-18 13:01:29 +000022
23//----------------------------------------------------------------------------
Chris Lattner46cbff62001-09-14 16:56:32 +000024// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
25// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
Vikram S. Adve0fb49802001-09-18 13:01:29 +000026//----------------------------------------------------------------------------
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +000027
Chris Lattner46cbff62001-09-14 16:56:32 +000028TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
Chris Lattner20b1ea02001-09-14 03:47:57 +000029
30
Vikram S. Adve9db43182001-10-22 13:44:23 +000031
Vikram S. Adve9db43182001-10-22 13:44:23 +000032//---------------------------------------------------------------------------
33// class UltraSparcFrameInfo
34//
35// Purpose:
36// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +000037// Starting offsets for each area of the stack frame are aligned at
38// a multiple of getStackFrameSizeAlignment().
Vikram S. Adve9db43182001-10-22 13:44:23 +000039//---------------------------------------------------------------------------
40
41int
Misha Brukmanfce11432002-10-28 00:28:31 +000042UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& ,
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000043 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000044{
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000045 pos = false; // static stack area grows downwards
46 return StaticAreaOffsetFromFP;
Vikram S. Adve9db43182001-10-22 13:44:23 +000047}
48
49int
Misha Brukmanfce11432002-10-28 00:28:31 +000050UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo,
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000051 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000052{
Vikram S. Adve0bc05162002-04-25 04:43:45 +000053 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
54
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000055 pos = false; // static stack area grows downwards
56 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
Vikram S. Adve00521d72001-11-12 23:26:35 +000057 return StaticAreaOffsetFromFP - autoVarsSize;
Vikram S. Adve9db43182001-10-22 13:44:23 +000058}
59
60int
Misha Brukmanfce11432002-10-28 00:28:31 +000061UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo,
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000062 bool& pos) const
Vikram S. Adve9db43182001-10-22 13:44:23 +000063{
Vikram S. Adve0bc05162002-04-25 04:43:45 +000064 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
65 mcInfo.freezeSpillsArea(); // ensure no more spill slots are added
66
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000067 pos = false; // static stack area grows downwards
68 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
69 unsigned int spillAreaSize = mcInfo.getRegSpillsSize();
Vikram S. Adve00521d72001-11-12 23:26:35 +000070 int offset = autoVarsSize + spillAreaSize;
Vikram S. Adve00521d72001-11-12 23:26:35 +000071 return StaticAreaOffsetFromFP - offset;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000072}
73
74int
Misha Brukmanfce11432002-10-28 00:28:31 +000075UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000076 bool& pos) const
77{
Vikram S. Advee6d2c412002-03-18 03:08:07 +000078 // 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;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000083 unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize();
Vikram S. Advee1f72802002-09-16 15:39:26 +000084 if (int extra = optArgsSize % getStackFrameSizeAlignment())
85 optArgsSize += (getStackFrameSizeAlignment() - extra);
Vikram S. Adve00521d72001-11-12 23:26:35 +000086 int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
Vikram S. Advee6d2c412002-03-18 03:08:07 +000087 assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
Vikram S. Adve00521d72001-11-12 23:26:35 +000088 return offset;
Vikram S. Adve9db43182001-10-22 13:44:23 +000089}
90
Ruchira Sasankae38bd5332001-09-15 00:30:44 +000091
Chris Lattner20b1ea02001-09-14 03:47:57 +000092//---------------------------------------------------------------------------
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
Vikram S. Adve0fb49802001-09-18 13:01:29 +0000103UltraSparc::UltraSparc()
104 : TargetMachine("UltraSparc-Native"),
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000105 instrInfo(*this),
106 schedInfo(*this),
107 regInfo(*this),
Vikram S. Adveb7048402001-11-09 02:16:04 +0000108 frameInfo(*this),
Vikram S. Adved55697c2002-09-20 00:52:09 +0000109 cacheInfo(*this),
110 optInfo(*this)
Vikram S. Adve0fb49802001-09-18 13:01:29 +0000111{
Chris Lattner20b1ea02001-09-14 03:47:57 +0000112 optSizeForSubWordData = 4;
113 minMemOpWordSize = 8;
114 maxAtomicMemOpWordSize = 8;
Chris Lattner20b1ea02001-09-14 03:47:57 +0000115}
116