]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/backend/rust-compile-fnparam.cc
Add cutoff information to profile_info and use it when forcing non-zero value
[thirdparty/gcc.git] / gcc / rust / backend / rust-compile-fnparam.cc
CommitLineData
6441eb6d 1// Copyright (C) 2020-2025 Free Software Foundation, Inc.
019b2f15
PH
2
3// This file is part of GCC.
4
5// GCC is free software; you can redistribute it and/or modify it under
6// the terms of the GNU General Public License as published by the Free
7// Software Foundation; either version 3, or (at your option) any later
8// version.
9
10// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13// for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with GCC; see the file COPYING3. If not see
17// <http://www.gnu.org/licenses/>.
18
19#include "rust-compile-fnparam.h"
20#include "rust-compile-pattern.h"
21
22#include "gimple-expr.h"
23
24namespace Rust {
25namespace Compile {
26
27CompileFnParam::CompileFnParam (Context *ctx, tree fndecl, tree decl_type,
d991a3f1 28 location_t locus)
019b2f15 29 : HIRCompileBase (ctx), fndecl (fndecl), decl_type (decl_type), locus (locus),
77fbe55f 30 compiled_param (Bvariable::error_variable ())
019b2f15
PH
31{}
32
33Bvariable *
c29a3bc9 34CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam &param,
d991a3f1 35 tree decl_type, location_t locus)
019b2f15
PH
36{
37 CompileFnParam compiler (ctx, fndecl, decl_type, locus);
c29a3bc9 38 param.get_param_name ().accept_vis (compiler);
019b2f15
PH
39 return compiler.compiled_param;
40}
41
42Bvariable *
c29a3bc9 43CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern &param,
d991a3f1 44 tree decl_type, location_t locus)
019b2f15
PH
45{
46 CompileFnParam compiler (ctx, fndecl, decl_type, locus);
c29a3bc9 47 param.accept_vis (compiler);
019b2f15
PH
48 return compiler.compiled_param;
49}
50
51void
52CompileFnParam::visit (HIR::IdentifierPattern &pattern)
53{
54 if (!pattern.is_mut ())
f14cbab8 55 decl_type = Backend::immutable_type (decl_type);
019b2f15 56
f14cbab8
OA
57 compiled_param
58 = Backend::parameter_variable (fndecl,
59 pattern.get_identifier ().as_string (),
60 decl_type, locus);
019b2f15
PH
61}
62
63void
64CompileFnParam::visit (HIR::WildcardPattern &pattern)
65{
f14cbab8 66 decl_type = Backend::immutable_type (decl_type);
019b2f15 67
f14cbab8 68 compiled_param = Backend::parameter_variable (fndecl, "_", decl_type, locus);
019b2f15
PH
69}
70
18d289ca
PH
71void
72CompileFnParam::visit (HIR::TuplePattern &pattern)
73{
74 compiled_param = create_tmp_param_var (decl_type);
75 CompilePatternBindings::Compile (
76 pattern, Backend::var_expression (compiled_param, locus), ctx);
77}
78
019b2f15
PH
79void
80CompileFnParam::visit (HIR::StructPattern &pattern)
81{
18d289ca
PH
82 compiled_param = create_tmp_param_var (decl_type);
83 CompilePatternBindings::Compile (
84 pattern, Backend::var_expression (compiled_param, locus), ctx);
019b2f15
PH
85}
86
87void
88CompileFnParam::visit (HIR::TupleStructPattern &pattern)
89{
18d289ca
PH
90 compiled_param = create_tmp_param_var (decl_type);
91 CompilePatternBindings::Compile (
92 pattern, Backend::var_expression (compiled_param, locus), ctx);
3e0437dc 93}
019b2f15 94
3e0437dc
MM
95void
96CompileFnParam::visit (HIR::ReferencePattern &pattern)
97{
18d289ca
PH
98 compiled_param = create_tmp_param_var (decl_type);
99 CompilePatternBindings::Compile (
100 pattern, Backend::var_expression (compiled_param, locus), ctx);
019b2f15
PH
101}
102
103Bvariable *
104CompileSelfParam::compile (Context *ctx, tree fndecl, HIR::SelfParam &self,
d991a3f1 105 tree decl_type, location_t locus)
019b2f15
PH
106{
107 bool is_immutable
108 = self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM
109 || self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM_REF;
110 if (is_immutable)
f14cbab8 111 decl_type = Backend::immutable_type (decl_type);
019b2f15 112
f14cbab8 113 return Backend::parameter_variable (fndecl, "self", decl_type, locus);
019b2f15
PH
114}
115
18d289ca 116Bvariable *
3e0437dc
MM
117CompileFnParam::create_tmp_param_var (tree decl_type)
118{
119 // generate the anon param
120 tree tmp_ident = create_tmp_var_name ("RSTPRM");
121 std::string cpp_str_identifier = std::string (IDENTIFIER_POINTER (tmp_ident));
122
f14cbab8 123 decl_type = Backend::immutable_type (decl_type);
18d289ca
PH
124 return Backend::parameter_variable (fndecl, cpp_str_identifier, decl_type,
125 locus);
3e0437dc
MM
126}
127
019b2f15
PH
128} // namespace Compile
129} // namespace Rust