53 static RegisterPass<MachineDCE>
54 R(
"machinedce",
"Symbol string based machine DCE for removing not used emulation functions",
false,
true);
63 if (avoid_recursion.find(&user) != avoid_recursion.end()) {
66 avoid_recursion.insert(&user);
77 for (UserList::iterator i= usesList.begin(); i != usesList.end(); i++) {
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."
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)) {
103 for (
unsigned i = 0, e = init->getNumOperands(); i != e; ++i) {
113 #ifdef DEBUG_MACHINE_DCE
114 std::cerr <<
"Initializing MachineDCE\n";
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")))
122 #ifdef DEBUG_MACHINE_DCE
123 std::cerr <<
"Added " << f->getName().str()
124 <<
" to entry/exit functions"
132 for (Module::const_global_iterator i = M.global_begin();
133 i != M.global_end(); i++) {
134 std::string name = i->getName().str();
136 if (!i->hasInitializer()) {
138 assert(
false &&
"No initializer. External linkage?");
141 const Constant* initializer = i->getInitializer();
143 const Type* type = initializer->getType();
144 errs() <<
"Data name: " << name
145 <<
"\ttype: " << type->getDescription() <<
"\n";
154 std::string funcName = F.getFunction().getName().str();
159 for (MachineFunction::const_iterator i = F.begin();
161 for (MachineBasicBlock::const_iterator j = i->begin();
162 j != i->end(); j++) {
164 for (
unsigned k = 0; k < j->getNumOperands(); k++) {
165 const MachineOperand& mo = j->getOperand(k);
170 moName = mo.getGlobal()->getName().str();
171 }
else if (mo.isSymbol()) {
172 moName = mo.getSymbolName();
175 if (!moName.empty()) {
196 #ifdef DEBUG_MACHINE_DCE
197 std::cerr <<
"Function was not referred add it to dce data: "
198 << func->first <<
"\n";