Files
swift-mirror/include/swift/AST/Builtins.h
Anna Zaks 740fc0a9d9 Revert "Revert "Reimplement integer arithmetic overflow checking to use special, error on overflow builtins""
(This only fails under -DSWIFT_OPTIMIZED=NO; most likely due to an llvm bug.)

We've decided that it's best to specialize each arithmetic builtin that could overflow, instead of calling a separate generic "staticReport" builtin and passing it enough info to produce the message. The main advantage of this approach is that it would be possible for the compiler to customize the message and better link it to the builtin that overflows. For example, the constants that participated in the computation could be printed. In addition, less code will be generated and the compiler could, in the future, automatically emit the overflow diagnostics/trap at runtime.

This patch introduces new versions of op_with_overflow swift builtins. Which are lowered to llvm.op_with_overflow builtins in IRGen after the static diagnostics. If the last argument to the builtins evaluates to true, the overflow is unintentional. CCP uses the builtins to diagnose the overflow detectable at compile time. FixedPoint is changed to rely on these in implementation of primitive arithmetic operations.

Swift SVN r9328
2013-10-14 21:42:33 +00:00

111 lines
3.4 KiB
C++

//===--- Builtins.h - Swift Builtin Functions -------------------*- 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 interface to builtin functions.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_BUILTINS_H
#define SWIFT_AST_BUILTINS_H
#include "swift/Basic/LLVM.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Attributes.h"
#include "swift/AST/Type.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/Support/ErrorHandling.h"
namespace swift {
class ASTContext;
class Identifier;
class ValueDecl;
/// Get the builtin type for the given name.
///
/// Returns a null type if the name is not a known builtin type name.
Type getBuiltinType(ASTContext &Context, StringRef Name);
/// OverloadedBuiltinKind - Whether and how a builtin is overloaded.
enum class OverloadedBuiltinKind : unsigned char {
/// The builtin is not overloaded.
None,
/// The builtin is overloaded over all integer types.
Integer,
/// The builtin is overloaded over all integer types and vectors of integers.
IntegerOrVector,
/// The builtin is overloaded over all integer types and the raw pointer type.
IntegerOrRawPointer,
/// The builtin is overloaded over all integer types, the raw pointer type,
/// and vectors of integers.
IntegerOrRawPointerOrVector,
/// The builtin is overloaded over all floating-point types.
Float,
/// The builtin is overloaded over all floating-point types and vectors of
/// floating-point types.
FloatOrVector,
/// The builtin has custom processing.
Special
};
/// BuiltinValueKind - The set of (possibly overloaded) builtin functions.
enum class BuiltinValueKind {
None = 0,
#define BUILTIN(Id, Name, Attrs) Id,
#include "swift/AST/Builtins.def"
};
/// Decode the type list of a builtin (e.g. mul_Int32) and return the base
/// name (e.g. "mul").
StringRef getBuiltinBaseName(ASTContext &C, StringRef Name,
SmallVectorImpl<Type> &Types);
/// Given an LLVM IR intrinsic name with argument types remove (e.g. like
/// "bswap") return the LLVM IR IntrinsicID for the intrinsic or 0 if the
/// intrinsic name doesn't match anything.
unsigned getLLVMIntrinsicID(StringRef Name, bool HasArgTypes);
/// Get the LLVM intrinsic ID that corresponds to the given builtin with
/// overflow.
llvm::Intrinsic::ID
getLLVMIntrinsicIDForBuiltinWithOverflow(BuiltinValueKind ID);
/// \brief Finds the builtin value with the given name.
///
/// Returns null if the name does not identifier a known builtin value.
ValueDecl *getBuiltinValue(ASTContext &Context, Identifier Name);
/// \brief The information identifying the builtin - it's kind and types.
struct BuiltinInfo {
BuiltinValueKind ID;
SmallVector<Type, 4> Types;
bool isReadNone() const;
};
/// \brief The information identifying the llvm intrinsic - it's id and types.
struct IntrinsicInfo {
llvm::Intrinsic::ID ID;
SmallVector<Type, 4> Types;
bool hasAttribute(llvm::Attribute::AttrKind Kind) const;
};
}
#endif