1 //===- OrderedBasicBlockTest.cpp - OrderedBasicBlock unit tests -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Analysis/OrderedBasicBlock.h"
11 #include "llvm/AsmParser/Parser.h"
12 #include "llvm/IR/BasicBlock.h"
13 #include "llvm/IR/Function.h"
14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/Support/DataTypes.h"
17 #include "llvm/Support/SourceMgr.h"
18 #include "gtest/gtest.h"
23 class OrderedBasicBlockTest
: public testing::Test
{
27 std::unique_ptr
<Module
> makeLLVMModule() {
28 const char *ModuleString
= R
"(define i32 @f(i32 %x) {
33 auto foo
= parseAssemblyString(ModuleString
, Err
, C
);
38 TEST_F(OrderedBasicBlockTest
, Basic
) {
39 auto M
= makeLLVMModule();
40 Function
*F
= M
->getFunction("f");
41 BasicBlock::iterator I
= F
->front().begin();
42 Instruction
*Add
= &*I
++;
43 Instruction
*Ret
= &*I
++;
45 OrderedBasicBlock
OBB(&F
->front());
46 // Intentionally duplicated to verify cached and uncached are the same.
47 EXPECT_FALSE(OBB
.dominates(Add
, Add
));
48 EXPECT_FALSE(OBB
.dominates(Add
, Add
));
49 EXPECT_TRUE(OBB
.dominates(Add
, Ret
));
50 EXPECT_TRUE(OBB
.dominates(Add
, Ret
));
51 EXPECT_FALSE(OBB
.dominates(Ret
, Add
));
52 EXPECT_FALSE(OBB
.dominates(Ret
, Add
));
53 EXPECT_FALSE(OBB
.dominates(Ret
, Ret
));
54 EXPECT_FALSE(OBB
.dominates(Ret
, Ret
));
57 } // end anonymous namespace
58 } // end namespace llvm