1//===--- BuiltinsBase.td - common structured used by builtins ---*- 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// Attributes 10// ========== 11 12class Attribute<string mangling> { 13 string Mangling = mangling; 14} 15 16class IndexedAttribute<string baseMangling, int I> : Attribute<baseMangling> { 17 int Index = I; 18} 19 20class MultiIndexAttribute<string baseMangling, list<int> Is> 21 : Attribute<baseMangling> { 22 list<int> Indices = Is; 23} 24 25// Standard Attributes 26// ------------------- 27def NoReturn : Attribute<"r">; 28 29// Attributes from the gnu:: namespace 30// ----------------------------------- 31def Const : Attribute<"c">; 32def NoThrow : Attribute<"n">; 33def Pure : Attribute<"U">; 34def ReturnsTwice : Attribute<"j">; 35// FIXME: gcc has nonnull 36 37// builtin-specific attributes 38// --------------------------- 39 40// Signature is meaningless, use custom typechecking. 41def CustomTypeChecking : Attribute<"t">; 42 43// Type is not important to semantic analysis and codegen; recognize as builtin 44// even if type doesn't match signature, and don't warn if we can't be sure the 45// type is right. 46def IgnoreSignature : Attribute<"T">; 47 48// Arguments are not evaluated for their side-effects. 49def UnevaluatedArguments : Attribute<"u">; 50 51// FIXME: This is misused in a lot of the places it is used currently. 52// This function is equivalent to a library function without the __builtin_ 53// prefix. This is relevant for CodeGen; it should not be used if custom CodeGen 54// is required for a builtin. 55def FunctionWithBuiltinPrefix : Attribute<"F">; 56 57def FunctionWithoutBuiltinPrefix : Attribute<"f">; 58 59// const, but only when -fno-math-errno and FP exceptions are ignored. 60def ConstIgnoringErrnoAndExceptions : Attribute<"e">; 61 62// const when FP exceptions are ignored. 63def ConstIgnoringExceptions : Attribute<"g">; 64 65// This function requires a specific header or an explicit declaration. 66def RequireDeclaration : Attribute<"h">; 67 68// FIXME: Why is this not simply the min_vector_width attribute? 69// Vector has to be at least N bits wide. 70class RequiredVectorWidth<int N> : IndexedAttribute<"V", N>; 71 72class PrintfFormat<int I> : IndexedAttribute<"p", I>; 73class VPrintfFormat<int I> : IndexedAttribute<"P", I>; 74class ScanfFormat<int I> : IndexedAttribute<"s", I>; 75class VScanfFormat<int I> : IndexedAttribute<"S", I>; 76 77// Other Attributes 78// ---------------- 79 80// Builtin can be constant evaluated 81def Constexpr : Attribute<"E">; 82// Builtin is immediate and must be constant evaluated. Implies Constexpr, and will only be supported in C++20 mode. 83def Consteval : Attribute<"EG">; 84 85// Callback behavior: the first index argument is called with the arguments 86// indicated by the remaining indices. 87class Callback<list<int> ArgIndices> : MultiIndexAttribute<"C", ArgIndices>; 88 89// Builtin kinds 90// ============= 91 92class Builtin { 93 list<string> Spellings; 94 list<Attribute> Attributes = []; 95 string Prototype; 96 string Namespace; 97 // On some platforms, some functions are actually macros. In that case we need 98 // to #undef them. 99 bit RequiresUndef = 0; 100 // Enables builtins to generate `long long` outside of OpenCL and `long` inside. 101 bit EnableOpenCLLong = 0; 102} 103 104class AtomicBuiltin : Builtin; 105 106class LibBuiltin<string header, string languages = "ALL_LANGUAGES"> : Builtin { 107 string Header = header; 108 string Languages = languages; 109 bit AddBuiltinPrefixedAlias = 0; 110 bit OnlyBuiltinPrefixedAliasIsConstexpr = 0; 111} 112 113class MSLibBuiltin<string header> : LibBuiltin<header, "ALL_MS_LANGUAGES">; 114class GNULibBuiltin<string header> : LibBuiltin<header, "ALL_GNU_LANGUAGES">; 115class ObjCLibBuiltin<string header> : LibBuiltin<header, "OBJC_LANG">; 116class CxxLibBuiltin<string header> : LibBuiltin<header, "CXX_LANG">; 117 118class LangBuiltin<string languages> : Builtin { 119 string Languages = languages; 120} 121 122class MSLangBuiltin : LangBuiltin<"ALL_MS_LANGUAGES">; 123class CoroLangBuiltin : LangBuiltin<"COR_LANG">; 124class OCLPipeLangBuiltin : LangBuiltin<"OCL_PIPE">; 125class OCL_DSELangBuiltin : LangBuiltin<"OCL_DSE">; 126class OCL_GASLangBuiltin : LangBuiltin<"OCL_GAS">; 127class OCLLangBuiltin : LangBuiltin<"ALL_OCL_LANGUAGES">; 128 129class TargetBuiltin : Builtin { 130 string Features = ""; 131} 132class TargetLibBuiltin : TargetBuiltin { 133 string Header; 134 string Languages = "ALL_LANGUAGES"; 135} 136 137class Template<list<string> substitutions, 138 list<string> affixes, 139 bit as_prefix = 0> { 140 list<string> Substitutions = substitutions; 141 list<string> Affixes = affixes; 142 bit AsPrefix = as_prefix; 143} 144