From c7c21969e889f9b15827cb8c4d2da818df8cb596 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 21 Jun 2024 14:05:26 -0400 Subject: [PATCH] xo-expression: + llvmintrinsics enum --- include/xo/expression/llvmintrinsic.hpp | 92 +++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 include/xo/expression/llvmintrinsic.hpp diff --git a/include/xo/expression/llvmintrinsic.hpp b/include/xo/expression/llvmintrinsic.hpp new file mode 100644 index 00000000..37f231fe --- /dev/null +++ b/include/xo/expression/llvmintrinsic.hpp @@ -0,0 +1,92 @@ +/** @file llvmintrinsic.hpp + * + * Author: Roland Conybeare + **/ + +#pragma once + +//#include + +namespace xo { + namespace ast { + /** @enum llvminstrinsic + * @brief enum to identify an LLVM instrinsic, e.g. @c IRBuilder::CreateFAdd + * + * Associate an @c llvminstrinsic with an AST @c Primitive p. + * Later, in @c xo::jit::IrPipeline + * - when generating code for @c xo::ast::Apply + * - with *p* is in the function-call position + * can use the associated llvm instrinsic instead of generating a function call + * @c Primitive::value + * + * @note llvm will still need to use @c Primitive::value, for example + * when handling an @c xo::ast::Apply instance where the function position + * is a computed function. + * @endnote + * + * @note + * NSW stands for 'no signed wrap' -> poison value if overflow (costs more) + * NUW stands for 'no unsigned wrap' -> poison value if overflow (costs more) + * @endnote + **/ + enum class llvmintrinsic { + /** sentinel value **/ + invalid = -1, + + /** -> IRBuilder::CreateAdd (add 2 integers, overflow silently) **/ + i_add, + + /** -> IRBuilder::CreateMul (multiply 2 integers, overflow silently) **/ + i_mul, + + /** -> IRBuilder::CreateFadd (add 2 floating-point numbers) **/ + fp_add, + + /** -> IRBuilder::CreateFmul (multiply 2 floating-point numbers) **/ + fp_mul, + + /** + * want to do whatever llvm IR @c llvm.sqrt.f64 and friends do. + * Not sure if that's an always-available function of something else + **/ + fp_sqrt, + + /** WIP **/ + fp_pow, + + /** WIP **/ + fp_sin, + + /** WIP **/ + fp_cos, + + /** WIP **/ + fp_tan, + + /** not an intrinsic. comes last, counts entries **/ + n_intrinsic + }; + + inline const char * + llvmintrinsic2str(llvmintrinsic x) + { + switch(x) { + case llvmintrinsic::invalid: return "?llvminstrinsic"; + case llvmintrinsic::i_add: return "i_add"; + case llvmintrinsic::i_mul: return "i_mul"; + case llvmintrinsic::fp_add: return "fp_add"; + case llvmintrinsic::fp_mul: return "fp_mul"; + case llvmintrinsic::fp_sqrt: return "fp_sqrt"; + case llvmintrinsic::fp_pow: return "fp_pow"; + case llvmintrinsic::fp_sin: return "fp_sin"; + case llvmintrinsic::fp_cos: return "fp_cos"; + case llvmintrinsic::fp_tan: return "fp_tan"; + default: break; + } + + return "???llvmintrinsic???"; + } /*llvmintrinsic2str*/ + } /*namespace ast*/ +} /*namespace xo*/ + +/** end llvmintrinsic.hpp **/