From 71e8c6f20fe4c5d9cfd6235c360d602f0d29a6ab Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Wed, 24 Apr 2019 06:55:50 +0000 Subject: Add "const" in GetUnderlyingObjects. NFC Summary: Both the input Value pointer and the returned Value pointers in GetUnderlyingObjects are now declared as const. It turned out that all current (in-tree) uses of GetUnderlyingObjects were trivial to update, being satisfied with have those Value pointers declared as const. Actually, in the past several of the users had to use const_cast, just because of ValueTracking not providing a version of GetUnderlyingObjects with "const" Value pointers. With this patch we get rid of those const casts. Reviewers: hfinkel, materi, jkorous Reviewed By: jkorous Subscribers: dexonsmith, jkorous, jholewinski, sdardis, eraman, hiraditya, jrtc27, atanasyan, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61038 llvm-svn: 359072 --- llvm/lib/Analysis/ValueTracking.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'llvm/lib/Analysis/ValueTracking.cpp') diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 3b08a2dc7a1..7c16b21c928 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -3771,26 +3771,27 @@ Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL, return V; } -void llvm::GetUnderlyingObjects(Value *V, SmallVectorImpl &Objects, +void llvm::GetUnderlyingObjects(const Value *V, + SmallVectorImpl &Objects, const DataLayout &DL, LoopInfo *LI, unsigned MaxLookup) { - SmallPtrSet Visited; - SmallVector Worklist; + SmallPtrSet Visited; + SmallVector Worklist; Worklist.push_back(V); do { - Value *P = Worklist.pop_back_val(); + const Value *P = Worklist.pop_back_val(); P = GetUnderlyingObject(P, DL, MaxLookup); if (!Visited.insert(P).second) continue; - if (SelectInst *SI = dyn_cast(P)) { + if (auto *SI = dyn_cast(P)) { Worklist.push_back(SI->getTrueValue()); Worklist.push_back(SI->getFalseValue()); continue; } - if (PHINode *PN = dyn_cast(P)) { + if (auto *PN = dyn_cast(P)) { // If this PHI changes the underlying object in every iteration of the // loop, don't look through it. Consider: // int **A; @@ -3851,10 +3852,10 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V, do { V = Working.pop_back_val(); - SmallVector Objs; - GetUnderlyingObjects(const_cast(V), Objs, DL); + SmallVector Objs; + GetUnderlyingObjects(V, Objs, DL); - for (Value *V : Objs) { + for (const Value *V : Objs) { if (!Visited.insert(V).second) continue; if (Operator::getOpcode(V) == Instruction::IntToPtr) { -- cgit v1.2.3