LLVM: include/llvm/Support/CheckedArithmetic.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_SUPPORT_CHECKEDARITHMETIC_H

15#define LLVM_SUPPORT_CHECKEDARITHMETIC_H

16

18

19#include

20#include <type_traits>

21

22namespace {

23

24

25

26

27template <typename T, typename F>

28std::enable_if_t<std::is_integral_v && sizeof(T) * 8 <= 64, std::optional>

32 bool Overflow;

34 if (Overflow)

35 return std::nullopt;

37}

38}

39

40namespace llvm {

41

42

43

44

45template

50

51

52

53

54template

59

60

61

62

63template

68

69

70

71

72template

73std::enable_if_t<std::is_signed_v, std::optional> checkedMulAdd(T A, T B,

74 T C) {

77 return std::nullopt;

78}

79

80

81

82

83template

84std::enable_if_t<std::is_unsigned_v, std::optional>

88

89

90

91

92template

93std::enable_if_t<std::is_unsigned_v, std::optional>

97

98

99

100

101template

102std::enable_if_t<std::is_unsigned_v, std::optional>

106 return std::nullopt;

107}

108

109}

110

111#endif

This file implements a class to represent arbitrary precision integral constant values and operations...

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

Class for arbitrary precision integers.

LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const

uint64_t getZExtValue() const

Get zero extended value.

LLVM_ABI APInt sadd_ov(const APInt &RHS, bool &Overflow) const

LLVM_ABI APInt uadd_ov(const APInt &RHS, bool &Overflow) const

LLVM_ABI APInt smul_ov(const APInt &RHS, bool &Overflow) const

LLVM_ABI APInt ssub_ov(const APInt &RHS, bool &Overflow) const

int64_t getSExtValue() const

Get sign extended value.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

std::enable_if_t< std::is_unsigned_v< T >, std::optional< T > > checkedMulUnsigned(T LHS, T RHS)

Multiply two unsigned integers LHS and RHS.

Definition CheckedArithmetic.h:94

std::enable_if_t< std::is_unsigned_v< T >, std::optional< T > > checkedAddUnsigned(T LHS, T RHS)

Add two unsigned integers LHS and RHS.

Definition CheckedArithmetic.h:85

std::enable_if_t< std::is_unsigned_v< T >, std::optional< T > > checkedMulAddUnsigned(T A, T B, T C)

Multiply unsigned integers A and B, and add C to the resulting product.

Definition CheckedArithmetic.h:103

std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedSub(T LHS, T RHS)

Subtract two signed integers LHS and RHS.

Definition CheckedArithmetic.h:55

std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedAdd(T LHS, T RHS)

Add two signed integers LHS and RHS.

Definition CheckedArithmetic.h:46

std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedMulAdd(T A, T B, T C)

Multiply A and B, and add C to the resulting product.

Definition CheckedArithmetic.h:73

std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedMul(T LHS, T RHS)

Multiply two signed integers LHS and RHS.

Definition CheckedArithmetic.h:64