-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Portable code is best, but sometimes when you have a high-level mathematical operation you want to perform, there are multiple ways to express it, and different ways are more or less suited to the instructions available on a given target. E.g. for integer division within some certain range you may want to use bit-tricks, or you may want to do it as float, depending on the floating point throughput of your target.
To support this, currently you have to plumb the damn target though every mathematical helper function, so that you can switch on it. This leads to ugly code. It would be cool if you could instead say something like:
Expr e = select(target_arch_is(Target::ARM), something, something_else)
I propose one new helper functions in IROperator.h for each enum in Target. They would each return a boolean Expr:
Expr target_arch_is(Target::Arch);
Expr target_os_is(Target::OS);
Expr target_processor_is(Target::Processor)
Expr target_has_feature(Target::Feature);
These Exprs would be calls to similarly-named intrinsics in the IR, with the enum arg converted to a constant integer. These intrinsics would be lowered to either true or false at the earliest possible opportunity (probably alongside strictify_float at the top of lowering).