A proper way to manually calculate the byte offset of GetElementPtr

To my understanding, the value of GetElementPtr can always be expressed by val = base + index_1 * length_1 + index_2 * length_2 + ...

where index_i is the i’th integer index and length_i is the i’th element length

The point that I need help with is that how to retrieve these information, I’ve searched the documentation and internet, and asked GPT, no one will give out an general answer.

As in GetElementPtrInst::accumulateConstantOffset?

it seems that I can use gep_type_iterator GTI = gep_type_begin(gep); to get the type and dl->getTypeSizeInBits(t) / 8; to get the size.