This is an archive of the discontinued LLVM Phabricator instance.

[Module] Track intrinsic IDs in module to skip unnecessary lowering.
Needs ReviewPublic

Authored by fhahn on Mar 27 2020, 11:22 AM.

Details

Reviewers
efriedma
Summary

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.

Diff Detail

Event Timeline

fhahn created this revision.Mar 27 2020, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2020, 11:22 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
efriedma added inline comments.Mar 27 2020, 12:05 PM
llvm/include/llvm/IR/Module.h
196

Hmm, this just stores the count, not the actual declarations? I guess that's okay, depending on how you expect to use it.

llvm/lib/IR/Function.cpp
246

We should probably try to detect mutation on the list directly. See SymbolTableListTraits.

In terms of the general approach, this seems reasonable. But maybe bring it up on llvmdev to see if anyone else has thoughts on it.

fhahn marked 2 inline comments as done.Mar 27 2020, 3:18 PM
fhahn added inline comments.
llvm/include/llvm/IR/Module.h
196

I am not sure if the list of declarations would be helpful during the actual lowering, because the lowering passes are function passes. And some require lowering/visiting them in a particular oder.

llvm/lib/IR/Function.cpp
246

Thanks I'll take a look