Xin Tong | 9d6f08a | 2017-06-06 02:34:41 +0000 | [diff] [blame] | 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); |
Xin Tong | 9d6f08a | 2017-06-06 02:34:41 +0000 | [diff] [blame] | 30 | } |
Daniel Berlin | 7c757ae | 2017-06-29 17:01:03 +0000 | [diff] [blame^] | 31 | return DT->dominates(InstA->getParent(), InstB->getParent()); |
Xin Tong | 9d6f08a | 2017-06-06 02:34:41 +0000 | [diff] [blame] | 32 | } |