Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===// |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the SPARC specific subclass of TargetSubtargetInfo. |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SparcSubtarget.h" |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 15 | #include "Sparc.h" |
Venkatraman Govindaraju | 3521dcd | 2013-06-01 04:51:18 +0000 | [diff] [blame] | 16 | #include "llvm/Support/MathExtras.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 17 | #include "llvm/Support/TargetRegistry.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 18 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 21 | #define DEBUG_TYPE "sparc-subtarget" |
| 22 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 23 | #define GET_SUBTARGETINFO_TARGET_DESC |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 24 | #define GET_SUBTARGETINFO_CTOR |
Evan Cheng | c9c090d | 2011-07-01 22:36:09 +0000 | [diff] [blame] | 25 | #include "SparcGenSubtargetInfo.inc" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 26 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 27 | void SparcSubtarget::anchor() { } |
| 28 | |
Eric Christopher | ca38fdc | 2014-06-26 22:33:55 +0000 | [diff] [blame] | 29 | SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU, |
| 30 | StringRef FS) { |
| 31 | IsV9 = false; |
| 32 | V8DeprecatedInsts = false; |
| 33 | IsVIS = false; |
| 34 | HasHardQuad = false; |
| 35 | UsePopc = false; |
Venkatraman Govindaraju | a54533ed | 2013-06-04 18:33:25 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 37 | // Determine default and user specified characteristics |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 38 | std::string CPUName = CPU; |
Venkatraman Govindaraju | a66b314 | 2014-01-11 23:56:13 +0000 | [diff] [blame] | 39 | if (CPUName.empty()) |
Eric Christopher | ca38fdc | 2014-06-26 22:33:55 +0000 | [diff] [blame] | 40 | CPUName = (Is64Bit) ? "v9" : "v8"; |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 41 | |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 42 | // Parse features string. |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 43 | ParseSubtargetFeatures(CPUName, FS); |
Jakob Stoklund Olesen | 6f39ce4 | 2014-01-26 08:12:34 +0000 | [diff] [blame] | 44 | |
| 45 | // Popc is a v9-only instruction. |
| 46 | if (!IsV9) |
| 47 | UsePopc = false; |
Eric Christopher | ca38fdc | 2014-06-26 22:33:55 +0000 | [diff] [blame] | 48 | |
| 49 | return *this; |
Chris Lattner | aa237256 | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 50 | } |
Venkatraman Govindaraju | 3521dcd | 2013-06-01 04:51:18 +0000 | [diff] [blame] | 51 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 52 | SparcSubtarget::SparcSubtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | ca38fdc | 2014-06-26 22:33:55 +0000 | [diff] [blame] | 53 | const std::string &FS, TargetMachine &TM, |
| 54 | bool is64Bit) |
Daniel Sanders | 153010c | 2015-09-15 14:08:28 +0000 | [diff] [blame] | 55 | : SparcGenSubtargetInfo(TargetTuple(TT), CPU, FS), Is64Bit(is64Bit), |
Eric Christopher | f5e9406 | 2015-01-30 23:46:43 +0000 | [diff] [blame] | 56 | InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this), |
Mehdi Amini | 157e5a6 | 2015-07-09 02:10:08 +0000 | [diff] [blame] | 57 | FrameLowering(*this) {} |
Venkatraman Govindaraju | 3521dcd | 2013-06-01 04:51:18 +0000 | [diff] [blame] | 58 | |
| 59 | int SparcSubtarget::getAdjustedFrameSize(int frameSize) const { |
| 60 | |
| 61 | if (is64Bit()) { |
| 62 | // All 64-bit stack frames must be 16-byte aligned, and must reserve space |
| 63 | // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128. |
| 64 | frameSize += 128; |
| 65 | // Frames with calls must also reserve space for 6 outgoing arguments |
| 66 | // whether they are used or not. LowerCall_64 takes care of that. |
James Y Knight | 3602286 | 2015-08-26 17:57:51 +0000 | [diff] [blame] | 67 | frameSize = RoundUpToAlignment(frameSize, 16); |
Venkatraman Govindaraju | 3521dcd | 2013-06-01 04:51:18 +0000 | [diff] [blame] | 68 | } else { |
| 69 | // Emit the correct save instruction based on the number of bytes in |
| 70 | // the frame. Minimum stack frame size according to V8 ABI is: |
| 71 | // 16 words for register window spill |
| 72 | // 1 word for address of returned aggregate-value |
| 73 | // + 6 words for passing parameters on the stack |
| 74 | // ---------- |
| 75 | // 23 words * 4 bytes per word = 92 bytes |
| 76 | frameSize += 92; |
| 77 | |
| 78 | // Round up to next doubleword boundary -- a double-word boundary |
| 79 | // is required by the ABI. |
| 80 | frameSize = RoundUpToAlignment(frameSize, 8); |
| 81 | } |
| 82 | return frameSize; |
| 83 | } |
James Y Knight | 1f3e6af | 2015-09-10 21:49:06 +0000 | [diff] [blame] | 84 | |
| 85 | bool SparcSubtarget::enableMachineScheduler() const { |
| 86 | return true; |
| 87 | } |