[compiler-rt] [llvm] [CallPromotionUtils]Implement conditional indirect call promotion with vtable-based comparison (PR #81378)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Tue May 14 20:43:07 PDT 2024


================
@@ -568,6 +589,46 @@ CallBase &llvm::promoteCallWithIfThenElse(CallBase &CB, Function *Callee,
   return promoteCall(NewInst, Callee);
 }
 
+Constant *llvm::getVTableAddressPointOffset(GlobalVariable *VTable,
+                                            uint32_t AddressPointOffset) {
+  Module &M = *VTable->getParent();
+  const DataLayout &DL = M.getDataLayout();
+  LLVMContext &Context = M.getContext();
+  Type *VTableType = VTable->getValueType();
+  assert(AddressPointOffset < DL.getTypeAllocSize(VTableType) &&
+         "Out-of-bound access");
+  APInt AddressPointOffsetAPInt(32, AddressPointOffset, false);
+  SmallVector<APInt> Indices =
+      DL.getGEPIndicesForOffset(VTableType, AddressPointOffsetAPInt);
----------------
minglotus-6 wrote:

@nikic thanks for taking a look!

Before I make the change, do you mean `getelementptr i8, ptr %p, i64 40` should be preferred over `getelementptr [[i32 x 10], x 10], ptr %p, i64 0, i64 1, i64 0`  as mentioned in https://groups.google.com/g/llvm-dev/c/U7D6z7ZnKy8?


https://github.com/llvm/llvm-project/pull/81378


More information about the llvm-commits mailing list