[clang] [llvm] [llvm][NFC] `APFloat`: Add missing semantics to enum (PR #117291)

Matthias Springer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 22:18:08 PST 2024


matthias-springer wrote:

There are various places in `APFloat.h` and `APFloat.cpp` that contain switch-case / if-check sequences for checking the type of semantics. I'm trying to reduce these. What I had in mind:

* Removing `APFloatBase::IEEEhalf()`, `APFloatBase::BFloat()`, ..., and use a single `APFloatBase::getSemantics` instead. (But there are a lot of places that call `IEEEHalf` etc.)
* Add function pointers `APInt (*convertToAPInt)(const APFloat &)` and `APFloat (*initFromAPInt)(const APInt &)` to `fltSemantics`. Each semantics can specify how to convert between APFloat and APInt. No more switch case statements in `IEEEFloat::bitcastToAPInt()` etc.
* Longer term: Turn `fltSemantics` into a public class that can be used to define custom floating-point types in downstream projects (without having to modify LLVM).

Any thoughts?

https://github.com/llvm/llvm-project/pull/117291


More information about the llvm-commits mailing list