clang
20.0.0git
lib
CodeGen
CGBlocks.h
Go to the documentation of this file.
1
//===-- CGBlocks.h - state for LLVM CodeGen for blocks ----------*- 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
// This is the internal state used for llvm translation for block literals.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_LIB_CODEGEN_CGBLOCKS_H
14
#define LLVM_CLANG_LIB_CODEGEN_CGBLOCKS_H
15
16
#include "
CGBuilder.h
"
17
#include "
CGCall.h
"
18
#include "
CGValue.h
"
19
#include "
CodeGenFunction.h
"
20
#include "
CodeGenTypes.h
"
21
#include "
clang/AST/CharUnits.h
"
22
#include "
clang/AST/Expr.h
"
23
#include "
clang/AST/ExprCXX.h
"
24
#include "
clang/AST/ExprObjC.h
"
25
#include "
clang/AST/Type.h
"
26
#include "
clang/Basic/TargetInfo.h
"
27
28
namespace
llvm
{
29
class
Value
;
30
}
31
32
namespace
clang
{
33
namespace
CodeGen {
34
35
class
CGBlockInfo;
36
37
// Flags stored in __block variables.
38
enum
BlockByrefFlags
{
39
BLOCK_BYREF_HAS_COPY_DISPOSE
= (1 << 25),
// compiler
40
BLOCK_BYREF_LAYOUT_MASK
= (0xF << 28),
// compiler
41
BLOCK_BYREF_LAYOUT_EXTENDED
= (1 << 28),
42
BLOCK_BYREF_LAYOUT_NON_OBJECT
= (2 << 28),
43
BLOCK_BYREF_LAYOUT_STRONG
= (3 << 28),
44
BLOCK_BYREF_LAYOUT_WEAK
= (4 << 28),
45
BLOCK_BYREF_LAYOUT_UNRETAINED
= (5 << 28)
46
};
47
48
enum
BlockLiteralFlags
{
49
BLOCK_IS_NOESCAPE
= (1 << 23),
50
BLOCK_HAS_COPY_DISPOSE
= (1 << 25),
51
BLOCK_HAS_CXX_OBJ
= (1 << 26),
52
BLOCK_IS_GLOBAL
= (1 << 28),
53
BLOCK_USE_STRET
= (1 << 29),
54
BLOCK_HAS_SIGNATURE
= (1 << 30),
55
BLOCK_HAS_EXTENDED_LAYOUT
= (1u << 31)
56
};
57
class
BlockFlags
{
58
uint32_t flags;
59
60
public
:
61
BlockFlags
(uint32_t flags) : flags(flags) {}
62
BlockFlags
() : flags(0) {}
63
BlockFlags
(
BlockLiteralFlags
flag) : flags(flag) {}
64
BlockFlags
(
BlockByrefFlags
flag) : flags(flag) {}
65
66
uint32_t
getBitMask
()
const
{
return
flags; }
67
bool
empty
()
const
{
return
flags == 0; }
68
69
friend
BlockFlags
operator|
(
BlockFlags
l,
BlockFlags
r) {
70
return
BlockFlags
(l.flags | r.flags);
71
}
72
friend
BlockFlags
&
operator|=
(
BlockFlags
&l,
BlockFlags
r) {
73
l.flags |= r.flags;
74
return
l;
75
}
76
friend
bool
operator&
(
BlockFlags
l,
BlockFlags
r) {
77
return
(l.flags & r.flags);
78
}
79
bool
operator==
(
BlockFlags
r) {
80
return
(flags == r.flags);
81
}
82
};
83
inline
BlockFlags
operator|
(
BlockLiteralFlags
l,
BlockLiteralFlags
r) {
84
return
BlockFlags
(l) |
BlockFlags
(r);
85
}
86
87
enum
BlockFieldFlag_t
{
88
BLOCK_FIELD_IS_OBJECT
= 0x03,
/* id, NSObject, __attribute__((NSObject)),
89
block, ... */
90
BLOCK_FIELD_IS_BLOCK
= 0x07,
/* a block variable */
91
92
BLOCK_FIELD_IS_BYREF
= 0x08,
/* the on stack structure holding the __block
93
variable */
94
BLOCK_FIELD_IS_WEAK
= 0x10,
/* declared __weak, only used in byref copy
95
helpers */
96
BLOCK_FIELD_IS_ARC
= 0x40,
/* field has ARC-specific semantics */
97
BLOCK_BYREF_CALLER
= 128,
/* called from __block (byref) copy/dispose
98
support routines */
99
BLOCK_BYREF_CURRENT_MAX
= 256
100
};
101
102
class