BuildBot fix, compiler complains about array decay to pointer
[llvm-core.git] / unittests / Analysis / OrderedInstructionsTest.cpp
blobdc1b25b8c02ec548ef70adce480f7885719cd2bc
1 //===- OrderedInstructions.cpp - Unit tests for OrderedInstructions ------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Analysis/OrderedInstructions.h"
11 #include "llvm/IR/BasicBlock.h"
12 #include "llvm/IR/Dominators.h"
13 #include "llvm/IR/IRBuilder.h"
14 #include "llvm/IR/Instructions.h"
15 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Module.h"
17 #include "gtest/gtest.h"
19 using namespace llvm;
21 /// Check intra-basicblock and inter-basicblock dominance using
22 /// OrderedInstruction.
23 TEST(OrderedInstructionsTest, DominanceTest) {
24 LLVMContext Ctx;
25 Module M("test", Ctx);
26 IRBuilder<> B(Ctx);
27 FunctionType *FTy =
28 FunctionType::get(Type::getVoidTy(Ctx), {B.getInt8PtrTy()}, false);
29 Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
31 // Create the function as follow and check for dominance relation.
33 // test():
34 // bbx:
35 // loadx;
36 // loady;
37 // bby:
38 // loadz;
39 // return;
41 // More specifically, check for loadx -> (dominates) loady,
42 // loady -> loadx and loady -> loadz.
44 // Create BBX with 2 loads.
45 BasicBlock *BBX = BasicBlock::Create(Ctx, "bbx", F);
46 B.SetInsertPoint(BBX);
47 Argument *PointerArg = &*F->arg_begin();
48 LoadInst *LoadInstX = B.CreateLoad(PointerArg);
49 LoadInst *LoadInstY = B.CreateLoad(PointerArg);
51 // Create BBY with 1 load.
52 BasicBlock *BBY = BasicBlock::Create(Ctx, "bby", F);
53 B.SetInsertPoint(BBY);
54 LoadInst *LoadInstZ = B.CreateLoad(PointerArg);
55 B.CreateRet(LoadInstZ);
56 std::unique_ptr<DominatorTree> DT(new DominatorTree(*F));
57 OrderedInstructions OI(&*DT);
59 // Intra-BB dominance test.
60 EXPECT_TRUE(OI.dominates(LoadInstX, LoadInstY));
61 EXPECT_FALSE(OI.dominates(LoadInstY, LoadInstX));
63 // Inter-BB dominance test.
64 EXPECT_TRUE(OI.dominates(LoadInstY, LoadInstZ));