Permalink
Browse files

use the earliest declared instead of lowest register

  • Loading branch information...
1 parent d725e42 commit ee956c184e1485b23d9cd230027f96987fbd7296 @andrewrk committed Oct 18, 2010
Showing with 16 additions and 19 deletions.
  1. +2 −2 code_generation.cpp
  2. +1 −4 tests/control_flow/maths.p
  3. +13 −13 two_way_map.h
View
@@ -892,7 +892,7 @@ void CodeGenerator::basic_block_value_numbering(BasicBlock * block) {
// replace operator instruction with a copy instruction if we can
std::string hash = hash_operator_instruction(block, operator_instruction);
- std::set<int> * registers = block->value_numbers.keys(hash);
+ std::list<int> * registers = block->value_numbers.keys(hash);
if (registers != NULL && registers->size() > 0) {
int lowest = *(registers->begin());
CopyInstruction * copy_instruction = new CopyInstruction(operator_instruction->dest, Variant(lowest, Variant::REGISTER));
@@ -1581,7 +1581,7 @@ CodeGenerator::Variant CodeGenerator::inline_value(BasicBlock * block, Variant r
if (register_or_const.type == Variant::REGISTER) {
Variant value = block->value_numbers.get(register_or_const._int);
if (value.type == Variant::VALUE_NUMBER) {
- std::set<int> * registers = block->value_numbers.keys(value);
+ std::list<int> * registers = block->value_numbers.keys(value);
int lowest = *(registers->begin());
return Variant(lowest, Variant::REGISTER);
} else {
@@ -27,10 +27,7 @@ class Main begin
print b;
- b := ---------a;
- print b;
-
- d := not not not not c;
+ d := not c;
print d;
View
@@ -2,22 +2,22 @@
#define TWO_WAY_MAP_H
#include <map>
-#include <set>
+#include <list>
template <class K, class V>
class TwoWayMap
{
public:
void associate(K key, V value);
- std::set<K> * keys(V value);
+ std::list<K> * keys(V value);
V get(K key);
// make this TwoWayMap equal to other
void associate_all(const TwoWayMap & other);
bool is_empty() const;
private:
std::map<K, V> forward;
- std::map<V, std::set<K> *> backward;
+ std::map<V, std::list<K> *> backward;
};
template <class K, class V>
@@ -33,7 +33,7 @@ bool TwoWayMap<K, V>::is_empty() const {
}
template <class K, class V>
-std::set<K> * TwoWayMap<K, V>::keys(V value){
+std::list<K> * TwoWayMap<K, V>::keys(V value){
if (backward.count(value))
return backward[value];
else
@@ -50,24 +50,24 @@ void TwoWayMap<K, V>::associate(K key, V value){
// destroy old association
if (forward.count(key)) {
V old_value = forward[key];
- std::set<K> * set = backward[old_value];
- set->erase(key);
- if (set->size() == 0) {
- delete set;
+ std::list<K> * list = backward[old_value];
+ list->remove(key);
+ if (list->size() == 0) {
+ delete list;
backward.erase(old_value);
}
}
// make new one
forward[key] = value;
- std::set<K> * set;
+ std::list<K> * list;
if (backward.count(value)) {
- set = backward[value];
+ list = backward[value];
} else {
- set = new std::set<K>();
- backward[value] = set;
+ list = new std::list<K>();
+ backward[value] = list;
}
- set->insert(key);
+ list->push_back(key);
}

0 comments on commit ee956c1

Please sign in to comment.