gccrs: Refactor builtin lookup and mapping interfaces
gccrs improves its builtin lookup and LLVM-to-GCC builtin mapping interfaces for better error handling and code clarity.
gccrs has refactored its interfaces for looking up and mapping built-in functions. The lookup functions now return optional<tree> for cleaner handling of absent builtins. The LLVM-to-GCC builtin mapping has been improved to return an expected<T> type, avoiding the need for pointer parameters and providing better error reporting through an associated emit method on the error type. These changes enhance the robustness and maintainability of the compiler’s backend.
In Details
This commit refactors the gccrs backend's handling of built-in functions. The BuiltinsContext::lookup_simple_builtin and lookup_gcc_builtin APIs are updated to return optional<tree>, simplifying the check for whether a builtin exists. More significantly, BuiltinsContext::map_llvm_to_gcc_builtin now returns expected<T> instead of using output parameters, improving error propagation. A new LlvmBuiltinMappingError struct replaces the old enum, providing associated functions and an emit method for more context-rich error reporting. These changes affect how intrinsic compilation an…
- built-in function
- A function that is recognized and handled directly by the compiler, often for performance reasons or to expose low-level operations. Examples include memory manipulation functions or type-specific operations.
- optional<T>
- A C++ type that may or may not contain a value of type T. It's used to represent values that might be absent, avoiding null pointers or special sentinel values.
- expected<T>
- A C++ type that represents either a value of type T or an error. It's often used for functions that can fail, allowing them to return either the successful result or a specific error object.
- tree
- In GCC, 'tree' refers to the internal representation of code structures. It's an abstract syntax tree-like data structure used by the compiler during various optimization and transformation passes.