[llvm-dev] [RFC] Enforcing immediate operands for intrinsics
Krzysztof Parzyszek via llvm-dev
llvm-dev at lists.llvm.org
Tue Feb 5 15:55:00 PST 2019
There is something similar going on in clang in SemaChecking.cpp. The
difference is that each target can write its own verification code,
which may check things like value ranges, for example.
The scheme you're proposing would invent a new attribute (a widespread
change) that only implements partial checks (i.e. "is argument immediate
or not").
Why not simply add a function to TTI that tells you whether a particular
Value is a valid n-th argument to the given intrinsic?
Something like
if (TTI.isValidArgument(IntOpc, Val, OpIdx))
Int->setOperand(Val, OpIdx);
-Krzysztof
On 2/5/2019 7:58 AM, Arsenault, Matthew via llvm-dev wrote:
> Hi,
>
> I would like to solve the longstanding need for a way to indicate which
> parameters to an intrinsic are required to be immediates. It should be
> possible to declare in tablegen which parameters must be a trivial
> constant, or else the IR is invalid.
>
> The verifier could then reject invalid intrinsic calls, so code handling
> the intrinsics doesn’t need to worry about invalid arguments. Currently
> any code that deals with such intrinsics needs to do type checks on the
> argument to avoid crashing on valid IR. This isn’t done particularly
> consistently (e.g. see r352904, or the follow-up r353097 for a recent
> example fix). From the codegen side, we do things like folding invalid
> intrinsic calls to undef during custom lowering, which is more
> boilerplate which shouldn’t be necessary.
>
> It’s also necessary in a few some passes to know it’s illegal to replace
> an argument with a constant. llvm::canReplaceOperandWithVariable
> currently has to conservatively assume any intrinsic arguments can’t be
> touched.
>
> I have 2 versions of partial implementations of this.
>
> 1. Uses a new intrinsic query table to return a bitmask of which
> operands need to be constant
> 2. Introduces a new parameter attribute
>
> My current preference is for option 2. I initially expected to create
> the table, but then I was creating an uglier way of tracking parameter
> properties that exactly tracked alongside the attribute handling. It
> seems cleaner to just put it there, even though it seems a bit overkill
> and looks slightly strange.
>
> The rules for the attribute will look like:
>
> * Only allowed on intrinsics declarations. It is not allowed on an
> arbitrary function
> * Not allowed on individual call sites
> * The parameter must be a trivial constant leaf (i.e. ConstantInt,
> ConstantFP, or Undef). No aggregates or vectors are allowed
> * It will be incompatible with all other parameter attributes such as
> sret or returned
>
> For bikeshedding the name, I’m currently calling the attribute
> “constant”, but I think this is a bad name. It doesn’t allow arbitrary
> constants (such as ConstantExprs), so I think something more like
> “immarg” ‘or “immediate” would be better.
>
> -Matt
>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
> Virus-free. www.avg.com
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>
>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
More information about the llvm-dev
mailing list