mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
modify CheckGEPInstructions to take a pointer and size instead of a vector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34166 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -111,10 +111,10 @@ namespace {
|
|||||||
// must-aliasing base pointers. This checks to see if the index expressions
|
// must-aliasing base pointers. This checks to see if the index expressions
|
||||||
// preclude the pointers from aliasing...
|
// preclude the pointers from aliasing...
|
||||||
AliasResult
|
AliasResult
|
||||||
CheckGEPInstructions(const Type* BasePtr1Ty, std::vector<Value*> &GEP1Ops,
|
CheckGEPInstructions(const Type* BasePtr1Ty,
|
||||||
unsigned G1Size,
|
Value **GEP1Ops, unsigned NumGEP1Ops, unsigned G1Size,
|
||||||
const Type *BasePtr2Ty, std::vector<Value*> &GEP2Ops,
|
const Type *BasePtr2Ty,
|
||||||
unsigned G2Size);
|
Value **GEP2Ops, unsigned NumGEP2Ops, unsigned G2Size);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register this pass...
|
// Register this pass...
|
||||||
@ -377,8 +377,10 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
|
|||||||
// do the comparison.
|
// do the comparison.
|
||||||
if (BasePtr1 == BasePtr2) {
|
if (BasePtr1 == BasePtr2) {
|
||||||
AliasResult GAlias =
|
AliasResult GAlias =
|
||||||
CheckGEPInstructions(BasePtr1->getType(), GEP1Ops, V1Size,
|
CheckGEPInstructions(BasePtr1->getType(),
|
||||||
BasePtr2->getType(), GEP2Ops, V2Size);
|
&GEP1Ops[0], GEP1Ops.size(), V1Size,
|
||||||
|
BasePtr2->getType(),
|
||||||
|
&GEP2Ops[0], GEP2Ops.size(), V2Size);
|
||||||
if (GAlias != MayAlias)
|
if (GAlias != MayAlias)
|
||||||
return GAlias;
|
return GAlias;
|
||||||
}
|
}
|
||||||
@ -472,8 +474,8 @@ static bool IndexOperandsEqual(Value *V1, Value *V2) {
|
|||||||
/// pointers from aliasing...
|
/// pointers from aliasing...
|
||||||
AliasAnalysis::AliasResult
|
AliasAnalysis::AliasResult
|
||||||
BasicAliasAnalysis::CheckGEPInstructions(
|
BasicAliasAnalysis::CheckGEPInstructions(
|
||||||
const Type* BasePtr1Ty, std::vector<Value*> &GEP1Ops, unsigned G1S,
|
const Type* BasePtr1Ty, Value **GEP1Ops, unsigned NumGEP1Ops, unsigned G1S,
|
||||||
const Type *BasePtr2Ty, std::vector<Value*> &GEP2Ops, unsigned G2S) {
|
const Type *BasePtr2Ty, Value **GEP2Ops, unsigned NumGEP2Ops, unsigned G2S) {
|
||||||
// We currently can't handle the case when the base pointers have different
|
// We currently can't handle the case when the base pointers have different
|
||||||
// primitive types. Since this is uncommon anyway, we are happy being
|
// primitive types. Since this is uncommon anyway, we are happy being
|
||||||
// extremely conservative.
|
// extremely conservative.
|
||||||
@ -484,7 +486,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
|
|
||||||
// Find the (possibly empty) initial sequence of equal values... which are not
|
// Find the (possibly empty) initial sequence of equal values... which are not
|
||||||
// necessarily constants.
|
// necessarily constants.
|
||||||
unsigned NumGEP1Operands = GEP1Ops.size(), NumGEP2Operands = GEP2Ops.size();
|
unsigned NumGEP1Operands = NumGEP1Ops, NumGEP2Operands = NumGEP2Ops;
|
||||||
unsigned MinOperands = std::min(NumGEP1Operands, NumGEP2Operands);
|
unsigned MinOperands = std::min(NumGEP1Operands, NumGEP2Operands);
|
||||||
unsigned MaxOperands = std::max(NumGEP1Operands, NumGEP2Operands);
|
unsigned MaxOperands = std::max(NumGEP1Operands, NumGEP2Operands);
|
||||||
unsigned UnequalOper = 0;
|
unsigned UnequalOper = 0;
|
||||||
@ -508,7 +510,10 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
// getelementptrs, check to see if the tail of the leftover one is all zeros.
|
// getelementptrs, check to see if the tail of the leftover one is all zeros.
|
||||||
// If so, return mustalias.
|
// If so, return mustalias.
|
||||||
if (UnequalOper == MinOperands) {
|
if (UnequalOper == MinOperands) {
|
||||||
if (GEP1Ops.size() < GEP2Ops.size()) std::swap(GEP1Ops, GEP2Ops);
|
if (NumGEP1Ops < NumGEP2Ops) {
|
||||||
|
std::swap(GEP1Ops, GEP2Ops);
|
||||||
|
std::swap(NumGEP1Ops, NumGEP2Ops);
|
||||||
|
}
|
||||||
|
|
||||||
bool AllAreZeros = true;
|
bool AllAreZeros = true;
|
||||||
for (unsigned i = UnequalOper; i != MaxOperands; ++i)
|
for (unsigned i = UnequalOper; i != MaxOperands; ++i)
|
||||||
@ -585,8 +590,10 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT,
|
Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT,
|
||||||
G1OC, G2OC);
|
G1OC, G2OC);
|
||||||
if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) {
|
if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) {
|
||||||
if (CV->getZExtValue()) // If they are comparable and G2 > G1
|
if (CV->getZExtValue()) { // If they are comparable and G2 > G1
|
||||||
std::swap(GEP1Ops, GEP2Ops); // Make GEP1 < GEP2
|
std::swap(GEP1Ops, GEP2Ops); // Make GEP1 < GEP2
|
||||||
|
std::swap(NumGEP1Ops, NumGEP2Ops);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,11 +609,13 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
// case, there may still be hope. Check this now.
|
// case, there may still be hope. Check this now.
|
||||||
if (FirstConstantOper == MinOperands) {
|
if (FirstConstantOper == MinOperands) {
|
||||||
// Make GEP1Ops be the longer one if there is a longer one.
|
// Make GEP1Ops be the longer one if there is a longer one.
|
||||||
if (GEP1Ops.size() < GEP2Ops.size())
|
if (NumGEP1Ops < NumGEP2Ops) {
|
||||||
std::swap(GEP1Ops, GEP2Ops);
|
std::swap(GEP1Ops, GEP2Ops);
|
||||||
|
std::swap(NumGEP1Ops, NumGEP2Ops);
|
||||||
|
}
|
||||||
|
|
||||||
// Is there anything to check?
|
// Is there anything to check?
|
||||||
if (GEP1Ops.size() > MinOperands) {
|
if (NumGEP1Ops > MinOperands) {
|
||||||
for (unsigned i = FirstConstantOper; i != MaxOperands; ++i)
|
for (unsigned i = FirstConstantOper; i != MaxOperands; ++i)
|
||||||
if (isa<ConstantInt>(GEP1Ops[i]) &&
|
if (isa<ConstantInt>(GEP1Ops[i]) &&
|
||||||
!cast<Constant>(GEP1Ops[i])->isNullValue()) {
|
!cast<Constant>(GEP1Ops[i])->isNullValue()) {
|
||||||
@ -619,13 +628,12 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
// Okay, now get the offset. This is the relative offset for the full
|
// Okay, now get the offset. This is the relative offset for the full
|
||||||
// instruction.
|
// instruction.
|
||||||
const TargetData &TD = getTargetData();
|
const TargetData &TD = getTargetData();
|
||||||
int64_t Offset1 = TD.getIndexedOffset(GEPPointerTy, &GEP1Ops[0],
|
int64_t Offset1 = TD.getIndexedOffset(GEPPointerTy, GEP1Ops,
|
||||||
GEP1Ops.size());
|
NumGEP1Ops);
|
||||||
|
|
||||||
// Now crop off any constants from the end...
|
// Now check without any constants at the end.
|
||||||
GEP1Ops.resize(MinOperands);
|
int64_t Offset2 = TD.getIndexedOffset(GEPPointerTy, GEP1Ops,
|
||||||
int64_t Offset2 = TD.getIndexedOffset(GEPPointerTy, &GEP1Ops[0],
|
MinOperands);
|
||||||
GEP1Ops.size());
|
|
||||||
|
|
||||||
// If the tail provided a bit enough offset, return noalias!
|
// If the tail provided a bit enough offset, return noalias!
|
||||||
if ((uint64_t)(Offset2-Offset1) >= SizeMax)
|
if ((uint64_t)(Offset2-Offset1) >= SizeMax)
|
||||||
@ -665,8 +673,8 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
|
|
||||||
// Loop over the rest of the operands...
|
// Loop over the rest of the operands...
|
||||||
for (unsigned i = FirstConstantOper+1; i != MaxOperands; ++i) {
|
for (unsigned i = FirstConstantOper+1; i != MaxOperands; ++i) {
|
||||||
const Value *Op1 = i < GEP1Ops.size() ? GEP1Ops[i] : 0;
|
const Value *Op1 = i < NumGEP1Ops ? GEP1Ops[i] : 0;
|
||||||
const Value *Op2 = i < GEP2Ops.size() ? GEP2Ops[i] : 0;
|
const Value *Op2 = i < NumGEP2Ops ? GEP2Ops[i] : 0;
|
||||||
// If they are equal, use a zero index...
|
// If they are equal, use a zero index...
|
||||||
if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) {
|
if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) {
|
||||||
if (!isa<ConstantInt>(Op1))
|
if (!isa<ConstantInt>(Op1))
|
||||||
@ -736,9 +744,9 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
|||||||
|
|
||||||
if (GEPPointerTy->getElementType()->isSized()) {
|
if (GEPPointerTy->getElementType()->isSized()) {
|
||||||
int64_t Offset1 =
|
int64_t Offset1 =
|
||||||
getTargetData().getIndexedOffset(GEPPointerTy,&GEP1Ops[0],GEP1Ops.size());
|
getTargetData().getIndexedOffset(GEPPointerTy, GEP1Ops, NumGEP1Ops);
|
||||||
int64_t Offset2 =
|
int64_t Offset2 =
|
||||||
getTargetData().getIndexedOffset(GEPPointerTy,&GEP2Ops[0],GEP2Ops.size());
|
getTargetData().getIndexedOffset(GEPPointerTy, GEP2Ops, NumGEP2Ops);
|
||||||
assert(Offset1<Offset2 && "There is at least one different constant here!");
|
assert(Offset1<Offset2 && "There is at least one different constant here!");
|
||||||
|
|
||||||
if ((uint64_t)(Offset2-Offset1) >= SizeMax) {
|
if ((uint64_t)(Offset2-Offset1) >= SizeMax) {
|
||||||
|
Reference in New Issue
Block a user