clang  14.0.0git
Lanai.cpp
Go to the documentation of this file.
1 //===--- Lanai.cpp - Implement Lanai target feature support ---------------===//
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 Lanai TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "Lanai.h"
15 #include "llvm/ADT/StringSwitch.h"
16 
17 using namespace clang;
18 using namespace clang::targets;
19 
20 const char *const LanaiTargetInfo::GCCRegNames[] = {
21  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
22  "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21",
23  "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
24 };
25 
27  return llvm::makeArrayRef(GCCRegNames);
28 }
29 
30 const TargetInfo::GCCRegAlias LanaiTargetInfo::GCCRegAliases[] = {
31  {{"pc"}, "r2"}, {{"sp"}, "r4"}, {{"fp"}, "r5"}, {{"rv"}, "r8"},
32  {{"rr1"}, "r10"}, {{"rr2"}, "r11"}, {{"rca"}, "r15"},
33 };
34 
36  return llvm::makeArrayRef(GCCRegAliases);
37 }
38 
39 bool LanaiTargetInfo::isValidCPUName(StringRef Name) const {
40  return llvm::StringSwitch<bool>(Name).Case("v11", true).Default(false);
41 }
43  SmallVectorImpl<StringRef> &Values) const {
44  Values.emplace_back("v11");
45 }
46 
48  CPU = llvm::StringSwitch<CPUKind>(Name).Case("v11", CK_V11).Default(CK_NONE);
49 
50  return CPU != CK_NONE;
51 }
52 
53 bool LanaiTargetInfo::hasFeature(StringRef Feature) const {
54  return llvm::StringSwitch<bool>(Feature).Case("lanai", true).Default(false);
55 }
56 
58  MacroBuilder &Builder) const {
59  // Define __lanai__ when building for target lanai.
60  Builder.defineMacro("__lanai__");
61 
62  // Set define for the CPU specified.
63  switch (CPU) {
64  case CK_V11:
65  Builder.defineMacro("__LANAI_V11__");
66  break;
67  case CK_NONE:
68  llvm_unreachable("Unhandled target CPU");
69  }
70 }
clang::targets::LanaiTargetInfo::hasFeature
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: Lanai.cpp:53
clang::targets::LanaiTargetInfo::fillValidCPUList
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: Lanai.cpp:42
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::targets::LanaiTargetInfo::getTargetDefines
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: Lanai.cpp:57
clang::targets::LanaiTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: Lanai.cpp:35
MacroBuilder.h
clang::TargetInfo::GCCRegAlias
Definition: TargetInfo.h:1142
clang::targets::LanaiTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: Lanai.cpp:39
Lanai.h
clang::targets::LanaiTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: Lanai.cpp:47
llvm::ArrayRef< const char * >
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang
Definition: CalledOnceCheck.h:17
clang::targets
Definition: AArch64.h:21
clang::targets::LanaiTargetInfo::getGCCRegNames
ArrayRef< const char * > getGCCRegNames() const override
Definition: Lanai.cpp:26
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::MacroBuilder
Definition: MacroBuilder.h:23