Skip to content

Add an AccessPath abstraction and formalize memory access #33121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 395 additions & 0 deletions docs/SILProgrammersManual.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H
#define SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H

#include "swift/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include <algorithm>
Expand All @@ -21,15 +22,18 @@ namespace swift {

// Trie node representing a sequence of unsigned integer indices.
class IndexTrieNode {
static const unsigned RootIdx = ~0U;
unsigned Index;
public:
static const int RootIndex = std::numeric_limits<int>::min();

private:
int Index;
llvm::SmallVector<IndexTrieNode*, 8> Children;
IndexTrieNode *Parent;

public:
IndexTrieNode(): Index(RootIdx), Parent(nullptr) {}
IndexTrieNode() : Index(RootIndex), Parent(nullptr) {}

explicit IndexTrieNode(unsigned V, IndexTrieNode *P): Index(V), Parent(P) {}
explicit IndexTrieNode(int V, IndexTrieNode *P) : Index(V), Parent(P) {}

IndexTrieNode(IndexTrieNode &) =delete;
IndexTrieNode &operator=(const IndexTrieNode&) =delete;
Expand All @@ -39,19 +43,18 @@ class IndexTrieNode {
delete N;
}

bool isRoot() const { return Index == RootIdx; }
bool isRoot() const { return Index == RootIndex; }

bool isLeaf() const { return Children.empty(); }

unsigned getIndex() const { return Index; }
int getIndex() const { return Index; }

IndexTrieNode *getChild(unsigned Idx) {
assert(Idx != RootIdx);
IndexTrieNode *getChild(int Idx) {
assert(Idx != RootIndex);

auto I = std::lower_bound(Children.begin(), Children.end(), Idx,
[](IndexTrieNode *a, unsigned i) {
return a->Index < i;
});
auto I =
std::lower_bound(Children.begin(), Children.end(), Idx,
[](IndexTrieNode *a, int i) { return a->Index < i; });
if (I != Children.end() && (*I)->Index == Idx)
return *I;
auto *N = new IndexTrieNode(Idx, this);
Expand Down
Loading