LLVM API Documentation
00001 //===-- SparcSubtarget.cpp - SPARC Subtarget Information ------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the SPARC specific subclass of TargetSubtargetInfo. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "SparcSubtarget.h" 00015 #include "Sparc.h" 00016 #include "llvm/Support/MathExtras.h" 00017 #include "llvm/Support/TargetRegistry.h" 00018 00019 using namespace llvm; 00020 00021 #define DEBUG_TYPE "sparc-subtarget" 00022 00023 #define GET_SUBTARGETINFO_TARGET_DESC 00024 #define GET_SUBTARGETINFO_CTOR 00025 #include "SparcGenSubtargetInfo.inc" 00026 00027 void SparcSubtarget::anchor() { } 00028 00029 static std::string computeDataLayout(const SparcSubtarget &ST) { 00030 // Sparc is big endian. 00031 std::string Ret = "E-m:e"; 00032 00033 // Some ABIs have 32bit pointers. 00034 if (!ST.is64Bit()) 00035 Ret += "-p:32:32"; 00036 00037 // Alignments for 64 bit integers. 00038 Ret += "-i64:64"; 00039 00040 // On SparcV9 128 floats are aligned to 128 bits, on others only to 64. 00041 // On SparcV9 registers can hold 64 or 32 bits, on others only 32. 00042 if (ST.is64Bit()) 00043 Ret += "-n32:64"; 00044 else 00045 Ret += "-f128:64-n32"; 00046 00047 if (ST.is64Bit()) 00048 Ret += "-S128"; 00049 else 00050 Ret += "-S64"; 00051 00052 return Ret; 00053 } 00054 00055 SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU, 00056 StringRef FS) { 00057 IsV9 = false; 00058 V8DeprecatedInsts = false; 00059 IsVIS = false; 00060 HasHardQuad = false; 00061 UsePopc = false; 00062 00063 // Determine default and user specified characteristics 00064 std::string CPUName = CPU; 00065 if (CPUName.empty()) 00066 CPUName = (Is64Bit) ? "v9" : "v8"; 00067 00068 // Parse features string. 00069 ParseSubtargetFeatures(CPUName, FS); 00070 00071 // Popc is a v9-only instruction. 00072 if (!IsV9) 00073 UsePopc = false; 00074 00075 return *this; 00076 } 00077 00078 SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU, 00079 const std::string &FS, TargetMachine &TM, 00080 bool is64Bit) 00081 : SparcGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit), 00082 DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS))), 00083 InstrInfo(*this), TLInfo(TM), TSInfo(DL), FrameLowering(*this) {} 00084 00085 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const { 00086 00087 if (is64Bit()) { 00088 // All 64-bit stack frames must be 16-byte aligned, and must reserve space 00089 // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128. 00090 frameSize += 128; 00091 // Frames with calls must also reserve space for 6 outgoing arguments 00092 // whether they are used or not. LowerCall_64 takes care of that. 00093 assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned"); 00094 } else { 00095 // Emit the correct save instruction based on the number of bytes in 00096 // the frame. Minimum stack frame size according to V8 ABI is: 00097 // 16 words for register window spill 00098 // 1 word for address of returned aggregate-value 00099 // + 6 words for passing parameters on the stack 00100 // ---------- 00101 // 23 words * 4 bytes per word = 92 bytes 00102 frameSize += 92; 00103 00104 // Round up to next doubleword boundary -- a double-word boundary 00105 // is required by the ABI. 00106 frameSize = RoundUpToAlignment(frameSize, 8); 00107 } 00108 return frameSize; 00109 }