LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-intrinsic.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 14 14
Test Date: 2026-03-28 14:25:54 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // This file is part of GCC.
       2              : 
       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.
       7              : 
       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.
      12              : 
      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/>.
      16              : 
      17              : #include "rust-compile-intrinsic.h"
      18              : #include "rust-compile-context.h"
      19              : #include "rust-builtins.h"
      20              : #include "rust-diagnostics.h"
      21              : #include "tree-core.h"
      22              : #include "rust-intrinsic-handlers.h"
      23              : #include "rust-intrinsic-values.h"
      24              : 
      25              : namespace Rust {
      26              : namespace Compile {
      27              : 
      28              : using IValue = Values::Intrinsics;
      29              : 
      30              : static const std::map<std::string, handlers::HandlerBuilder> generic_intrinsics
      31              :   = {{IValue::OFFSET, handlers::offset},
      32              :      {IValue::SIZE_OF, handlers::sizeof_handler},
      33              :      {IValue::TRANSMUTE, handlers::transmute},
      34              :      {IValue::ROTATE_LEFT, handlers::rotate_left},
      35              :      {IValue::ROTATE_RIGHT, handlers::rotate_right},
      36              :      {IValue::WRAPPING_ADD, handlers::wrapping_op (PLUS_EXPR)},
      37              :      {IValue::WRAPPING_SUB, handlers::wrapping_op (MINUS_EXPR)},
      38              :      {IValue::WRAPPING_MUL, handlers::wrapping_op (MULT_EXPR)},
      39              :      {IValue::ADD_WITH_OVERFLOW, handlers::op_with_overflow (PLUS_EXPR)},
      40              :      {IValue::SUB_WITH_OVERFLOW, handlers::op_with_overflow (MINUS_EXPR)},
      41              :      {IValue::MUL_WITH_OVERFLOW, handlers::op_with_overflow (MULT_EXPR)},
      42              :      {IValue::COPY, handlers::copy (true)},
      43              :      {IValue::COPY_NONOVERLAPPING, handlers::copy (false)},
      44              :      {IValue::PREFETCH_READ_DATA, handlers::prefetch_read_data},
      45              :      {IValue::PREFETCH_WRITE_DATA, handlers::prefetch_write_data},
      46              :      {IValue::ATOMIC_STORE_SEQCST, handlers::atomic_store (__ATOMIC_SEQ_CST)},
      47              :      {IValue::ATOMIC_STORE_RELEASE, handlers::atomic_store (__ATOMIC_RELEASE)},
      48              :      {IValue::ATOMIC_STORE_RELAXED, handlers::atomic_store (__ATOMIC_RELAXED)},
      49              :      {IValue::ATOMIC_STORE_UNORDERED,
      50              :       handlers::atomic_store (__ATOMIC_RELAXED)},
      51              :      {IValue::ATOMIC_LOAD_SEQCST, handlers::atomic_load (__ATOMIC_SEQ_CST)},
      52              :      {IValue::ATOMIC_LOAD_ACQUIRE, handlers::atomic_load (__ATOMIC_ACQUIRE)},
      53              :      {IValue::ATOMIC_LOAD_RELAXED, handlers::atomic_load (__ATOMIC_RELAXED)},
      54              :      {IValue::ATOMIC_LOAD_UNORDERED, handlers::atomic_load (__ATOMIC_RELAXED)},
      55              :      {IValue::UNCHECKED_ADD, handlers::unchecked_op (PLUS_EXPR)},
      56              :      {IValue::UNCHECKED_SUB, handlers::unchecked_op (MINUS_EXPR)},
      57              :      {IValue::UNCHECKED_MUL, handlers::unchecked_op (MULT_EXPR)},
      58              :      {IValue::UNCHECKED_DIV, handlers::unchecked_op (TRUNC_DIV_EXPR)},
      59              :      {IValue::UNCHECKED_REM, handlers::unchecked_op (TRUNC_MOD_EXPR)},
      60              :      {IValue::UNCHECKED_SHL, handlers::unchecked_op (LSHIFT_EXPR)},
      61              :      {IValue::UNCHECKED_SHR, handlers::unchecked_op (RSHIFT_EXPR)},
      62              :      {IValue::UNINIT, handlers::uninit},
      63              :      {IValue::MOVE_VAL_INIT, handlers::move_val_init},
      64              :      {IValue::LIKELY, handlers::expect (true)},
      65              :      {IValue::UNLIKELY, handlers::expect (false)},
      66              :      {IValue::ASSUME, handlers::assume},
      67              :      {IValue::TRY, handlers::try_handler (false)},
      68              :      {IValue::CATCH_UNWIND, handlers::try_handler (true)},
      69              :      {IValue::DISCRIMINANT_VALUE, handlers::discriminant_value},
      70              :      {IValue::VARIANT_COUNT, handlers::variant_count},
      71              :      {IValue::BSWAP, handlers::bswap_handler}};
      72              : 
      73         2507 : Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
      74              : 
      75              : /**
      76              :  * Returns a FUNC_DECL corresponding to the intrinsic function FNTYPE. If a
      77              :  * corresponding builtin exists, returns it. If not, search in the generic
      78              :  * intrinsics declared and delegate the return to the corresponding handler.
      79              :  *
      80              :  * @param fntype The Rust function type that should be implemented by the
      81              :  * compiler
      82              :  */
      83              : tree
      84         2507 : Intrinsics::compile (TyTy::FnType *fntype)
      85              : {
      86         2507 :   rust_assert (fntype->get_abi () == ABI::INTRINSIC);
      87              : 
      88         2507 :   tree builtin = error_mark_node;
      89         2507 :   BuiltinsContext &builtin_ctx = BuiltinsContext::get ();
      90              : 
      91         5014 :   if (builtin_ctx.lookup_simple_builtin (fntype->get_identifier (), &builtin))
      92          309 :     return builtin;
      93              : 
      94              :   // is it an generic builtin?
      95         4396 :   auto it = generic_intrinsics.find (fntype->get_identifier ());
      96         2198 :   if (it != generic_intrinsics.end ())
      97         2191 :     return it->second (ctx, fntype);
      98              : 
      99            7 :   location_t locus = ctx->get_mappings ().lookup_location (fntype->get_ref ());
     100           14 :   rust_error_at (locus, ErrorCode::E0093,
     101              :                  "unrecognized intrinsic function: %qs",
     102            7 :                  fntype->get_identifier ().c_str ());
     103              : 
     104            7 :   return error_mark_node;
     105              : }
     106              : 
     107              : } // namespace Compile
     108              : } // namespace Rust
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.