1
1
#include " CIRGenTBAA.h"
2
+ #include " CIRGenCXXABI.h"
2
3
#include " CIRGenTypes.h"
3
4
#include " mlir/IR/BuiltinAttributes.h"
4
5
#include " mlir/IR/MLIRContext.h"
5
6
#include " mlir/Interfaces/DataLayoutInterfaces.h"
6
7
#include " clang/AST/ASTContext.h"
7
8
#include " clang/AST/RecordLayout.h"
8
- #include " clang/CIR/Dialect/IR/CIRTypes.h"
9
- #include " clang/CIR/MissingFeatures.h"
10
9
#include " llvm/Support/ErrorHandling.h"
11
10
namespace clang ::CIRGen {
12
11
@@ -22,159 +21,44 @@ CIRGenTBAA::CIRGenTBAA(mlir::MLIRContext *mlirContext,
22
21
: mlirContext(mlirContext), astContext(astContext), types(types),
23
22
moduleOp (moduleOp), codeGenOpts(codeGenOpts), features(features) {}
24
23
25
- cir::TBAAAttr CIRGenTBAA::getChar () {
26
- return cir::TBAAScalarAttr::get (mlirContext,
27
- cir::IntType::get (mlirContext, 1 , true ));
28
- }
29
-
30
- static bool typeHasMayAlias (clang::QualType qty) {
31
- // Tagged types have declarations, and therefore may have attributes.
32
- if (auto *td = qty->getAsTagDecl ())
33
- if (td->hasAttr <MayAliasAttr>())
34
- return true ;
35
-
36
- // Also look for may_alias as a declaration attribute on a typedef.
37
- // FIXME: We should follow GCC and model may_alias as a type attribute
38
- // rather than as a declaration attribute.
39
- while (auto *tt = qty->getAs <TypedefType>()) {
40
- if (tt->getDecl ()->hasAttr <MayAliasAttr>())
41
- return true ;
42
- qty = tt->desugar ();
43
- }
44
- return false ;
45
- }
46
-
47
- // / Check if the given type is a valid base type to be used in access tags.
48
- static bool isValidBaseType (clang::QualType qty) {
49
- if (const clang::RecordType *tty = qty->getAs <clang::RecordType>()) {
50
- const clang::RecordDecl *rd = tty->getDecl ()->getDefinition ();
51
- // Incomplete types are not valid base access types.
52
- if (!rd)
53
- return false ;
54
- if (rd->hasFlexibleArrayMember ())
55
- return false ;
56
- // rd can be struct, union, class, interface or enum.
57
- // For now, we only handle struct and class.
58
- if (rd->isStruct () || rd->isClass ())
59
- return true ;
60
- }
61
- return false ;
62
- }
63
-
64
24
cir::TBAAAttr CIRGenTBAA::getTypeInfo (clang::QualType qty) {
65
- // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
66
- if (codeGenOpts.OptimizationLevel == 0 || codeGenOpts.RelaxedAliasing ) {
67
- return nullptr ;
68
- }
69
-
70
- // If the type has the may_alias attribute (even on a typedef), it is
71
- // effectively in the general char alias class.
72
- if (typeHasMayAlias (qty)) {
73
- assert (!cir::MissingFeatures::tbaaMayAlias ());
74
- return getChar ();
75
- }
76
- // We need this function to not fall back to returning the "omnipotent char"
77
- // type node for aggregate and union types. Otherwise, any dereference of an
78
- // aggregate will result into the may-alias access descriptor, meaning all
79
- // subsequent accesses to direct and indirect members of that aggregate will
80
- // be considered may-alias too.
81
- // function.
82
- if (isValidBaseType (qty)) {
83
- // TODO(cir): support TBAA with struct
84
- return tbaa_NYI (mlirContext);
85
- }
86
-
87
- const clang::Type *ty = astContext.getCanonicalType (qty).getTypePtr ();
88
- if (metadataCache.contains (ty)) {
89
- return metadataCache[ty];
90
- }
91
-
92
- // Note that the following helper call is allowed to add new nodes to the
93
- // cache, which invalidates all its previously obtained iterators. So we
94
- // first generate the node for the type and then add that node to the
95
- // cache.
96
- auto typeNode = cir::TBAAScalarAttr::get (mlirContext, types.ConvertType (qty));
97
- return metadataCache[ty] = typeNode;
25
+ return tbaa_NYI (mlirContext);
98
26
}
99
27
100
28
TBAAAccessInfo CIRGenTBAA::getAccessInfo (clang::QualType accessType) {
101
- // Pointee values may have incomplete types, but they shall never be
102
- // dereferenced.
103
- if (accessType->isIncompleteType ()) {
104
- assert (!cir::MissingFeatures::tbaaIncompleteType ());
105
- return TBAAAccessInfo::getIncompleteInfo ();
106
- }
107
-
108
- if (typeHasMayAlias (accessType)) {
109
- assert (!cir::MissingFeatures::tbaaMayAlias ());
110
- return TBAAAccessInfo::getMayAliasInfo ();
111
- }
112
-
113
- uint64_t size = astContext.getTypeSizeInChars (accessType).getQuantity ();
114
- return TBAAAccessInfo (getTypeInfo (accessType), size);
29
+ return TBAAAccessInfo ();
115
30
}
116
31
117
32
TBAAAccessInfo CIRGenTBAA::getVTablePtrAccessInfo (mlir::Type vtablePtrType) {
118
- // TODO(cir): support vtable ptr
119
- assert (!cir::MissingFeatures::tbaaVTablePtr ());
120
33
return TBAAAccessInfo ();
121
34
}
122
35
123
36
mlir::ArrayAttr CIRGenTBAA::getTBAAStructInfo (clang::QualType qty) {
124
- assert (!cir::MissingFeatures::tbaaStruct () && " tbaa.struct NYI" );
125
- return mlir::ArrayAttr ();
37
+ return mlir::ArrayAttr::get (mlirContext, {});
126
38
}
127
39
128
40
cir::TBAAAttr CIRGenTBAA::getBaseTypeInfo (clang::QualType qty) {
129
41
return tbaa_NYI (mlirContext);
130
42
}
131
43
132
- cir::TBAAAttr CIRGenTBAA::getAccessTagInfo (TBAAAccessInfo tbaaInfo) {
133
- assert (!tbaaInfo.isIncomplete () &&
134
- " Access to an object of an incomplete type!" );
135
-
136
- if (tbaaInfo.isMayAlias ()) {
137
- assert (!cir::MissingFeatures::tbaaMayAlias ());
138
- tbaaInfo = TBAAAccessInfo (getChar (), tbaaInfo.size );
139
- }
140
- if (!tbaaInfo.accessType ) {
141
- return nullptr ;
142
- }
143
-
144
- if (!codeGenOpts.StructPathTBAA )
145
- tbaaInfo = TBAAAccessInfo (tbaaInfo.accessType , tbaaInfo.size );
146
-
147
- if (!tbaaInfo.baseType ) {
148
- tbaaInfo.baseType = tbaaInfo.accessType ;
149
- assert (!tbaaInfo.offset &&
150
- " Nonzero offset for an access with no base type!" );
151
- }
152
- if (codeGenOpts.NewStructPathTBAA ) {
153
- llvm_unreachable (" NYI" );
154
- }
155
- if (tbaaInfo.baseType == tbaaInfo.accessType ) {
156
- return tbaaInfo.accessType ;
157
- }
158
- return tbaa_NYI (mlirContext);
44
+ mlir::ArrayAttr CIRGenTBAA::getAccessTagInfo (TBAAAccessInfo tbaaInfo) {
45
+ return mlir::ArrayAttr::get (mlirContext, {tbaa_NYI (mlirContext)});
159
46
}
160
47
161
48
TBAAAccessInfo CIRGenTBAA::mergeTBAAInfoForCast (TBAAAccessInfo sourceInfo,
162
49
TBAAAccessInfo targetInfo) {
163
- assert (!cir::MissingFeatures::tbaaMergeTBAAInfo ());
164
50
return TBAAAccessInfo ();
165
51
}
166
52
167
53
TBAAAccessInfo
168
54
CIRGenTBAA::mergeTBAAInfoForConditionalOperator (TBAAAccessInfo infoA,
169
55
TBAAAccessInfo infoB) {
170
- assert (!cir::MissingFeatures::tbaaMergeTBAAInfo ());
171
56
return TBAAAccessInfo ();
172
57
}
173
58
174
59
TBAAAccessInfo
175
60
CIRGenTBAA::mergeTBAAInfoForMemoryTransfer (TBAAAccessInfo destInfo,
176
61
TBAAAccessInfo srcInfo) {
177
- assert (!cir::MissingFeatures::tbaaMergeTBAAInfo ());
178
62
return TBAAAccessInfo ();
179
63
}
180
64
0 commit comments