forked from OSchip/llvm-project
[opaque pointer types] [NFC] Add an explicit type argument to ConstantFoldLoadFromConstPtr.
Reviewers: mjacob, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16418 llvm-svn: 258472
This commit is contained in:
parent
71e9a2a4c4
commit
1423921a24
|
@ -95,7 +95,7 @@ Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
|
||||||
/// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
|
/// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
|
||||||
/// produce if it is constant and determinable. If this is not determinable,
|
/// produce if it is constant and determinable. If this is not determinable,
|
||||||
/// return null.
|
/// return null.
|
||||||
Constant *ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout &DL);
|
Constant *ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL);
|
||||||
|
|
||||||
/// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
|
/// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
|
||||||
/// getelementptr constantexpr, return the constant value being addressed by the
|
/// getelementptr constantexpr, return the constant value being addressed by the
|
||||||
|
|
|
@ -399,9 +399,9 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
|
static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
|
||||||
|
Type *LoadTy,
|
||||||
const DataLayout &DL) {
|
const DataLayout &DL) {
|
||||||
PointerType *PTy = cast<PointerType>(C->getType());
|
PointerType *PTy = cast<PointerType>(C->getType());
|
||||||
Type *LoadTy = PTy->getElementType();
|
|
||||||
IntegerType *IntType = dyn_cast<IntegerType>(LoadTy);
|
IntegerType *IntType = dyn_cast<IntegerType>(LoadTy);
|
||||||
|
|
||||||
// If this isn't an integer load we can't fold it directly.
|
// If this isn't an integer load we can't fold it directly.
|
||||||
|
@ -414,19 +414,19 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
|
||||||
// an actual new load.
|
// an actual new load.
|
||||||
Type *MapTy;
|
Type *MapTy;
|
||||||
if (LoadTy->isHalfTy())
|
if (LoadTy->isHalfTy())
|
||||||
MapTy = Type::getInt16PtrTy(C->getContext(), AS);
|
MapTy = Type::getInt16Ty(C->getContext());
|
||||||
else if (LoadTy->isFloatTy())
|
else if (LoadTy->isFloatTy())
|
||||||
MapTy = Type::getInt32PtrTy(C->getContext(), AS);
|
MapTy = Type::getInt32Ty(C->getContext());
|
||||||
else if (LoadTy->isDoubleTy())
|
else if (LoadTy->isDoubleTy())
|
||||||
MapTy = Type::getInt64PtrTy(C->getContext(), AS);
|
MapTy = Type::getInt64Ty(C->getContext());
|
||||||
else if (LoadTy->isVectorTy()) {
|
else if (LoadTy->isVectorTy()) {
|
||||||
MapTy = PointerType::getIntNPtrTy(C->getContext(),
|
MapTy = PointerType::getIntNTy(C->getContext(),
|
||||||
DL.getTypeAllocSizeInBits(LoadTy), AS);
|
DL.getTypeAllocSizeInBits(LoadTy));
|
||||||
} else
|
} else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
C = FoldBitCast(C, MapTy, DL);
|
C = FoldBitCast(C, MapTy->getPointerTo(AS), DL);
|
||||||
if (Constant *Res = FoldReinterpretLoadFromConstPtr(C, DL))
|
if (Constant *Res = FoldReinterpretLoadFromConstPtr(C, MapTy, DL))
|
||||||
return FoldBitCast(Res, LoadTy, DL);
|
return FoldBitCast(Res, LoadTy, DL);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -479,13 +479,15 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
|
||||||
}
|
}
|
||||||
|
|
||||||
static Constant *ConstantFoldLoadThroughBitcast(ConstantExpr *CE,
|
static Constant *ConstantFoldLoadThroughBitcast(ConstantExpr *CE,
|
||||||
|
Type *DestTy,
|
||||||
const DataLayout &DL) {
|
const DataLayout &DL) {
|
||||||
auto *DestPtrTy = dyn_cast<PointerType>(CE->getType());
|
auto *SrcPtr = CE->getOperand(0);
|
||||||
if (!DestPtrTy)
|
auto *SrcPtrTy = dyn_cast<PointerType>(SrcPtr->getType());
|
||||||
|
if (!SrcPtrTy)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
Type *DestTy = DestPtrTy->getElementType();
|
Type *SrcTy = SrcPtrTy->getPointerElementType();
|
||||||
|
|
||||||
Constant *C = ConstantFoldLoadFromConstPtr(CE->getOperand(0), DL);
|
Constant *C = ConstantFoldLoadFromConstPtr(SrcPtr, SrcTy, DL);
|
||||||
if (!C)
|
if (!C)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -524,7 +526,7 @@ static Constant *ConstantFoldLoadThroughBitcast(ConstantExpr *CE,
|
||||||
|
|
||||||
/// Return the value that a load from C would produce if it is constant and
|
/// Return the value that a load from C would produce if it is constant and
|
||||||
/// determinable. If this is not determinable, return null.
|
/// determinable. If this is not determinable, return null.
|
||||||
Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
|
Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty,
|
||||||
const DataLayout &DL) {
|
const DataLayout &DL) {
|
||||||
// First, try the easy cases:
|
// First, try the easy cases:
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
|
||||||
|
@ -533,7 +535,7 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
|
||||||
|
|
||||||
if (auto *GA = dyn_cast<GlobalAlias>(C))
|
if (auto *GA = dyn_cast<GlobalAlias>(C))
|
||||||
if (GA->getAliasee() && !GA->mayBeOverridden())
|
if (GA->getAliasee() && !GA->mayBeOverridden())
|
||||||
return ConstantFoldLoadFromConstPtr(GA->getAliasee(), DL);
|
return ConstantFoldLoadFromConstPtr(GA->getAliasee(), Ty, DL);
|
||||||
|
|
||||||
// If the loaded value isn't a constant expr, we can't handle it.
|
// If the loaded value isn't a constant expr, we can't handle it.
|
||||||
ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
|
ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
|
||||||
|
@ -551,7 +553,7 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CE->getOpcode() == Instruction::BitCast)
|
if (CE->getOpcode() == Instruction::BitCast)
|
||||||
if (Constant *LoadedC = ConstantFoldLoadThroughBitcast(CE, DL))
|
if (Constant *LoadedC = ConstantFoldLoadThroughBitcast(CE, Ty, DL))
|
||||||
return LoadedC;
|
return LoadedC;
|
||||||
|
|
||||||
// Instead of loading constant c string, use corresponding integer value
|
// Instead of loading constant c string, use corresponding integer value
|
||||||
|
@ -559,7 +561,6 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
|
||||||
StringRef Str;
|
StringRef Str;
|
||||||
if (getConstantStringInfo(CE, Str) && !Str.empty()) {
|
if (getConstantStringInfo(CE, Str) && !Str.empty()) {
|
||||||
unsigned StrLen = Str.size();
|
unsigned StrLen = Str.size();
|
||||||
Type *Ty = cast<PointerType>(CE->getType())->getElementType();
|
|
||||||
unsigned NumBits = Ty->getPrimitiveSizeInBits();
|
unsigned NumBits = Ty->getPrimitiveSizeInBits();
|
||||||
// Replace load with immediate integer if the result is an integer or fp
|
// Replace load with immediate integer if the result is an integer or fp
|
||||||
// value.
|
// value.
|
||||||
|
@ -594,16 +595,15 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
|
||||||
if (GlobalVariable *GV =
|
if (GlobalVariable *GV =
|
||||||
dyn_cast<GlobalVariable>(GetUnderlyingObject(CE, DL))) {
|
dyn_cast<GlobalVariable>(GetUnderlyingObject(CE, DL))) {
|
||||||
if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
|
if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
|
||||||
Type *ResTy = cast<PointerType>(C->getType())->getElementType();
|
|
||||||
if (GV->getInitializer()->isNullValue())
|
if (GV->getInitializer()->isNullValue())
|
||||||
return Constant::getNullValue(ResTy);
|
return Constant::getNullValue(Ty);
|
||||||
if (isa<UndefValue>(GV->getInitializer()))
|
if (isa<UndefValue>(GV->getInitializer()))
|
||||||
return UndefValue::get(ResTy);
|
return UndefValue::get(Ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try hard to fold loads from bitcasted strange and non-type-safe things.
|
// Try hard to fold loads from bitcasted strange and non-type-safe things.
|
||||||
return FoldReinterpretLoadFromConstPtr(CE, DL);
|
return FoldReinterpretLoadFromConstPtr(CE, Ty, DL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Constant *ConstantFoldLoadInst(const LoadInst *LI,
|
static Constant *ConstantFoldLoadInst(const LoadInst *LI,
|
||||||
|
@ -611,7 +611,7 @@ static Constant *ConstantFoldLoadInst(const LoadInst *LI,
|
||||||
if (LI->isVolatile()) return nullptr;
|
if (LI->isVolatile()) return nullptr;
|
||||||
|
|
||||||
if (Constant *C = dyn_cast<Constant>(LI->getOperand(0)))
|
if (Constant *C = dyn_cast<Constant>(LI->getOperand(0)))
|
||||||
return ConstantFoldLoadFromConstPtr(C, DL);
|
return ConstantFoldLoadFromConstPtr(C, LI->getType(), DL);
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3261,7 +3261,7 @@ static const Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
|
||||||
|
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I))
|
if (LoadInst *LI = dyn_cast<LoadInst>(I))
|
||||||
if (!LI->isVolatile())
|
if (!LI->isVolatile())
|
||||||
return ConstantFoldLoadFromConstPtr(ConstOps[0], Q.DL);
|
return ConstantFoldLoadFromConstPtr(ConstOps[0], LI->getType(), Q.DL);
|
||||||
|
|
||||||
return ConstantFoldInstOperands(I, ConstOps, Q.DL, Q.TLI);
|
return ConstantFoldInstOperands(I, ConstOps, Q.DL, Q.TLI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5915,7 +5915,7 @@ static Constant *EvaluateExpression(Value *V, const Loop *L,
|
||||||
Operands[1], DL, TLI);
|
Operands[1], DL, TLI);
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
if (!LI->isVolatile())
|
if (!LI->isVolatile())
|
||||||
return ConstantFoldLoadFromConstPtr(Operands[0], DL);
|
return ConstantFoldLoadFromConstPtr(Operands[0], LI->getType(), DL);
|
||||||
}
|
}
|
||||||
return ConstantFoldInstOperands(I, Operands, DL, TLI);
|
return ConstantFoldInstOperands(I, Operands, DL, TLI);
|
||||||
}
|
}
|
||||||
|
@ -6303,7 +6303,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
|
||||||
Operands[1], DL, &TLI);
|
Operands[1], DL, &TLI);
|
||||||
else if (const LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
else if (const LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
if (!LI->isVolatile())
|
if (!LI->isVolatile())
|
||||||
C = ConstantFoldLoadFromConstPtr(Operands[0], DL);
|
C = ConstantFoldLoadFromConstPtr(Operands[0], LI->getType(), DL);
|
||||||
} else
|
} else
|
||||||
C = ConstantFoldInstOperands(I, Operands, DL, &TLI);
|
C = ConstantFoldInstOperands(I, Operands, DL, &TLI);
|
||||||
if (!C) return V;
|
if (!C) return V;
|
||||||
|
|
|
@ -5450,7 +5450,7 @@ static SDValue getMemCmpLoad(const Value *PtrVal, MVT LoadVT,
|
||||||
PointerType::getUnqual(LoadTy));
|
PointerType::getUnqual(LoadTy));
|
||||||
|
|
||||||
if (const Constant *LoadCst = ConstantFoldLoadFromConstPtr(
|
if (const Constant *LoadCst = ConstantFoldLoadFromConstPtr(
|
||||||
const_cast<Constant *>(LoadInput), *Builder.DL))
|
const_cast<Constant *>(LoadInput), LoadTy, *Builder.DL))
|
||||||
return Builder.getValue(LoadCst);
|
return Builder.getValue(LoadCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1117,7 +1117,7 @@ static int AnalyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
|
||||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
||||||
OffsetCst);
|
OffsetCst);
|
||||||
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
||||||
if (ConstantFoldLoadFromConstPtr(Src, DL))
|
if (ConstantFoldLoadFromConstPtr(Src, LoadTy, DL))
|
||||||
return Offset;
|
return Offset;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1279,7 +1279,7 @@ static Value *GetMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
|
||||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
||||||
OffsetCst);
|
OffsetCst);
|
||||||
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
||||||
return ConstantFoldLoadFromConstPtr(Src, DL);
|
return ConstantFoldLoadFromConstPtr(Src, LoadTy, DL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1094,7 +1094,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform load from a constant into a constant if possible.
|
// Transform load from a constant into a constant if possible.
|
||||||
if (Constant *C = ConstantFoldLoadFromConstPtr(Ptr, DL)) {
|
if (Constant *C = ConstantFoldLoadFromConstPtr(Ptr, I.getType(), DL)) {
|
||||||
if (isa<UndefValue>(C))
|
if (isa<UndefValue>(C))
|
||||||
return;
|
return;
|
||||||
return markConstant(IV, &I, C);
|
return markConstant(IV, &I, C);
|
||||||
|
|
Loading…
Reference in New Issue