OpenASIP  2.0
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
llvm::MachineDCE Struct Reference

#include <MachineDCE.hh>

Inheritance diagram for llvm::MachineDCE:
Inheritance graph
Collaboration diagram for llvm::MachineDCE:
Collaboration graph

Public Types

typedef std::map< std::string, MachineFunction * > FunctionMap
 
typedef std::set< std::string > UserList
 
typedef std::map< std::string, UserListUserRelations
 
typedef std::set< const std::string * > AvoidRecursionSet
 
typedef std::set< std::string > UnusedFunctionsList
 

Public Member Functions

 MachineDCE ()
 
virtual bool doInitialization (Module &M) override
 
virtual bool runOnMachineFunction (MachineFunction &F) override
 
virtual bool doFinalization (Module &M) override
 
virtual StringRef getPassName () const override
 
bool canFindStart (const std::string &user, AvoidRecursionSet &avoid_recursion)
 
void addInitializer (const Constant *init, std::string &name)
 

Public Attributes

FunctionMap functionMappings_
 Function name to MachineFunction map. More...
 
UserRelations usersOfValue_
 List of users of a symbol. More...
 
UserList baseUsers_
 If users are traced to this list it means that function cannot be eliminated. More...
 
UnusedFunctionsList removeableFunctions
 

Static Public Attributes

static char ID = 0
 

Detailed Description

Definition at line 66 of file MachineDCE.hh.

Member Typedef Documentation

◆ AvoidRecursionSet

typedef std::set<const std::string*> llvm::MachineDCE::AvoidRecursionSet

Definition at line 72 of file MachineDCE.hh.

◆ FunctionMap

typedef std::map<std::string, MachineFunction*> llvm::MachineDCE::FunctionMap

Definition at line 69 of file MachineDCE.hh.

◆ UnusedFunctionsList

typedef std::set<std::string> llvm::MachineDCE::UnusedFunctionsList

Definition at line 96 of file MachineDCE.hh.

◆ UserList

typedef std::set<std::string> llvm::MachineDCE::UserList

Definition at line 70 of file MachineDCE.hh.

◆ UserRelations

typedef std::map<std::string, UserList> llvm::MachineDCE::UserRelations

Definition at line 71 of file MachineDCE.hh.

Constructor & Destructor Documentation

◆ MachineDCE()

llvm::MachineDCE::MachineDCE ( )
inline

Definition at line 68 of file MachineDCE.hh.

68 : MachineFunctionPass(ID) {}

Member Function Documentation

◆ addInitializer()

void MachineDCE::addInitializer ( const Constant *  init,
std::string &  name 
)

Definition at line 85 of file MachineDCE.cc.

85  {
86 
87  if (const GlobalValue* gv = dyn_cast<GlobalValue>(init)) {
88 #ifdef DEBUG_MACHINE_DCE
89  errs() << "Added data " << name
90  << " to uses of value: " << gv->getName()
91  << " and " << name << " to baseUsers."
92  << "\n";
93 #endif
94  baseUsers_.insert(name);
95  usersOfValue_[gv->getName().str()].insert(name);
96  }
97 
98  if ((dyn_cast<ConstantArray>(init) != NULL) ||
99  (dyn_cast<ConstantStruct>(init) != NULL) ||
100  (dyn_cast<ConstantVector>(init) != NULL) ||
101  (dyn_cast<ConstantExpr>(init) != NULL)) {
102 
103  for (unsigned i = 0, e = init->getNumOperands(); i != e; ++i) {
104  //init->getOperand(i)->dump();
105  //addInitializer(dyn_cast<const Constant*>(init->getOperand(i)), name);
106  addInitializer(cast<Constant>(init->getOperand(i)), name);
107  }
108  }
109 }

References baseUsers_, and usersOfValue_.

Referenced by doInitialization().

◆ canFindStart()

bool MachineDCE::canFindStart ( const std::string &  user,
AvoidRecursionSet avoid_recursion 
)

Returns true if can find startpoint.

Definition at line 62 of file MachineDCE.cc.

62  {
63  if (avoid_recursion.find(&user) != avoid_recursion.end()) {
64  return false;
65  } else {
66  avoid_recursion.insert(&user);
67  }
68 
69  // current function is actually the start point.. nice job.
70  if (baseUsers_.find(user) != baseUsers_.end()) {
71  return true;
72  }
73 
74  UserList &usesList = usersOfValue_[user];
75 
76  // check if this function is used by start point to be sure...
77  for (UserList::iterator i= usesList.begin(); i != usesList.end(); i++) {
78  if (canFindStart((*i), avoid_recursion)) {
79  return true;
80  }
81  }
82  return false;
83 }

References baseUsers_, and usersOfValue_.

Referenced by doFinalization().

◆ doFinalization()

bool MachineDCE::doFinalization ( Module &  M)
overridevirtual

Definition at line 185 of file MachineDCE.cc.

185  {
186 
187  // errs() << "Finalizing MachineDCE\n";
188 
189  // For all functions check that they are reached from entrypoint of module.
190  for (FunctionMap::iterator func = functionMappings_.begin();
191  func != functionMappings_.end(); ++func) {
192 
193  AvoidRecursionSet avoid_recursion;
194 
195  if (!canFindStart(func->first, avoid_recursion)) {
196 #ifdef DEBUG_MACHINE_DCE
197  std::cerr << "Function was not referred add it to dce data: "
198  << func->first << "\n";
199 #endif
200  removeableFunctions.insert(func->first);
201  }
202  }
203 
204  return true;
205 }

References canFindStart(), functionMappings_, and removeableFunctions.

Here is the call graph for this function:

◆ doInitialization()

bool MachineDCE::doInitialization ( Module &  M)
overridevirtual

Definition at line 111 of file MachineDCE.cc.

111  {
112 
113 #ifdef DEBUG_MACHINE_DCE
114  std::cerr << "Initializing MachineDCE\n";
115 #endif
116 
117  for (Module::const_iterator f = M.begin(), e = M.end(); f != e; ++f) {
118  if (!(f->getName().equals("_start") ||
119  f->getName().equals("_exit")))
120  continue;
121  baseUsers_.insert(f->getName().data());
122 #ifdef DEBUG_MACHINE_DCE
123  std::cerr << "Added " << f->getName().str()
124  << " to entry/exit functions"
125  << std::endl;
126  f->dump();
127 #endif
128  continue;
129  }
130 
131  // Go through global variables to find out.
132  for (Module::const_global_iterator i = M.global_begin();
133  i != M.global_end(); i++) {
134  std::string name = i->getName().str();
135 
136  if (!i->hasInitializer()) {
137  continue;
138  assert(false && "No initializer. External linkage?");
139  }
140 
141  const Constant* initializer = i->getInitializer();
142 #if 0
143  const Type* type = initializer->getType();
144  errs() << "Data name: " << name
145  << "\ttype: " << type->getDescription() << "\n";
146 #endif
147  addInitializer(initializer, name);
148  }
149 
150  return true;
151 }

References addInitializer(), assert, and baseUsers_.

Here is the call graph for this function:

◆ getPassName()

virtual StringRef llvm::MachineDCE::getPassName ( ) const
inlineoverridevirtual

Definition at line 88 of file MachineDCE.hh.

88  {
89  return "TCE deadcode elimination of unused emulation functions";
90  }

◆ runOnMachineFunction()

bool MachineDCE::runOnMachineFunction ( MachineFunction &  F)
overridevirtual

Definition at line 153 of file MachineDCE.cc.

153  {
154  std::string funcName = F.getFunction().getName().str();
155 
156  // add function to function map...
157  functionMappings_[funcName] = &F;
158 
159  for (MachineFunction::const_iterator i = F.begin();
160  i != F.end(); i++) {
161  for (MachineBasicBlock::const_iterator j = i->begin();
162  j != i->end(); j++) {
163 
164  for (unsigned k = 0; k < j->getNumOperands(); k++) {
165  const MachineOperand& mo = j->getOperand(k);
166 
167  std::string moName;
168 
169  if (mo.isGlobal()) {
170  moName = mo.getGlobal()->getName().str();
171  } else if (mo.isSymbol()) {
172  moName = mo.getSymbolName();
173  }
174 
175  if (!moName.empty()) {
176  usersOfValue_[moName].insert(funcName);
177  }
178  }
179  }
180  }
181  return true;
182 }

References functionMappings_, and usersOfValue_.

Member Data Documentation

◆ baseUsers_

UserList llvm::MachineDCE::baseUsers_

If users are traced to this list it means that function cannot be eliminated.

Definition at line 82 of file MachineDCE.hh.

Referenced by addInitializer(), canFindStart(), and doInitialization().

◆ functionMappings_

FunctionMap llvm::MachineDCE::functionMappings_

Function name to MachineFunction map.

Definition at line 75 of file MachineDCE.hh.

Referenced by doFinalization(), and runOnMachineFunction().

◆ ID

char MachineDCE::ID = 0
static

Definition at line 67 of file MachineDCE.hh.

◆ removeableFunctions

UnusedFunctionsList llvm::MachineDCE::removeableFunctions

Definition at line 97 of file MachineDCE.hh.

Referenced by llvm::LLVMTCEBuilder::deleteDeadProcedures(), and doFinalization().

◆ usersOfValue_

UserRelations llvm::MachineDCE::usersOfValue_

List of users of a symbol.

Definition at line 78 of file MachineDCE.hh.

Referenced by addInitializer(), canFindStart(), and runOnMachineFunction().


The documentation for this struct was generated from the following files:
llvm::MachineDCE::ID
static char ID
Definition: MachineDCE.hh:67
llvm::MachineDCE::baseUsers_
UserList baseUsers_
If users are traced to this list it means that function cannot be eliminated.
Definition: MachineDCE.hh:82
llvm::MachineDCE::canFindStart
bool canFindStart(const std::string &user, AvoidRecursionSet &avoid_recursion)
Definition: MachineDCE.cc:62
llvm::MachineDCE::functionMappings_
FunctionMap functionMappings_
Function name to MachineFunction map.
Definition: MachineDCE.hh:75
assert
#define assert(condition)
Definition: Application.hh:86
llvm::MachineDCE::AvoidRecursionSet
std::set< const std::string * > AvoidRecursionSet
Definition: MachineDCE.hh:72
llvm::MachineDCE::addInitializer
void addInitializer(const Constant *init, std::string &name)
Definition: MachineDCE.cc:85
llvm::MachineDCE::usersOfValue_
UserRelations usersOfValue_
List of users of a symbol.
Definition: MachineDCE.hh:78
llvm::MachineDCE::removeableFunctions
UnusedFunctionsList removeableFunctions
Definition: MachineDCE.hh:97
llvm::MachineDCE::UserList
std::set< std::string > UserList
Definition: MachineDCE.hh:70