LoongArchTargetParser.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //==-- LoongArch64TargetParser - Parser for LoongArch64 features --*- 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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements a target parser to recognise LoongArch hardware features
  10. // such as CPU/ARCH and extension names.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/TargetParser/LoongArchTargetParser.h"
  14. using namespace llvm;
  15. using namespace llvm::LoongArch;
  16. const FeatureInfo AllFeatures[] = {
  17. #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},
  18. #include "llvm/TargetParser/LoongArchTargetParser.def"
  19. };
  20. const ArchInfo AllArchs[] = {
  21. #define LOONGARCH_ARCH(NAME, KIND, FEATURES) \
  22. {NAME, LoongArch::ArchKind::KIND, FEATURES},
  23. #include "llvm/TargetParser/LoongArchTargetParser.def"
  24. };
  25. LoongArch::ArchKind LoongArch::parseArch(StringRef Arch) {
  26. for (const auto A : AllArchs)
  27. if (A.Name == Arch)
  28. return A.Kind;
  29. return LoongArch::ArchKind::AK_INVALID;
  30. }
  31. bool LoongArch::getArchFeatures(StringRef Arch,
  32. std::vector<StringRef> &Features) {
  33. for (const auto A : AllArchs) {
  34. if (A.Name == Arch) {
  35. for (const auto F : AllFeatures)
  36. if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID)
  37. Features.push_back(F.Name);
  38. return true;
  39. }
  40. }
  41. return false;
  42. }