Path: blob/main/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
35294 views
//===-- LoongArchSubtarget.cpp - LoongArch Subtarget Information -*- C++ -*--=//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the LoongArch specific subclass of TargetSubtargetInfo.9//10//===----------------------------------------------------------------------===//1112#include "LoongArchSubtarget.h"13#include "LoongArchFrameLowering.h"14#include "MCTargetDesc/LoongArchBaseInfo.h"1516using namespace llvm;1718#define DEBUG_TYPE "loongarch-subtarget"1920#define GET_SUBTARGETINFO_TARGET_DESC21#define GET_SUBTARGETINFO_CTOR22#include "LoongArchGenSubtargetInfo.inc"2324void LoongArchSubtarget::anchor() {}2526LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(27const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,28StringRef ABIName) {29bool Is64Bit = TT.isArch64Bit();30if (CPU.empty() || CPU == "generic")31CPU = Is64Bit ? "generic-la64" : "generic-la32";3233if (TuneCPU.empty())34TuneCPU = CPU;3536ParseSubtargetFeatures(CPU, TuneCPU, FS);37initializeProperties(TuneCPU);38if (Is64Bit) {39GRLenVT = MVT::i64;40GRLen = 64;41}4243if (HasLA32 == HasLA64)44report_fatal_error("Please use one feature of 32bit and 64bit.");4546if (Is64Bit && HasLA32)47report_fatal_error("Feature 32bit should be used for loongarch32 target.");4849if (!Is64Bit && HasLA64)50report_fatal_error("Feature 64bit should be used for loongarch64 target.");5152TargetABI = LoongArchABI::computeTargetABI(TT, getFeatureBits(), ABIName);5354return *this;55}5657void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {58// Initialize CPU specific properties. We should add a tablegen feature for59// this in the future so we can specify it together with the subtarget60// features.6162// TODO: Check TuneCPU and override defaults (that are for LA464) once we63// support optimizing for more uarchs.6465// Default to the alignment settings empirically confirmed to perform best66// on LA464, with 4-wide instruction fetch and decode stages. These settings67// can also be overridden in initializeProperties.68//69// We default to such higher-than-minimum alignments because we assume that:70//71// * these settings should benefit most existing uarchs/users,72// * future general-purpose LoongArch cores are likely to have issue widths73// equal to or wider than 4,74// * instruction sequences best for LA464 should not pessimize other future75// uarchs, and76// * narrower cores would not suffer much (aside from slightly increased77// ICache footprint maybe), compared to the gains everywhere else.78PrefFunctionAlignment = Align(32);79PrefLoopAlignment = Align(16);80MaxBytesForAlignment = 16;81}8283LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,84StringRef TuneCPU, StringRef FS,85StringRef ABIName,86const TargetMachine &TM)87: LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),88FrameLowering(89initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),90InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}919293