blob: dc780542ce68696c0433e395d9f7ead5db6f36ae [file] [log] [blame]
Xin Tong9d6f08a2017-06-06 02:34:41 +00001//===-- 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"
15using 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.
20bool 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);
Xin Tong9d6f08a2017-06-06 02:34:41 +000030 }
Daniel Berlin7c757ae2017-06-29 17:01:03 +000031 return DT->dominates(InstA->getParent(), InstB->getParent());
Xin Tong9d6f08a2017-06-06 02:34:41 +000032}