summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Analysis/DemandedBits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Analysis/DemandedBits.cpp')
-rw-r--r--contrib/llvm/lib/Analysis/DemandedBits.cpp66
1 files changed, 42 insertions, 24 deletions
diff --git a/contrib/llvm/lib/Analysis/DemandedBits.cpp b/contrib/llvm/lib/Analysis/DemandedBits.cpp
index 6f92ba6..a3f8b7f 100644
--- a/contrib/llvm/lib/Analysis/DemandedBits.cpp
+++ b/contrib/llvm/lib/Analysis/DemandedBits.cpp
@@ -20,8 +20,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/DemandedBits.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -44,25 +42,29 @@ using namespace llvm;
#define DEBUG_TYPE "demanded-bits"
-char DemandedBits::ID = 0;
-INITIALIZE_PASS_BEGIN(DemandedBits, "demanded-bits", "Demanded bits analysis",
- false, false)
+char DemandedBitsWrapperPass::ID = 0;
+INITIALIZE_PASS_BEGIN(DemandedBitsWrapperPass, "demanded-bits",
+ "Demanded bits analysis", false, false)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
-INITIALIZE_PASS_END(DemandedBits, "demanded-bits", "Demanded bits analysis",
- false, false)
+INITIALIZE_PASS_END(DemandedBitsWrapperPass, "demanded-bits",
+ "Demanded bits analysis", false, false)
-DemandedBits::DemandedBits() : FunctionPass(ID), F(nullptr), Analyzed(false) {
- initializeDemandedBitsPass(*PassRegistry::getPassRegistry());
+DemandedBitsWrapperPass::DemandedBitsWrapperPass() : FunctionPass(ID) {
+ initializeDemandedBitsWrapperPassPass(*PassRegistry::getPassRegistry());
}
-void DemandedBits::getAnalysisUsage(AnalysisUsage &AU) const {
+void DemandedBitsWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.setPreservesAll();
}
+void DemandedBitsWrapperPass::print(raw_ostream &OS, const Module *M) const {
+ DB->print(OS);
+}
+
static bool isAlwaysLive(Instruction *I) {
return isa<TerminatorInst>(I) || isa<DbgInfoIntrinsic>(I) ||
I->isEHPad() || I->mayHaveSideEffects();
@@ -86,13 +88,13 @@ void DemandedBits::determineLiveOperandBits(
KnownZero = APInt(BitWidth, 0);
KnownOne = APInt(BitWidth, 0);
computeKnownBits(const_cast<Value *>(V1), KnownZero, KnownOne, DL, 0,
- AC, UserI, DT);
+ &AC, UserI, &DT);
if (V2) {
KnownZero2 = APInt(BitWidth, 0);
KnownOne2 = APInt(BitWidth, 0);
computeKnownBits(const_cast<Value *>(V2), KnownZero2, KnownOne2, DL,
- 0, AC, UserI, DT);
+ 0, &AC, UserI, &DT);
}
};
@@ -245,19 +247,22 @@ void DemandedBits::determineLiveOperandBits(
}
}
-bool DemandedBits::runOnFunction(Function& Fn) {
- F = &Fn;
- Analyzed = false;
+bool DemandedBitsWrapperPass::runOnFunction(Function &F) {
+ auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
+ auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ DB.emplace(F, AC, DT);
return false;
}
+void DemandedBitsWrapperPass::releaseMemory() {
+ DB.reset();
+}
+
void DemandedBits::performAnalysis() {
if (Analyzed)
// Analysis already completed for this function.
return;
Analyzed = true;
- AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F);
- DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
Visited.clear();
AliveBits.clear();
@@ -265,7 +270,7 @@ void DemandedBits::performAnalysis() {
SmallVector<Instruction*, 128> Worklist;
// Collect the set of "root" instructions that are known live.
- for (Instruction &I : instructions(*F)) {
+ for (Instruction &I : instructions(F)) {
if (!isAlwaysLive(&I))
continue;
@@ -370,16 +375,29 @@ bool DemandedBits::isInstructionDead(Instruction *I) {
!isAlwaysLive(I);
}
-void DemandedBits::print(raw_ostream &OS, const Module *M) const {
- // This is gross. But the alternative is making all the state mutable
- // just because of this one debugging method.
- const_cast<DemandedBits*>(this)->performAnalysis();
+void DemandedBits::print(raw_ostream &OS) {
+ performAnalysis();
for (auto &KV : AliveBits) {
OS << "DemandedBits: 0x" << utohexstr(KV.second.getLimitedValue()) << " for "
<< *KV.first << "\n";
}
}
-FunctionPass *llvm::createDemandedBitsPass() {
- return new DemandedBits();
+FunctionPass *llvm::createDemandedBitsWrapperPass() {
+ return new DemandedBitsWrapperPass();
+}
+
+char DemandedBitsAnalysis::PassID;
+
+DemandedBits DemandedBitsAnalysis::run(Function &F,
+ AnalysisManager<Function> &AM) {
+ auto &AC = AM.getResult<AssumptionAnalysis>(F);
+ auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
+ return DemandedBits(F, AC, DT);
+}
+
+PreservedAnalyses DemandedBitsPrinterPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ AM.getResult<DemandedBitsAnalysis>(F).print(OS);
+ return PreservedAnalyses::all();
}
OpenPOWER on IntegriCloud