1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[NFC] Move findAllocaForValue into ValueTracking.h

Differential Revision: https://reviews.llvm.org/D84616
This commit is contained in:
Vitaly Buka 2020-07-30 18:22:59 -07:00
parent b712ce0b7d
commit fe28af466f
5 changed files with 41 additions and 42 deletions

View File

@ -28,6 +28,7 @@
namespace llvm {
class AddOperator;
class AllocaInst;
class APInt;
class AssumptionCache;
class DominatorTree;
@ -413,6 +414,10 @@ class Value;
SmallVectorImpl<Value *> &Objects,
const DataLayout &DL);
/// Finds alloca where the value comes from.
AllocaInst *
findAllocaForValue(Value *V, DenseMap<Value *, AllocaInst *> &AllocaForValue);
/// Return true if the only users of this pointer are lifetime markers.
bool onlyUsedByLifetimeMarkers(const Value *V);

View File

@ -305,10 +305,6 @@ bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder,
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
DIBuilder &Builder, int Offset = 0);
/// Finds alloca where the value comes from.
AllocaInst *findAllocaForValue(Value *V,
DenseMap<Value *, AllocaInst *> &AllocaForValue);
/// Assuming the instruction \p I is going to be deleted, attempt to salvage
/// debug users of \p I by writing the effect of \p I in a DIExpression. If it
/// cannot be salvaged changes its debug uses to undef.

View File

@ -4313,6 +4313,41 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V,
return true;
}
AllocaInst *
llvm::findAllocaForValue(Value *V,
DenseMap<Value *, AllocaInst *> &AllocaForValue) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(V))
return AI;
// See if we've already calculated (or started to calculate) alloca for a
// given value.
auto I = AllocaForValue.find(V);
if (I != AllocaForValue.end())
return I->second;
// Store 0 while we're calculating alloca for value V to avoid
// infinite recursion if the value references itself.
AllocaForValue[V] = nullptr;
AllocaInst *Res = nullptr;
if (CastInst *CI = dyn_cast<CastInst>(V))
Res = findAllocaForValue(CI->getOperand(0), AllocaForValue);
else if (PHINode *PN = dyn_cast<PHINode>(V)) {
for (Value *IncValue : PN->incoming_values()) {
// Allow self-referencing phi-nodes.
if (IncValue == PN)
continue;
AllocaInst *IncValueAI = findAllocaForValue(IncValue, AllocaForValue);
// AI for incoming values should exist and should all be equal.
if (IncValueAI == nullptr || (Res != nullptr && IncValueAI != Res))
return nullptr;
Res = IncValueAI;
}
} else if (GetElementPtrInst *EP = dyn_cast<GetElementPtrInst>(V)) {
Res = findAllocaForValue(EP->getPointerOperand(), AllocaForValue);
}
if (Res)
AllocaForValue[V] = Res;
return Res;
}
static bool onlyUsedByLifetimeMarkersOrDroppableInstsHelper(
const Value *V, bool AllowLifetime, bool AllowDroppable) {
for (const User *U : V->users()) {

View File

@ -153,6 +153,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"

View File

@ -3028,44 +3028,6 @@ bool llvm::canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx) {
}
}
using AllocaForValueMapTy = DenseMap<Value *, AllocaInst *>;
AllocaInst *llvm::findAllocaForValue(Value *V,
AllocaForValueMapTy &AllocaForValue) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(V))
return AI;
// See if we've already calculated (or started to calculate) alloca for a
// given value.
AllocaForValueMapTy::iterator I = AllocaForValue.find(V);
if (I != AllocaForValue.end())
return I->second;
// Store 0 while we're calculating alloca for value V to avoid
// infinite recursion if the value references itself.
AllocaForValue[V] = nullptr;
AllocaInst *Res = nullptr;
if (CastInst *CI = dyn_cast<CastInst>(V))
Res = findAllocaForValue(CI->getOperand(0), AllocaForValue);
else if (PHINode *PN = dyn_cast<PHINode>(V)) {
for (Value *IncValue : PN->incoming_values()) {
// Allow self-referencing phi-nodes.
if (IncValue == PN)
continue;
AllocaInst *IncValueAI = findAllocaForValue(IncValue, AllocaForValue);
// AI for incoming values should exist and should all be equal.
if (IncValueAI == nullptr || (Res != nullptr && IncValueAI != Res))
return nullptr;
Res = IncValueAI;
}
} else if (GetElementPtrInst *EP = dyn_cast<GetElementPtrInst>(V)) {
Res = findAllocaForValue(EP->getPointerOperand(), AllocaForValue);
} else {
LLVM_DEBUG(dbgs() << "Alloca search cancelled on unknown instruction: "
<< *V << "\n");
}
if (Res)
AllocaForValue[V] = Res;
return Res;
}
Value *llvm::invertCondition(Value *Condition) {
// First: Check if it's a constant
if (Constant *C = dyn_cast<Constant>(Condition))