+++ /dev/null
-//===- llvm/Transforms/Utils/OrderedInstructions.h -------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines an efficient way to check for dominance relation between 2
-// instructions.
-//
-// FIXME: This is really just a convenience wrapper to check dominance between
-// two arbitrary instructions in different basic blocks. We should fold it into
-// DominatorTree, which is the more widely used interface.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_ORDEREDINSTRUCTIONS_H
-#define LLVM_ANALYSIS_ORDEREDINSTRUCTIONS_H
-
-namespace llvm {
-
-class DominatorTree;
-class Instruction;
-
-class OrderedInstructions {
- /// The dominator tree of the parent function.
- DominatorTree *DT;
-
- /// Return true if the first instruction comes before the second in the
- /// same basic block. It will create an ordered basic block, if it does
- /// not yet exist in OBBMap.
- bool localDominates(const Instruction *, const Instruction *) const;
-
-public:
- /// Constructor.
- OrderedInstructions(DominatorTree *DT) : DT(DT) {}
-
- /// Return true if first instruction dominates the second.
- bool dominates(const Instruction *, const Instruction *) const;
-
- /// Return true if the first instruction comes before the second in the
- /// dominator tree DFS traversal if they are in different basic blocks,
- /// or if the first instruction comes before the second in the same basic
- /// block.
- bool dfsBefore(const Instruction *, const Instruction *) const;
-
- // Return true if the first instruction comes before the second in the
- // dominator tree BFS traversal based on the level number of nodes in
- // dominator tree if they are in different basic blocks else if the first
- // instruction comes before the second in the same basic block.
- bool domTreeLevelBefore(const Instruction *, const Instruction *) const;
-};
-
-} // end namespace llvm
-
-#endif // LLVM_ANALYSIS_ORDEREDINSTRUCTIONS_H
ObjCARCAnalysisUtils.cpp
ObjCARCInstKind.cpp
OptimizationRemarkEmitter.cpp
- OrderedInstructions.cpp
PHITransAddr.cpp
PhiValues.cpp
PostDominators.cpp
+++ /dev/null
-//===-- OrderedInstructions.cpp - Instruction dominance function ---------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines utility to check dominance relation of 2 instructions.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Analysis/OrderedInstructions.h"
-#include "llvm/IR/Dominators.h"
-
-using namespace llvm;
-
-bool OrderedInstructions::localDominates(const Instruction *InstA,
- const Instruction *InstB) const {
- assert(InstA->getParent() == InstB->getParent() &&
- "Instructions must be in the same basic block");
-
- return InstA->comesBefore(InstB);
-}
-
-/// Given 2 instructions, check for dominance relation if the instructions are
-/// in the same basic block. Otherwise, use dominator tree.
-bool OrderedInstructions::dominates(const Instruction *InstA,
- const Instruction *InstB) const {
- // Use ordered basic block to do dominance check in case the 2 instructions
- // are in the same basic block.
- if (InstA->getParent() == InstB->getParent())
- return localDominates(InstA, InstB);
- return DT->dominates(InstA->getParent(), InstB->getParent());
-}
-
-bool OrderedInstructions::dfsBefore(const Instruction *InstA,
- const Instruction *InstB) const {
- // Use ordered basic block in case the 2 instructions are in the same basic
- // block.
- if (InstA->getParent() == InstB->getParent())
- return localDominates(InstA, InstB);
-
- DomTreeNode *DA = DT->getNode(InstA->getParent());
- DomTreeNode *DB = DT->getNode(InstB->getParent());
- return DA->getDFSNumIn() < DB->getDFSNumIn();
-}
-
-bool OrderedInstructions::domTreeLevelBefore(const Instruction *InstA,
- const Instruction *InstB) const {
- // Use ordered basic block in case the 2 instructions are in the same basic
- // block.
- if (InstA->getParent() == InstB->getParent())
- return localDominates(InstA, InstB);
-
- DomTreeNode *DA = DT->getNode(InstA->getParent());
- DomTreeNode *DB = DT->getNode(InstB->getParent());
- return DA->getLevel() < DB->getLevel();
-}
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/DependenceAnalysis.h"
-#include "llvm/Analysis/OrderedInstructions.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Dominators.h"
};
} // namespace
+static bool domTreeLevelBefore(DominatorTree *DT, const Instruction *InstA,
+ const Instruction *InstB) {
+ // Use ordered basic block in case the 2 instructions are in the same
+ // block.
+ if (InstA->getParent() == InstB->getParent())
+ return InstA->comesBefore(InstB);
+
+ DomTreeNode *DA = DT->getNode(InstA->getParent());
+ DomTreeNode *DB = DT->getNode(InstB->getParent());
+ return DA->getLevel() < DB->getLevel();
+}
+
const Optional<ControlConditions> ControlConditions::collectControlConditions(
const BasicBlock &BB, const BasicBlock &Dominator, const DominatorTree &DT,
const PostDominatorTree &PDT, unsigned MaxLookup) {
if (&InsertPoint == OpInst || !DT.dominates(OpInst, &InsertPoint))
return false;
- OrderedInstructions OI(&DT);
DT.updateDFSNumbers();
- const bool MoveForward = OI.domTreeLevelBefore(&I, &InsertPoint);
+ const bool MoveForward = domTreeLevelBefore(&DT, &I, &InsertPoint);
Instruction &StartInst = (MoveForward ? I : InsertPoint);
Instruction &EndInst = (MoveForward ? InsertPoint : I);
SmallPtrSet<Instruction *, 10> InstsToCheck;
LoopNestTest.cpp
MemoryBuiltinsTest.cpp
MemorySSATest.cpp
- OrderedInstructionsTest.cpp
PhiValuesTest.cpp
ProfileSummaryInfoTest.cpp
ScalarEvolutionTest.cpp
ValueLatticeTest.cpp
ValueTrackingTest.cpp
VectorUtilsTest.cpp
- )
\ No newline at end of file
+ )
+++ /dev/null
-//===- OrderedInstructions.cpp - Unit tests for OrderedInstructions ------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Analysis/OrderedInstructions.h"
-#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/Dominators.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-/// Check intra-basicblock and inter-basicblock dominance using
-/// OrderedInstruction.
-TEST(OrderedInstructionsTest, DominanceTest) {
- LLVMContext Ctx;
- Module M("test", Ctx);
- IRBuilder<> B(Ctx);
- FunctionType *FTy =
- FunctionType::get(Type::getVoidTy(Ctx), {B.getInt8PtrTy()}, false);
- Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
-
- // Create the function as follow and check for dominance relation.
- //
- // test():
- // bbx:
- // loadx;
- // loady;
- // bby:
- // loadz;
- // return;
- //
- // More specifically, check for loadx -> (dominates) loady,
- // loady -> loadx and loady -> loadz.
- //
- // Create BBX with 2 loads.
- BasicBlock *BBX = BasicBlock::Create(Ctx, "bbx", F);
- B.SetInsertPoint(BBX);
- Argument *PointerArg = &*F->arg_begin();
- LoadInst *LoadInstX = B.CreateLoad(B.getInt8Ty(), PointerArg);
- LoadInst *LoadInstY = B.CreateLoad(B.getInt8Ty(), PointerArg);
-
- // Create BBY with 1 load.
- BasicBlock *BBY = BasicBlock::Create(Ctx, "bby", F);
- B.SetInsertPoint(BBY);
- LoadInst *LoadInstZ = B.CreateLoad(B.getInt8Ty(), PointerArg);
- B.CreateRet(LoadInstZ);
- std::unique_ptr<DominatorTree> DT(new DominatorTree(*F));
- OrderedInstructions OI(&*DT);
-
- // Intra-BB dominance test.
- EXPECT_TRUE(OI.dominates(LoadInstX, LoadInstY));
- EXPECT_FALSE(OI.dominates(LoadInstY, LoadInstX));
-
- // Inter-BB dominance test.
- EXPECT_TRUE(OI.dominates(LoadInstY, LoadInstZ));
-}
"ObjCARCAnalysisUtils.cpp",
"ObjCARCInstKind.cpp",
"OptimizationRemarkEmitter.cpp",
- "OrderedInstructions.cpp",
"PHITransAddr.cpp",
"PhiValues.cpp",
"PostDominators.cpp",
"LoopNestTest.cpp",
"MemoryBuiltinsTest.cpp",
"MemorySSATest.cpp",
- "OrderedInstructionsTest.cpp",
"PhiValuesTest.cpp",
"ProfileSummaryInfoTest.cpp",
"ScalarEvolutionTest.cpp",