Fix undefined behavior in the Mips backend.
[oota-llvm.git] / lib / Target / Mips / MipsSubtarget.cpp
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 #include "MipsSubtarget.h"
15 #include "Mips.h"
16 #include "llvm/Support/TargetRegistry.h"
17
18 #define GET_SUBTARGETINFO_TARGET_DESC
19 #define GET_SUBTARGETINFO_CTOR
20 #include "MipsGenSubtargetInfo.inc"
21
22 using namespace llvm;
23
24 void MipsSubtarget::anchor() { }
25
26 MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
27                              const std::string &FS, bool little) :
28   MipsGenSubtargetInfo(TT, CPU, FS),
29   MipsArchVersion(Mips32), MipsABI(UnknownABI), IsLittle(little),
30   IsSingleFloat(false), IsFP64bit(false), IsGP64bit(false), HasVFPU(false),
31   IsLinux(true), HasSEInReg(false), HasCondMov(false), HasMulDivAdd(false),
32   HasMinMax(false), HasSwap(false), HasBitCount(false)
33 {
34   std::string CPUName = CPU;
35   if (CPUName.empty())
36     CPUName = "mips32";
37
38   // Parse features string.
39   ParseSubtargetFeatures(CPUName, FS);
40
41   // Initialize scheduling itinerary for the specified CPU.
42   InstrItins = getInstrItineraryForCPU(CPUName);
43
44   // Set MipsABI if it hasn't been set yet.
45   if (MipsABI == UnknownABI)
46     MipsABI = hasMips64() ? N64 : O32;
47
48   // Check if Architecture and ABI are compatible.
49   assert(((!hasMips64() && (isABI_O32() || isABI_EABI())) ||
50           (hasMips64() && (isABI_N32() || isABI_N64()))) &&
51          "Invalid  Arch & ABI pair.");
52
53   // Is the target system Linux ?
54   if (TT.find("linux") == std::string::npos)
55     IsLinux = false;
56 }