Path: blob/main/contrib/llvm-project/clang/lib/Basic/Targets/BPF.h
35269 views
//===--- BPF.h - Declare BPF target feature support -------------*- 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 declares BPF TargetInfo objects.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H13#define LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H1415#include "clang/Basic/TargetInfo.h"16#include "clang/Basic/TargetOptions.h"17#include "llvm/Support/Compiler.h"18#include "llvm/TargetParser/Triple.h"1920namespace clang {21namespace targets {2223class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {24bool HasAlu32 = false;2526public:27BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)28: TargetInfo(Triple) {29LongWidth = LongAlign = PointerWidth = PointerAlign = 64;30SizeType = UnsignedLong;31PtrDiffType = SignedLong;32IntPtrType = SignedLong;33IntMaxType = SignedLong;34Int64Type = SignedLong;35RegParmMax = 5;36if (Triple.getArch() == llvm::Triple::bpfeb) {37resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");38} else {39resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");40}41MaxAtomicPromoteWidth = 64;42MaxAtomicInlineWidth = 64;43TLSSupported = false;44}4546void getTargetDefines(const LangOptions &Opts,47MacroBuilder &Builder) const override;4849bool hasFeature(StringRef Feature) const override {50return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";51}5253void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,54bool Enabled) const override {55Features[Name] = Enabled;56}57bool handleTargetFeatures(std::vector<std::string> &Features,58DiagnosticsEngine &Diags) override;5960ArrayRef<Builtin::Info> getTargetBuiltins() const override;6162std::string_view getClobbers() const override { return ""; }6364BuiltinVaListKind getBuiltinVaListKind() const override {65return TargetInfo::VoidPtrBuiltinVaList;66}6768bool isValidGCCRegisterName(StringRef Name) const override { return true; }69ArrayRef<const char *> getGCCRegNames() const override {70return std::nullopt;71}7273bool validateAsmConstraint(const char *&Name,74TargetInfo::ConstraintInfo &Info) const override {75switch (*Name) {76default:77break;78case 'w':79if (HasAlu32) {80Info.setAllowsRegister();81}82break;83}84return true;85}8687ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {88return std::nullopt;89}9091bool allowDebugInfoForExternalRef() const override { return true; }9293CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {94switch (CC) {95default:96return CCCR_Warning;97case CC_C:98case CC_OpenCLKernel:99return CCCR_OK;100}101}102103bool isValidCPUName(StringRef Name) const override;104105void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;106107bool setCPU(const std::string &Name) override {108if (Name == "v3" || Name == "v4") {109HasAlu32 = true;110}111112StringRef CPUName(Name);113return isValidCPUName(CPUName);114}115116std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {117return std::make_pair(32, 32);118}119};120} // namespace targets121} // namespace clang122#endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H123124125