LLVM  11.0.0git
OrderedInstructions.cpp
Go to the documentation of this file.
1 //===-- OrderedInstructions.cpp - Instruction dominance function ---------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines utility to check dominance relation of 2 instructions.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/IR/Dominators.h"
15 
16 using namespace llvm;
17 
18 bool OrderedInstructions::localDominates(const Instruction *InstA,
19  const Instruction *InstB) const {
20  assert(InstA->getParent() == InstB->getParent() &&
21  "Instructions must be in the same basic block");
22 
23  return InstA->comesBefore(InstB);
24 }
25 
26 /// Given 2 instructions, check for dominance relation if the instructions are
27 /// in the same basic block. Otherwise, use dominator tree.
29  const Instruction *InstB) const {
30  // Use ordered basic block to do dominance check in case the 2 instructions
31  // are in the same basic block.
32  if (InstA->getParent() == InstB->getParent())
33  return localDominates(InstA, InstB);
34  return DT->dominates(InstA->getParent(), InstB->getParent());
35 }
36 
38  const Instruction *InstB) const {
39  // Use ordered basic block in case the 2 instructions are in the same basic
40  // block.
41  if (InstA->getParent() == InstB->getParent())
42  return localDominates(InstA, InstB);
43 
44  DomTreeNode *DA = DT->getNode(InstA->getParent());
45  DomTreeNode *DB = DT->getNode(InstB->getParent());
46  return DA->getDFSNumIn() < DB->getDFSNumIn();
47 }
48 
50  const Instruction *InstB) const {
51  // Use ordered basic block in case the 2 instructions are in the same basic
52  // block.
53  if (InstA->getParent() == InstB->getParent())
54  return localDominates(InstA, InstB);
55 
56  DomTreeNode *DA = DT->getNode(InstA->getParent());
57  DomTreeNode *DB = DT->getNode(InstB->getParent());
58  return DA->getLevel() < DB->getLevel();
59 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool dominates(const Instruction *, const Instruction *) const
Return true if first instruction dominates the second.
unsigned getDFSNumIn() const
getDFSNumIn/getDFSNumOut - These return the DFS visitation order for nodes in the dominator tree...
bool dfsBefore(const Instruction *, const Instruction *) const
Return true if the first instruction comes before the second in the dominator tree DFS traversal if t...
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Definition: Dominators.cpp:251
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool domTreeLevelBefore(const Instruction *, const Instruction *) const
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
unsigned getLevel() const
const BasicBlock * getParent() const
Definition: Instruction.h:94