1 //===- OrderedBasicBlockTest.cpp - OrderedBasicBlock unit tests -----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/OrderedBasicBlock.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/IR/BasicBlock.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/DataTypes.h"
16 #include "llvm/Support/SourceMgr.h"
17 #include "gtest/gtest.h"
22 class OrderedBasicBlockTest
: public testing::Test
{
26 std::unique_ptr
<Module
> makeLLVMModule() {
27 const char *ModuleString
= R
"(define i32 @f(i32 %x) {
32 auto foo
= parseAssemblyString(ModuleString
, Err
, C
);
37 TEST_F(OrderedBasicBlockTest
, Basic
) {
38 auto M
= makeLLVMModule();
39 Function
*F
= M
->getFunction("f");
40 BasicBlock::iterator I
= F
->front().begin();
41 Instruction
*Add
= &*I
++;
42 Instruction
*Ret
= &*I
++;
44 OrderedBasicBlock
OBB(&F
->front());
45 // Intentionally duplicated to verify cached and uncached are the same.
46 EXPECT_FALSE(OBB
.dominates(Add
, Add
));
47 EXPECT_FALSE(OBB
.dominates(Add
, Add
));
48 EXPECT_TRUE(OBB
.dominates(Add
, Ret
));
49 EXPECT_TRUE(OBB
.dominates(Add
, Ret
));
50 EXPECT_FALSE(OBB
.dominates(Ret
, Add
));
51 EXPECT_FALSE(OBB
.dominates(Ret
, Add
));
52 EXPECT_FALSE(OBB
.dominates(Ret
, Ret
));
53 EXPECT_FALSE(OBB
.dominates(Ret
, Ret
));
56 } // end anonymous namespace
57 } // end namespace llvm