mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Cleanup whitespace and indentation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80451 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c34ee42595
commit
f8a87e8343
@ -49,7 +49,7 @@ static Constant *BitCastConstantVector(LLVMContext &Context, ConstantVector *CV,
|
|||||||
unsigned NumElts = DstTy->getNumElements();
|
unsigned NumElts = DstTy->getNumElements();
|
||||||
if (NumElts != CV->getNumOperands())
|
if (NumElts != CV->getNumOperands())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Check to verify that all elements of the input are simple.
|
// Check to verify that all elements of the input are simple.
|
||||||
for (unsigned i = 0; i != NumElts; ++i) {
|
for (unsigned i = 0; i != NumElts; ++i) {
|
||||||
if (!isa<ConstantInt>(CV->getOperand(i)) &&
|
if (!isa<ConstantInt>(CV->getOperand(i)) &&
|
||||||
@ -79,7 +79,7 @@ foldConstantCastPair(
|
|||||||
assert(Op && Op->isCast() && "Can't fold cast of cast without a cast!");
|
assert(Op && Op->isCast() && "Can't fold cast of cast without a cast!");
|
||||||
assert(DstTy && DstTy->isFirstClassType() && "Invalid cast destination type");
|
assert(DstTy && DstTy->isFirstClassType() && "Invalid cast destination type");
|
||||||
assert(CastInst::isCast(opc) && "Invalid cast opcode");
|
assert(CastInst::isCast(opc) && "Invalid cast opcode");
|
||||||
|
|
||||||
// The the types and opcodes for the two Cast constant expressions
|
// The the types and opcodes for the two Cast constant expressions
|
||||||
const Type *SrcTy = Op->getOperand(0)->getType();
|
const Type *SrcTy = Op->getOperand(0)->getType();
|
||||||
const Type *MidTy = Op->getType();
|
const Type *MidTy = Op->getType();
|
||||||
@ -96,7 +96,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
|||||||
const Type *SrcTy = V->getType();
|
const Type *SrcTy = V->getType();
|
||||||
if (SrcTy == DestTy)
|
if (SrcTy == DestTy)
|
||||||
return V; // no-op cast
|
return V; // no-op cast
|
||||||
|
|
||||||
// Check to see if we are casting a pointer to an aggregate to a pointer to
|
// Check to see if we are casting a pointer to an aggregate to a pointer to
|
||||||
// the first element. If so, return the appropriate GEP instruction.
|
// the first element. If so, return the appropriate GEP instruction.
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(V->getType()))
|
if (const PointerType *PTy = dyn_cast<PointerType>(V->getType()))
|
||||||
@ -120,13 +120,13 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ElTy == DPTy->getElementType())
|
if (ElTy == DPTy->getElementType())
|
||||||
// This GEP is inbounds because all indices are zero.
|
// This GEP is inbounds because all indices are zero.
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
|
return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
|
||||||
IdxList.size());
|
IdxList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle casts from one vector constant to another. We know that the src
|
// Handle casts from one vector constant to another. We know that the src
|
||||||
// and dest type have the same size (otherwise its an illegal cast).
|
// and dest type have the same size (otherwise its an illegal cast).
|
||||||
if (const VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
|
if (const VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
|
||||||
@ -137,7 +137,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
|||||||
// First, check for null. Undef is already handled.
|
// First, check for null. Undef is already handled.
|
||||||
if (isa<ConstantAggregateZero>(V))
|
if (isa<ConstantAggregateZero>(V))
|
||||||
return Constant::getNullValue(DestTy);
|
return Constant::getNullValue(DestTy);
|
||||||
|
|
||||||
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
|
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
|
||||||
return BitCastConstantVector(Context, CV, DestPTy);
|
return BitCastConstantVector(Context, CV, DestPTy);
|
||||||
}
|
}
|
||||||
@ -149,12 +149,12 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
|||||||
return ConstantExpr::getBitCast(
|
return ConstantExpr::getBitCast(
|
||||||
ConstantVector::get(&V, 1), DestPTy);
|
ConstantVector::get(&V, 1), DestPTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, implement bitcast folding now. The code below doesn't handle
|
// Finally, implement bitcast folding now. The code below doesn't handle
|
||||||
// bitcast right.
|
// bitcast right.
|
||||||
if (isa<ConstantPointerNull>(V)) // ptr->ptr cast.
|
if (isa<ConstantPointerNull>(V)) // ptr->ptr cast.
|
||||||
return ConstantPointerNull::get(cast<PointerType>(DestTy));
|
return ConstantPointerNull::get(cast<PointerType>(DestTy));
|
||||||
|
|
||||||
// Handle integral constant input.
|
// Handle integral constant input.
|
||||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
|
||||||
if (DestTy->isInteger())
|
if (DestTy->isInteger())
|
||||||
@ -341,7 +341,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context,
|
|||||||
if (Val->isNullValue()) // ee(zero, x) -> zero
|
if (Val->isNullValue()) // ee(zero, x) -> zero
|
||||||
return Constant::getNullValue(
|
return Constant::getNullValue(
|
||||||
cast<VectorType>(Val->getType())->getElementType());
|
cast<VectorType>(Val->getType())->getElementType());
|
||||||
|
|
||||||
if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) {
|
if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) {
|
||||||
if (const ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
|
if (const ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
|
||||||
return CVal->getOperand(CIdx->getZExtValue());
|
return CVal->getOperand(CIdx->getZExtValue());
|
||||||
@ -417,7 +417,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C,
|
|||||||
unsigned EltNo) {
|
unsigned EltNo) {
|
||||||
if (const ConstantVector *CV = dyn_cast<ConstantVector>(C))
|
if (const ConstantVector *CV = dyn_cast<ConstantVector>(C))
|
||||||
return CV->getOperand(EltNo);
|
return CV->getOperand(EltNo);
|
||||||
|
|
||||||
const Type *EltTy = cast<VectorType>(C->getType())->getElementType();
|
const Type *EltTy = cast<VectorType>(C->getType())->getElementType();
|
||||||
if (isa<ConstantAggregateZero>(C))
|
if (isa<ConstantAggregateZero>(C))
|
||||||
return Constant::getNullValue(EltTy);
|
return Constant::getNullValue(EltTy);
|
||||||
@ -661,7 +661,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
if (CI2->isZero()) return const_cast<Constant*>(C2); // X & 0 == 0
|
if (CI2->isZero()) return const_cast<Constant*>(C2); // X & 0 == 0
|
||||||
if (CI2->isAllOnesValue())
|
if (CI2->isAllOnesValue())
|
||||||
return const_cast<Constant*>(C1); // X & -1 == X
|
return const_cast<Constant*>(C1); // X & -1 == X
|
||||||
|
|
||||||
if (const ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) {
|
if (const ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) {
|
||||||
// (zext i32 to i64) & 4294967295 -> (zext i32 to i64)
|
// (zext i32 to i64) & 4294967295 -> (zext i32 to i64)
|
||||||
if (CE1->getOpcode() == Instruction::ZExt) {
|
if (CE1->getOpcode() == Instruction::ZExt) {
|
||||||
@ -672,17 +672,17 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
|
if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
|
||||||
return const_cast<Constant*>(C1);
|
return const_cast<Constant*>(C1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If and'ing the address of a global with a constant, fold it.
|
// If and'ing the address of a global with a constant, fold it.
|
||||||
if (CE1->getOpcode() == Instruction::PtrToInt &&
|
if (CE1->getOpcode() == Instruction::PtrToInt &&
|
||||||
isa<GlobalValue>(CE1->getOperand(0))) {
|
isa<GlobalValue>(CE1->getOperand(0))) {
|
||||||
GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
|
GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
|
||||||
|
|
||||||
// Functions are at least 4-byte aligned.
|
// Functions are at least 4-byte aligned.
|
||||||
unsigned GVAlign = GV->getAlignment();
|
unsigned GVAlign = GV->getAlignment();
|
||||||
if (isa<Function>(GV))
|
if (isa<Function>(GV))
|
||||||
GVAlign = std::max(GVAlign, 4U);
|
GVAlign = std::max(GVAlign, 4U);
|
||||||
|
|
||||||
if (GVAlign > 1) {
|
if (GVAlign > 1) {
|
||||||
unsigned DstWidth = CI2->getType()->getBitWidth();
|
unsigned DstWidth = CI2->getType()->getBitWidth();
|
||||||
unsigned SrcWidth = std::min(DstWidth, Log2_32(GVAlign));
|
unsigned SrcWidth = std::min(DstWidth, Log2_32(GVAlign));
|
||||||
@ -712,7 +712,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point we know neither constant is an UndefValue.
|
// At this point we know neither constant is an UndefValue.
|
||||||
if (const ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
|
if (const ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
|
||||||
if (const ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
|
if (const ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
|
||||||
@ -989,7 +989,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
case Instruction::Xor:
|
case Instruction::Xor:
|
||||||
// No change of opcode required.
|
// No change of opcode required.
|
||||||
return ConstantFoldBinaryInstruction(Context, Opcode, C2, C1);
|
return ConstantFoldBinaryInstruction(Context, Opcode, C2, C1);
|
||||||
|
|
||||||
case Instruction::Shl:
|
case Instruction::Shl:
|
||||||
case Instruction::LShr:
|
case Instruction::LShr:
|
||||||
case Instruction::AShr:
|
case Instruction::AShr:
|
||||||
@ -1005,7 +1005,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't know how to fold this.
|
// We don't know how to fold this.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1113,7 +1113,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context,
|
|||||||
// Nothing more we can do
|
// Nothing more we can do
|
||||||
return FCmpInst::BAD_FCMP_PREDICATE;
|
return FCmpInst::BAD_FCMP_PREDICATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the first operand is simple and second is ConstantExpr, swap operands.
|
// If the first operand is simple and second is ConstantExpr, swap operands.
|
||||||
FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(Context, V2, V1);
|
FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(Context, V2, V1);
|
||||||
if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE)
|
if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE)
|
||||||
@ -1177,11 +1177,11 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
|
|||||||
R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
|
R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
|
||||||
if (R && !R->isZero())
|
if (R && !R->isZero())
|
||||||
return pred;
|
return pred;
|
||||||
|
|
||||||
// If we couldn't figure it out, bail.
|
// If we couldn't figure it out, bail.
|
||||||
return ICmpInst::BAD_ICMP_PREDICATE;
|
return ICmpInst::BAD_ICMP_PREDICATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the first operand is simple, swap operands.
|
// If the first operand is simple, swap operands.
|
||||||
ICmpInst::Predicate SwappedRelation =
|
ICmpInst::Predicate SwappedRelation =
|
||||||
evaluateICmpRelation(Context, V2, V1, isSigned);
|
evaluateICmpRelation(Context, V2, V1, isSigned);
|
||||||
@ -1489,7 +1489,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
|||||||
SmallVector<Constant*, 16> C1Elts, C2Elts;
|
SmallVector<Constant*, 16> C1Elts, C2Elts;
|
||||||
C1->getVectorElements(Context, C1Elts);
|
C1->getVectorElements(Context, C1Elts);
|
||||||
C2->getVectorElements(Context, C2Elts);
|
C2->getVectorElements(Context, C2Elts);
|
||||||
|
|
||||||
// If we can constant fold the comparison of each element, constant fold
|
// If we can constant fold the comparison of each element, constant fold
|
||||||
// the whole vector comparison.
|
// the whole vector comparison.
|
||||||
SmallVector<Constant*, 4> ResElts;
|
SmallVector<Constant*, 4> ResElts;
|
||||||
@ -1554,7 +1554,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
|||||||
Result = 1;
|
Result = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we evaluated the result, return it now.
|
// If we evaluated the result, return it now.
|
||||||
if (Result != -1)
|
if (Result != -1)
|
||||||
return ConstantInt::get(Type::getInt1Ty(Context), Result);
|
return ConstantInt::get(Type::getInt1Ty(Context), Result);
|
||||||
@ -1631,11 +1631,11 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
|||||||
if (pred == ICmpInst::ICMP_NE) Result = 1;
|
if (pred == ICmpInst::ICMP_NE) Result = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we evaluated the result, return it now.
|
// If we evaluated the result, return it now.
|
||||||
if (Result != -1)
|
if (Result != -1)
|
||||||
return ConstantInt::get(Type::getInt1Ty(Context), Result);
|
return ConstantInt::get(Type::getInt1Ty(Context), Result);
|
||||||
|
|
||||||
if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
|
if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
|
||||||
// If C2 is a constant expr and C1 isn't, flip them around and fold the
|
// If C2 is a constant expr and C1 isn't, flip them around and fold the
|
||||||
// other way if possible.
|
// other way if possible.
|
||||||
@ -1663,7 +1663,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
|
Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
|
||||||
const Constant *C,
|
const Constant *C,
|
||||||
@ -1759,7 +1759,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
|
|||||||
return ConstantExpr::getGetElementPtr(
|
return ConstantExpr::getGetElementPtr(
|
||||||
(Constant*)CE->getOperand(0), Idxs, NumIdx);
|
(Constant*)CE->getOperand(0), Idxs, NumIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1)
|
// Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1)
|
||||||
// Into: inttoptr (i64 0 to i8*)
|
// Into: inttoptr (i64 0 to i8*)
|
||||||
// This happens with pointers to member functions in C++.
|
// This happens with pointers to member functions in C++.
|
||||||
@ -1768,7 +1768,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
|
|||||||
cast<PointerType>(CE->getType())->getElementType() == Type::getInt8Ty(Context)) {
|
cast<PointerType>(CE->getType())->getElementType() == Type::getInt8Ty(Context)) {
|
||||||
Constant *Base = CE->getOperand(0);
|
Constant *Base = CE->getOperand(0);
|
||||||
Constant *Offset = Idxs[0];
|
Constant *Offset = Idxs[0];
|
||||||
|
|
||||||
// Convert the smaller integer to the larger type.
|
// Convert the smaller integer to the larger type.
|
||||||
if (Offset->getType()->getPrimitiveSizeInBits() <
|
if (Offset->getType()->getPrimitiveSizeInBits() <
|
||||||
Base->getType()->getPrimitiveSizeInBits())
|
Base->getType()->getPrimitiveSizeInBits())
|
||||||
@ -1776,11 +1776,10 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
|
|||||||
else if (Base->getType()->getPrimitiveSizeInBits() <
|
else if (Base->getType()->getPrimitiveSizeInBits() <
|
||||||
Offset->getType()->getPrimitiveSizeInBits())
|
Offset->getType()->getPrimitiveSizeInBits())
|
||||||
Base = ConstantExpr::getZExt(Base, Offset->getType());
|
Base = ConstantExpr::getZExt(Base, Offset->getType());
|
||||||
|
|
||||||
Base = ConstantExpr::getAdd(Base, Offset);
|
Base = ConstantExpr::getAdd(Base, Offset);
|
||||||
return ConstantExpr::getIntToPtr(Base, CE->getType());
|
return ConstantExpr::getIntToPtr(Base, CE->getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user