Skip to content

Commit

Permalink
[indvars] Missing variables at Og:
Browse files Browse the repository at this point in the history
https://bugs.llvm.org/show_bug.cgi?id=51735
llvm#51077

Address @nikic comments about layering violation.
- Move code to 'LoopInfo.h'.
  • Loading branch information
CarlosAlbertoEnciso committed Apr 10, 2024
1 parent 9e4c629 commit 6187569
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 24 additions & 0 deletions llvm/include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "llvm/IR/CFG.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h"
#include "llvm/Support/GenericLoopInfo.h"
#include <algorithm>
Expand Down Expand Up @@ -392,13 +394,35 @@ class LLVM_EXTERNAL_VISIBILITY Loop : public LoopBase<BasicBlock, Loop> {
return "<unnamed loop>";
}

/// Preserve the induction variable exit value and its debug users by the
/// 'indvars' pass if the loop can deleted. Those debug users will be used
/// by the 'loop-delete' pass.
void preserveDebugInductionVariableInfo(
Value *FinalValue, SmallVector<DbgVariableIntrinsic *> DbgUsers) {
IndVarFinalValue = FinalValue;
for (DbgVariableIntrinsic *DebugUser : DbgUsers)
IndVarDebugUsers.push_back(DebugUser);
}

Value *getDebugInductionVariableFinalValue() { return IndVarFinalValue; }
SmallVector<WeakVH> &getDebugInductionVariableDebugUsers() {
return IndVarDebugUsers;
}

private:
Loop() = default;

friend class LoopInfoBase<BasicBlock, Loop>;
friend class LoopBase<BasicBlock, Loop>;
explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}
~Loop() = default;

// Induction variable exit value and its debug users, preserved by the
// 'indvars' pass, when it detects that the loop can be deleted and the
// there are no PHIs to be rewritten.
// For now, we only preserve single induction variables.
Value *IndVarFinalValue = nullptr;
SmallVector<WeakVH> IndVarDebugUsers;
};

// Implementation in Support/GenericLoopInfoImpl.h
Expand Down
24 changes: 0 additions & 24 deletions llvm/include/llvm/Support/GenericLoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/GenericDomTree.h"

Expand Down Expand Up @@ -77,13 +75,6 @@ template <class BlockT, class LoopT> class LoopBase {
const LoopBase<BlockT, LoopT> &
operator=(const LoopBase<BlockT, LoopT> &) = delete;

// Induction variable exit value and its debug users, preserved by the
// 'indvars' pass, when it detects that the loop can be deleted and the
// there are no PHIs to be rewritten.
// For now, we only preserve single induction variables.
Value *IndVarFinalValue = nullptr;
SmallVector<WeakVH> IndVarDebugUsers;

public:
/// Return the nesting level of this loop. An outer-most loop has depth 1,
/// for consistency with loop depth values used for basic blocks, where depth
Expand Down Expand Up @@ -260,21 +251,6 @@ template <class BlockT, class LoopT> class LoopBase {
[&](BlockT *Pred) { return contains(Pred); });
}

/// Preserve the induction variable exit value and its debug users by the
/// 'indvars' pass if the loop can deleted. Those debug users will be used
/// by the 'loop-delete' pass.
void preserveDebugInductionVariableInfo(
Value *FinalValue, SmallVector<DbgVariableIntrinsic *> DbgUsers) {
IndVarFinalValue = FinalValue;
for (DbgVariableIntrinsic *DebugUser : DbgUsers)
IndVarDebugUsers.push_back(DebugUser);
}

Value *getDebugInductionVariableFinalValue() { return IndVarFinalValue; }
SmallVector<WeakVH> &getDebugInductionVariableDebugUsers() {
return IndVarDebugUsers;
}

//===--------------------------------------------------------------------===//
// APIs for simple analysis of the loop.
//
Expand Down

0 comments on commit 6187569

Please sign in to comment.