Skip to content

Commit

Permalink
fix type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich committed Aug 12, 2023
1 parent a7db7a6 commit d6c628a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion enzyme/Enzyme/TypeAnalysis/Trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <map>
#include <limits>
#include <stdexcept>
#include <cassert>

#define private public

Expand Down Expand Up @@ -184,7 +185,7 @@ class trie_const_iterator {

explicit trie_const_iterator(const trie<Key, T, Allocator> *trie, const trie_node<Key, Index, value_type> *n) : _trie(trie), _node{n} {}

explicit trie_const_iterator(const trie_iterator<Key, Index, T, Allocator> iter) : _trie(iter._trie), _node{iter._node} {}
trie_const_iterator(const trie_iterator<Key, Index, T, Allocator> iter) : _trie(iter._trie), _node{iter._node} {}

trie_const_iterator(const trie_const_iterator &other) : _trie(other._trie), _node(other._node) {}

Expand Down
21 changes: 10 additions & 11 deletions enzyme/Enzyme/TypeAnalysis/TypeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "../Utils.h"
#include "BaseType.h"
#include "ConcreteType.h"
#include "Trie.h"

/// Maximum offset for type trees to keep
extern "C" {
Expand All @@ -64,15 +65,13 @@ static inline std::string to_string(const std::vector<int> x) {
class TypeTree;

typedef std::shared_ptr<const TypeTree> TypeResult;
typedef std::map<const std::vector<int>, ConcreteType> ConcreteTypeMapType;
typedef std::map<const std::vector<int>, const TypeResult> TypeTreeMapType;

/// Class representing the underlying types of values as
/// sequences of offsets to a ConcreteType
class TypeTree : public std::enable_shared_from_this<TypeTree> {
private:
// mapping of known indices to type if one exists
ConcreteTypeMapType mapping;
trie<std::vector<int>, ConcreteType> mapping;
std::vector<int> minIndices;

public:
Expand All @@ -84,7 +83,7 @@ class TypeTree : public std::enable_shared_from_this<TypeTree> {
}

/// Utility helper to lookup the mapping
const ConcreteTypeMapType &getMapping() const { return mapping; }
const trie<std::vector<int>, ConcreteType> &getMapping() const { return mapping; }

/// Lookup the underlying ConcreteType at a given offset sequence
/// or Unknown if none exists
Expand Down Expand Up @@ -888,7 +887,7 @@ class TypeTree : public std::enable_shared_from_this<TypeTree> {
minIndices = RHS.minIndices;
mapping.clear();
for (const auto &elems : RHS.mapping) {
mapping.emplace(elems);
mapping.insert(elems);
}
return true;
}
Expand Down Expand Up @@ -1121,20 +1120,20 @@ class TypeTree : public std::enable_shared_from_this<TypeTree> {
}

// mapings just on the right
for (auto &pair : RHS.mapping) {
for (auto&& [key, ct] : RHS.mapping) {
// TODO propagate non-first level operands:
// Special handling is necessary here because a pointer to an int
// binop with something should not apply the binop rules to the
// underlying data but instead a different rule
if (pair.first.size() > 0) {
if (key.size() > 0) {
continue;
}

if (mapping.find(pair.first) == RHS.mapping.end()) {
if (RHS.mapping.end() == mapping.find(key)) {
ConcreteType CT = BaseType::Unknown;
changed |= CT.binopIn(pair.second, Op);
changed |= CT.binopIn(ct, Op);
if (CT != BaseType::Unknown) {
mapping.insert(std::make_pair(pair.first, CT));
mapping.insert(std::make_pair(key, CT));
}
}
}
Expand Down

0 comments on commit d6c628a

Please sign in to comment.