Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
99f6ab7e
Commit
99f6ab7e
authored
17 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
Add initial iterator support for folding set.
llvm-svn: 42589
parent
f0e5011d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/include/llvm/ADT/FoldingSet.h
+51
-0
51 additions, 0 deletions
llvm/include/llvm/ADT/FoldingSet.h
llvm/lib/Support/FoldingSet.cpp
+32
-0
32 additions, 0 deletions
llvm/lib/Support/FoldingSet.cpp
with
83 additions
and
0 deletions
llvm/include/llvm/ADT/FoldingSet.h
+
51
−
0
View file @
99f6ab7e
...
...
@@ -220,6 +220,8 @@ protected:
typedef
FoldingSetImpl
::
Node
FoldingSetNode
;
typedef
FoldingSetImpl
::
NodeID
FoldingSetNodeID
;
template
<
class
T
>
class
FoldingSetIterator
;
//===----------------------------------------------------------------------===//
/// FoldingSet - This template class is used to instantiate a specialized
/// implementation of the folding set to the node class T. T must be a
...
...
@@ -238,6 +240,14 @@ public:
explicit
FoldingSet
(
unsigned
Log2InitSize
=
6
)
:
FoldingSetImpl
(
Log2InitSize
)
{}
typedef
FoldingSetIterator
<
T
>
iterator
;
iterator
begin
()
{
return
iterator
(
Buckets
);
}
iterator
end
()
{
return
iterator
(
Buckets
+
NumBuckets
);
}
typedef
FoldingSetIterator
<
const
T
>
const_iterator
;
const_iterator
begin
()
const
{
return
const_iterator
(
Buckets
);
}
const_iterator
end
()
const
{
return
const_iterator
(
Buckets
+
NumBuckets
);
}
/// GetOrInsertNode - If there is an existing simple Node exactly
/// equal to the specified node, return it. Otherwise, insert 'N' and
...
...
@@ -254,6 +264,47 @@ public:
}
};
//===----------------------------------------------------------------------===//
/// FoldingSetIteratorImpl - This is the common iterator support shared by all
/// folding sets, which knows how to walk the folding set hash table.
class
FoldingSetIteratorImpl
{
protected:
FoldingSetNode
*
NodePtr
;
FoldingSetIteratorImpl
(
void
**
Bucket
);
void
advance
();
public:
bool
operator
==
(
const
FoldingSetIteratorImpl
&
RHS
)
const
{
return
NodePtr
==
RHS
.
NodePtr
;
}
bool
operator
!=
(
const
FoldingSetIteratorImpl
&
RHS
)
const
{
return
NodePtr
!=
RHS
.
NodePtr
;
}
};
template
<
class
T
>
class
FoldingSetIterator
:
public
FoldingSetIteratorImpl
{
public:
FoldingSetIterator
(
void
**
Bucket
)
:
FoldingSetIteratorImpl
(
Bucket
)
{}
T
&
operator
*
()
const
{
return
*
static_cast
<
T
*>
(
NodePtr
);
}
T
*
operator
->
()
const
{
return
static_cast
<
T
*>
(
NodePtr
);
}
inline
FoldingSetIterator
&
operator
++
()
{
// Preincrement
advance
();
return
*
this
;
}
FoldingSetIterator
operator
++
(
int
)
{
// Postincrement
FoldingSetIterator
tmp
=
*
this
;
++*
this
;
return
tmp
;
}
};
}
// End of namespace llvm.
...
...
This diff is collapsed.
Click to expand it.
llvm/lib/Support/FoldingSet.cpp
+
32
−
0
View file @
99f6ab7e
...
...
@@ -151,6 +151,7 @@ static FoldingSetImpl::Node *GetNextPtr(void *NextInBucketPtr) {
/// testing.
static
void
**
GetBucketPtr
(
void
*
NextInBucketPtr
)
{
intptr_t
Ptr
=
reinterpret_cast
<
intptr_t
>
(
NextInBucketPtr
);
assert
((
Ptr
&
1
)
&&
"Not a bucket pointer"
);
return
reinterpret_cast
<
void
**>
(
Ptr
&
~
intptr_t
(
1
));
}
...
...
@@ -323,3 +324,34 @@ FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
InsertNode
(
N
,
IP
);
return
N
;
}
//===----------------------------------------------------------------------===//
// FoldingSetIteratorImpl Implementation
FoldingSetIteratorImpl
::
FoldingSetIteratorImpl
(
void
**
Bucket
)
{
// Skip to the first non-null non-self-cycle bucket.
while
(
*
Bucket
==
0
||
GetNextPtr
(
*
Bucket
)
==
0
)
++
Bucket
;
NodePtr
=
static_cast
<
FoldingSetNode
*>
(
*
Bucket
);
}
void
FoldingSetIteratorImpl
::
advance
()
{
// If there is another link within this bucket, go to it.
void
*
Probe
=
NodePtr
->
getNextInBucket
();
if
(
FoldingSetNode
*
NextNodeInBucket
=
GetNextPtr
(
Probe
))
NodePtr
=
NextNodeInBucket
;
else
{
// Otherwise, this is the last link in this bucket.
void
**
Bucket
=
GetBucketPtr
(
Probe
);
// Skip to the next non-null non-self-cycle bucket.
do
{
++
Bucket
;
}
while
(
*
Bucket
==
0
||
GetNextPtr
(
*
Bucket
)
==
0
);
NodePtr
=
static_cast
<
FoldingSetNode
*>
(
*
Bucket
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment