Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "MCTargetDesc/LoongArchBaseInfo.h"
16
17
using namespace llvm;
18
19
#define DEBUG_TYPE "loongarch-subtarget"
20
21
#define GET_SUBTARGETINFO_TARGET_DESC
22
#define GET_SUBTARGETINFO_CTOR
23
#include "LoongArchGenSubtargetInfo.inc"
24
25
0
void LoongArchSubtarget::anchor() {}
26
27
LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
28
    const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
29
0
    StringRef ABIName) {
30
0
  bool Is64Bit = TT.isArch64Bit();
31
0
  if (CPU.empty() || CPU == "generic")
32
0
    CPU = Is64Bit ? "generic-la64" : "generic-la32";
33
34
0
  if (TuneCPU.empty())
35
0
    TuneCPU = CPU;
36
37
0
  ParseSubtargetFeatures(CPU, TuneCPU, FS);
38
0
  initializeProperties(TuneCPU);
39
0
  if (Is64Bit) {
40
0
    GRLenVT = MVT::i64;
41
0
    GRLen = 64;
42
0
  }
43
44
0
  if (HasLA32 == HasLA64)
45
0
    report_fatal_error("Please use one feature of 32bit and 64bit.");
46
47
0
  if (Is64Bit && HasLA32)
48
0
    report_fatal_error("Feature 32bit should be used for loongarch32 target.");
49
50
0
  if (!Is64Bit && HasLA64)
51
0
    report_fatal_error("Feature 64bit should be used for loongarch64 target.");
52
53
0
  TargetABI = LoongArchABI::computeTargetABI(TT, ABIName);
54
55
0
  return *this;
56
0
}
57
58
0
void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {
59
  // Initialize CPU specific properties. We should add a tablegen feature for
60
  // this in the future so we can specify it together with the subtarget
61
  // features.
62
63
  // TODO: Check TuneCPU and override defaults (that are for LA464) once we
64
  // support optimizing for more uarchs.
65
66
  // Default to the alignment settings empirically confirmed to perform best
67
  // on LA464, with 4-wide instruction fetch and decode stages. These settings
68
  // can also be overridden in initializeProperties.
69
  //
70
  // We default to such higher-than-minimum alignments because we assume that:
71
  //
72
  // * these settings should benefit most existing uarchs/users,
73
  // * future general-purpose LoongArch cores are likely to have issue widths
74
  //   equal to or wider than 4,
75
  // * instruction sequences best for LA464 should not pessimize other future
76
  //   uarchs, and
77
  // * narrower cores would not suffer much (aside from slightly increased
78
  //   ICache footprint maybe), compared to the gains everywhere else.
79
0
  PrefFunctionAlignment = Align(32);
80
0
  PrefLoopAlignment = Align(16);
81
0
  MaxBytesForAlignment = 16;
82
0
}
83
84
LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,
85
                                       StringRef TuneCPU, StringRef FS,
86
                                       StringRef ABIName,
87
                                       const TargetMachine &TM)
88
    : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
89
      FrameLowering(
90
          initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
91
0
      InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}