aboutsummaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-03 15:20:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-03 15:20:36 +0000
commitd288ef4c1788d3a951a7558c68312c2d320612b1 (patch)
treeece909a5200f95f85f0813599a9500620f4d9217 /lib/IR
parentf382538d471e38a9b98f016c4caebd24c8d60b62 (diff)
Notes
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/DIBuilder.cpp33
-rw-r--r--lib/IR/DebugLoc.cpp81
-rw-r--r--lib/IR/OptBisect.cpp15
3 files changed, 29 insertions, 100 deletions
diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp
index 7e6f9a7804b9..7754ac03b43d 100644
--- a/lib/IR/DIBuilder.cpp
+++ b/lib/IR/DIBuilder.cpp
@@ -39,6 +39,21 @@ void DIBuilder::trackIfUnresolved(MDNode *N) {
UnresolvedNodes.emplace_back(N);
}
+void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
+ MDTuple *Temp = SP->getVariables().get();
+ if (!Temp || !Temp->isTemporary())
+ return;
+
+ SmallVector<Metadata *, 4> Variables;
+
+ auto PV = PreservedVariables.find(SP);
+ if (PV != PreservedVariables.end())
+ Variables.append(PV->second.begin(), PV->second.end());
+
+ DINodeArray AV = getOrCreateArray(Variables);
+ TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
+}
+
void DIBuilder::finalize() {
if (!CUNode) {
assert(!AllowUnresolvedNodes &&
@@ -62,25 +77,11 @@ void DIBuilder::finalize() {
CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
- auto resolveVariables = [&](DISubprogram *SP) {
- MDTuple *Temp = SP->getVariables().get();
- if (!Temp)
- return;
-
- SmallVector<Metadata *, 4> Variables;
-
- auto PV = PreservedVariables.find(SP);
- if (PV != PreservedVariables.end())
- Variables.append(PV->second.begin(), PV->second.end());
-
- DINodeArray AV = getOrCreateArray(Variables);
- TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
- };
for (auto *SP : SPs)
- resolveVariables(SP);
+ finalizeSubprogram(SP);
for (auto *N : RetainValues)
if (auto *SP = dyn_cast<DISubprogram>(N))
- resolveVariables(SP);
+ finalizeSubprogram(SP);
if (!AllGVs.empty())
CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
diff --git a/lib/IR/DebugLoc.cpp b/lib/IR/DebugLoc.cpp
index b7e3f0c6779e..0485fece7c42 100644
--- a/lib/IR/DebugLoc.cpp
+++ b/lib/IR/DebugLoc.cpp
@@ -99,87 +99,6 @@ DebugLoc DebugLoc::appendInlinedAt(DebugLoc DL, DILocation *InlinedAt,
return Last;
}
-/// Reparent \c Scope from \c OrigSP to \c NewSP.
-static DIScope *reparentScope(LLVMContext &Ctx, DIScope *Scope,
- DISubprogram *OrigSP, DISubprogram *NewSP,
- DenseMap<const MDNode *, MDNode *> &Cache) {
- SmallVector<DIScope *, 3> ScopeChain;
- DIScope *Last = NewSP;
- DIScope *CurScope = Scope;
- do {
- if (auto *SP = dyn_cast<DISubprogram>(CurScope)) {
- // Don't rewrite this scope chain if it doesn't lead to the replaced SP.
- if (SP != OrigSP)
- return Scope;
- Cache.insert({OrigSP, NewSP});
- break;
- }
- if (auto *Found = Cache[CurScope]) {
- Last = cast<DIScope>(Found);
- break;
- }
- ScopeChain.push_back(CurScope);
- } while ((CurScope = CurScope->getScope().resolve()));
-
- // Starting from the top, rebuild the nodes to point to the new inlined-at
- // location (then rebuilding the rest of the chain behind it) and update the
- // map of already-constructed inlined-at nodes.
- for (const DIScope *MD : reverse(ScopeChain)) {
- if (auto *LB = dyn_cast<DILexicalBlock>(MD))
- Cache[MD] = Last = DILexicalBlock::getDistinct(
- Ctx, Last, LB->getFile(), LB->getLine(), LB->getColumn());
- else if (auto *LB = dyn_cast<DILexicalBlockFile>(MD))
- Cache[MD] = Last = DILexicalBlockFile::getDistinct(
- Ctx, Last, LB->getFile(), LB->getDiscriminator());
- else
- llvm_unreachable("illegal parent scope");
- }
- return Last;
-}
-
-void DebugLoc::reparentDebugInfo(Instruction &I, DISubprogram *OrigSP,
- DISubprogram *NewSP,
- DenseMap<const MDNode *, MDNode *> &Cache) {
- auto DL = I.getDebugLoc();
- if (!OrigSP || !NewSP || OrigSP == NewSP || !DL)
- return;
-
- // Reparent the debug location.
- auto &Ctx = I.getContext();
- DILocation *InlinedAt = DL->getInlinedAt();
- if (InlinedAt) {
- while (auto *IA = InlinedAt->getInlinedAt())
- InlinedAt = IA;
- auto NewScope =
- reparentScope(Ctx, InlinedAt->getScope(), OrigSP, NewSP, Cache);
- InlinedAt =
- DebugLoc::get(InlinedAt->getLine(), InlinedAt->getColumn(), NewScope);
- }
- I.setDebugLoc(
- DebugLoc::get(DL.getLine(), DL.getCol(),
- reparentScope(Ctx, DL->getScope(), OrigSP, NewSP, Cache),
- DebugLoc::appendInlinedAt(DL, InlinedAt, Ctx, Cache,
- ReplaceLastInlinedAt)));
-
- // Fix up debug variables to point to NewSP.
- auto reparentVar = [&](DILocalVariable *Var) {
- return DILocalVariable::get(
- Ctx,
- cast<DILocalScope>(
- reparentScope(Ctx, Var->getScope(), OrigSP, NewSP, Cache)),
- Var->getName(), Var->getFile(), Var->getLine(), Var->getType(),
- Var->getArg(), Var->getFlags(), Var->getAlignInBits());
- };
- if (auto *DbgValue = dyn_cast<DbgValueInst>(&I)) {
- auto *Var = DbgValue->getVariable();
- I.setOperand(2, MetadataAsValue::get(Ctx, reparentVar(Var)));
- } else if (auto *DbgDeclare = dyn_cast<DbgDeclareInst>(&I)) {
- auto *Var = DbgDeclare->getVariable();
- I.setOperand(1, MetadataAsValue::get(Ctx, reparentVar(Var)));
- }
-}
-
-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DebugLoc::dump() const {
if (!Loc)
diff --git a/lib/IR/OptBisect.cpp b/lib/IR/OptBisect.cpp
index b670c817569a..a03a6fb62237 100644
--- a/lib/IR/OptBisect.cpp
+++ b/lib/IR/OptBisect.cpp
@@ -16,6 +16,7 @@
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/OptBisect.h"
#include "llvm/Pass.h"
@@ -53,13 +54,20 @@ static std::string getDescription(const BasicBlock &BB) {
}
static std::string getDescription(const Loop &L) {
- // FIXME: I'd like to be able to provide a better description here, but
- // calling L->getHeader() would introduce a new dependency on the
- // LLVMCore library.
+ // FIXME: Move into LoopInfo so we can get a better description
+ // (and avoid a circular dependency between IR and Analysis).
return "loop";
}
+static std::string getDescription(const Region &R) {
+ // FIXME: Move into RegionInfo so we can get a better description
+ // (and avoid a circular dependency between IR and Analysis).
+ return "region";
+}
+
static std::string getDescription(const CallGraphSCC &SCC) {
+ // FIXME: Move into CallGraphSCCPass to avoid circular dependency between
+ // IR and Analysis.
std::string Desc = "SCC (";
bool First = true;
for (CallGraphNode *CGN : SCC) {
@@ -83,6 +91,7 @@ template bool OptBisect::shouldRunPass(const Pass *, const Function &);
template bool OptBisect::shouldRunPass(const Pass *, const BasicBlock &);
template bool OptBisect::shouldRunPass(const Pass *, const Loop &);
template bool OptBisect::shouldRunPass(const Pass *, const CallGraphSCC &);
+template bool OptBisect::shouldRunPass(const Pass *, const Region &);
template <class UnitT>
bool OptBisect::shouldRunPass(const Pass *P, const UnitT &U) {