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