xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
181ad6265SDimitry Andric //===-- LoongArchSubtarget.cpp - LoongArch Subtarget Information -*- C++ -*--=//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric //
981ad6265SDimitry Andric // This file implements the LoongArch specific subclass of TargetSubtargetInfo.
1081ad6265SDimitry Andric //
1181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
1281ad6265SDimitry Andric 
1381ad6265SDimitry Andric #include "LoongArchSubtarget.h"
1481ad6265SDimitry Andric #include "LoongArchFrameLowering.h"
1581ad6265SDimitry Andric 
1681ad6265SDimitry Andric using namespace llvm;
1781ad6265SDimitry Andric 
1881ad6265SDimitry Andric #define DEBUG_TYPE "loongarch-subtarget"
1981ad6265SDimitry Andric 
2081ad6265SDimitry Andric #define GET_SUBTARGETINFO_TARGET_DESC
2181ad6265SDimitry Andric #define GET_SUBTARGETINFO_CTOR
2281ad6265SDimitry Andric #include "LoongArchGenSubtargetInfo.inc"
2381ad6265SDimitry Andric 
2481ad6265SDimitry Andric void LoongArchSubtarget::anchor() {}
2581ad6265SDimitry Andric 
2681ad6265SDimitry Andric LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
2781ad6265SDimitry Andric     const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
2881ad6265SDimitry Andric     StringRef ABIName) {
2981ad6265SDimitry Andric   bool Is64Bit = TT.isArch64Bit();
30*bdd1243dSDimitry Andric   if (CPU.empty() || CPU == "generic")
3181ad6265SDimitry Andric     CPU = Is64Bit ? "generic-la64" : "generic-la32";
3281ad6265SDimitry Andric 
3381ad6265SDimitry Andric   if (TuneCPU.empty())
3481ad6265SDimitry Andric     TuneCPU = CPU;
3581ad6265SDimitry Andric 
3681ad6265SDimitry Andric   ParseSubtargetFeatures(CPU, TuneCPU, FS);
3781ad6265SDimitry Andric   if (Is64Bit) {
3881ad6265SDimitry Andric     GRLenVT = MVT::i64;
3981ad6265SDimitry Andric     GRLen = 64;
4081ad6265SDimitry Andric   }
4181ad6265SDimitry Andric 
42*bdd1243dSDimitry Andric   if (HasLA32 == HasLA64)
43*bdd1243dSDimitry Andric     report_fatal_error("Please use one feature of 32bit and 64bit.");
44*bdd1243dSDimitry Andric 
45*bdd1243dSDimitry Andric   if (Is64Bit && HasLA32)
46*bdd1243dSDimitry Andric     report_fatal_error("Feature 32bit should be used for loongarch32 target.");
47*bdd1243dSDimitry Andric 
48*bdd1243dSDimitry Andric   if (!Is64Bit && HasLA64)
49*bdd1243dSDimitry Andric     report_fatal_error("Feature 64bit should be used for loongarch64 target.");
50*bdd1243dSDimitry Andric 
5181ad6265SDimitry Andric   // TODO: ILP32{S,F} LP64{S,F}
5281ad6265SDimitry Andric   TargetABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
5381ad6265SDimitry Andric   return *this;
5481ad6265SDimitry Andric }
5581ad6265SDimitry Andric 
5681ad6265SDimitry Andric LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,
5781ad6265SDimitry Andric                                        StringRef TuneCPU, StringRef FS,
5881ad6265SDimitry Andric                                        StringRef ABIName,
5981ad6265SDimitry Andric                                        const TargetMachine &TM)
6081ad6265SDimitry Andric     : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
6181ad6265SDimitry Andric       FrameLowering(
6281ad6265SDimitry Andric           initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
6381ad6265SDimitry Andric       InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}
64