108 lines · cpp
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-exception6//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 "LoongArchSelectionDAGInfo.h"16#include "MCTargetDesc/LoongArchBaseInfo.h"17 18using namespace llvm;19 20#define DEBUG_TYPE "loongarch-subtarget"21 22#define GET_SUBTARGETINFO_TARGET_DESC23#define GET_SUBTARGETINFO_CTOR24#include "LoongArchGenSubtargetInfo.inc"25 26static cl::opt<bool> UseAA("loongarch-use-aa", cl::init(true),27 cl::desc("Enable the use of AA during codegen."));28 29void LoongArchSubtarget::anchor() {}30 31// Enable use of alias analysis during code generation (during MI scheduling,32// DAGCombine, etc.).33bool LoongArchSubtarget::useAA() const { return UseAA; }34 35LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(36 const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,37 StringRef ABIName) {38 bool Is64Bit = TT.isArch64Bit();39 if (CPU.empty() || CPU == "generic")40 CPU = Is64Bit ? "generic-la64" : "generic-la32";41 42 if (TuneCPU.empty())43 TuneCPU = CPU;44 45 ParseSubtargetFeatures(CPU, TuneCPU, FS);46 initializeProperties(TuneCPU);47 if (Is64Bit) {48 GRLenVT = MVT::i64;49 GRLen = 64;50 }51 52 if (HasLA32 == HasLA64)53 report_fatal_error("Please use one feature of 32bit and 64bit.");54 55 if (Is64Bit && HasLA32)56 report_fatal_error("Feature 32bit should be used for loongarch32 target.");57 58 if (!Is64Bit && HasLA64)59 report_fatal_error("Feature 64bit should be used for loongarch64 target.");60 61 TargetABI = LoongArchABI::computeTargetABI(TT, getFeatureBits(), ABIName);62 63 return *this;64}65 66void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {67 // Initialize CPU specific properties. We should add a tablegen feature for68 // this in the future so we can specify it together with the subtarget69 // features.70 71 // TODO: Check TuneCPU and override defaults (that are for LA464) once we72 // support optimizing for more uarchs.73 74 // Default to the alignment settings empirically confirmed to perform best75 // on LA464, with 4-wide instruction fetch and decode stages. These settings76 // can also be overridden in initializeProperties.77 //78 // We default to such higher-than-minimum alignments because we assume that:79 //80 // * these settings should benefit most existing uarchs/users,81 // * future general-purpose LoongArch cores are likely to have issue widths82 // equal to or wider than 4,83 // * instruction sequences best for LA464 should not pessimize other future84 // uarchs, and85 // * narrower cores would not suffer much (aside from slightly increased86 // ICache footprint maybe), compared to the gains everywhere else.87 PrefFunctionAlignment = Align(32);88 PrefLoopAlignment = Align(16);89 MaxBytesForAlignment = 16;90}91 92LoongArchSubtarget::LoongArchSubtarget(const Triple &TT, StringRef CPU,93 StringRef TuneCPU, StringRef FS,94 StringRef ABIName,95 const TargetMachine &TM)96 : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),97 FrameLowering(98 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),99 InstrInfo(*this), TLInfo(TM, *this) {100 TSInfo = std::make_unique<LoongArchSelectionDAGInfo>();101}102 103LoongArchSubtarget::~LoongArchSubtarget() = default;104 105const SelectionDAGTargetInfo *LoongArchSubtarget::getSelectionDAGInfo() const {106 return TSInfo.get();107}108