1 //===-- OrderedInstructions.cpp - Instruction dominance function ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines utility to check dominance relation of 2 instructions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Transforms/Utils/OrderedInstructions.h"
17 /// Given 2 instructions, use OrderedBasicBlock to check for dominance relation
18 /// if the instructions are in the same basic block, Otherwise, use dominator
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);
31 return DT->dominates(InstA->getParent(), InstB->getParent());