Chris Lattner | 1d21f3e | 2002-04-09 05:21:26 +0000 | [diff] [blame] | 1 | //===-- 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. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 7 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 8 | #include "SparcInternals.h" |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 9 | #include "llvm/Target/Sparc.h" |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 10 | #include "llvm/Function.h" |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 11 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 12 | using std::cerr; |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 13 | |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 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" |
| 21 | }; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 22 | |
| 23 | //---------------------------------------------------------------------------- |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 24 | // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine |
| 25 | // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 26 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 28 | TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 29 | |
| 30 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 31 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 32 | //--------------------------------------------------------------------------- |
| 33 | // class UltraSparcFrameInfo |
| 34 | // |
| 35 | // Purpose: |
| 36 | // Interface to stack frame layout info for the UltraSPARC. |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 37 | // Starting offsets for each area of the stack frame are aligned at |
| 38 | // a multiple of getStackFrameSizeAlignment(). |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 39 | //--------------------------------------------------------------------------- |
| 40 | |
| 41 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 42 | UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& , |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 43 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 44 | { |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 45 | pos = false; // static stack area grows downwards |
| 46 | return StaticAreaOffsetFromFP; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 50 | UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo, |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 51 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 52 | { |
Vikram S. Adve | 0bc0516 | 2002-04-25 04:43:45 +0000 | [diff] [blame] | 53 | mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added |
| 54 | |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 55 | pos = false; // static stack area grows downwards |
| 56 | unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize(); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 57 | return StaticAreaOffsetFromFP - autoVarsSize; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 61 | UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo, |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 62 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 63 | { |
Vikram S. Adve | 0bc0516 | 2002-04-25 04:43:45 +0000 | [diff] [blame] | 64 | mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added |
| 65 | mcInfo.freezeSpillsArea(); // ensure no more spill slots are added |
| 66 | |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 67 | pos = false; // static stack area grows downwards |
| 68 | unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize(); |
| 69 | unsigned int spillAreaSize = mcInfo.getRegSpillsSize(); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 70 | int offset = autoVarsSize + spillAreaSize; |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 71 | return StaticAreaOffsetFromFP - offset; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 75 | UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo, |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 76 | bool& pos) const |
| 77 | { |
Vikram S. Adve | e6d2c41 | 2002-03-18 03:08:07 +0000 | [diff] [blame] | 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. |
| 82 | pos = false; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 83 | unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize(); |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 84 | if (int extra = optArgsSize % getStackFrameSizeAlignment()) |
| 85 | optArgsSize += (getStackFrameSizeAlignment() - extra); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 86 | int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP; |
Vikram S. Adve | e6d2c41 | 2002-03-18 03:08:07 +0000 | [diff] [blame] | 87 | assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 88 | return offset; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 92 | //--------------------------------------------------------------------------- |
| 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. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 103 | UltraSparc::UltraSparc() |
| 104 | : TargetMachine("UltraSparc-Native"), |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 105 | instrInfo(*this), |
| 106 | schedInfo(*this), |
| 107 | regInfo(*this), |
Vikram S. Adve | b704840 | 2001-11-09 02:16:04 +0000 | [diff] [blame] | 108 | frameInfo(*this), |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 109 | cacheInfo(*this), |
| 110 | optInfo(*this) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 111 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 112 | optSizeForSubWordData = 4; |
| 113 | minMemOpWordSize = 8; |
| 114 | maxAtomicMemOpWordSize = 8; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 115 | } |
| 116 | |