//===--- Builtins.def - Builtins Macro Metaprogramming Database -*- C++ -*-===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See http://swift.org/LICENSE.txt for license information // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // // This file defines the database of builtin functions. // // BUILTIN(Id, Name, Attrs) // - Id is an identifier suitable for use in C++ // - Name is a string literal for the name to which the builtin should be // bound in Swift // - Attrs specifies information about attributes of the function: // n -> readnone // //===----------------------------------------------------------------------===// /// Cast operations have type T1 -> T2. #ifndef BUILTIN_CAST_OPERATION #define BUILTIN_CAST_OPERATION(Id, Name, Attrs) BUILTIN(Id, Name, Attrs) #endif BUILTIN_CAST_OPERATION(Trunc , "trunc", "n") BUILTIN_CAST_OPERATION(ZExt , "zext", "n") BUILTIN_CAST_OPERATION(SExt , "sext", "n") BUILTIN_CAST_OPERATION(FPToUI , "fptoui", "n") BUILTIN_CAST_OPERATION(FPToSI , "fptosi", "n") BUILTIN_CAST_OPERATION(UIToFP , "uitofp", "n") BUILTIN_CAST_OPERATION(SIToFP , "sitofp", "n") BUILTIN_CAST_OPERATION(FPTrunc , "fptrunc", "n") BUILTIN_CAST_OPERATION(FPExt , "fpext", "n") BUILTIN_CAST_OPERATION(PtrToInt, "ptrtoint", "n") BUILTIN_CAST_OPERATION(IntToPtr, "inttoptr", "n") BUILTIN_CAST_OPERATION(BitCast , "bitcast", "n") #undef BUILTIN_CAST_OPERATION /// Cast-or-bitcast operations have type T1 -> T2. /// T1 and T2 may be the same size, unlike the corresponding true casts. #ifndef BUILTIN_CAST_OR_BITCAST_OPERATION #define BUILTIN_CAST_OR_BITCAST_OPERATION(Id, Name, Attrs) BUILTIN(Id, Name, Attrs) #endif BUILTIN_CAST_OR_BITCAST_OPERATION(TruncOrBitCast, "truncOrBitCast", "n") BUILTIN_CAST_OR_BITCAST_OPERATION(ZExtOrBitCast, "zextOrBitCast", "n") BUILTIN_CAST_OR_BITCAST_OPERATION(SExtOrBitCast, "sextOrBitCast", "n") #undef BUILTIN_CAST_OR_BITCAST_OPERATION /// Binary operations have type (T,T) -> T. #ifndef BUILTIN_BINARY_OPERATION #define BUILTIN_BINARY_OPERATION(Id, Name, Attrs, Overload) \ BUILTIN(Id, Name, Attrs) #endif BUILTIN_BINARY_OPERATION(Add, "add", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(FAdd, "fadd", "n", FloatOrVector) BUILTIN_BINARY_OPERATION(And, "and", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(AShr, "ashr", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(LShr, "lshr", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(Or, "or", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(FDiv, "fdiv", "n", FloatOrVector) BUILTIN_BINARY_OPERATION(Mul, "mul", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(FMul, "fmul", "n", FloatOrVector) BUILTIN_BINARY_OPERATION(SDiv, "sdiv", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(ExactSDiv, "sdiv_exact", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(Shl, "shl", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(SRem, "srem", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(Sub, "sub", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(FSub, "fsub", "n", FloatOrVector) BUILTIN_BINARY_OPERATION(UDiv, "udiv", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(ExactUDiv, "udiv_exact", "n", IntegerOrVector) BUILTIN_BINARY_OPERATION(URem, "urem", "n", Integer) BUILTIN_BINARY_OPERATION(Xor, "xor", "n", IntegerOrVector) #undef BUILTIN_BINARY_OPERATION /// These builtins are analogous the similarly named llvm intrinsics. The /// difference between the two is that these are not expected to overflow, /// so we should produce a compile time error if we can statically prove /// that they do. #ifndef BUILTIN_BINARY_OPERATION_WITH_OVERFLOW #define BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(Id, Name, UncheckedID, Attrs, Overload) \ BUILTIN(Id, Name, Attrs) #endif BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(SAddOver, "sadd_with_overflow", Add, "n", Integer) BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(UAddOver, "uadd_with_overflow", Add, "n", Integer) BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(SSubOver, "ssub_with_overflow", Sub, "n", Integer) BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(USubOver, "usub_with_overflow", Sub, "n", Integer) BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(SMulOver, "smul_with_overflow", Mul, "n", Integer) BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(UMulOver, "umul_with_overflow", Mul, "n", Integer) #undef BUILTIN_BINARY_OPERATION_WITH_OVERFLOW /// Unary operations have type (T) -> T. #ifndef BUILTIN_UNARY_OPERATION #define BUILTIN_UNARY_OPERATION(Id, Name, Attrs, Overload) \ BUILTIN(Id, Name, Attrs) #endif // "fneg" is a separate builtin because its LLVM representation is // 'fsub -0.0, %x', but defining it in swift as // 'func [prefix] -(x) { -0.0 - x }' would be infinitely recursive. BUILTIN_UNARY_OPERATION(FNeg, "fneg", "n", FloatOrVector) #undef BUILTIN_UNARY_OPERATION // Binary predicates have type (T,T) -> i1 or (T, T) -> Vector for scalars // and vectors, respectively. #ifndef BUILTIN_BINARY_PREDICATE #define BUILTIN_BINARY_PREDICATE(Id, Name, Attrs, Overload) \ BUILTIN(Id, Name, Attrs) #endif BUILTIN_BINARY_PREDICATE(ICMP_EQ, "cmp_eq", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_NE, "cmp_ne", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_SLE, "cmp_sle", "n", IntegerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_SLT, "cmp_slt", "n", IntegerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_SGE, "cmp_sge", "n", IntegerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_SGT, "cmp_sgt", "n", IntegerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_ULE, "cmp_ule", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_ULT, "cmp_ult", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_UGE, "cmp_uge", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(ICMP_UGT, "cmp_ugt", "n", IntegerOrRawPointerOrVector) BUILTIN_BINARY_PREDICATE(FCMP_OEQ, "fcmp_oeq", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_OGT, "fcmp_ogt", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_OGE, "fcmp_oge", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_OLT, "fcmp_olt", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_OLE, "fcmp_ole", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_ONE, "fcmp_one", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_ORD, "fcmp_ord", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_UEQ, "fcmp_ueq", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_UGT, "fcmp_ugt", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_UGE, "fcmp_uge", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_ULT, "fcmp_ult", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_ULE, "fcmp_ule", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_UNE, "fcmp_une", "n", FloatOrVector) BUILTIN_BINARY_PREDICATE(FCMP_UNO, "fcmp_uno", "n", FloatOrVector) #undef BUILTIN_BINARY_PREDICATE // BUILTIN_SIL_OPERATION - Operations that can be lowered to SIL instructions. // These have various types. // Since these operations will be lowered to SIL Instructions, we do not // assign any attributes on them. #ifndef BUILTIN_SIL_OPERATION #define BUILTIN_SIL_OPERATION(Id, Name, Overload) BUILTIN(Id, Name, "") #endif /// retain: T -> () BUILTIN_SIL_OPERATION(Retain, "retain", Special) /// release: T -> () BUILTIN_SIL_OPERATION(Release, "release", Special) /// autorelease: T -> () BUILTIN_SIL_OPERATION(Autorelease, "autorelease", Special) /// Load has type (Builtin.RawPointer) -> T BUILTIN_SIL_OPERATION(Load, "load", Special) /// Take has type (Builtin.RawPointer) -> T BUILTIN_SIL_OPERATION(Take, "take", Special) /// Destroy has type (T.Type, Builtin.RawPointer) -> () BUILTIN_SIL_OPERATION(Destroy, "destroy", Special) /// Assign has type (T, Builtin.RawPointer) -> () BUILTIN_SIL_OPERATION(Assign, "assign", Special) /// Init has type (T, Builtin.RawPointer) -> () BUILTIN_SIL_OPERATION(Init, "initialize", Special) /// CastToNativeObject has type (T) -> Builtin.NativeObject. BUILTIN_SIL_OPERATION(CastToNativeObject, "castToNativeObject", Special) /// CastFromNativeObject has type (Builtin.NativeObject) -> T BUILTIN_SIL_OPERATION(CastFromNativeObject, "castFromNativeObject", Special) /// BridgeToRawPointer has type (T) -> Builtin.RawPointer BUILTIN_SIL_OPERATION(BridgeToRawPointer, "bridgeToRawPointer", Special) /// BridgeFromRawPointer (Builtin.RawPointer) -> T /// SILGen requires that T is a single retainable pointer. /// Bridging to/from a raw pointer does not imply a retain. BUILTIN_SIL_OPERATION(BridgeFromRawPointer, "bridgeFromRawPointer", Special) /// addressof ([inout] T) -> Builtin.RawPointer /// Returns a RawPointer pointing to an lvalue. The returned pointer is only /// valid within the scope of the statement for logical lvalues. BUILTIN_SIL_OPERATION(AddressOf, "addressof", Special) /// typeof(T) -> T.Type /// Returns the runtime type of a value. BUILTIN_SIL_OPERATION(TypeOf, "typeof", Special) /// GetElementPtr has type (Builtin.RawPointer, T) -> Builtin.RawPointer BUILTIN_SIL_OPERATION(Gep, "gep", Integer) /// condfail(Int1) -> () /// Triggers a runtime failure if the condition is true. BUILTIN_SIL_OPERATION(CondFail, "condfail", Special) /// fixLifetime(T) -> () /// Fixes the lifetime of any heap references in a value. BUILTIN_SIL_OPERATION(FixLifetime, "fixLifetime", Special) #undef BUILTIN_SIL_OPERATION // BUILTIN_MISC_OPERATION - Miscellaneous operations without a unifying class. // These have various types. #ifndef BUILTIN_MISC_OPERATION #define BUILTIN_MISC_OPERATION(Id, Name, Attrs, Overload) \ BUILTIN(Id, Name, Attrs) #endif /// Sizeof has type T.Type -> Int BUILTIN_MISC_OPERATION(Sizeof, "sizeof", "n", Special) /// Strideof has type T.Type -> Int BUILTIN_MISC_OPERATION(Strideof, "strideof", "n", Special) /// Alignof has type T.Type -> Int BUILTIN_MISC_OPERATION(Alignof, "alignof", "n", Special) /// AllocRaw has type (Int, Int) -> Builtin.RawPointer BUILTIN_MISC_OPERATION(AllocRaw, "allocRaw", "", Special) /// DeallocRaw has type (Builtin.RawPointer, Int) -> () BUILTIN_MISC_OPERATION(DeallocRaw, "deallocRaw", "", Special) /// Fence has type () -> (). BUILTIN_MISC_OPERATION(Fence, "fence", "", None) /// CmpXChg has type (Builtin.RawPointer, T, T) -> T. BUILTIN_MISC_OPERATION(CmpXChg, "cmpxchg", "", Special) /// AtomicRMW has type (Builtin.RawPointer, T) -> T. BUILTIN_MISC_OPERATION(AtomicRMW, "atomicrmw", "", IntegerOrRawPointer) /// ExtractElement has type (Vector, Int32) -> T BUILTIN_MISC_OPERATION(ExtractElement, "extractelement", "n", Special) /// InsertElement has type (Vector, T, Int32) -> Vector. BUILTIN_MISC_OPERATION(InsertElement, "insertelement", "n", Special) /// StaticReport has type (Builtin.Int1, Builtin.Int1, Builtin.RawPointer) -> () BUILTIN_MISC_OPERATION(StaticReport, "staticReport", "", Special) /// assert_configuration has type () -> Builtin.Int32 /// Returns the selected assertion configuration. BUILTIN_MISC_OPERATION(AssertConf, "assert_configuration", "n", Special) /// Special truncation builtins that check for sign and overflow errors. These /// take an integer as an input and return a tuple of the truncated result and /// an error bit. The name of each builtin is extended with the "from" /// (sign-agnostic) builtin integer type and the "to" integer type. /// We require the source type size to be larger than the destination type size /// (number of bits). BUILTIN_MISC_OPERATION(UToSCheckedTrunc, "u_to_s_checked_trunc", "n", Special) BUILTIN_MISC_OPERATION(SToSCheckedTrunc, "s_to_s_checked_trunc", "n", Special) BUILTIN_MISC_OPERATION(SToUCheckedTrunc, "s_to_u_checked_trunc", "n", Special) BUILTIN_MISC_OPERATION(UToUCheckedTrunc, "u_to_u_checked_trunc", "n", Special) /// Checked conversions for signed <-> unsigned integers of the same size. /// Returns a tuple containing the conversion result as well as /// the sign error / overflow bit. BUILTIN_MISC_OPERATION(SUCheckedConversion, "s_to_u_checked_conversion", "n", Special) BUILTIN_MISC_OPERATION(USCheckedConversion, "u_to_s_checked_conversion", "n", Special) /// IntToFPWithOverflow has type (Integer) -> Float BUILTIN_MISC_OPERATION(IntToFPWithOverflow, "itofp_with_overflow", "n", Special) // FIXME: shufflevector /// once has type (Builtin.RawPointer, () -> ()) BUILTIN_MISC_OPERATION(Once, "once", "", Special) /// unreachable has type @noreturn () -> () BUILTIN_MISC_OPERATION(Unreachable, "unreachable", "", Special) /// conditionallyUnreachable has type @noreturn () -> () BUILTIN_MISC_OPERATION(CondUnreachable, "conditionallyUnreachable", "", Special) /// DestroyArray has type (T.Type, Builtin.RawPointer, Builtin.Word) -> () BUILTIN_MISC_OPERATION(DestroyArray, "destroyArray", "", Special) /// CopyArray, TakeArrayFrontToBack, and TakeArrayBackToFront all have type /// (T.Type, Builtin.RawPointer, Builtin.RawPointer, Builtin.Word) -> () BUILTIN_MISC_OPERATION(CopyArray, "copyArray", "", Special) BUILTIN_MISC_OPERATION(TakeArrayFrontToBack, "takeArrayFrontToBack", "", Special) BUILTIN_MISC_OPERATION(TakeArrayBackToFront, "takeArrayBackToFront", "", Special) #undef BUILTIN_MISC_OPERATION // BUILTIN_TYPE_TRAIT_OPERATION - Compile-time type trait operations. #ifndef BUILTIN_TYPE_TRAIT_OPERATION #define BUILTIN_TYPE_TRAIT_OPERATION(Id, Name) \ BUILTIN(Id, #Name, "n") #endif /// canBeClass(T.Type) -> Builtin.Int1 /// At compile time, evaluate whether T is or can be bound to a class or /// @objc protocol type. BUILTIN_TYPE_TRAIT_OPERATION(CanBeObjCClass, canBeClass) #undef BUILTIN_TYPE_TRAIT_OPERATION #undef BUILTIN