There are various intrinsic lowering passes and they currently all
require iterating over the whole function, even if there are no calls to
the intrinsics they are interested in.
This patch extends Module with a way to query if an intrinsic ID has any
declarations in the module. This can be used as a relatively cheap proxy
to bail out early from a lowering pass.
It adds a new optional map IntrinsicsInModule to Module and an
containsIntrinsicDeclaration helper. IntrinsicsInModule is initialized
the first time containsIntrinsicDeclaration is called and
getOrInsertFunction & Function::eraseFromParent() are updated to
update the map.
One thing that should probably be added as well is a way for lowering
pass to ensure they do not miss an intrinsic check if the add support
for new intrinsics.
Hmm, this just stores the count, not the actual declarations? I guess that's okay, depending on how you expect to use it.