c++: Prevent overwriting arguments when merging duplicates [PR112588]
[official-gcc.git] / gcc / rust / backend / rust-builtins.h
blobc2825107faff2317a40b696c3477b62139475f26
1 // This file is part of GCC.
3 // GCC is free software; you can redistribute it and/or modify it under
4 // the terms of the GNU General Public License as published by the Free
5 // Software Foundation; either version 3, or (at your option) any later
6 // version.
8 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 // for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with GCC; see the file COPYING3. If not see
15 // <http://www.gnu.org/licenses/>.
17 #ifndef RUST_BUILTINS_H
18 #define RUST_BUILTINS_H
20 #include "rust-system.h"
21 #include "rust-tree.h"
22 #include "langhooks.h"
23 #include "tree.h"
25 namespace Rust {
26 namespace Compile {
28 // https://github.com/rust-lang/rust/blob/master/library/core/src/intrinsics.rs
29 // https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs
30 // https://github.com/Rust-GCC/gccrs/issues/658
32 // let llvm_name = match name {
33 // sym::sqrtf32 => "llvm.sqrt.f32",
34 // sym::sqrtf64 => "llvm.sqrt.f64",
35 // sym::powif32 => "llvm.powi.f32",
36 // sym::powif64 => "llvm.powi.f64",
37 // sym::sinf32 => "llvm.sin.f32",
38 // sym::sinf64 => "llvm.sin.f64",
39 // sym::cosf32 => "llvm.cos.f32",
40 // sym::cosf64 => "llvm.cos.f64",
41 // sym::powf32 => "llvm.pow.f32",
42 // sym::powf64 => "llvm.pow.f64",
43 // sym::expf32 => "llvm.exp.f32",
44 // sym::expf64 => "llvm.exp.f64",
45 // sym::exp2f32 => "llvm.exp2.f32",
46 // sym::exp2f64 => "llvm.exp2.f64",
47 // sym::logf32 => "llvm.log.f32",
48 // sym::logf64 => "llvm.log.f64",
49 // sym::log10f32 => "llvm.log10.f32",
50 // sym::log10f64 => "llvm.log10.f64",
51 // sym::log2f32 => "llvm.log2.f32",
52 // sym::log2f64 => "llvm.log2.f64",
53 // sym::fmaf32 => "llvm.fma.f32",
54 // sym::fmaf64 => "llvm.fma.f64",
55 // sym::fabsf32 => "llvm.fabs.f32",
56 // sym::fabsf64 => "llvm.fabs.f64",
57 // sym::minnumf32 => "llvm.minnum.f32",
58 // sym::minnumf64 => "llvm.minnum.f64",
59 // sym::maxnumf32 => "llvm.maxnum.f32",
60 // sym::maxnumf64 => "llvm.maxnum.f64",
61 // sym::copysignf32 => "llvm.copysign.f32",
62 // sym::copysignf64 => "llvm.copysign.f64",
63 // sym::floorf32 => "llvm.floor.f32",
64 // sym::floorf64 => "llvm.floor.f64",
65 // sym::ceilf32 => "llvm.ceil.f32",
66 // sym::ceilf64 => "llvm.ceil.f64",
67 // sym::truncf32 => "llvm.trunc.f32",
68 // sym::truncf64 => "llvm.trunc.f64",
69 // sym::rintf32 => "llvm.rint.f32",
70 // sym::rintf64 => "llvm.rint.f64",
71 // sym::nearbyintf32 => "llvm.nearbyint.f32",
72 // sym::nearbyintf64 => "llvm.nearbyint.f64",
73 // sym::roundf32 => "llvm.round.f32",
74 // sym::roundf64 => "llvm.round.f64",
75 // _ => return None,
76 // };
77 // Some(cx.get_intrinsic(&llvm_name))
78 class BuiltinsContext
80 public:
81 static BuiltinsContext &get ();
83 bool lookup_simple_builtin (const std::string &name, tree *builtin);
85 private:
86 BuiltinsContext ();
88 void setup_overflow_fns ();
89 void setup_math_fns ();
90 void setup_atomic_fns ();
92 void setup ();
94 // Define a builtin function. BCODE is the builtin function code
95 // defined by builtins.def. NAME is the name of the builtin function.
96 // LIBNAME is the name of the corresponding library function, and is
97 // NULL if there isn't one. FNTYPE is the type of the function.
98 // CONST_P is true if the function has the const attribute.
99 // NORETURN_P is true if the function has the noreturn attribute.
100 void define_builtin (const std::string rust_name, built_in_function bcode,
101 const char *name, const char *libname, tree fntype,
102 int flags);
104 bool lookup_gcc_builtin (const std::string &name, tree *builtin);
106 // A mapping of the GCC built-ins exposed to GCC Rust.
107 std::map<std::string, tree> builtin_functions_;
108 std::map<std::string, std::string> rust_intrinsic_to_gcc_builtin;
111 } // namespace Compile
112 } // namespace Rust
114 #endif // RUST_BUILTINS_H