Path: blob/main/contrib/llvm-project/clang/lib/Basic/BuiltinTargetFeatures.h
35233 views
//===-- CodeGenFunction.h - Target features for builtin ---------*- 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 is the internal required target features for builtin.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_BASIC_BUILTINTARGETFEATURES_H13#define LLVM_CLANG_LIB_BASIC_BUILTINTARGETFEATURES_H14#include "llvm/ADT/StringMap.h"15#include "llvm/ADT/StringRef.h"1617using llvm::StringRef;1819namespace clang {20namespace Builtin {21/// TargetFeatures - This class is used to check whether the builtin function22/// has the required tagert specific features. It is able to support the23/// combination of ','(and), '|'(or), and '()'. By default, the priority of24/// ',' is higher than that of '|' .25/// E.g:26/// A,B|C means the builtin function requires both A and B, or C.27/// If we want the builtin function requires both A and B, or both A and C,28/// there are two ways: A,B|A,C or A,(B|C).29/// The FeaturesList should not contain spaces, and brackets must appear in30/// pairs.31class TargetFeatures {32struct FeatureListStatus {33bool HasFeatures;34StringRef CurFeaturesList;35};3637const llvm::StringMap<bool> &CallerFeatureMap;3839FeatureListStatus getAndFeatures(StringRef FeatureList) {40int InParentheses = 0;41bool HasFeatures = true;42size_t SubexpressionStart = 0;43for (size_t i = 0, e = FeatureList.size(); i < e; ++i) {44char CurrentToken = FeatureList[i];45switch (CurrentToken) {46default:47break;48case '(':49if (InParentheses == 0)50SubexpressionStart = i + 1;51++InParentheses;52break;53case ')':54--InParentheses;55assert(InParentheses >= 0 && "Parentheses are not in pair");56[[fallthrough]];57case '|':58case ',':59if (InParentheses == 0) {60if (HasFeatures && i != SubexpressionStart) {61StringRef F = FeatureList.slice(SubexpressionStart, i);62HasFeatures = CurrentToken == ')' ? hasRequiredFeatures(F)63: CallerFeatureMap.lookup(F);64}65SubexpressionStart = i + 1;66if (CurrentToken == '|') {67return {HasFeatures, FeatureList.substr(SubexpressionStart)};68}69}70break;71}72}73assert(InParentheses == 0 && "Parentheses are not in pair");74if (HasFeatures && SubexpressionStart != FeatureList.size())75HasFeatures =76CallerFeatureMap.lookup(FeatureList.substr(SubexpressionStart));77return {HasFeatures, StringRef()};78}7980public:81bool hasRequiredFeatures(StringRef FeatureList) {82FeatureListStatus FS = {false, FeatureList};83while (!FS.HasFeatures && !FS.CurFeaturesList.empty())84FS = getAndFeatures(FS.CurFeaturesList);85return FS.HasFeatures;86}8788TargetFeatures(const llvm::StringMap<bool> &CallerFeatureMap)89: CallerFeatureMap(CallerFeatureMap) {}90};9192} // namespace Builtin93} // namespace clang94#endif /* CLANG_LIB_BASIC_BUILTINTARGETFEATURES_H */959697