[clang] [CIR] Handle lowering for most of Relative-Vtables (PR #247288)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 30 15:49:42 PST 2026
================
@@ -3491,6 +3576,147 @@ CIRToLLVMGlobalOpLowering::setupRegionInitializedLLVMGlobalOp(
return newGlobalOp;
}
+static mlir::SymbolRefAttr
+getComdatAttrHelper(mlir::ModuleOp modOp, mlir::OpBuilder &builder,
+ StringRef symName, mlir::LLVM::ComdatOp &comdatOp,
+ mlir::SymbolTableCollection &symbolTables);
+
+/// Build the initializer of the relative layout vtable that is the LLVM global
+/// \p vtableSym.
+///
+/// Every entry is 32 bits wide. An offset is stored as is. A function or RTTI
+/// entry is stored as the distance from the address point of the vtable it is
+/// in to the entry's target, which is the function itself, or the proxy of the
+/// RTTI. The RTTI symbols whose proxy is needed are appended to \p rttiRefs.
+static mlir::Value lowerRelativeVTableInit(
+ mlir::ConversionPatternRewriter &rewriter,
+ mlir::SymbolTableCollection &symbolTables, mlir::ModuleOp mod,
+ mlir::Location loc, llvm::StringRef vtableSym, cir::VTableAttr vtable,
+ mlir::Type llvmTy, llvm::SmallVectorImpl<llvm::StringRef> &rttiRefs) {
+ mlir::MLIRContext *ctx = rewriter.getContext();
+ auto ptrTy = mlir::LLVM::LLVMPointerType::get(ctx);
+ mlir::Type i32Ty = rewriter.getI32Type();
+ mlir::Type intPtrTy =
+ rewriter.getIntegerType(mlir::DataLayout(mod).getTypeSizeInBits(ptrTy));
----------------
erichkeane wrote:
It isn't particularly testable, but I did it anyway (needs a CIR test). There was a little bit of wiring through to make it work right.
https://github.com/llvm/llvm-project/pull/247288
More information about the cfe-commits
mailing list