1*bdd1243dSDimitry Andric //==-- LoongArch64TargetParser - Parser for LoongArch64 features --*- C++ -*-=// 2*bdd1243dSDimitry Andric // 3*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*bdd1243dSDimitry Andric // 7*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 8*bdd1243dSDimitry Andric // 9*bdd1243dSDimitry Andric // This file implements a target parser to recognise LoongArch hardware features 10*bdd1243dSDimitry Andric // such as CPU/ARCH and extension names. 11*bdd1243dSDimitry Andric // 12*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 13*bdd1243dSDimitry Andric 14*bdd1243dSDimitry Andric #include "llvm/TargetParser/LoongArchTargetParser.h" 15*bdd1243dSDimitry Andric 16*bdd1243dSDimitry Andric using namespace llvm; 17*bdd1243dSDimitry Andric using namespace llvm::LoongArch; 18*bdd1243dSDimitry Andric 19*bdd1243dSDimitry Andric const FeatureInfo AllFeatures[] = { 20*bdd1243dSDimitry Andric #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND}, 21*bdd1243dSDimitry Andric #include "llvm/TargetParser/LoongArchTargetParser.def" 22*bdd1243dSDimitry Andric }; 23*bdd1243dSDimitry Andric 24*bdd1243dSDimitry Andric const ArchInfo AllArchs[] = { 25*bdd1243dSDimitry Andric #define LOONGARCH_ARCH(NAME, KIND, FEATURES) \ 26*bdd1243dSDimitry Andric {NAME, LoongArch::ArchKind::KIND, FEATURES}, 27*bdd1243dSDimitry Andric #include "llvm/TargetParser/LoongArchTargetParser.def" 28*bdd1243dSDimitry Andric }; 29*bdd1243dSDimitry Andric 30*bdd1243dSDimitry Andric LoongArch::ArchKind LoongArch::parseArch(StringRef Arch) { 31*bdd1243dSDimitry Andric for (const auto A : AllArchs) 32*bdd1243dSDimitry Andric if (A.Name == Arch) 33*bdd1243dSDimitry Andric return A.Kind; 34*bdd1243dSDimitry Andric 35*bdd1243dSDimitry Andric return LoongArch::ArchKind::AK_INVALID; 36*bdd1243dSDimitry Andric } 37*bdd1243dSDimitry Andric 38*bdd1243dSDimitry Andric bool LoongArch::getArchFeatures(StringRef Arch, 39*bdd1243dSDimitry Andric std::vector<StringRef> &Features) { 40*bdd1243dSDimitry Andric for (const auto A : AllArchs) { 41*bdd1243dSDimitry Andric if (A.Name == Arch) { 42*bdd1243dSDimitry Andric for (const auto F : AllFeatures) 43*bdd1243dSDimitry Andric if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID) 44*bdd1243dSDimitry Andric Features.push_back(F.Name); 45*bdd1243dSDimitry Andric return true; 46*bdd1243dSDimitry Andric } 47*bdd1243dSDimitry Andric } 48*bdd1243dSDimitry Andric return false; 49*bdd1243dSDimitry Andric } 50