In swift, we want to be able to call c++ virtual methods by looking up in the virtual table. There appears to exist no way currently, via the standard APIs, to take a CXXMethodDecl and a llvm::Value representing a this-ptr and construct the llvm instructions necessary to extract the method from the virtual table as well as adjust the this-ptr.
For reference, this is used in https://github.com/apple/swift/pull/26658.
This isn't the right header for this. More thoughts on this point below.
The documentation should describe the expected relationship between this and the method. I imagine that thisPtr is expected to already be a pointer to the type which declares the method (i.e. MD->getParent()), and in the appropriate address space.
Please name this something like emitLoadOfCXXVirtualMethod.
This particular case will probably never need control flow or temporary memory, but I wonder if we should go ahead and introduce an abstraction that bundles the CGM and the builder so that we can teach it to handle those in the future. If you do, you could just define it in its own header and then make this a method on that.
I think it would be totally reasonable to pull Clang's Address.h up to include/clang/CodeGen instead of breaking it down here.
Also, this really needs to return a CGCallee, which might require pulling that up as well. The reason why should be clear in a few weeks.