[LLVMdev] [cfe-dev] Clang devirtualization proposal
Sanjoy Das
sanjoy at playingwithpointers.com
Sat Aug 1 14:05:50 PDT 2015
> The trouble is that we want to express ideas like "at this call site, but
> not others, I know that this call will not mutate state through this
> pointer". We can't express that with the llvm type system we have today.
Yes; to do that we'll effectively have to introduce some form of
quantification.
IOW: we'd have to have 4x the number of pointer types we have today --
each pointer type should be quantifiable with `noaccess`, `read`,
`write` and `readwrite` (the second one may not be very useful if we
do not want to support memory with only `PROT_WRITE`).
Functions and other consumers types would then have to be modified to
allow universal (and other forms of?) quantification. I should be able to
write a function `@calc` of the type:
"forall $domain in { noaccess, read, write, readwrite }: i8* $domain -> i32"
Once we can quantify function types this way, we should be able to
call a function of the above type (say) with a `i8* read`. The
compiler can then specialize / inline / otherwise optimize that
specific call to `@calc` with the assumption that all stores through a
pointer (in the context of this specific call) of type `i8* read` are
`unreachable`.
I agree that this is fairly complex, especially for a low level IR.
But the key problem with `readonly` is that there is no run-time
mirror of the `readonly`ness of an SSA value (we cannot implement a
`is_readonly` predicate to call at runtime), so we have to have it present in
the type system all the way. `nonnull` or `dereferenceable` do not
have the same problem because they are run-time properties (though
implementing `is_dereferenceable` may be difficult in practice).
-- Sanjoy
More information about the llvm-dev
mailing list