MipsSubtarget.cpp revision a430cb613b6e93c05f128b04323c57acfd08686d
1//===-- MipsSubtarget.cpp - Mips Subtarget Information --------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the Mips specific subclass of TargetSubtargetInfo. 11// 12//===----------------------------------------------------------------------===// 13 14#define DEBUG_TYPE "mips-subtarget" 15 16#include "MipsMachineFunction.h" 17#include "MipsSubtarget.h" 18#include "MipsTargetMachine.h" 19#include "Mips.h" 20#include "MipsRegisterInfo.h" 21#include "llvm/IR/Attributes.h" 22#include "llvm/IR/Function.h" 23#include "llvm/Support/CommandLine.h" 24#include "llvm/Support/Debug.h" 25#include "llvm/Support/TargetRegistry.h" 26#include "llvm/Support/raw_ostream.h" 27 28#define GET_SUBTARGETINFO_TARGET_DESC 29#define GET_SUBTARGETINFO_CTOR 30#include "MipsGenSubtargetInfo.inc" 31 32 33using namespace llvm; 34 35// FIXME: Maybe this should be on by default when Mips16 is specified 36// 37static cl::opt<bool> Mixed16_32( 38 "mips-mixed-16-32", 39 cl::init(false), 40 cl::desc("Allow for a mixture of Mips16 " 41 "and Mips32 code in a single source file"), 42 cl::Hidden); 43 44void MipsSubtarget::anchor() { } 45 46MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU, 47 const std::string &FS, bool little, 48 Reloc::Model _RM, MipsTargetMachine *_TM) : 49 MipsGenSubtargetInfo(TT, CPU, FS), 50 MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little), 51 IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false), 52 IsLinux(true), HasSEInReg(false), HasCondMov(false), HasSwap(false), 53 HasBitCount(false), HasFPIdx(false), 54 InMips16Mode(false), InMicroMipsMode(false), HasDSP(false), HasDSPR2(false), 55 AllowMixed16_32(Mixed16_32), 56 RM(_RM), OverrideMode(NoOverride), TM(_TM) 57{ 58 std::string CPUName = CPU; 59 if (CPUName.empty()) 60 CPUName = "mips32"; 61 62 // Parse features string. 63 ParseSubtargetFeatures(CPUName, FS); 64 65 PreviousInMips16Mode = InMips16Mode; 66 67 // Initialize scheduling itinerary for the specified CPU. 68 InstrItins = getInstrItineraryForCPU(CPUName); 69 70 // Set MipsABI if it hasn't been set yet. 71 if (MipsABI == UnknownABI) 72 MipsABI = hasMips64() ? N64 : O32; 73 74 // Check if Architecture and ABI are compatible. 75 assert(((!hasMips64() && (isABI_O32() || isABI_EABI())) || 76 (hasMips64() && (isABI_N32() || isABI_N64()))) && 77 "Invalid Arch & ABI pair."); 78 79 // Is the target system Linux ? 80 if (TT.find("linux") == std::string::npos) 81 IsLinux = false; 82 83 // Set UseSmallSection. 84 UseSmallSection = !IsLinux && (RM == Reloc::Static); 85} 86 87bool 88MipsSubtarget::enablePostRAScheduler(CodeGenOpt::Level OptLevel, 89 TargetSubtargetInfo::AntiDepBreakMode &Mode, 90 RegClassVector &CriticalPathRCs) const { 91 Mode = TargetSubtargetInfo::ANTIDEP_NONE; 92 CriticalPathRCs.clear(); 93 CriticalPathRCs.push_back(hasMips64() ? 94 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass); 95 return OptLevel >= CodeGenOpt::Aggressive; 96} 97 98//FIXME: This logic for reseting the subtarget along with 99// the helper classes can probably be simplified but there are a lot of 100// cases so we will defer rewriting this to later. 101// 102void MipsSubtarget::resetSubtarget(MachineFunction *MF) { 103 bool ChangeToMips16 = false, ChangeToNoMips16 = false; 104 DEBUG(dbgs() << "resetSubtargetFeatures" << "\n"); 105 AttributeSet FnAttrs = MF->getFunction()->getAttributes(); 106 ChangeToMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex, 107 "mips16"); 108 ChangeToNoMips16 = FnAttrs.hasAttribute(AttributeSet::FunctionIndex, 109 "nomips16"); 110 assert (!(ChangeToMips16 & ChangeToNoMips16) && 111 "mips16 and nomips16 specified on the same function"); 112 if (ChangeToMips16) { 113 if (PreviousInMips16Mode) 114 return; 115 OverrideMode = Mips16Override; 116 PreviousInMips16Mode = true; 117 TM->setHelperClassesMips16(); 118 return; 119 } else if (ChangeToNoMips16) { 120 if (!PreviousInMips16Mode) 121 return; 122 OverrideMode = NoMips16Override; 123 PreviousInMips16Mode = false; 124 TM->setHelperClassesMipsSE(); 125 return; 126 } else { 127 if (OverrideMode == NoOverride) 128 return; 129 OverrideMode = NoOverride; 130 DEBUG(dbgs() << "back to default" << "\n"); 131 if (inMips16Mode() && !PreviousInMips16Mode) { 132 TM->setHelperClassesMips16(); 133 PreviousInMips16Mode = true; 134 } else if (!inMips16Mode() && PreviousInMips16Mode) { 135 TM->setHelperClassesMipsSE(); 136 PreviousInMips16Mode = false; 137 } 138 return; 139 } 140} 141 142