This is an archive of the discontinued LLVM Phabricator instance.

[IR] Take const references to LLVMContext
AbandonedPublic

Authored by modocache on Nov 23 2019, 6:34 PM.

Details

Summary

I tried to pass a const LLVMContext & to llvm::Type::getInt32Ty and
was surprised that it didn't work. Upon closer inspection, llvm::Type
defines many static functions that just access a member of LLVMContext
and LLVMContextImpl, and so -- as far as I can tell -- may as well
take a const reference, not a mutable reference.

I didn't want to change too much at once, so this patch just adds const
to one-line static functions defined on llvm::Type. For example, I left
llvm::Type::getIntNTy alone since that calls llvm::IntegerType::get,
which in turn calls the llvm::Type constructor, which sets the
LLVMContext &Context member of llvm::Type -- changing ALL of those
to use const LLVMContext & seemed like something I could do in a later
patch (if it would work at all, as of now I don't know that it would).

Event Timeline

modocache created this revision.Nov 23 2019, 6:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2019, 6:34 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
modocache abandoned this revision.Nov 23 2019, 6:49 PM
modocache added a subscriber: mehdi_amini.

I spoke with @mehdi_amini in the (experimental?) LLVM Discord and his take was that this leaks internal implementation details of LLVMContext: while accessing these types can in fact use const because LLVMContext constructs the types eagerly (as a performance optimization), there's no reason LLVMContext must do so eagerly. Modifying these to take a const reference inhibits the ability to change LLVMContext to lazily construct these types, and so this isn't a desirable change.