mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-26 12:20:42 +00:00
[opaque pointer type] API migration for GEP constant factories
Require the pointee type to be passed explicitly and assert that it is correct. For now it's possible to pass nullptr here (and I've done so in a few places in this patch) but eventually that will be disallowed once all clients have been updated or removed. It'll be a long road to get all the way there... but if you have the cahnce to update your callers to pass the type explicitly without depending on a pointer's element type, that would be a good thing to do soon and a necessary thing to do eventually. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233938 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -671,8 +671,8 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0,
|
||||
|
||||
/// If array indices are not pointer-sized integers, explicitly cast them so
|
||||
/// that they aren't implicitly casted by the getelementptr.
|
||||
static Constant *CastGEPIndices(ArrayRef<Constant *> Ops, Type *ResultTy,
|
||||
const DataLayout &DL,
|
||||
static Constant *CastGEPIndices(Type *SrcTy, ArrayRef<Constant *> Ops,
|
||||
Type *ResultTy, const DataLayout &DL,
|
||||
const TargetLibraryInfo *TLI) {
|
||||
Type *IntPtrTy = DL.getIntPtrType(ResultTy);
|
||||
|
||||
@@ -698,7 +698,7 @@ static Constant *CastGEPIndices(ArrayRef<Constant *> Ops, Type *ResultTy,
|
||||
if (!Any)
|
||||
return nullptr;
|
||||
|
||||
Constant *C = ConstantExpr::getGetElementPtr(Ops[0], NewIdxs);
|
||||
Constant *C = ConstantExpr::getGetElementPtr(SrcTy, Ops[0], NewIdxs);
|
||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, DL, TLI))
|
||||
C = Folded;
|
||||
@@ -724,7 +724,7 @@ static Constant* StripPtrCastKeepAS(Constant* Ptr) {
|
||||
}
|
||||
|
||||
/// If we can symbolically evaluate the GEP constant expression, do so.
|
||||
static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
|
||||
static Constant *SymbolicallyEvaluateGEP(Type *SrcTy, ArrayRef<Constant *> Ops,
|
||||
Type *ResultTy, const DataLayout &DL,
|
||||
const TargetLibraryInfo *TLI) {
|
||||
Constant *Ptr = Ops[0];
|
||||
@@ -866,7 +866,7 @@ static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
|
||||
return nullptr;
|
||||
|
||||
// Create a GEP.
|
||||
Constant *C = ConstantExpr::getGetElementPtr(Ptr, NewIdxs);
|
||||
Constant *C = ConstantExpr::getGetElementPtr(SrcTy, Ptr, NewIdxs);
|
||||
assert(C->getType()->getPointerElementType() == Ty &&
|
||||
"Computed GetElementPtr has unexpected type!");
|
||||
|
||||
@@ -1086,13 +1086,15 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
|
||||
return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2]);
|
||||
case Instruction::ShuffleVector:
|
||||
return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
|
||||
case Instruction::GetElementPtr:
|
||||
if (Constant *C = CastGEPIndices(Ops, DestTy, DL, TLI))
|
||||
case Instruction::GetElementPtr: {
|
||||
Type *SrcTy = nullptr;
|
||||
if (Constant *C = CastGEPIndices(SrcTy, Ops, DestTy, DL, TLI))
|
||||
return C;
|
||||
if (Constant *C = SymbolicallyEvaluateGEP(Ops, DestTy, DL, TLI))
|
||||
if (Constant *C = SymbolicallyEvaluateGEP(SrcTy, Ops, DestTy, DL, TLI))
|
||||
return C;
|
||||
|
||||
return ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1));
|
||||
return ConstantExpr::getGetElementPtr(SrcTy, Ops[0], Ops.slice(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user