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/CodeGen/MachineCodeForMethod.h"
14 // Build the MachineInstruction Description Array...
15 const 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"
23 //----------------------------------------------------------------------------
24 // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
25 // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
26 //----------------------------------------------------------------------------
28 TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
32 //---------------------------------------------------------------------------
33 // class UltraSparcFrameInfo
36 // Interface to stack frame layout info for the UltraSPARC.
37 // Starting offsets for each area of the stack frame are aligned at
38 // a multiple of getStackFrameSizeAlignment().
39 //---------------------------------------------------------------------------
42 UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineCodeForMethod& ,
45 pos = false; // static stack area grows downwards
46 return StaticAreaOffsetFromFP;
50 UltraSparcFrameInfo::getRegSpillAreaOffset(MachineCodeForMethod& mcInfo,
53 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
55 pos = false; // static stack area grows downwards
56 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
57 return StaticAreaOffsetFromFP - autoVarsSize;
61 UltraSparcFrameInfo::getTmpAreaOffset(MachineCodeForMethod& mcInfo,
64 mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
65 mcInfo.freezeSpillsArea(); // ensure no more spill slots are added
67 pos = false; // static stack area grows downwards
68 unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
69 unsigned int spillAreaSize = mcInfo.getRegSpillsSize();
70 int offset = autoVarsSize + spillAreaSize;
71 return StaticAreaOffsetFromFP - offset;
75 UltraSparcFrameInfo::getDynamicAreaOffset(MachineCodeForMethod& mcInfo,
78 // 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.
83 unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize();
84 if (int extra = optArgsSize % getStackFrameSizeAlignment())
85 optArgsSize += (getStackFrameSizeAlignment() - extra);
86 int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
87 assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
92 //---------------------------------------------------------------------------
93 // class UltraSparcMachine
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.
101 //---------------------------------------------------------------------------
103 UltraSparc::UltraSparc()
104 : TargetMachine("UltraSparc-Native"),
112 optSizeForSubWordData = 4;
113 minMemOpWordSize = 8;
114 maxAtomicMemOpWordSize = 8;