You've already forked linux-packaging-mono
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
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
ExecutionEngine
FuzzMutate
IR
AsmWriterTest.cpp
AttributesTest.cpp
BasicBlockTest.cpp
CFGBuilder.cpp
CFGBuilder.h
CMakeLists.txt
ConstantRangeTest.cpp
ConstantsTest.cpp
DebugInfoTest.cpp
DebugTypeODRUniquingTest.cpp
DominatorTreeBatchUpdatesTest.cpp
DominatorTreeTest.cpp
FunctionTest.cpp
IRBuilderTest.cpp
InstructionsTest.cpp
IntrinsicsTest.cpp
LegacyPassManagerTest.cpp
MDBuilderTest.cpp
MetadataTest.cpp
ModuleTest.cpp
PassBuilderCallbacksTest.cpp
PassManagerTest.cpp
PatternMatch.cpp
TypeBuilderTest.cpp
TypesTest.cpp
UseTest.cpp
UserTest.cpp
ValueHandleTest.cpp
ValueMapTest.cpp
ValueTest.cpp
VerifierTest.cpp
WaymarkTest.cpp
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
82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
![]() |
//===- llvm/unittest/IR/BasicBlockTest.cpp - BasicBlock unit tests --------===//
|
||
|
//
|
||
|
// The LLVM Compiler Infrastructure
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "llvm/IR/BasicBlock.h"
|
||
|
#include "llvm/ADT/STLExtras.h"
|
||
|
#include "llvm/IR/Function.h"
|
||
|
#include "llvm/IR/IRBuilder.h"
|
||
|
#include "llvm/IR/LLVMContext.h"
|
||
|
#include "llvm/IR/Module.h"
|
||
|
#include "llvm/IR/NoFolder.h"
|
||
|
#include "gmock/gmock-matchers.h"
|
||
|
#include "gtest/gtest.h"
|
||
|
#include <memory>
|
||
|
|
||
|
namespace llvm {
|
||
|
namespace {
|
||
|
|
||
|
TEST(BasicBlockTest, PhiRange) {
|
||
|
LLVMContext Context;
|
||
|
|
||
|
// Create the main block.
|
||
|
std::unique_ptr<BasicBlock> BB(BasicBlock::Create(Context));
|
||
|
|
||
|
// Create some predecessors of it.
|
||
|
std::unique_ptr<BasicBlock> BB1(BasicBlock::Create(Context));
|
||
|
BranchInst::Create(BB.get(), BB1.get());
|
||
|
std::unique_ptr<BasicBlock> BB2(BasicBlock::Create(Context));
|
||
|
BranchInst::Create(BB.get(), BB2.get());
|
||
|
|
||
|
// Make sure this doesn't crash if there are no phis.
|
||
|
for (auto &PN : BB->phis()) {
|
||
|
(void)PN;
|
||
|
EXPECT_TRUE(false) << "empty block should have no phis";
|
||
|
}
|
||
|
|
||
|
// Make it a cycle.
|
||
|
auto *BI = BranchInst::Create(BB.get(), BB.get());
|
||
|
|
||
|
// Now insert some PHI nodes.
|
||
|
auto *Int32Ty = Type::getInt32Ty(Context);
|
||
|
auto *P1 = PHINode::Create(Int32Ty, /*NumReservedValues*/ 3, "phi.1", BI);
|
||
|
auto *P2 = PHINode::Create(Int32Ty, /*NumReservedValues*/ 3, "phi.2", BI);
|
||
|
auto *P3 = PHINode::Create(Int32Ty, /*NumReservedValues*/ 3, "phi.3", BI);
|
||
|
|
||
|
// Some non-PHI nodes.
|
||
|
auto *Sum = BinaryOperator::CreateAdd(P1, P2, "sum", BI);
|
||
|
|
||
|
// Now wire up the incoming values that are interesting.
|
||
|
P1->addIncoming(P2, BB.get());
|
||
|
P2->addIncoming(P1, BB.get());
|
||
|
P3->addIncoming(Sum, BB.get());
|
||
|
|
||
|
// Finally, let's iterate them, which is the thing we're trying to test.
|
||
|
// We'll use this to wire up the rest of the incoming values.
|
||
|
for (auto &PN : BB->phis()) {
|
||
|
PN.addIncoming(UndefValue::get(Int32Ty), BB1.get());
|
||
|
PN.addIncoming(UndefValue::get(Int32Ty), BB2.get());
|
||
|
}
|
||
|
|
||
|
// Test that we can use const iterators and generally that the iterators
|
||
|
// behave like iterators.
|
||
|
BasicBlock::const_phi_iterator CI;
|
||
|
CI = BB->phis().begin();
|
||
|
EXPECT_NE(CI, BB->phis().end());
|
||
|
|
||
|
// And iterate a const range.
|
||
|
for (const auto &PN : const_cast<const BasicBlock *>(BB.get())->phis()) {
|
||
|
EXPECT_EQ(BB.get(), PN.getIncomingBlock(0));
|
||
|
EXPECT_EQ(BB1.get(), PN.getIncomingBlock(1));
|
||
|
EXPECT_EQ(BB2.get(), PN.getIncomingBlock(2));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} // End anonymous namespace.
|
||
|
} // End llvm namespace.
|