mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 16:24:23 +00:00
Recommit r236670: [opaque pointer type] Pass explicit pointer type through GEP constant folding""
Clang regressions were caused by more stringent assertion checking introduced by this change. Small fix needed to clang has been committed in r236751. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236752 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -2028,7 +2028,7 @@ static bool isIndexInRangeOfSequentialType(const SequentialType *STy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename IndexTy>
|
template<typename IndexTy>
|
||||||
static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C,
|
||||||
bool inBounds,
|
bool inBounds,
|
||||||
ArrayRef<IndexTy> Idxs) {
|
ArrayRef<IndexTy> Idxs) {
|
||||||
if (Idxs.empty()) return C;
|
if (Idxs.empty()) return C;
|
||||||
@ -2165,9 +2165,9 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
|||||||
// factored out into preceding dimensions.
|
// factored out into preceding dimensions.
|
||||||
bool Unknown = false;
|
bool Unknown = false;
|
||||||
SmallVector<Constant *, 8> NewIdxs;
|
SmallVector<Constant *, 8> NewIdxs;
|
||||||
Type *Ty = C->getType();
|
Type *Ty = PointeeTy;
|
||||||
Type *Prev = nullptr;
|
Type *Prev = C->getType();
|
||||||
for (unsigned i = 0, e = Idxs.size(); i != e;
|
for (unsigned i = 1, e = Idxs.size(); i != e;
|
||||||
Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
|
Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
|
||||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
|
||||||
if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
|
if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
|
||||||
@ -2229,7 +2229,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
|||||||
if (!Unknown && !inBounds)
|
if (!Unknown && !inBounds)
|
||||||
if (auto *GV = dyn_cast<GlobalVariable>(C))
|
if (auto *GV = dyn_cast<GlobalVariable>(C))
|
||||||
if (!GV->hasExternalWeakLinkage() && isInBoundsIndices(Idxs))
|
if (!GV->hasExternalWeakLinkage() && isInBoundsIndices(Idxs))
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(nullptr, C, Idxs);
|
return ConstantExpr::getInBoundsGetElementPtr(PointeeTy, C, Idxs);
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -2237,11 +2237,27 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
|||||||
Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
|
Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
|
||||||
bool inBounds,
|
bool inBounds,
|
||||||
ArrayRef<Constant *> Idxs) {
|
ArrayRef<Constant *> Idxs) {
|
||||||
return ConstantFoldGetElementPtrImpl(C, inBounds, Idxs);
|
return ConstantFoldGetElementPtrImpl(
|
||||||
|
cast<PointerType>(C->getType()->getScalarType())->getElementType(), C,
|
||||||
|
inBounds, Idxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
|
Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
|
||||||
bool inBounds,
|
bool inBounds,
|
||||||
ArrayRef<Value *> Idxs) {
|
ArrayRef<Value *> Idxs) {
|
||||||
return ConstantFoldGetElementPtrImpl(C, inBounds, Idxs);
|
return ConstantFoldGetElementPtrImpl(
|
||||||
|
cast<PointerType>(C->getType()->getScalarType())->getElementType(), C,
|
||||||
|
inBounds, Idxs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Constant *llvm::ConstantFoldGetElementPtr(Type *Ty, Constant *C,
|
||||||
|
bool inBounds,
|
||||||
|
ArrayRef<Constant *> Idxs) {
|
||||||
|
return ConstantFoldGetElementPtrImpl(Ty, C, inBounds, Idxs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Constant *llvm::ConstantFoldGetElementPtr(Type *Ty, Constant *C,
|
||||||
|
bool inBounds,
|
||||||
|
ArrayRef<Value *> Idxs) {
|
||||||
|
return ConstantFoldGetElementPtrImpl(Ty, C, inBounds, Idxs);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,10 @@ namespace llvm {
|
|||||||
ArrayRef<Constant *> Idxs);
|
ArrayRef<Constant *> Idxs);
|
||||||
Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
|
Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
|
||||||
ArrayRef<Value *> Idxs);
|
ArrayRef<Value *> Idxs);
|
||||||
|
Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool inBounds,
|
||||||
|
ArrayRef<Constant *> Idxs);
|
||||||
|
Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool inBounds,
|
||||||
|
ArrayRef<Value *> Idxs);
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2015,14 +2015,16 @@ Constant *ConstantExpr::getSelect(Constant *C, Constant *V1, Constant *V2,
|
|||||||
Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
|
Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
|
||||||
ArrayRef<Value *> Idxs, bool InBounds,
|
ArrayRef<Value *> Idxs, bool InBounds,
|
||||||
Type *OnlyIfReducedTy) {
|
Type *OnlyIfReducedTy) {
|
||||||
if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs))
|
|
||||||
return FC; // Fold a few common cases.
|
|
||||||
|
|
||||||
if (!Ty)
|
if (!Ty)
|
||||||
Ty = cast<PointerType>(C->getType()->getScalarType())->getElementType();
|
Ty = cast<PointerType>(C->getType()->getScalarType())->getElementType();
|
||||||
else
|
else
|
||||||
assert(Ty ==
|
assert(
|
||||||
cast<PointerType>(C->getType()->getScalarType())->getElementType());
|
Ty ==
|
||||||
|
cast<PointerType>(C->getType()->getScalarType())->getContainedType(0u));
|
||||||
|
|
||||||
|
if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InBounds, Idxs))
|
||||||
|
return FC; // Fold a few common cases.
|
||||||
|
|
||||||
// Get the result type of the getelementptr!
|
// Get the result type of the getelementptr!
|
||||||
Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
|
Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
|
||||||
assert(DestTy && "GEP indices invalid!");
|
assert(DestTy && "GEP indices invalid!");
|
||||||
|
@ -564,7 +564,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
|
|||||||
if (Val >= NewGlobals.size()) Val = 0; // Out of bound array access.
|
if (Val >= NewGlobals.size()) Val = 0; // Out of bound array access.
|
||||||
|
|
||||||
Value *NewPtr = NewGlobals[Val];
|
Value *NewPtr = NewGlobals[Val];
|
||||||
Type *NewTy = NewGlobals[Val]->getType();
|
Type *NewTy = NewGlobals[Val]->getValueType();
|
||||||
|
|
||||||
// Form a shorter GEP if needed.
|
// Form a shorter GEP if needed.
|
||||||
if (GEP->getNumOperands() > 3) {
|
if (GEP->getNumOperands() > 3) {
|
||||||
@ -575,7 +575,6 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
|
|||||||
Idxs.push_back(CE->getOperand(i));
|
Idxs.push_back(CE->getOperand(i));
|
||||||
NewPtr =
|
NewPtr =
|
||||||
ConstantExpr::getGetElementPtr(NewTy, cast<Constant>(NewPtr), Idxs);
|
ConstantExpr::getGetElementPtr(NewTy, cast<Constant>(NewPtr), Idxs);
|
||||||
NewTy = GetElementPtrInst::getIndexedType(NewTy, Idxs);
|
|
||||||
} else {
|
} else {
|
||||||
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
|
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
|
||||||
SmallVector<Value*, 8> Idxs;
|
SmallVector<Value*, 8> Idxs;
|
||||||
@ -583,8 +582,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
|
|||||||
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
|
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
|
||||||
Idxs.push_back(GEPI->getOperand(i));
|
Idxs.push_back(GEPI->getOperand(i));
|
||||||
NewPtr = GetElementPtrInst::Create(
|
NewPtr = GetElementPtrInst::Create(
|
||||||
NewPtr->getType()->getPointerElementType(), NewPtr, Idxs,
|
NewTy, NewPtr, Idxs, GEPI->getName() + "." + Twine(Val), GEPI);
|
||||||
GEPI->getName() + "." + Twine(Val), GEPI);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GEP->replaceAllUsesWith(NewPtr);
|
GEP->replaceAllUsesWith(NewPtr);
|
||||||
|
Reference in New Issue
Block a user