mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
switch ConvertScalar_InsertValue to use an IRBuilder, no
functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63651 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
|
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
|
#include "llvm/Support/IRBuilder.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
@@ -131,7 +132,7 @@ namespace {
|
|||||||
Value *ConvertUsesOfLoadToScalar(LoadInst *LI, AllocaInst *NewAI,
|
Value *ConvertUsesOfLoadToScalar(LoadInst *LI, AllocaInst *NewAI,
|
||||||
uint64_t Offset);
|
uint64_t Offset);
|
||||||
Value *ConvertScalar_InsertValue(Value *StoredVal, Value *ExistingVal,
|
Value *ConvertScalar_InsertValue(Value *StoredVal, Value *ExistingVal,
|
||||||
uint64_t Offset, Instruction *InsertPt);
|
uint64_t Offset, IRBuilder<> &Builder);
|
||||||
static Instruction *isOnlyCopiedFromConstantGlobal(AllocationInst *AI);
|
static Instruction *isOnlyCopiedFromConstantGlobal(AllocationInst *AI);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1326,9 +1327,12 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset) {
|
|||||||
|
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
|
if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
|
||||||
assert(SI->getOperand(0) != Ptr && "Consistency error!");
|
assert(SI->getOperand(0) != Ptr && "Consistency error!");
|
||||||
Value *Old = new LoadInst(NewAI, NewAI->getName()+".in", SI);
|
|
||||||
Value *New = ConvertScalar_InsertValue(SI->getOperand(0), Old, Offset,SI);
|
IRBuilder<> Builder(SI->getParent(), SI);
|
||||||
new StoreInst(New, NewAI, SI);
|
Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str());
|
||||||
|
Value *New = ConvertScalar_InsertValue(SI->getOperand(0), Old, Offset,
|
||||||
|
Builder);
|
||||||
|
Builder.CreateStore(New, NewAI);
|
||||||
SI->eraseFromParent();
|
SI->eraseFromParent();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1364,10 +1368,12 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset) {
|
|||||||
for (unsigned i = 1; i != NumBytes; ++i)
|
for (unsigned i = 1; i != NumBytes; ++i)
|
||||||
APVal |= APVal << 8;
|
APVal |= APVal << 8;
|
||||||
|
|
||||||
Value *Old = new LoadInst(NewAI, NewAI->getName()+".in", MSI);
|
IRBuilder<> Builder(MSI->getParent(), MSI);
|
||||||
|
|
||||||
|
Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str());
|
||||||
Value *New = ConvertScalar_InsertValue(ConstantInt::get(APVal), Old,
|
Value *New = ConvertScalar_InsertValue(ConstantInt::get(APVal), Old,
|
||||||
Offset, MSI);
|
Offset, Builder);
|
||||||
new StoreInst(New, NewAI, MSI);
|
Builder.CreateStore(New, NewAI);
|
||||||
MSI->eraseFromParent();
|
MSI->eraseFromParent();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1477,7 +1483,7 @@ Value *SROA::ConvertUsesOfLoadToScalar(LoadInst *LI, AllocaInst *NewAI,
|
|||||||
/// Offset is an offset from the original alloca, in bits that need to be
|
/// Offset is an offset from the original alloca, in bits that need to be
|
||||||
/// shifted to the right.
|
/// shifted to the right.
|
||||||
Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
||||||
uint64_t Offset, Instruction *IP) {
|
uint64_t Offset, IRBuilder<> &Builder) {
|
||||||
|
|
||||||
// Convert the stored type to the actual type, shift it left to insert
|
// Convert the stored type to the actual type, shift it left to insert
|
||||||
// then 'or' into place.
|
// then 'or' into place.
|
||||||
@@ -1487,17 +1493,17 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
// If the result alloca is a vector type, this is either an element
|
// If the result alloca is a vector type, this is either an element
|
||||||
// access or a bitcast to another vector type.
|
// access or a bitcast to another vector type.
|
||||||
if (isa<VectorType>(SV->getType())) {
|
if (isa<VectorType>(SV->getType())) {
|
||||||
SV = new BitCastInst(SV, AllocaType, SV->getName(), IP);
|
SV = Builder.CreateBitCast(SV, AllocaType, "tmp");
|
||||||
} else {
|
} else {
|
||||||
// Must be an element insertion.
|
// Must be an element insertion.
|
||||||
unsigned Elt = Offset/TD->getTypePaddedSizeInBits(VTy->getElementType());
|
unsigned Elt = Offset/TD->getTypePaddedSizeInBits(VTy->getElementType());
|
||||||
|
|
||||||
if (SV->getType() != VTy->getElementType())
|
if (SV->getType() != VTy->getElementType())
|
||||||
SV = new BitCastInst(SV, VTy->getElementType(), "tmp", IP);
|
SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp");
|
||||||
|
|
||||||
SV = InsertElementInst::Create(Old, SV,
|
SV = Builder.CreateInsertElement(Old, SV,
|
||||||
ConstantInt::get(Type::Int32Ty, Elt),
|
ConstantInt::get(Type::Int32Ty, Elt),
|
||||||
"tmp", IP);
|
"tmp");
|
||||||
}
|
}
|
||||||
return SV;
|
return SV;
|
||||||
}
|
}
|
||||||
@@ -1506,9 +1512,10 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
if (const StructType *ST = dyn_cast<StructType>(SV->getType())) {
|
if (const StructType *ST = dyn_cast<StructType>(SV->getType())) {
|
||||||
const StructLayout &Layout = *TD->getStructLayout(ST);
|
const StructLayout &Layout = *TD->getStructLayout(ST);
|
||||||
for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {
|
for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {
|
||||||
Value *Elt = ExtractValueInst::Create(SV, i, "tmp", IP);
|
Value *Elt = Builder.CreateExtractValue(SV, i, "tmp");
|
||||||
Old = ConvertScalar_InsertValue(Elt, Old,
|
Old = ConvertScalar_InsertValue(Elt, Old,
|
||||||
Offset+Layout.getElementOffset(i), IP);
|
Offset+Layout.getElementOffset(i),
|
||||||
|
Builder);
|
||||||
}
|
}
|
||||||
return Old;
|
return Old;
|
||||||
}
|
}
|
||||||
@@ -1516,8 +1523,8 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
if (const ArrayType *AT = dyn_cast<ArrayType>(SV->getType())) {
|
if (const ArrayType *AT = dyn_cast<ArrayType>(SV->getType())) {
|
||||||
uint64_t EltSize = TD->getTypePaddedSizeInBits(AT->getElementType());
|
uint64_t EltSize = TD->getTypePaddedSizeInBits(AT->getElementType());
|
||||||
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
|
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
|
||||||
Value *Elt = ExtractValueInst::Create(SV, i, "tmp", IP);
|
Value *Elt = Builder.CreateExtractValue(SV, i, "tmp");
|
||||||
Old = ConvertScalar_InsertValue(Elt, Old, Offset+i*EltSize, IP);
|
Old = ConvertScalar_InsertValue(Elt, Old, Offset+i*EltSize, Builder);
|
||||||
}
|
}
|
||||||
return Old;
|
return Old;
|
||||||
}
|
}
|
||||||
@@ -1529,19 +1536,19 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType());
|
unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType());
|
||||||
unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType);
|
unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType);
|
||||||
if (SV->getType()->isFloatingPoint() || isa<VectorType>(SV->getType()))
|
if (SV->getType()->isFloatingPoint() || isa<VectorType>(SV->getType()))
|
||||||
SV = new BitCastInst(SV, IntegerType::get(SrcWidth), SV->getName(), IP);
|
SV = Builder.CreateBitCast(SV, IntegerType::get(SrcWidth), "tmp");
|
||||||
else if (isa<PointerType>(SV->getType()))
|
else if (isa<PointerType>(SV->getType()))
|
||||||
SV = new PtrToIntInst(SV, TD->getIntPtrType(), SV->getName(), IP);
|
SV = Builder.CreatePtrToInt(SV, TD->getIntPtrType(), "tmp");
|
||||||
|
|
||||||
// Zero extend or truncate the value if needed.
|
// Zero extend or truncate the value if needed.
|
||||||
if (SV->getType() != AllocaType) {
|
if (SV->getType() != AllocaType) {
|
||||||
if (SV->getType()->getPrimitiveSizeInBits() <
|
if (SV->getType()->getPrimitiveSizeInBits() <
|
||||||
AllocaType->getPrimitiveSizeInBits())
|
AllocaType->getPrimitiveSizeInBits())
|
||||||
SV = new ZExtInst(SV, AllocaType, SV->getName(), IP);
|
SV = Builder.CreateZExt(SV, AllocaType, "tmp");
|
||||||
else {
|
else {
|
||||||
// Truncation may be needed if storing more than the alloca can hold
|
// Truncation may be needed if storing more than the alloca can hold
|
||||||
// (undefined behavior).
|
// (undefined behavior).
|
||||||
SV = new TruncInst(SV, AllocaType, SV->getName(), IP);
|
SV = Builder.CreateTrunc(SV, AllocaType, "tmp");
|
||||||
SrcWidth = DestWidth;
|
SrcWidth = DestWidth;
|
||||||
SrcStoreWidth = DestStoreWidth;
|
SrcStoreWidth = DestStoreWidth;
|
||||||
}
|
}
|
||||||
@@ -1564,14 +1571,10 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
// only some bits in the structure are set.
|
// only some bits in the structure are set.
|
||||||
APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth));
|
APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth));
|
||||||
if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) {
|
if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) {
|
||||||
SV = BinaryOperator::CreateShl(SV,
|
SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(), ShAmt), "tmp");
|
||||||
ConstantInt::get(SV->getType(), ShAmt),
|
|
||||||
SV->getName(), IP);
|
|
||||||
Mask <<= ShAmt;
|
Mask <<= ShAmt;
|
||||||
} else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) {
|
} else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) {
|
||||||
SV = BinaryOperator::CreateLShr(SV,
|
SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(), -ShAmt), "tmp");
|
||||||
ConstantInt::get(SV->getType(), -ShAmt),
|
|
||||||
SV->getName(), IP);
|
|
||||||
Mask = Mask.lshr(-ShAmt);
|
Mask = Mask.lshr(-ShAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1579,9 +1582,8 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
|||||||
// in the new bits.
|
// in the new bits.
|
||||||
if (SrcWidth != DestWidth) {
|
if (SrcWidth != DestWidth) {
|
||||||
assert(DestWidth > SrcWidth);
|
assert(DestWidth > SrcWidth);
|
||||||
Old = BinaryOperator::CreateAnd(Old, ConstantInt::get(~Mask),
|
Old = Builder.CreateAnd(Old, ConstantInt::get(~Mask), "mask");
|
||||||
Old->getName()+".mask", IP);
|
SV = Builder.CreateOr(Old, SV, "ins");
|
||||||
SV = BinaryOperator::CreateOr(Old, SV, SV->getName()+".ins", IP);
|
|
||||||
}
|
}
|
||||||
return SV;
|
return SV;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user