[syntax tree]: debugging phi-nodes simplification

This commit is contained in:
Philippe Tillet
2019-01-06 21:33:53 -05:00
parent 179890c7ad
commit 0dd4a52ce5
2 changed files with 12 additions and 2 deletions

View File

@@ -86,6 +86,7 @@ public:
// Utils // Utils
void replace_all_uses_with(value *target); void replace_all_uses_with(value *target);
void replace_uses_of_with(value *before, value *after);
private: private:
std::vector<use> ops_; std::vector<use> ops_;

View File

@@ -1,4 +1,5 @@
#include "ir/value.h" #include "ir/value.h"
#include <iostream>
#include <cassert> #include <cassert>
namespace tdl{ namespace tdl{
@@ -64,10 +65,18 @@ unsigned user::get_num_operands() const {
} }
void user::replace_all_uses_with(value *target) { void user::replace_all_uses_with(value *target) {
for(use &u: uses_){ for(use &u: uses_)
u.set(target); if(auto *usr = dynamic_cast<user*>(u.get())){
std::cout << "replacing " << this << " by " << target << " in " << usr << std::endl;
usr->replace_uses_of_with(this, target);
} }
} }
void user::replace_uses_of_with(value *before, value *after) {
for(use &u: ops_)
if(u.get() == before)
u.set(after);
}
} }
} }