File: ExtraInhabitants.h

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (123 lines) | stat: -rw-r--r-- 4,511 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//===--- ExtraInhabitants.h - Extra inhabitant routines ---------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines routines for working with extra inhabitants.
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_IRGEN_EXTRAINHABITANTS_H
#define SWIFT_IRGEN_EXTRAINHABITANTS_H

#include "IRGen.h"

namespace llvm {
class APInt;
class ConstantInt;
class Value;
}

namespace swift {
namespace irgen {

class Address;
class Alignment;
class IRGenFunction;
class IRGenModule;

/// Whether the zero pointer is a valid value (i.e. not a valid
/// extra inhabitant) of a particular pointer type.
enum IsNullable_t: bool {
  IsNotNullable = false,
  IsNullable = true
};

/// Information about a particular pointer type.
struct PointerInfo {
  Alignment PointeeAlign;
  uint8_t NumReservedLowBits;
  IsNullable_t Nullable;

  static PointerInfo forHeapObject(const IRGenModule &IGM);
  static PointerInfo forFunction(const IRGenModule &IGM);
  static PointerInfo forAligned(Alignment pointeeAlign) {
    return {pointeeAlign, 0, IsNotNullable};
  }

  PointerInfo withNullable(IsNullable_t nullable) const {
    return {PointeeAlign, NumReservedLowBits, nullable};
  }

  /// Return the number of extra inhabitant representations for
  /// pointers with these properties: i.e. the number of values
  /// that do not collide with any valid pointers.
  unsigned getExtraInhabitantCount(const IRGenModule &IGM) const;


  /// Return an indexed extra inhabitant constant for a pointer
  /// with these properties.
  ///
  /// If the pointer appears within a larger aggregate, the
  /// 'bits' and 'offset' arguments can be used to position
  /// the inhabitant within the larger integer constant.
  llvm::APInt getFixedExtraInhabitantValue(const IRGenModule &IGM,
                                           unsigned bits,
                                           unsigned index,
                                           unsigned offset) const;

  /// Given the address of storage for a pointer with these
  /// properties, return the extra inhabitant index of the
  /// value, or -1 if the value is a valid pointer.  Always
  /// produces an i32. 
  llvm::Value *getExtraInhabitantIndex(IRGenFunction &IGF,
                                       Address src) const;

  /// Store an extra inhabitant representation for the given
  /// dynamic extra inhabitant index into the given storage.
  void storeExtraInhabitant(IRGenFunction &IGF,
                            llvm::Value *index,
                            Address dest) const;
};

/*****************************************************************************/

/// \group Extra inhabitants of heap object pointers.

/// Return the number of extra inhabitant representations for heap objects,
/// that is, the number of invalid heap object pointer values that can be used
/// to represent enum tags for enums involving a reference type as a payload.
unsigned getHeapObjectExtraInhabitantCount(const IRGenModule &IGM);
  
/// Return an indexed extra inhabitant constant for a heap object pointer.
///
/// If the pointer appears within a larger aggregate, the 'bits' and 'offset'
/// arguments can be used to position the inhabitant within the larger integer
/// constant.
llvm::APInt getHeapObjectFixedExtraInhabitantValue(const IRGenModule &IGM,
                                                   unsigned bits,
                                                   unsigned index,
                                                   unsigned offset);
  
/// Calculate the index of a heap object extra inhabitant representation stored
/// in memory.
llvm::Value *getHeapObjectExtraInhabitantIndex(IRGenFunction &IGF,
                                               Address src);

/// Calculate an extra inhabitant representation from an index and store it to
/// memory.
void storeHeapObjectExtraInhabitant(IRGenFunction &IGF,
                                    llvm::Value *index,
                                    Address dest);

} // end namespace irgen
} // end namespace swift

#endif