1ef9421dcSWeining Lu //===-- LoongArchTargetParser - Parser for LoongArch features --*- C++ -*-====// 2f09cf34dSArchibald Elliott // 3f09cf34dSArchibald Elliott // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4f09cf34dSArchibald Elliott // See https://llvm.org/LICENSE.txt for license information. 5f09cf34dSArchibald Elliott // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f09cf34dSArchibald Elliott // 7f09cf34dSArchibald Elliott //===----------------------------------------------------------------------===// 8f09cf34dSArchibald Elliott // 9f09cf34dSArchibald Elliott // This file implements a target parser to recognise LoongArch hardware features 10f09cf34dSArchibald Elliott // such as CPU/ARCH and extension names. 11f09cf34dSArchibald Elliott // 12f09cf34dSArchibald Elliott //===----------------------------------------------------------------------===// 13f09cf34dSArchibald Elliott 14f09cf34dSArchibald Elliott #include "llvm/TargetParser/LoongArchTargetParser.h" 15f09cf34dSArchibald Elliott 16c4eb880dSWeining Lu using namespace llvm; 17c4eb880dSWeining Lu using namespace llvm::LoongArch; 18f09cf34dSArchibald Elliott 19f09cf34dSArchibald Elliott const FeatureInfo AllFeatures[] = { 20f09cf34dSArchibald Elliott #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND}, 21f09cf34dSArchibald Elliott #include "llvm/TargetParser/LoongArchTargetParser.def" 22f09cf34dSArchibald Elliott }; 23f09cf34dSArchibald Elliott 24f09cf34dSArchibald Elliott const ArchInfo AllArchs[] = { 25f09cf34dSArchibald Elliott #define LOONGARCH_ARCH(NAME, KIND, FEATURES) \ 26f09cf34dSArchibald Elliott {NAME, LoongArch::ArchKind::KIND, FEATURES}, 27f09cf34dSArchibald Elliott #include "llvm/TargetParser/LoongArchTargetParser.def" 28f09cf34dSArchibald Elliott }; 29f09cf34dSArchibald Elliott 30c4eb880dSWeining Lu bool LoongArch::isValidArchName(StringRef Arch) { 31f09cf34dSArchibald Elliott for (const auto A : AllArchs) 32f09cf34dSArchibald Elliott if (A.Name == Arch) 33ef9421dcSWeining Lu return true; 34ef9421dcSWeining Lu return false; 35f09cf34dSArchibald Elliott } 36f09cf34dSArchibald Elliott 37c4eb880dSWeining Lu bool LoongArch::getArchFeatures(StringRef Arch, 38c4eb880dSWeining Lu std::vector<StringRef> &Features) { 39f09cf34dSArchibald Elliott for (const auto A : AllArchs) { 40f09cf34dSArchibald Elliott if (A.Name == Arch) { 41f09cf34dSArchibald Elliott for (const auto F : AllFeatures) 42ef9421dcSWeining Lu if ((A.Features & F.Kind) == F.Kind) 43f09cf34dSArchibald Elliott Features.push_back(F.Name); 44f09cf34dSArchibald Elliott return true; 45f09cf34dSArchibald Elliott } 46f09cf34dSArchibald Elliott } 475a1b9896SAmi-zhang 485a1b9896SAmi-zhang if (Arch == "la64v1.0" || Arch == "la64v1.1") { 495a1b9896SAmi-zhang Features.push_back("+64bit"); 505a1b9896SAmi-zhang Features.push_back("+d"); 515a1b9896SAmi-zhang Features.push_back("+lsx"); 525a1b9896SAmi-zhang Features.push_back("+ual"); 535b9c76b6Stangaac if (Arch == "la64v1.1") { 545a1b9896SAmi-zhang Features.push_back("+frecipe"); 555b9c76b6Stangaac Features.push_back("+lam-bh"); 56427be076Stangaac Features.push_back("+lamcas"); 571d460207Stangaac Features.push_back("+ld-seq-sa"); 58f4379db4Stangaac Features.push_back("+div32"); 59*19834b46Stangaac Features.push_back("+scq"); 605b9c76b6Stangaac } 615a1b9896SAmi-zhang return true; 625a1b9896SAmi-zhang } 635a1b9896SAmi-zhang 64f09cf34dSArchibald Elliott return false; 65f09cf34dSArchibald Elliott } 66f62c9252SWeining Lu 67f62c9252SWeining Lu bool LoongArch::isValidCPUName(StringRef Name) { return isValidArchName(Name); } 68f62c9252SWeining Lu 69f62c9252SWeining Lu void LoongArch::fillValidCPUList(SmallVectorImpl<StringRef> &Values) { 70f62c9252SWeining Lu for (const auto A : AllArchs) 71f62c9252SWeining Lu Values.emplace_back(A.Name); 72f62c9252SWeining Lu } 73f62c9252SWeining Lu 74f62c9252SWeining Lu StringRef LoongArch::getDefaultArch(bool Is64Bit) { 75f62c9252SWeining Lu // TODO: use a real 32-bit arch name. 76f62c9252SWeining Lu return Is64Bit ? "loongarch64" : ""; 77f62c9252SWeining Lu } 78