1 //===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
3 // This file contains the code for the Sparc Target that does not fit in any of
4 // the other files in this directory.
6 //===----------------------------------------------------------------------===//
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"
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"
25 //----------------------------------------------------------------------------
26 // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
27 // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
28 //----------------------------------------------------------------------------
30 TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
34 //---------------------------------------------------------------------------
35 // class UltraSparcFrameInfo
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 //---------------------------------------------------------------------------
44 UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineCodeForMethod& ,
47 pos = false; // static stack area grows downwards
48 return StaticAreaOffsetFromFP;
52 UltraSparcFrameInfo::getRegSpillAreaOffset(MachineCodeForMethod& mcInfo,
55 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
57 pos = false; // static stack area grows downwards
58 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
59 return StaticAreaOffsetFromFP - autoVarsSize;
63 UltraSparcFrameInfo::getTmpAreaOffset(MachineCodeForMethod& mcInfo,
66 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
67 mcInfo.freezeSpillsArea(); // ensure no more spill slots are added
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;
77 UltraSparcFrameInfo::getDynamicAreaOffset(MachineCodeForMethod& mcInfo,
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.
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);
94 //---------------------------------------------------------------------------
95 // class UltraSparcMachine
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.
103 //---------------------------------------------------------------------------
105 UltraSparc::UltraSparc()
106 : TargetMachine("UltraSparc-Native"),
114 optSizeForSubWordData = 4;
115 minMemOpWordSize = 8;
116 maxAtomicMemOpWordSize = 8;