|
15 | 15 |
|
16 | 16 | #include "CIRGenBuilder.h" |
17 | 17 | #include "CIRGenCall.h" |
| 18 | +#include "CIRGenTBAA.h" |
18 | 19 | #include "CIRGenTypeCache.h" |
19 | 20 | #include "CIRGenTypes.h" |
20 | 21 | #include "CIRGenVTables.h" |
21 | 22 | #include "CIRGenValue.h" |
22 | 23 |
|
23 | 24 | #include "clang/AST/CharUnits.h" |
| 25 | +#include "clang/CIR/Dialect/IR/CIRAttrs.h" |
24 | 26 | #include "clang/CIR/Dialect/IR/CIRDataLayout.h" |
25 | 27 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
26 | 28 |
|
27 | 29 | #include "TargetInfo.h" |
| 30 | +#include "mlir/Dialect/LLVMIR/LLVMAttrs.h" |
28 | 31 | #include "mlir/IR/Builders.h" |
29 | 32 | #include "mlir/IR/BuiltinOps.h" |
30 | 33 | #include "mlir/IR/MLIRContext.h" |
@@ -85,6 +88,8 @@ class CIRGenModule : public CIRGenTypeCache { |
85 | 88 |
|
86 | 89 | std::unique_ptr<CIRGenCXXABI> abi; |
87 | 90 |
|
| 91 | + std::unique_ptr<CIRGenTBAA> tbaa; |
| 92 | + |
88 | 93 | CIRGenTypes genTypes; |
89 | 94 |
|
90 | 95 | /// Holds information about C++ vtables. |
@@ -324,6 +329,51 @@ class CIRGenModule : public CIRGenTypeCache { |
324 | 329 | /// with codegen. |
325 | 330 | clang::CharUnits getNaturalTypeAlignment(clang::QualType t, |
326 | 331 | LValueBaseInfo *baseInfo); |
| 332 | + /// Get attribute used to describe accesses to objects of |
| 333 | + /// the given type. |
| 334 | + cir::TBAAAttr getTBAATypeInfo(QualType QTy); |
| 335 | + |
| 336 | + /// Get TBAA information that describes an access to an object of the given |
| 337 | + /// type. |
| 338 | + TBAAAccessInfo getTBAAAccessInfo(QualType accessType); |
| 339 | + |
| 340 | + /// Get the TBAA information that describes an access to a virtual table |
| 341 | + /// pointer. |
| 342 | + TBAAAccessInfo getTBAAVTablePtrAccessInfo(mlir::Type VTablePtrType); |
| 343 | + |
| 344 | + mlir::ArrayAttr getTBAAStructInfo(QualType QTy); |
| 345 | + |
| 346 | + /// Get metadata that describes the given base access type. Return null if the |
| 347 | + /// type is not suitable for use in TBAA access tags. |
| 348 | + cir::TBAAAttr getTBAABaseTypeInfo(QualType QTy); |
| 349 | + |
| 350 | + cir::TBAAAttr getTBAAAccessTagInfo(TBAAAccessInfo tbaaInfo); |
| 351 | + |
| 352 | + /// Get merged TBAA information for the purposes of type casts. |
| 353 | + TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, |
| 354 | + TBAAAccessInfo TargetInfo); |
| 355 | + |
| 356 | + /// Get merged TBAA information for the purposes of conditional operator. |
| 357 | + TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, |
| 358 | + TBAAAccessInfo InfoB); |
| 359 | + |
| 360 | + /// Get merged TBAA information for the purposes of memory transfer calls. |
| 361 | + TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, |
| 362 | + TBAAAccessInfo SrcInfo); |
| 363 | + |
| 364 | + /// Get TBAA information for an access with a given base lvalue. |
| 365 | + TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType) { |
| 366 | + if (Base.getTBAAInfo().isMayAlias()) |
| 367 | + return TBAAAccessInfo::getMayAliasInfo(); |
| 368 | + return getTBAAAccessInfo(AccessType); |
| 369 | + } |
| 370 | + |
| 371 | + template <typename Op> |
| 372 | + void decorateOperationWithTBAA(Op op, TBAAAccessInfo tbaaInfo) { |
| 373 | + if (auto tag = getTBAAAccessTagInfo(tbaaInfo)) { |
| 374 | + op.setTbaaAttr(tag); |
| 375 | + } |
| 376 | + } |
327 | 377 |
|
328 | 378 | /// TODO: Add TBAAAccessInfo |
329 | 379 | CharUnits getDynamicOffsetAlignment(CharUnits actualBaseAlign, |
|
0 commit comments