Skip to content

Commit 4a96555

Browse files
committed
Address review feedback
1 parent 9200392 commit 4a96555

File tree

12 files changed

+48
-97
lines changed

12 files changed

+48
-97
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,31 +2620,25 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
26202620
}];
26212621

26222622
let arguments = (ins
2623-
OptionalAttr<FlatSymbolRefAttr>:$name,
2624-
Optional<CIR_AnyType>:$sym_addr,
2623+
FlatSymbolRefAttr:$name,
26252624
CIR_AddressPointAttr:$address_point
26262625
);
26272626

26282627
let results = (outs Res<CIR_PtrToVPtr, "", []>:$addr);
26292628

26302629
let assemblyFormat = [{
26312630
`(`
2632-
($name^)?
2633-
($sym_addr^ `:` type($sym_addr))?
2634-
`,`
2635-
`address_point` `=` $address_point
2631+
$name `,` `address_point` `=` $address_point
26362632
`)`
26372633
`:` qualified(type($addr)) attr-dict
26382634
}];
2639-
2640-
let hasVerifier = 1;
26412635
}
26422636

26432637
//===----------------------------------------------------------------------===//
2644-
// VTableGetVptr
2638+
// VTableGetVPtr
26452639
//===----------------------------------------------------------------------===//
26462640

2647-
def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2641+
def CIR_VTableGetVPtrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
26482642
let summary = "Get a the address of the vtable pointer for an object";
26492643
let description = [{
26502644
The `vtable.get_vptr` operation retrieves the address of the vptr for a
@@ -2663,13 +2657,13 @@ def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
26632657
}];
26642658

26652659
let arguments = (ins
2666-
Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src);
2667-
2668-
let results = (outs CIR_PtrToVPtr:$vptr_ty);
2660+
Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src
2661+
);
26692662

2663+
let results = (outs CIR_PtrToVPtr:$result);
26702664

26712665
let assemblyFormat = [{
2672-
$src `:` qualified(type($src)) `->` qualified(type($vptr_ty)) attr-dict
2666+
$src `:` qualified(type($src)) `->` qualified(type($result)) attr-dict
26732667
}];
26742668

26752669
}
@@ -2689,14 +2683,18 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
26892683
the address of the virtual function pointer, which can then be loaded and
26902684
called.
26912685

2686+
The `vptr` operand must be a `!cir.ptr<!cir.vptr>` value, which would
2687+
have been returned by a previous call to `cir.vatble.get_vptr`. The
2688+
`index` operand is an index of the virtual function in the vtable.
2689+
26922690
The return type is a pointer-to-pointer to the function type.
26932691

26942692
Example:
26952693
```mlir
26962694
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_C>>, !cir.ptr<!rec_C>
26972695
%3 = cir.vtable.get_vptr %2 : !cir.ptr<!rec_C> -> !cir.ptr<!cir.vptr>
26982696
%4 = cir.load %3 : !cir.ptr<!cir.vptr>, !cir.vptr
2699-
%5 = cir.vtable.get_virtual_fn_addr(%4, index = 2) : !cir.vptr
2697+
%5 = cir.vtable.get_virtual_fn_addr %4[2] : !cir.vptr
27002698
-> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>) -> !s32i>>>
27012699
%6 = cir.load align(8) %5 : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>)
27022700
-> !s32i>>>,
@@ -2708,30 +2706,13 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
27082706

27092707
let arguments = (ins
27102708
Arg<CIR_VPtrType, "vptr", [MemRead]>:$vptr,
2711-
IndexAttr:$index_attr);
2709+
I64Attr:$index);
27122710

2713-
let results = (outs CIR_PointerType:$vfptr_ty);
2711+
let results = (outs CIR_PointerType:$result);
27142712

27152713
let assemblyFormat = [{
2716-
`(`
2717-
$vptr `,` `index` `=` $index_attr
2718-
`)`
2719-
`:` qualified(type($vptr)) `,` qualified(type($vfptr_ty)) attr-dict
2720-
}];
2721-
2722-
let builders = [
2723-
OpBuilder<(ins "mlir::Type":$type,
2724-
"mlir::Value":$value,
2725-
"unsigned":$index),
2726-
[{
2727-
mlir::APInt fnIdx(64, index);
2728-
build($_builder, $_state, type, value, fnIdx);
2729-
}]>
2730-
];
2731-
2732-
let extraClassDeclaration = [{
2733-
/// Return the index of the record member being accessed.
2734-
uint64_t getIndex() { return getIndexAttr().getZExtValue(); }
2714+
$vptr `[` $index `]` attr-dict
2715+
`:` qualified(type($vptr)) `->` qualified(type($result))
27352716
}];
27362717
}
27372718

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ def CIR_AnyDataMemberType : CIR_TypeBase<"::cir::DataMemberType",
267267
// VPtr type predicates
268268
//===----------------------------------------------------------------------===//
269269

270-
def CIR_AnyVPtrType : CIR_TypeBase<"::cir::VPtrType",
271-
"vptr type">;
270+
def CIR_AnyVPtrType : CIR_TypeBase<"::cir::VPtrType", "vptr type">;
272271

273272
def CIR_PtrToVPtr : CIR_PtrToType<CIR_AnyVPtrType>;
274273

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
347347
// CIR_VPtrType
348348
//===----------------------------------------------------------------------===//
349349

350-
def CIR_VPtrType : CIR_Type<"VPtr", "vptr",
351-
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
350+
def CIR_VPtrType : CIR_Type<"VPtr", "vptr", [
351+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>
352+
]> {
352353

353354
let summary = "CIR type that is used for the vptr member of C++ objects";
354355
let description = [{

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ void CIRGenFunction::emitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
17051705

17061706
mlir::Value CIRGenFunction::getVTablePtr(mlir::Location Loc, Address This,
17071707
const CXXRecordDecl *RD) {
1708-
auto VTablePtr = builder.create<cir::VTableGetVptrOp>(
1708+
auto VTablePtr = builder.create<cir::VTableGetVPtrOp>(
17091709
Loc, builder.getPtrToVPtrType(), This.getPointer());
17101710
Address VTablePtrAddr = Address(VTablePtr, This.getAlignment());
17111711

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,9 @@ cir::GlobalOp CIRGenItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
935935
CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer(
936936
CIRGenFunction &CGF, GlobalDecl GD, Address This, mlir::Type Ty,
937937
SourceLocation Loc) {
938+
auto &builder = CGM.getBuilder();
938939
auto loc = CGF.getLoc(Loc);
939-
auto TyPtr = CGF.getBuilder().getPointerTo(Ty);
940+
auto TyPtr = builder.getPointerTo(Ty);
940941
auto *MethodDecl = cast<CXXMethodDecl>(GD.getDecl());
941942
auto VTable = CGF.getVTablePtr(loc, This, MethodDecl->getParent());
942943

@@ -951,11 +952,10 @@ CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer(
951952
if (CGM.getItaniumVTableContext().isRelativeLayout()) {
952953
llvm_unreachable("NYI");
953954
} else {
954-
auto VTableSlotPtr =
955-
CGF.getBuilder().create<cir::VTableGetVirtualFnAddrOp>(
956-
loc, CGF.getBuilder().getPointerTo(TyPtr), VTable, VTableIndex);
957-
VFuncLoad = CGF.getBuilder().createAlignedLoad(loc, TyPtr, VTableSlotPtr,
958-
CGF.getPointerAlign());
955+
auto VTableSlotPtr = builder.create<cir::VTableGetVirtualFnAddrOp>(
956+
loc, builder.getPointerTo(TyPtr), VTable, VTableIndex);
957+
VFuncLoad = builder.createAlignedLoad(loc, TyPtr, VTableSlotPtr,
958+
CGF.getPointerAlign());
959959
}
960960

961961
// Add !invariant.load md to virtual function load to indicate that
@@ -1013,7 +1013,7 @@ CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
10131013

10141014
return builder.create<cir::VTableAddrPointOp>(
10151015
CGM.getLoc(VTableClass->getSourceRange()), vtablePtrTy,
1016-
mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()), mlir::Value{},
1016+
mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()),
10171017
cir::AddressPointAttr::get(CGM.getBuilder().getContext(),
10181018
AddressPoint.VTableIndex,
10191019
AddressPoint.AddressPointIndex));

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,10 +2396,7 @@ cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
23962396

23972397
LogicalResult
23982398
cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2399-
// vtable ptr is not coming from a symbol.
2400-
if (!getName())
2401-
return success();
2402-
auto name = *getName();
2399+
StringRef name = getName();
24032400

24042401
// Verify that the result type underlying pointer type matches the type of
24052402
// the referenced cir.global or cir.func op.
@@ -2417,24 +2414,6 @@ cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
24172414
return success();
24182415
}
24192416

2420-
LogicalResult cir::VTableAddrPointOp::verify() {
2421-
// The operation uses either a symbol or a value to operate, but not both
2422-
if (getName() && getSymAddr())
2423-
return emitOpError("should use either a symbol or value, but not both");
2424-
2425-
// If not a symbol, stick with the concrete type used for getSymAddr.
2426-
if (getSymAddr())
2427-
return success();
2428-
2429-
auto resultType = getAddr().getType();
2430-
auto resTy = cir::PointerType::get(cir::VPtrType::get(getContext()));
2431-
2432-
if (resultType != resTy)
2433-
return emitOpError("result type must be '")
2434-
<< resTy << "', but provided result type is '" << resultType << "'";
2435-
return success();
2436-
}
2437-
24382417
//===----------------------------------------------------------------------===//
24392418
// VTTAddrPointOp
24402419
//===----------------------------------------------------------------------===//

clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ buildDynamicCastToVoidAfterNullCheck(CIRBaseBuilderTy &builder,
118118
auto vptrTy = cir::VPtrType::get(builder.getContext());
119119
auto vptrPtrTy = builder.getPointerTo(vptrTy);
120120
auto vptrPtr =
121-
builder.create<cir::VTableGetVptrOp>(loc, vptrPtrTy, op.getSrc());
121+
builder.create<cir::VTableGetVPtrOp>(loc, vptrPtrTy, op.getSrc());
122122
auto vptr = builder.createLoad(loc, vptrPtr);
123123
auto elementPtr =
124124
builder.createBitcast(vptr, builder.getPointerTo(vtableElemTy));

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,22 +3866,13 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
38663866
mlir::ConversionPatternRewriter &rewriter) const {
38673867
const auto *converter = getTypeConverter();
38683868
auto targetType = converter->convertType(op.getType());
3869-
mlir::Value symAddr = op.getSymAddr();
38703869
llvm::SmallVector<mlir::LLVM::GEPArg> offsets;
38713870
mlir::Type eltType;
3872-
if (!symAddr) {
3873-
symAddr = getValueForVTableSymbol(op, rewriter, getTypeConverter(),
3874-
op.getNameAttr(), eltType);
3875-
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3876-
0, op.getAddressPointAttr().getIndex(),
3877-
op.getAddressPointAttr().getOffset()};
3878-
} else {
3879-
// Get indirect vtable address point retrieval
3880-
symAddr = adaptor.getSymAddr();
3881-
eltType = converter->convertType(symAddr.getType());
3882-
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3883-
op.getAddressPointAttr().getOffset()};
3884-
}
3871+
mlir::Value symAddr = getValueForVTableSymbol(
3872+
op, rewriter, getTypeConverter(), op.getNameAttr(), eltType);
3873+
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3874+
0, op.getAddressPointAttr().getIndex(),
3875+
op.getAddressPointAttr().getOffset()};
38853876

38863877
assert(eltType && "Shouldn't ever be missing an eltType here");
38873878
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(op, targetType, eltType,
@@ -3890,8 +3881,8 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
38903881
return mlir::success();
38913882
}
38923883

3893-
mlir::LogicalResult CIRToLLVMVTableGetVptrOpLowering::matchAndRewrite(
3894-
cir::VTableGetVptrOp op, OpAdaptor adaptor,
3884+
mlir::LogicalResult CIRToLLVMVTableGetVPtrOpLowering::matchAndRewrite(
3885+
cir::VTableGetVPtrOp op, OpAdaptor adaptor,
38953886
mlir::ConversionPatternRewriter &rewriter) const {
38963887
// cir.vtable.get_vptr is equivalent to a bitcast from the source object
38973888
// pointer to the vptr type. Since the LLVM dialect uses opaque pointers
@@ -4565,7 +4556,7 @@ void populateCIRToLLVMConversionPatterns(
45654556
CIRToLLVMVecSplatOpLowering,
45664557
CIRToLLVMVecTernaryOpLowering,
45674558
CIRToLLVMVTableAddrPointOpLowering,
4568-
CIRToLLVMVTableGetVptrOpLowering,
4559+
CIRToLLVMVTableGetVPtrOpLowering,
45694560
CIRToLLVMVTableGetVirtualFnAddrOpLowering,
45704561
CIRToLLVMVTTAddrPointOpLowering
45714562
#define GET_BUILTIN_LOWERING_LIST

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,13 @@ class CIRToLLVMVTableAddrPointOpLowering
10341034
mlir::ConversionPatternRewriter &) const override;
10351035
};
10361036

1037-
class CIRToLLVMVTableGetVptrOpLowering
1038-
: public mlir::OpConversionPattern<cir::VTableGetVptrOp> {
1037+
class CIRToLLVMVTableGetVPtrOpLowering
1038+
: public mlir::OpConversionPattern<cir::VTableGetVPtrOp> {
10391039
public:
1040-
using mlir::OpConversionPattern<cir::VTableGetVptrOp>::OpConversionPattern;
1040+
using mlir::OpConversionPattern<cir::VTableGetVPtrOp>::OpConversionPattern;
10411041

10421042
mlir::LogicalResult
1043-
matchAndRewrite(cir::VTableGetVptrOp op, OpAdaptor,
1043+
matchAndRewrite(cir::VTableGetVPtrOp op, OpAdaptor,
10441044
mlir::ConversionPatternRewriter &) const override;
10451045
};
10461046

clang/test/CIR/CodeGen/derived-to-base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void vcall(C1 &c1) {
120120
// CHECK: %6 = cir.load{{.*}} %3 : !cir.ptr<!rec_buffy>, !rec_buffy
121121
// CHECK: %7 = cir.vtable.get_vptr %4 : !cir.ptr<!rec_C1> -> !cir.ptr<!cir.vptr>
122122
// CHECK: %8 = cir.load{{.*}} %7 : !cir.ptr<!cir.vptr>, !cir.vptr
123-
// CHECK: %9 = cir.vtable.get_virtual_fn_addr(%8, index = 2) : !cir.vptr, !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i>>>
123+
// CHECK: %9 = cir.vtable.get_virtual_fn_addr %8[2] : !cir.vptr -> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i>>>
124124
// CHECK: %10 = cir.load align(8) %9 : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i>>>, !cir.ptr<!cir.func<(!cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i>>
125125
// CHECK: %11 = cir.call %10(%4, %5, %6) : (!cir.ptr<!cir.func<(!cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i>>, !cir.ptr<!rec_C1>, !s32i, !rec_buffy) -> !s32i
126126
// CHECK: cir.return

0 commit comments

Comments
 (0)