blob: 2de09ada27a81808bae8202d5a2b4234d7e92b9a [file] [log] [blame]
Nick Lewycky1a4021a2011-02-20 08:38:20 +00001//===- Local.cpp - Unit tests for Local -----------------------------------===//
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//===----------------------------------------------------------------------===//
9
10#include "gtest/gtest.h"
11#include "llvm/BasicBlock.h"
12#include "llvm/Instructions.h"
13#include "llvm/LLVMContext.h"
14#include "llvm/Support/IRBuilder.h"
15#include "llvm/Transforms/Utils/Local.h"
16
17using namespace llvm;
18
19TEST(Local, RecursivelyDeleteDeadPHINodes) {
20 LLVMContext &C(getGlobalContext());
21
22 IRBuilder<> builder(C);
23
24 // Make blocks
25 BasicBlock *bb0 = BasicBlock::Create(C);
26 BasicBlock *bb1 = BasicBlock::Create(C);
27
28 builder.SetInsertPoint(bb0);
29 PHINode *phi = builder.CreatePHI(Type::getInt32Ty(C));
30 BranchInst *br0 = builder.CreateCondBr(builder.getTrue(), bb0, bb1);
31
32 builder.SetInsertPoint(bb1);
33 BranchInst *br1 = builder.CreateBr(bb0);
34
35 phi->addIncoming(phi, bb0);
36 phi->addIncoming(phi, bb1);
37
38 // The PHI will be removed
39 EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
40
41 // Make sure the blocks only contain the branches
42 EXPECT_EQ(&bb0->front(), br0);
43 EXPECT_EQ(&bb1->front(), br1);
44
Nick Lewyckyeff5e692011-02-20 18:05:56 +000045 builder.SetInsertPoint(bb0);
46 phi = builder.CreatePHI(Type::getInt32Ty(C));
47
48 EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
49
Nick Lewycky1a4021a2011-02-20 08:38:20 +000050 bb0->dropAllReferences();
51 bb1->dropAllReferences();
52 delete bb0;
53 delete bb1;
54}