Path: blob/main/contrib/llvm-project/llvm/lib/TargetParser/LoongArchTargetParser.cpp
35233 views
//===-- LoongArchTargetParser - Parser for LoongArch features --*- 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 a target parser to recognise LoongArch hardware features9// such as CPU/ARCH and extension names.10//11//===----------------------------------------------------------------------===//1213#include "llvm/TargetParser/LoongArchTargetParser.h"1415using namespace llvm;16using namespace llvm::LoongArch;1718const FeatureInfo AllFeatures[] = {19#define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},20#include "llvm/TargetParser/LoongArchTargetParser.def"21};2223const ArchInfo AllArchs[] = {24#define LOONGARCH_ARCH(NAME, KIND, FEATURES) \25{NAME, LoongArch::ArchKind::KIND, FEATURES},26#include "llvm/TargetParser/LoongArchTargetParser.def"27};2829bool LoongArch::isValidArchName(StringRef Arch) {30for (const auto A : AllArchs)31if (A.Name == Arch)32return true;33return false;34}3536bool LoongArch::getArchFeatures(StringRef Arch,37std::vector<StringRef> &Features) {38for (const auto A : AllArchs) {39if (A.Name == Arch) {40for (const auto F : AllFeatures)41if ((A.Features & F.Kind) == F.Kind)42Features.push_back(F.Name);43return true;44}45}4647if (Arch == "la64v1.0" || Arch == "la64v1.1") {48Features.push_back("+64bit");49Features.push_back("+d");50Features.push_back("+lsx");51Features.push_back("+ual");52if (Arch == "la64v1.1")53Features.push_back("+frecipe");54return true;55}5657return false;58}5960bool LoongArch::isValidCPUName(StringRef Name) { return isValidArchName(Name); }6162void LoongArch::fillValidCPUList(SmallVectorImpl<StringRef> &Values) {63for (const auto A : AllArchs)64Values.emplace_back(A.Name);65}6667StringRef LoongArch::getDefaultArch(bool Is64Bit) {68// TODO: use a real 32-bit arch name.69return Is64Bit ? "loongarch64" : "";70}717273