xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1 //===-- LoongArchSubtarget.cpp - LoongArch Subtarget Information -*- C++ -*--=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the LoongArch specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LoongArchSubtarget.h"
14 #include "LoongArchFrameLowering.h"
15 
16 using namespace llvm;
17 
18 #define DEBUG_TYPE "loongarch-subtarget"
19 
20 #define GET_SUBTARGETINFO_TARGET_DESC
21 #define GET_SUBTARGETINFO_CTOR
22 #include "LoongArchGenSubtargetInfo.inc"
23 
24 void LoongArchSubtarget::anchor() {}
25 
26 LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
27     const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
28     StringRef ABIName) {
29   bool Is64Bit = TT.isArch64Bit();
30   if (CPU.empty() || CPU == "generic")
31     CPU = Is64Bit ? "generic-la64" : "generic-la32";
32 
33   if (TuneCPU.empty())
34     TuneCPU = CPU;
35 
36   ParseSubtargetFeatures(CPU, TuneCPU, FS);
37   if (Is64Bit) {
38     GRLenVT = MVT::i64;
39     GRLen = 64;
40   }
41 
42   if (HasLA32 == HasLA64)
43     report_fatal_error("Please use one feature of 32bit and 64bit.");
44 
45   if (Is64Bit && HasLA32)
46     report_fatal_error("Feature 32bit should be used for loongarch32 target.");
47 
48   if (!Is64Bit && HasLA64)
49     report_fatal_error("Feature 64bit should be used for loongarch64 target.");
50 
51   // TODO: ILP32{S,F} LP64{S,F}
52   TargetABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
53   return *this;
54 }
55 
56 LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,
57                                        StringRef TuneCPU, StringRef FS,
58                                        StringRef ABIName,
59                                        const TargetMachine &TM)
60     : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
61       FrameLowering(
62           initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
63       InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}
64