PandA-2024.02
use_counting.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
41 #include "use_counting.hpp"
42 
43 #include "Parameter.hpp"
44 #include "application_manager.hpp"
45 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
46 #include "design_flow_graph.hpp"
47 #include "design_flow_manager.hpp"
48 #include "ext_tree_node.hpp"
49 #include "string_manipulation.hpp" // for GET_CLASS
50 #include "tree_basic_block.hpp"
51 #include "tree_helper.hpp"
52 #include "tree_manager.hpp"
53 #include "tree_node.hpp"
54 #include "tree_reindex.hpp"
55 #include <list>
56 #include <utility>
57 
59  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
60  : FunctionFrontendFlowStep(_AppM, _function_id, USE_COUNTING, _design_flow_manager, _parameters)
61 {
62  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
63 }
64 
65 use_counting::~use_counting() = default;
66 
69 {
71  switch(relationship_type)
72  {
74  {
75  relationships.insert(std::make_pair(REBUILD_INITIALIZATION2, SAME_FUNCTION));
76  break;
77  }
79  {
80  relationships.insert(std::make_pair(REMOVE_CLOBBER_GA, SAME_FUNCTION));
81  relationships.insert(std::make_pair(HWCALL_INJECTION, SAME_FUNCTION));
82  relationships.insert(std::make_pair(SWITCH_FIX, SAME_FUNCTION));
83  relationships.insert(std::make_pair(REBUILD_INITIALIZATION, SAME_FUNCTION));
84  relationships.insert(std::make_pair(IR_LOWERING, SAME_FUNCTION));
85  break;
86  }
88  {
89  break;
90  }
91  default:
92  {
94  }
95  }
96  return relationships;
97 }
98 
100 {
101  const auto TM = AppM->get_tree_manager();
102  const auto fd = GetPointerS<const function_decl>(TM->CGetTreeNode(function_id));
103  const auto sl = GetPointerS<const statement_list>(GET_CONST_NODE(fd->body));
104  const auto th_debug = tree_helper::debug_level;
106  for(const auto& bbi_bb : sl->list_of_bloc)
107  {
108  const auto& bb = bbi_bb.second;
109  for(const auto& statement_node : bb->CGetStmtList())
110  {
111  const auto ssa_uses = tree_helper::ComputeSsaUses(statement_node);
112  for(const auto& ssa_use : ssa_uses)
113  {
114  const auto sn = GetPointerS<ssa_name>(GET_NODE(ssa_use.first));
115  for(auto uses = ssa_use.second; uses; --uses)
116  {
117  sn->AddUseStmt(statement_node);
118  }
119  }
120  }
121  for(const auto& phi_node : bb->CGetPhiList())
122  {
123  const auto ssa_uses = tree_helper::ComputeSsaUses(phi_node);
124  for(const auto& ssa_use : ssa_uses)
125  {
126  const auto sn = GetPointerS<ssa_name>(GET_NODE(ssa_use.first));
127  for(auto uses = ssa_use.second; uses; --uses)
128  {
129  sn->AddUseStmt(phi_node);
130  }
131  }
132  GetPointerS<gimple_phi>(GET_NODE(phi_node))->SetSSAUsesComputed();
133  }
134  bb->SetSSAUsesComputed();
135  }
136 
137  tree_helper::debug_level = th_debug;
138  // THROW_ASSERT(TM->check_ssa_uses(function_id), "Inconsistent ssa uses: post");
140 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
static int debug_level
debug level (set by Parameter)
File containing functions and utilities to support the printing of debug messagges.
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
DesignFlowStep_Status InternalExec() override
Counts how many time a ssa_name is read.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Data structure describing a basic block at tree level.
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Analysis step counting how many time a ssa_name is used.
Classes to describe design flow graph.
#define GET_CONST_NODE(t)
Definition: tree_node.hpp:347
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
Wrapper of design_flow.
This file collects some utility functions.
const unsigned int function_id
The index of the function to be analyzed.
~use_counting() override
Destructor.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
static void ComputeSsaUses(const tree_nodeRef &, TreeNodeMap< size_t > &uses)
recursively compute the references to the ssa_name variables used in a statement
Class specification of the manager of the tree structures extracted from the raw file.
use_counting(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
int sl
Definition: adpcm.c:105

Generated on Mon Feb 12 2024 13:02:52 for PandA-2024.02 by doxygen 1.8.13