]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Transforms/Utils/OrderedInstructions.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r306956, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Transforms / Utils / OrderedInstructions.cpp
1 //===-- OrderedInstructions.cpp - Instruction dominance function ---------===//
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 // This file defines utility to check dominance relation of 2 instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Transforms/Utils/OrderedInstructions.h"
15 using namespace llvm;
16
17 /// Given 2 instructions, use OrderedBasicBlock to check for dominance relation
18 /// if the instructions are in the same basic block, Otherwise, use dominator
19 /// tree.
20 bool OrderedInstructions::dominates(const Instruction *InstA,
21                                     const Instruction *InstB) const {
22   const BasicBlock *IBB = InstA->getParent();
23   // Use ordered basic block to do dominance check in case the 2 instructions
24   // are in the same basic block.
25   if (IBB == InstB->getParent()) {
26     auto OBB = OBBMap.find(IBB);
27     if (OBB == OBBMap.end())
28       OBB = OBBMap.insert({IBB, make_unique<OrderedBasicBlock>(IBB)}).first;
29     return OBB->second->dominates(InstA, InstB);
30   }
31   return DT->dominates(InstA->getParent(), InstB->getParent());
32 }