/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Utils/OrderedInstructions.cpp
Line | Count | Source |
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 | | bool OrderedInstructions::localDominates(const Instruction *InstA, |
18 | 9.52M | const Instruction *InstB) const { |
19 | 9.52M | assert(InstA->getParent() == InstB->getParent() && |
20 | 9.52M | "Instructions must be in the same basic block"); |
21 | 9.52M | |
22 | 9.52M | const BasicBlock *IBB = InstA->getParent(); |
23 | 9.52M | auto OBB = OBBMap.find(IBB); |
24 | 9.52M | if (OBB == OBBMap.end()) |
25 | 517k | OBB = OBBMap.insert({IBB, make_unique<OrderedBasicBlock>(IBB)}).first; |
26 | 9.52M | return OBB->second->dominates(InstA, InstB); |
27 | 9.52M | } |
28 | | |
29 | | /// Given 2 instructions, use OrderedBasicBlock to check for dominance relation |
30 | | /// if the instructions are in the same basic block, Otherwise, use dominator |
31 | | /// tree. |
32 | | bool OrderedInstructions::dominates(const Instruction *InstA, |
33 | 18.5k | const Instruction *InstB) const { |
34 | 18.5k | // Use ordered basic block to do dominance check in case the 2 instructions |
35 | 18.5k | // are in the same basic block. |
36 | 18.5k | if (InstA->getParent() == InstB->getParent()) |
37 | 18.5k | return localDominates(InstA, InstB); |
38 | 1 | return DT->dominates(InstA->getParent(), InstB->getParent()); |
39 | 1 | } |
40 | | |
41 | | bool OrderedInstructions::dfsBefore(const Instruction *InstA, |
42 | 15.5M | const Instruction *InstB) const { |
43 | 15.5M | // Use ordered basic block in case the 2 instructions are in the same basic |
44 | 15.5M | // block. |
45 | 15.5M | if (InstA->getParent() == InstB->getParent()) |
46 | 9.50M | return localDominates(InstA, InstB); |
47 | 6.05M | |
48 | 6.05M | DomTreeNode *DA = DT->getNode(InstA->getParent()); |
49 | 6.05M | DomTreeNode *DB = DT->getNode(InstB->getParent()); |
50 | 6.05M | return DA->getDFSNumIn() < DB->getDFSNumIn(); |
51 | 6.05M | } |