xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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())
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   // TODO: ILP32{S,F} LP64{S,F}
43   TargetABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
44   return *this;
45 }
46 
47 LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,
48                                        StringRef TuneCPU, StringRef FS,
49                                        StringRef ABIName,
50                                        const TargetMachine &TM)
51     : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
52       FrameLowering(
53           initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
54       InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}
55