PandA-2024.02
un_comparison_lowering.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) 2016-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  */
43 
45 #include "Parameter.hpp"
46 
48 #include "application_manager.hpp"
49 #include "function_behavior.hpp"
50 
52 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
53 #include "string_manipulation.hpp" // for GET_CLASS
54 #include "tree_basic_block.hpp"
55 #include "tree_helper.hpp"
56 #include "tree_manager.hpp"
57 #include "tree_manipulation.hpp"
58 #include "tree_node.hpp"
59 #include "tree_reindex.hpp"
60 
62  const DesignFlowManagerConstRef _design_flow_manager,
63  const ParameterConstRef _parameters)
64  : FunctionFrontendFlowStep(_AppM, _function_id, UN_COMPARISON_LOWERING, _design_flow_manager, _parameters)
65 {
66  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
67 }
68 
70 
73 {
75  switch(relationship_type)
76  {
78  {
79  relationships.insert(std::make_pair(EXTRACT_GIMPLE_COND_OP, SAME_FUNCTION));
80  relationships.insert(std::make_pair(USE_COUNTING, SAME_FUNCTION));
81  break;
82  }
84  {
85  break;
86  }
88  {
89  break;
90  }
91  default:
92  {
94  }
95  }
96  return relationships;
97 }
98 
100 {
101  bool modified = false;
102  const auto TreeM = AppM->get_tree_manager();
103  const auto tree_man = tree_manipulationRef(new tree_manipulation(TreeM, parameters, AppM));
104  const auto curr_tn = TreeM->CGetTreeNode(function_id);
105  const auto Scpe = TreeM->CGetTreeReindex(function_id);
106  const auto fd = GetPointerS<const function_decl>(curr_tn);
107  const auto sl = GetPointerS<const statement_list>(GET_CONST_NODE(fd->body));
108  for(const auto& block : sl->list_of_bloc)
109  {
110  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing BB" + STR(block.first));
111  for(const auto& stmt : block.second->CGetStmtList())
112  {
113  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing " + stmt->ToString());
114  if(GET_CONST_NODE(stmt)->get_kind() != gimple_assign_K)
115  {
117  continue;
118  }
119  const auto ga = GetPointerS<const gimple_assign>(GET_CONST_NODE(stmt));
120  const auto rhs_kind = GET_CONST_NODE(ga->op1)->get_kind();
121  if(rhs_kind == unlt_expr_K || rhs_kind == unge_expr_K || rhs_kind == ungt_expr_K || rhs_kind == unle_expr_K ||
122  rhs_kind == ltgt_expr_K)
123  {
124  const auto be = GetPointerS<const binary_expr>(GET_CONST_NODE(ga->op1));
125  const auto srcp_string = be->include_name + ":" + STR(be->line_number) + ":" + STR(be->column_number);
126  kind new_kind = error_mark_K;
127  if(rhs_kind == unlt_expr_K)
128  {
129  new_kind = ge_expr_K;
130  }
131  else if(rhs_kind == unge_expr_K)
132  {
133  new_kind = lt_expr_K;
134  }
135  else if(rhs_kind == ungt_expr_K)
136  {
137  new_kind = le_expr_K;
138  }
139  else if(rhs_kind == unle_expr_K)
140  {
141  new_kind = gt_expr_K;
142  }
143  else if(rhs_kind == ltgt_expr_K)
144  {
145  new_kind = eq_expr_K;
146  }
147  else
148  {
149  THROW_UNREACHABLE("");
150  }
151 
152  const auto booleanType = tree_man->GetBooleanType();
153  const auto new_be = tree_man->create_binary_operation(booleanType, be->op0, be->op1, srcp_string, new_kind);
154  const auto new_ga = tree_man->CreateGimpleAssign(booleanType, TreeM->CreateUniqueIntegerCst(0, booleanType),
155  TreeM->CreateUniqueIntegerCst(1, booleanType), new_be,
156  function_id, srcp_string);
157  block.second->PushBefore(new_ga, stmt, AppM);
158  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Created " + STR(new_ga));
159  const auto new_not = tree_man->create_unary_operation(
160  booleanType, GetPointerS<const gimple_assign>(GET_CONST_NODE(new_ga))->op0, srcp_string,
161  truth_not_expr_K);
162  if(GET_INDEX_CONST_NODE(be->type) != GET_INDEX_CONST_NODE(booleanType))
163  {
164  const auto new_ga_not = tree_man->CreateGimpleAssign(
165  booleanType, TreeM->CreateUniqueIntegerCst(0, booleanType),
166  TreeM->CreateUniqueIntegerCst(1, booleanType), new_not, function_id, srcp_string);
167  block.second->PushBefore(new_ga_not, stmt, AppM);
168  const auto new_nop = tree_man->create_unary_operation(
169  be->type, GetPointerS<const gimple_assign>(GET_CONST_NODE(new_ga_not))->op0, srcp_string,
170  nop_expr_K);
171  TreeM->ReplaceTreeNode(stmt, ga->op1, new_nop);
172  }
173  else
174  {
175  TreeM->ReplaceTreeNode(stmt, ga->op1, new_not);
176  }
177  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Transformed into " + STR(stmt));
178  THROW_ASSERT(!ga->vdef && ga->vuses.empty() && ga->vovers.empty(), "Unhandled virtual ssas");
179  modified = true;
180  }
181  else
182  {
184  }
185  }
186  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed BB" + STR(block.first));
187  }
188  if(modified)
189  {
190  function_behavior->UpdateBBVersion();
191  }
193 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
File containing functions and utilities to support the printing of debug messagges.
Step successfully executed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
refcount< tree_manipulation > tree_manipulationRef
RelationshipType
The relationship type.
Source must be executed to satisfy target.
~UnComparisonLowering() override
Destructor.
Data structure describing a basic block at tree level.
#define STR(s)
Macro which performs a lexical_cast to a string.
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
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.
DesignFlowStep_Status InternalExec() override
Fixes the var_decl duplication.
UnComparisonLowering(const application_managerRef AppM, unsigned int _function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
kind
#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.
Step that replace uneq_expr, ltgt_expr, unge_expr, ungt_expr, unle_expr and unlt_expr.
Class defining some useful functions to create tree nodes and to manipulate the tree manager...
This struct specifies the block node.
Definition: tree_node.hpp:1820
This file collects some utility functions.
const unsigned int function_id
The index of the function to be analyzed.
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
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
#define GET_INDEX_CONST_NODE(t)
Definition: tree_node.hpp:363
This class creates a layer to add nodes and to manipulate the tree_nodes manager. ...
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
int sl
Definition: adpcm.c:105
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

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