Skip to content

Commit 15b8c9f

Browse files
committed
Address review feedback
1 parent ad17f66 commit 15b8c9f

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
@@ -2605,31 +2605,25 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
26052605
}];
26062606

26072607
let arguments = (ins
2608-
OptionalAttr<FlatSymbolRefAttr>:$name,
2609-
Optional<CIR_AnyType>:$sym_addr,
2608+
FlatSymbolRefAttr:$name,
26102609
CIR_AddressPointAttr:$address_point
26112610
);
26122611

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

26152614
let assemblyFormat = [{
26162615
`(`
2617-
($name^)?
2618-
($sym_addr^ `:` type($sym_addr))?
2619-
`,`
2620-
`address_point` `=` $address_point
2616+
$name `,` `address_point` `=` $address_point
26212617
`)`
26222618
`:` qualified(type($addr)) attr-dict
26232619
}];
2624-
2625-
let hasVerifier = 1;
26262620
}
26272621

26282622
//===----------------------------------------------------------------------===//
2629-
// VTableGetVptr
2623+
// VTableGetVPtr
26302624
//===----------------------------------------------------------------------===//
26312625

2632-
def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2626+
def CIR_VTableGetVPtrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
26332627
let summary = "Get a the address of the vtable pointer for an object";
26342628
let description = [{
26352629
The `vtable.get_vptr` operation retrieves the address of the vptr for a
@@ -2648,13 +2642,13 @@ def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
26482642
}];
26492643

26502644
let arguments = (ins
2651-
Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src);
2652-
2653-
let results = (outs CIR_PtrToVPtr:$vptr_ty);
2645+
Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src
2646+
);
26542647

2648+
let results = (outs CIR_PtrToVPtr:$result);
26552649

26562650
let assemblyFormat = [{
2657-
$src `:` qualified(type($src)) `->` qualified(type($vptr_ty)) attr-dict
2651+
$src `:` qualified(type($src)) `->` qualified(type($result)) attr-dict
26582652
}];
26592653

26602654
}
@@ -2674,14 +2668,18 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
26742668
the address of the virtual function pointer, which can then be loaded and
26752669
called.
26762670

2671+
The `vptr` operand must be a `!cir.ptr<!cir.vptr>` value, which would
2672+
have been returned by a previous call to `cir.vatble.get_vptr`. The
2673+
`index` operand is an index of the virtual function in the vtable.
2674+
26772675
The return type is a pointer-to-pointer to the function type.
26782676

26792677
Example:
26802678
```mlir
26812679
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_C>>, !cir.ptr<!rec_C>
26822680
%3 = cir.vtable.get_vptr %2 : !cir.ptr<!rec_C> -> !cir.ptr<!cir.vptr>
26832681
%4 = cir.load %3 : !cir.ptr<!cir.vptr>, !cir.vptr
2684-
%5 = cir.vtable.get_virtual_fn_addr(%4, index = 2) : !cir.vptr
2682+
%5 = cir.vtable.get_virtual_fn_addr %4[2] : !cir.vptr
26852683
-> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>) -> !s32i>>>
26862684
%6 = cir.load align(8) %5 : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>)
26872685
-> !s32i>>>,
@@ -2693,30 +2691,13 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
26932691

26942692
let arguments = (ins
26952693
Arg<CIR_VPtrType, "vptr", [MemRead]>:$vptr,
2696-
IndexAttr:$index_attr);
2694+
I64Attr:$index);
26972695

2698-
let results = (outs CIR_PointerType:$vfptr_ty);
2696+
let results = (outs CIR_PointerType:$result);
26992697

27002698
let assemblyFormat = [{
2701-
`(`
2702-
$vptr `,` `index` `=` $index_attr
2703-
`)`
2704-
`:` qualified(type($vptr)) `,` qualified(type($vfptr_ty)) attr-dict
2705-
}];
2706-
2707-
let builders = [
2708-
OpBuilder<(ins "mlir::Type":$type,
2709-
"mlir::Value":$value,
2710-
"unsigned":$index),
2711-
[{
2712-
mlir::APInt fnIdx(64, index);
2713-
build($_builder, $_state, type, value, fnIdx);
2714-
}]>
2715-
];
2716-
2717-
let extraClassDeclaration = [{
2718-
/// Return the index of the record member being accessed.
2719-
uint64_t getIndex() { return getIndexAttr().getZExtValue(); }
2699+
$vptr `[` $index `]` attr-dict
2700+
`:` qualified(type($vptr)) `->` qualified(type($result))
27202701
}];
27212702
}
27222703

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
@@ -928,8 +928,9 @@ cir::GlobalOp CIRGenItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
928928
CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer(
929929
CIRGenFunction &CGF, GlobalDecl GD, Address This, mlir::Type Ty,
930930
SourceLocation Loc) {
931+
auto &builder = CGM.getBuilder();
931932
auto loc = CGF.getLoc(Loc);
932-
auto TyPtr = CGF.getBuilder().getPointerTo(Ty);
933+
auto TyPtr = builder.getPointerTo(Ty);
933934
auto *MethodDecl = cast<CXXMethodDecl>(GD.getDecl());
934935
auto VTable = CGF.getVTablePtr(loc, This, MethodDecl->getParent());
935936

@@ -944,11 +945,10 @@ CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer(
944945
if (CGM.getItaniumVTableContext().isRelativeLayout()) {
945946
llvm_unreachable("NYI");
946947
} else {
947-
auto VTableSlotPtr =
948-
CGF.getBuilder().create<cir::VTableGetVirtualFnAddrOp>(
949-
loc, CGF.getBuilder().getPointerTo(TyPtr), VTable, VTableIndex);
950-
VFuncLoad = CGF.getBuilder().createAlignedLoad(loc, TyPtr, VTableSlotPtr,
951-
CGF.getPointerAlign());
948+
auto VTableSlotPtr = builder.create<cir::VTableGetVirtualFnAddrOp>(
949+
loc, builder.getPointerTo(TyPtr), VTable, VTableIndex);
950+
VFuncLoad = builder.createAlignedLoad(loc, TyPtr, VTableSlotPtr,
951+
CGF.getPointerAlign());
952952
}
953953

954954
// Add !invariant.load md to virtual function load to indicate that
@@ -1006,7 +1006,7 @@ CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
10061006

10071007
return builder.create<cir::VTableAddrPointOp>(
10081008
CGM.getLoc(VTableClass->getSourceRange()), vtablePtrTy,
1009-
mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()), mlir::Value{},
1009+
mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()),
10101010
cir::AddressPointAttr::get(CGM.getBuilder().getContext(),
10111011
AddressPoint.VTableIndex,
10121012
AddressPoint.AddressPointIndex));

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

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

23992399
LogicalResult
24002400
cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2401-
// vtable ptr is not coming from a symbol.
2402-
if (!getName())
2403-
return success();
2404-
auto name = *getName();
2401+
StringRef name = getName();
24052402

24062403
// Verify that the result type underlying pointer type matches the type of
24072404
// the referenced cir.global or cir.func op.
@@ -2419,24 +2416,6 @@ cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
24192416
return success();
24202417
}
24212418

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

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
@@ -3802,22 +3802,13 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
38023802
mlir::ConversionPatternRewriter &rewriter) const {
38033803
const auto *converter = getTypeConverter();
38043804
auto targetType = converter->convertType(op.getType());
3805-
mlir::Value symAddr = op.getSymAddr();
38063805
llvm::SmallVector<mlir::LLVM::GEPArg> offsets;
38073806
mlir::Type eltType;
3808-
if (!symAddr) {
3809-
symAddr = getValueForVTableSymbol(op, rewriter, getTypeConverter(),
3810-
op.getNameAttr(), eltType);
3811-
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3812-
0, op.getAddressPointAttr().getIndex(),
3813-
op.getAddressPointAttr().getOffset()};
3814-
} else {
3815-
// Get indirect vtable address point retrieval
3816-
symAddr = adaptor.getSymAddr();
3817-
eltType = converter->convertType(symAddr.getType());
3818-
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3819-
op.getAddressPointAttr().getOffset()};
3820-
}
3807+
mlir::Value symAddr = getValueForVTableSymbol(
3808+
op, rewriter, getTypeConverter(), op.getNameAttr(), eltType);
3809+
offsets = llvm::SmallVector<mlir::LLVM::GEPArg>{
3810+
0, op.getAddressPointAttr().getIndex(),
3811+
op.getAddressPointAttr().getOffset()};
38213812

38223813
assert(eltType && "Shouldn't ever be missing an eltType here");
38233814
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(op, targetType, eltType,
@@ -3826,8 +3817,8 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
38263817
return mlir::success();
38273818
}
38283819

3829-
mlir::LogicalResult CIRToLLVMVTableGetVptrOpLowering::matchAndRewrite(
3830-
cir::VTableGetVptrOp op, OpAdaptor adaptor,
3820+
mlir::LogicalResult CIRToLLVMVTableGetVPtrOpLowering::matchAndRewrite(
3821+
cir::VTableGetVPtrOp op, OpAdaptor adaptor,
38313822
mlir::ConversionPatternRewriter &rewriter) const {
38323823
// cir.vtable.get_vptr is equivalent to a bitcast from the source object
38333824
// pointer to the vptr type. Since the LLVM dialect uses opaque pointers
@@ -4500,7 +4491,7 @@ void populateCIRToLLVMConversionPatterns(
45004491
CIRToLLVMVecSplatOpLowering,
45014492
CIRToLLVMVecTernaryOpLowering,
45024493
CIRToLLVMVTableAddrPointOpLowering,
4503-
CIRToLLVMVTableGetVptrOpLowering,
4494+
CIRToLLVMVTableGetVPtrOpLowering,
45044495
CIRToLLVMVTableGetVirtualFnAddrOpLowering,
45054496
CIRToLLVMVTTAddrPointOpLowering
45064497
#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
@@ -1018,13 +1018,13 @@ class CIRToLLVMVTableAddrPointOpLowering
10181018
mlir::ConversionPatternRewriter &) const override;
10191019
};
10201020

1021-
class CIRToLLVMVTableGetVptrOpLowering
1022-
: public mlir::OpConversionPattern<cir::VTableGetVptrOp> {
1021+
class CIRToLLVMVTableGetVPtrOpLowering
1022+
: public mlir::OpConversionPattern<cir::VTableGetVPtrOp> {
10231023
public:
1024-
using mlir::OpConversionPattern<cir::VTableGetVptrOp>::OpConversionPattern;
1024+
using mlir::OpConversionPattern<cir::VTableGetVPtrOp>::OpConversionPattern;
10251025

10261026
mlir::LogicalResult
1027-
matchAndRewrite(cir::VTableGetVptrOp op, OpAdaptor,
1027+
matchAndRewrite(cir::VTableGetVPtrOp op, OpAdaptor,
10281028
mlir::ConversionPatternRewriter &) const override;
10291029
};
10301030

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)