PandA-2024.02
extract_gimple_cond_op.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  */
43 
45 #include "Parameter.hpp"
46 
48 #include "application_manager.hpp"
49 #include "function_behavior.hpp"
50 
52 #include "tree_basic_block.hpp"
53 #include "tree_helper.hpp"
54 #include "tree_manager.hpp"
55 #include "tree_manipulation.hpp"
56 #include "tree_node.hpp"
57 #include "tree_reindex.hpp"
58 
60 #include "dbgPrintHelper.hpp"
61 #include "string_manipulation.hpp" // for GET_CLASS
62 
64  const DesignFlowManagerConstRef _design_flow_manager,
65  const unsigned int _function_id, const ParameterConstRef _parameters)
66  : FunctionFrontendFlowStep(_AppM, _function_id, EXTRACT_GIMPLE_COND_OP, _design_flow_manager, _parameters),
67  bb_modified(false)
68 {
69  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
70 }
71 
73 
75 {
76  bb_modified = false;
77 }
78 
81 {
83  switch(relationship_type)
84  {
86  {
87  relationships.insert(std::make_pair(USE_COUNTING, SAME_FUNCTION));
88  break;
89  }
91  {
92  break;
93  }
95  {
96  break;
97  }
98  default:
99  {
100  THROW_UNREACHABLE("");
101  }
102  }
103  return relationships;
104 }
105 
107 {
108  bb_modified = false;
109  const auto TM = AppM->get_tree_manager();
110  const auto tree_man = tree_manipulationConstRef(new tree_manipulation(TM, parameters, AppM));
111  const auto fd = GetPointer<function_decl>(TM->GetTreeNode(function_id));
112  const auto sl = GetPointer<statement_list>(GET_NODE(fd->body));
113  for(const auto& block : sl->list_of_bloc)
114  {
115  const auto& stmt_list = block.second->CGetStmtList();
116  if(stmt_list.size())
117  {
118  const auto last_stmt = stmt_list.back();
119  auto gc = GetPointer<gimple_cond>(GET_NODE(last_stmt));
120  if(gc && (!tree_helper::IsBooleanType(gc->op0) ||
121  (GET_NODE(gc->op0)->get_kind() != ssa_name_K && !GetPointer<cst_node>(GET_NODE(gc->op0)))))
122  {
123  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---fixing gimple cond: " + last_stmt->ToString());
124  auto new_gc_cond = tree_man->ExtractCondition(last_stmt, block.second, function_id);
125  TM->ReplaceTreeNode(last_stmt, gc->op0, new_gc_cond);
126  bb_modified = true;
127  }
128  }
129  }
130  bb_modified ? function_behavior->UpdateBBVersion() : 0;
132 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Analysis step that extract condition from gimple_cond.
#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.
DesignFlowStep_Status InternalExec() override
Updates the tree to have a more compliant CFG.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Data structure describing a basic block at tree level.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
ExtractGimpleCondOp(const application_managerRef AppM, const DesignFlowManagerConstRef design_flow_manager, const unsigned int function_id, const ParameterConstRef parameters)
Constructor.
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.
static bool IsBooleanType(const tree_nodeConstRef &type)
Return true if the treenode is of bool type.
bool bb_modified
flag used to restart code motion step
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
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
refcount< const tree_manipulation > tree_manipulationConstRef
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
~ExtractGimpleCondOp() override
Destructor.
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

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