Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
bindings
cmake
docs
examples
include
lib
projects
resources
runtimes
scripts
test
tools
unittests
ADT
APFloatTest.cpp.REMOVED.git-id
APIntTest.cpp
APSIntTest.cpp
ArrayRefTest.cpp
BitVectorTest.cpp
BitmaskEnumTest.cpp
BreadthFirstIteratorTest.cpp
BumpPtrListTest.cpp
CMakeLists.txt
DAGDeltaAlgorithmTest.cpp
DeltaAlgorithmTest.cpp
DenseMapTest.cpp
DenseSetTest.cpp
DepthFirstIteratorTest.cpp
EquivalenceClassesTest.cpp
FoldingSet.cpp
FunctionRefTest.cpp
HashingTest.cpp
IListBaseTest.cpp
IListIteratorTest.cpp
IListNodeBaseTest.cpp
IListNodeTest.cpp
IListSentinelTest.cpp
IListTest.cpp
ImmutableMapTest.cpp
ImmutableSetTest.cpp
IntEqClassesTest.cpp
IntervalMapTest.cpp
IntrusiveRefCntPtrTest.cpp
IteratorTest.cpp
MakeUniqueTest.cpp
MapVectorTest.cpp
MappedIteratorTest.cpp
OptionalTest.cpp
PackedVectorTest.cpp
PointerEmbeddedIntTest.cpp
PointerIntPairTest.cpp
PointerSumTypeTest.cpp
PointerUnionTest.cpp
PostOrderIteratorTest.cpp
PriorityWorklistTest.cpp
RangeAdapterTest.cpp
SCCIteratorTest.cpp
STLExtrasTest.cpp
ScopeExitTest.cpp
SequenceTest.cpp
SetVectorTest.cpp
SimpleIListTest.cpp
SmallPtrSetTest.cpp
SmallStringTest.cpp
SmallVectorTest.cpp
SparseBitVectorTest.cpp
SparseMultiSetTest.cpp
SparseSetTest.cpp
StringExtrasTest.cpp
StringMapTest.cpp
StringRefTest.cpp
StringSwitchTest.cpp
TestGraph.h
TinyPtrVectorTest.cpp
TripleTest.cpp
TwineTest.cpp
VariadicFunctionTest.cpp
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
ExecutionEngine
FuzzMutate
IR
LineEditor
Linker
MC
MI
Object
ObjectYAML
Option
ProfileData
Support
Target
Transforms
XRay
tools
CMakeLists.txt
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
version.txt.in
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/llvm/unittests/ADT/SCCIteratorTest.cpp

122 lines
4.5 KiB
C++
Raw Normal View History

//===----- llvm/unittest/ADT/SCCIteratorTest.cpp - SCCIterator tests ------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SCCIterator.h"
#include "TestGraph.h"
#include "gtest/gtest.h"
#include <limits.h>
using namespace llvm;
namespace llvm {
TEST(SCCIteratorTest, AllSmallGraphs) {
// Test SCC computation against every graph with NUM_NODES nodes or less.
// Since SCC considers every node to have an implicit self-edge, we only
// create graphs for which every node has a self-edge.
#define NUM_NODES 4
#define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1))
typedef Graph<NUM_NODES> GT;
/// Enumerate all graphs using NUM_GRAPHS bits.
static_assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT, "Too many graphs!");
for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS);
++GraphDescriptor) {
GT G;
// Add edges as specified by the descriptor.
unsigned DescriptorCopy = GraphDescriptor;
for (unsigned i = 0; i != NUM_NODES; ++i)
for (unsigned j = 0; j != NUM_NODES; ++j) {
// Always add a self-edge.
if (i == j) {
G.AddEdge(i, j);
continue;
}
if (DescriptorCopy & 1)
G.AddEdge(i, j);
DescriptorCopy >>= 1;
}
// Test the SCC logic on this graph.
/// NodesInSomeSCC - Those nodes which are in some SCC.
GT::NodeSubset NodesInSomeSCC;
for (scc_iterator<GT> I = scc_begin(G), E = scc_end(G); I != E; ++I) {
const std::vector<GT::NodeType *> &SCC = *I;
// Get the nodes in this SCC as a NodeSubset rather than a vector.
GT::NodeSubset NodesInThisSCC;
for (unsigned i = 0, e = SCC.size(); i != e; ++i)
NodesInThisSCC.AddNode(SCC[i]->first);
// There should be at least one node in every SCC.
EXPECT_FALSE(NodesInThisSCC.isEmpty());
// Check that every node in the SCC is reachable from every other node in
// the SCC.
for (unsigned i = 0; i != NUM_NODES; ++i)
if (NodesInThisSCC.count(i)) {
EXPECT_TRUE(NodesInThisSCC.isSubsetOf(G.NodesReachableFrom(i)));
}
// OK, now that we now that every node in the SCC is reachable from every
// other, this means that the set of nodes reachable from any node in the
// SCC is the same as the set of nodes reachable from every node in the
// SCC. Check that for every node N not in the SCC but reachable from the
// SCC, no element of the SCC is reachable from N.
for (unsigned i = 0; i != NUM_NODES; ++i)
if (NodesInThisSCC.count(i)) {
GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i);
GT::NodeSubset ReachableButNotInSCC =
NodesReachableFromSCC.Meet(NodesInThisSCC.Complement());
for (unsigned j = 0; j != NUM_NODES; ++j)
if (ReachableButNotInSCC.count(j)) {
EXPECT_TRUE(G.NodesReachableFrom(j).Meet(NodesInThisSCC).isEmpty());
}
// The result must be the same for all other nodes in this SCC, so
// there is no point in checking them.
break;
}
// This is indeed a SCC: a maximal set of nodes for which each node is
// reachable from every other.
// Check that we didn't already see this SCC.
EXPECT_TRUE(NodesInSomeSCC.Meet(NodesInThisSCC).isEmpty());
NodesInSomeSCC = NodesInSomeSCC.Join(NodesInThisSCC);
// Check a property that is specific to the LLVM SCC iterator and
// guaranteed by it: if a node in SCC S1 has an edge to a node in
// SCC S2, then S1 is visited *after* S2. This means that the set
// of nodes reachable from this SCC must be contained either in the
// union of this SCC and all previously visited SCC's.
for (unsigned i = 0; i != NUM_NODES; ++i)
if (NodesInThisSCC.count(i)) {
GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i);
EXPECT_TRUE(NodesReachableFromSCC.isSubsetOf(NodesInSomeSCC));
// The result must be the same for all other nodes in this SCC, so
// there is no point in checking them.
break;
}
}
// Finally, check that the nodes in some SCC are exactly those that are
// reachable from the initial node.
EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0));
}
}
}