summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/PredicateInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils/PredicateInfo.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/PredicateInfo.cpp95
1 files changed, 58 insertions, 37 deletions
diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index 16b80923bf5..4002c71fbf3 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -1,61 +1,78 @@
-//===-- PredicateInfo.cpp - PredicateInfo Builder--------------------===//
+//===- PredicateInfo.cpp - PredicateInfo Builder --------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
-//===----------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
//
// This file implements the PredicateInfo class.
//
-//===----------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/PredicateInfo.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
-#include "llvm/Analysis/CFG.h"
+#include "llvm/IR/Argument.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
-#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
-#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Metadata.h"
-#include "llvm/IR/Module.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
-#include "llvm/Transforms/Scalar.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/OrderedInstructions.h"
#include <algorithm>
-#define DEBUG_TYPE "predicateinfo"
+#include <cassert>
+#include <cstddef>
+#include <tuple>
+#include <utility>
+
using namespace llvm;
using namespace PatternMatch;
using namespace llvm::PredicateInfoClasses;
+#define DEBUG_TYPE "predicateinfo"
+
INITIALIZE_PASS_BEGIN(PredicateInfoPrinterLegacyPass, "print-predicateinfo",
"PredicateInfo Printer", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_END(PredicateInfoPrinterLegacyPass, "print-predicateinfo",
"PredicateInfo Printer", false, false)
+
static cl::opt<bool> VerifyPredicateInfo(
"verify-predicateinfo", cl::init(false), cl::Hidden,
cl::desc("Verify PredicateInfo in legacy printer pass."));
+
DEBUG_COUNTER(RenameCounter, "predicateinfo-rename",
"Controls which variables are renamed with predicateinfo");
-namespace {
// Given a predicate info that is a type of branching terminator, get the
// branching block.
-const BasicBlock *getBranchBlock(const PredicateBase *PB) {
+static const BasicBlock *getBranchBlock(const PredicateBase *PB) {
assert(isa<PredicateWithEdge>(PB) &&
"Only branches and switches should have PHIOnly defs that "
"require branch blocks.");
@@ -72,17 +89,31 @@ static Instruction *getBranchTerminator(const PredicateBase *PB) {
// Given a predicate info that is a type of branching terminator, get the
// edge this predicate info represents
-const std::pair<BasicBlock *, BasicBlock *>
+static const std::pair<BasicBlock *, BasicBlock *>
getBlockEdge(const PredicateBase *PB) {
assert(isa<PredicateWithEdge>(PB) &&
"Not a predicate info type we know how to get an edge from.");
const auto *PEdge = cast<PredicateWithEdge>(PB);
return std::make_pair(PEdge->From, PEdge->To);
}
+
+// Perform a strict weak ordering on instructions and arguments.
+static bool valueComesBefore(OrderedInstructions &OI, const Value *A,
+ const Value *B) {
+ auto *ArgA = dyn_cast_or_null<Argument>(A);
+ auto *ArgB = dyn_cast_or_null<Argument>(B);
+ if (ArgA && !ArgB)
+ return true;
+ if (ArgB && !ArgA)
+ return false;
+ if (ArgA && ArgB)
+ return ArgA->getArgNo() < ArgB->getArgNo();
+ return OI.dominates(cast<Instruction>(A), cast<Instruction>(B));
}
namespace llvm {
namespace PredicateInfoClasses {
+
enum LocalNum {
// Operations that must appear first in the block.
LN_First,
@@ -107,25 +138,12 @@ struct ValueDFS {
bool EdgeOnly = false;
};
-// Perform a strict weak ordering on instructions and arguments.
-static bool valueComesBefore(OrderedInstructions &OI, const Value *A,
- const Value *B) {
- auto *ArgA = dyn_cast_or_null<Argument>(A);
- auto *ArgB = dyn_cast_or_null<Argument>(B);
- if (ArgA && !ArgB)
- return true;
- if (ArgB && !ArgA)
- return false;
- if (ArgA && ArgB)
- return ArgA->getArgNo() < ArgB->getArgNo();
- return OI.dominates(cast<Instruction>(A), cast<Instruction>(B));
-}
-
// This compares ValueDFS structures, creating OrderedBasicBlocks where
// necessary to compare uses/defs in the same block. Doing so allows us to walk
// the minimum number of instructions necessary to compute our def/use ordering.
struct ValueDFS_Compare {
OrderedInstructions &OI;
+
ValueDFS_Compare(OrderedInstructions &OI) : OI(OI) {}
bool operator()(const ValueDFS &A, const ValueDFS &B) const {
@@ -219,7 +237,8 @@ struct ValueDFS_Compare {
}
};
-} // namespace PredicateInfoClasses
+} // end namespace PredicateInfoClasses
+} // end namespace llvm
bool PredicateInfo::stackIsInScope(const ValueDFSStack &Stack,
const ValueDFS &VDUse) const {
@@ -289,7 +308,8 @@ void PredicateInfo::convertUsesToDFSOrdered(
// Collect relevant operations from Comparison that we may want to insert copies
// for.
-void collectCmpOps(CmpInst *Comparison, SmallVectorImpl<Value *> &CmpOperands) {
+static void collectCmpOps(CmpInst *Comparison,
+ SmallVectorImpl<Value *> &CmpOperands) {
auto *Op0 = Comparison->getOperand(0);
auto *Op1 = Comparison->getOperand(1);
if (Op0 == Op1)
@@ -424,6 +444,7 @@ void PredicateInfo::processBranch(BranchInst *BI, BasicBlock *BranchBB,
CmpOperands.clear();
}
}
+
// Process a block terminating switch, and place relevant operations to be
// renamed into OpsToRename.
void PredicateInfo::processSwitch(SwitchInst *SI, BasicBlock *BranchBB,
@@ -697,7 +718,7 @@ PredicateInfo::PredicateInfo(Function &F, DominatorTree &DT,
buildPredicateInfo();
}
-PredicateInfo::~PredicateInfo() {}
+PredicateInfo::~PredicateInfo() = default;
void PredicateInfo::verifyPredicateInfo() const {}
@@ -739,16 +760,17 @@ PreservedAnalyses PredicateInfoPrinterPass::run(Function &F,
/// comments.
class PredicateInfoAnnotatedWriter : public AssemblyAnnotationWriter {
friend class PredicateInfo;
+
const PredicateInfo *PredInfo;
public:
PredicateInfoAnnotatedWriter(const PredicateInfo *M) : PredInfo(M) {}
- virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
- formatted_raw_ostream &OS) {}
+ void emitBasicBlockStartAnnot(const BasicBlock *BB,
+ formatted_raw_ostream &OS) override {}
- virtual void emitInstructionAnnot(const Instruction *I,
- formatted_raw_ostream &OS) {
+ void emitInstructionAnnot(const Instruction *I,
+ formatted_raw_ostream &OS) override {
if (const auto *PI = PredInfo->getPredicateInfoFor(I)) {
OS << "; Has predicate info\n";
if (const auto *PB = dyn_cast<PredicateBranch>(PI)) {
@@ -791,4 +813,3 @@ PreservedAnalyses PredicateInfoVerifierPass::run(Function &F,
return PreservedAnalyses::all();
}
-}
OpenPOWER on IntegriCloud