#include "llvm/Analysis/StackLifetime.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include <algorithm>
#include <tuple>
usingnamespacellvm;
#define DEBUG_TYPE …
const StackLifetime::LiveRange &
StackLifetime::getLiveRange(const AllocaInst *AI) const { … }
bool StackLifetime::isReachable(const Instruction *I) const { … }
bool StackLifetime::isAliveAfter(const AllocaInst *AI,
const Instruction *I) const { … }
static const AllocaInst *findMatchingAlloca(const IntrinsicInst &II,
const DataLayout &DL) { … }
void StackLifetime::collectMarkers() { … }
void StackLifetime::calculateLocalLiveness() { … }
void StackLifetime::calculateLiveIntervals() { … }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void StackLifetime::dumpAllocas() const {
dbgs() << "Allocas:\n";
for (unsigned AllocaNo = 0; AllocaNo < NumAllocas; ++AllocaNo)
dbgs() << " " << AllocaNo << ": " << *Allocas[AllocaNo] << "\n";
}
LLVM_DUMP_METHOD void StackLifetime::dumpBlockLiveness() const {
dbgs() << "Block liveness:\n";
for (auto IT : BlockLiveness) {
const BasicBlock *BB = IT.getFirst();
const BlockLifetimeInfo &BlockInfo = BlockLiveness.find(BB)->getSecond();
auto BlockRange = BlockInstRange.find(BB)->getSecond();
dbgs() << " BB (" << BB->getName() << ") [" << BlockRange.first << ", " << BlockRange.second
<< "): begin " << BlockInfo.Begin << ", end " << BlockInfo.End
<< ", livein " << BlockInfo.LiveIn << ", liveout "
<< BlockInfo.LiveOut << "\n";
}
}
LLVM_DUMP_METHOD void StackLifetime::dumpLiveRanges() const {
dbgs() << "Alloca liveness:\n";
for (unsigned AllocaNo = 0; AllocaNo < NumAllocas; ++AllocaNo)
dbgs() << " " << AllocaNo << ": " << LiveRanges[AllocaNo] << "\n";
}
#endif
StackLifetime::StackLifetime(const Function &F,
ArrayRef<const AllocaInst *> Allocas,
LivenessType Type)
: … { … }
void StackLifetime::run() { … }
class StackLifetime::LifetimeAnnotationWriter
: public AssemblyAnnotationWriter { … };
void StackLifetime::print(raw_ostream &OS) { … }
PreservedAnalyses StackLifetimePrinterPass::run(Function &F,
FunctionAnalysisManager &AM) { … }
void StackLifetimePrinterPass::printPipeline(
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { … }