Skip to content

Commit 089a2b4

Browse files
committed
[CIR][CIRGen] Add support for TBAA
1 parent dbf320e commit 089a2b4

24 files changed

+1613
-168
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
160160
llvm_unreachable("Zero initializer for given type is NYI");
161161
}
162162

163-
mlir::Value createLoad(mlir::Location loc, mlir::Value ptr,
164-
bool isVolatile = false, uint64_t alignment = 0) {
163+
mlir::cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
164+
bool isVolatile = false,
165+
uint64_t alignment = 0) {
165166
mlir::IntegerAttr intAttr;
166167
if (alignment)
167168
intAttr = mlir::IntegerAttr::get(
@@ -575,8 +576,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
575576
});
576577

577578
if (last != block->rend())
578-
return OpBuilder::InsertPoint(block,
579-
++mlir::Block::iterator(&*last));
579+
return OpBuilder::InsertPoint(block, ++mlir::Block::iterator(&*last));
580580
return OpBuilder::InsertPoint(block, block->begin());
581581
};
582582

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct MissingFeatures {
5858
// sanitizer related type check features
5959
static bool buildTypeCheck() { return false; }
6060
static bool tbaa() { return false; }
61+
static bool tbaa_struct() { return false; }
6162
static bool cleanups() { return false; }
6263
static bool emitNullabilityCheck() { return false; }
6364
static bool ptrAuth() { return false; }

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
590590
case AtomicExpr::AO__atomic_load:
591591
case AtomicExpr::AO__scoped_atomic_load_n:
592592
case AtomicExpr::AO__scoped_atomic_load: {
593-
auto *load = builder.createLoad(loc, Ptr).getDefiningOp();
593+
auto load = builder.createLoad(loc, Ptr);
594594
// FIXME(cir): add scope information.
595595
assert(!MissingFeatures::syncScopeID());
596596
load->setAttr("mem_order", orderAttr);
@@ -1468,8 +1468,7 @@ void CIRGenFunction::buildAtomicStore(RValue rvalue, LValue dest,
14681468
if (IsVolatile)
14691469
store.setIsVolatile(true);
14701470

1471-
// DecorateInstructionWithTBAA
1472-
assert(!MissingFeatures::tbaa());
1471+
CGM.decorateOperationWithTBAA(store, dest.getTBAAInfo());
14731472
return;
14741473
}
14751474

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,8 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
843843
addr.getAlignment());
844844
}
845845

846-
mlir::Value createLoad(mlir::Location loc, Address addr,
847-
bool isVolatile = false) {
846+
mlir::cir::LoadOp createLoad(mlir::Location loc, Address addr,
847+
bool isVolatile = false) {
848848
auto ptrTy =
849849
mlir::dyn_cast<mlir::cir::PointerType>(addr.getPointer().getType());
850850
if (addr.getElementType() != ptrTy.getPointee())

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,14 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
743743
assert(!MissingFeatures::addressSpace());
744744
VTableField = builder.createElementBitCast(loc, VTableField,
745745
VTableAddressPoint.getType());
746-
builder.createStore(loc, VTableAddressPoint, VTableField);
747-
assert(!MissingFeatures::tbaa());
746+
auto storeOp = builder.createStore(loc, VTableAddressPoint, VTableField);
747+
TBAAAccessInfo TBAAInfo =
748+
CGM.getTBAAVTablePtrAccessInfo(VTableAddressPoint.getType());
749+
CGM.decorateOperationWithTBAA(storeOp, TBAAInfo);
750+
if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
751+
CGM.getCodeGenOpts().StrictVTablePointers) {
752+
assert(!MissingFeatures::createInvariantGroup());
753+
}
748754
}
749755

750756
void CIRGenFunction::initializeVTablePointers(mlir::Location loc,
@@ -1663,14 +1669,16 @@ mlir::Value CIRGenFunction::getVTablePtr(mlir::Location Loc, Address This,
16631669

16641670
Address CIRGenFunction::buildCXXMemberDataPointerAddress(
16651671
const Expr *E, Address base, mlir::Value memberPtr,
1666-
const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo) {
1672+
const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo,
1673+
TBAAAccessInfo *tbaaInfo) {
16671674
assert(!MissingFeatures::cxxABI());
16681675

16691676
auto op = builder.createGetIndirectMember(getLoc(E->getSourceRange()),
16701677
base.getPointer(), memberPtr);
16711678

16721679
QualType memberType = memberPtrType->getPointeeType();
1673-
CharUnits memberAlign = CGM.getNaturalTypeAlignment(memberType, baseInfo);
1680+
CharUnits memberAlign =
1681+
CGM.getNaturalTypeAlignment(memberType, baseInfo, tbaaInfo);
16741682
memberAlign = CGM.getDynamicOffsetAlignment(
16751683
base.getAlignment(), memberPtrType->getClass()->getAsCXXRecordDecl(),
16761684
memberAlign);

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void CIRGenFunction::buildAutoVarInit(const AutoVarEmission &emission) {
327327
// its removal/optimization to the CIR lowering.
328328
if (!constant || isa<CXXTemporaryObjectExpr>(Init)) {
329329
initializeWhatIsTechnicallyUninitialized(Loc);
330-
LValue lv = LValue::makeAddr(Loc, type, AlignmentSource::Decl);
330+
LValue lv = makeAddrLValue(Loc, type);
331331
buildExprAsInit(Init, &D, lv);
332332
// In case lv has uses it means we indeed initialized something
333333
// out of it while trying to build the expression, mark it as such.

0 commit comments

Comments
 (0)