1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

[CGP] fix formatting/typos in MemCmpExpansion; NFC

llvm-svn: 304830
This commit is contained in:
Sanjay Patel 2017-06-06 20:30:47 +00:00
parent ac409fc223
commit f14b349546

View File

@ -1753,13 +1753,13 @@ void MemCmpExpansion::emitLoadCompareByteBlock(unsigned Index, int GEPIndex) {
Builder.SetInsertPoint(LoadCmpBlocks[Index]); Builder.SetInsertPoint(LoadCmpBlocks[Index]);
Type *LoadSizeType = Type::getInt8Ty(CI->getContext()); Type *LoadSizeType = Type::getInt8Ty(CI->getContext());
// Cast source to LoadSizeType* // Cast source to LoadSizeType*.
if (Source1->getType() != LoadSizeType) if (Source1->getType() != LoadSizeType)
Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo()); Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo());
if (Source2->getType() != LoadSizeType) if (Source2->getType() != LoadSizeType)
Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo()); Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo());
// Get the base address using the GEPIndex // Get the base address using the GEPIndex.
if (GEPIndex != 0) { if (GEPIndex != 0) {
Source1 = Builder.CreateGEP(LoadSizeType, Source1, Source1 = Builder.CreateGEP(LoadSizeType, Source1,
ConstantInt::get(LoadSizeType, GEPIndex)); ConstantInt::get(LoadSizeType, GEPIndex));
@ -1777,16 +1777,15 @@ void MemCmpExpansion::emitLoadCompareByteBlock(unsigned Index, int GEPIndex) {
PhiRes->addIncoming(Diff, LoadCmpBlocks[Index]); PhiRes->addIncoming(Diff, LoadCmpBlocks[Index]);
if (Index < (LoadCmpBlocks.size() - 1)) { if (Index < (LoadCmpBlocks.size() - 1)) {
// Early exit branch if difference found to EndBlock, otherwise continue to // Early exit branch if difference found to EndBlock. Otherwise, continue to
// next LoadCmpBlock // next LoadCmpBlock,
Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_NE, Diff, Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_NE, Diff,
ConstantInt::get(Diff->getType(), 0)); ConstantInt::get(Diff->getType(), 0));
BranchInst *CmpBr = BranchInst *CmpBr =
BranchInst::Create(EndBlock, LoadCmpBlocks[Index + 1], Cmp); BranchInst::Create(EndBlock, LoadCmpBlocks[Index + 1], Cmp);
Builder.Insert(CmpBr); Builder.Insert(CmpBr);
} else { } else {
// The last block has an unconditional branch to EndBlock // The last block has an unconditional branch to EndBlock.
BranchInst *CmpBr = BranchInst::Create(EndBlock); BranchInst *CmpBr = BranchInst::Create(EndBlock);
Builder.Insert(CmpBr); Builder.Insert(CmpBr);
} }
@ -1826,13 +1825,13 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
Value *Source1 = CI->getArgOperand(0); Value *Source1 = CI->getArgOperand(0);
Value *Source2 = CI->getArgOperand(1); Value *Source2 = CI->getArgOperand(1);
// Cast source to LoadSizeType* // Cast source to LoadSizeType*.
if (Source1->getType() != LoadSizeType) if (Source1->getType() != LoadSizeType)
Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo()); Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo());
if (Source2->getType() != LoadSizeType) if (Source2->getType() != LoadSizeType)
Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo()); Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo());
// Get the base address using the GEPIndex // Get the base address using the GEPIndex.
if (GEPIndex != 0) { if (GEPIndex != 0) {
Source1 = Builder.CreateGEP(LoadSizeType, Source1, Source1 = Builder.CreateGEP(LoadSizeType, Source1,
ConstantInt::get(LoadSizeType, GEPIndex)); ConstantInt::get(LoadSizeType, GEPIndex));
@ -1840,7 +1839,7 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
ConstantInt::get(LoadSizeType, GEPIndex)); ConstantInt::get(LoadSizeType, GEPIndex));
} }
// Load LoadSizeType from the base address // Load LoadSizeType from the base address.
Value *LoadSrc1 = Builder.CreateLoad(LoadSizeType, Source1); Value *LoadSrc1 = Builder.CreateLoad(LoadSizeType, Source1);
Value *LoadSrc2 = Builder.CreateLoad(LoadSizeType, Source2); Value *LoadSrc2 = Builder.CreateLoad(LoadSizeType, Source2);
if (LoadSizeType != MaxLoadType) { if (LoadSizeType != MaxLoadType) {
@ -1863,10 +1862,10 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
return OutList; return OutList;
}; };
// Pair wise OR the XOR results // Pairwise OR the XOR results.
OrList = pairWiseOr(XorList); OrList = pairWiseOr(XorList);
// Pair wise OR the OR results until one result left // Pairwise OR the OR results until one result left.
while (OrList.size() != 1) { while (OrList.size() != 1) {
OrList = pairWiseOr(OrList); OrList = pairWiseOr(OrList);
} }
@ -1876,14 +1875,14 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
BasicBlock *NextBB = (Index == (LoadCmpBlocks.size() - 1)) BasicBlock *NextBB = (Index == (LoadCmpBlocks.size() - 1))
? EndBlock ? EndBlock
: LoadCmpBlocks[Index + 1]; : LoadCmpBlocks[Index + 1];
// Early exit branch if difference found to ResultBlock, otherwise continue to // Early exit branch if difference found to ResultBlock. Otherwise,
// next LoadCmpBlock or EndBlock. // continue to next LoadCmpBlock or EndBlock.
BranchInst *CmpBr = BranchInst::Create(ResBlock.BB, NextBB, Cmp); BranchInst *CmpBr = BranchInst::Create(ResBlock.BB, NextBB, Cmp);
Builder.Insert(CmpBr); Builder.Insert(CmpBr);
// Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0 // Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0
// since early exit to ResultBlock was not taken (no difference was found in // since early exit to ResultBlock was not taken (no difference was found in
// any of the bytes) // any of the bytes).
if (Index == LoadCmpBlocks.size() - 1) { if (Index == LoadCmpBlocks.size() - 1) {
Value *Zero = ConstantInt::get(Type::getInt32Ty(CI->getContext()), 0); Value *Zero = ConstantInt::get(Type::getInt32Ty(CI->getContext()), 0);
PhiRes->addIncoming(Zero, LoadCmpBlocks[Index]); PhiRes->addIncoming(Zero, LoadCmpBlocks[Index]);
@ -1915,13 +1914,13 @@ void MemCmpExpansion::emitLoadCompareBlock(unsigned Index, int LoadSize,
Value *Source2 = CI->getArgOperand(1); Value *Source2 = CI->getArgOperand(1);
Builder.SetInsertPoint(LoadCmpBlocks[Index]); Builder.SetInsertPoint(LoadCmpBlocks[Index]);
// Cast source to LoadSizeType* // Cast source to LoadSizeType*.
if (Source1->getType() != LoadSizeType) if (Source1->getType() != LoadSizeType)
Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo()); Source1 = Builder.CreateBitCast(Source1, LoadSizeType->getPointerTo());
if (Source2->getType() != LoadSizeType) if (Source2->getType() != LoadSizeType)
Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo()); Source2 = Builder.CreateBitCast(Source2, LoadSizeType->getPointerTo());
// Get the base address using the GEPIndex // Get the base address using the GEPIndex.
if (GEPIndex != 0) { if (GEPIndex != 0) {
Source1 = Builder.CreateGEP(LoadSizeType, Source1, Source1 = Builder.CreateGEP(LoadSizeType, Source1,
ConstantInt::get(LoadSizeType, GEPIndex)); ConstantInt::get(LoadSizeType, GEPIndex));
@ -1929,7 +1928,7 @@ void MemCmpExpansion::emitLoadCompareBlock(unsigned Index, int LoadSize,
ConstantInt::get(LoadSizeType, GEPIndex)); ConstantInt::get(LoadSizeType, GEPIndex));
} }
// Load LoadSizeType from the base address // Load LoadSizeType from the base address.
Value *LoadSrc1 = Builder.CreateLoad(LoadSizeType, Source1); Value *LoadSrc1 = Builder.CreateLoad(LoadSizeType, Source1);
Value *LoadSrc2 = Builder.CreateLoad(LoadSizeType, Source2); Value *LoadSrc2 = Builder.CreateLoad(LoadSizeType, Source2);
@ -1961,14 +1960,14 @@ void MemCmpExpansion::emitLoadCompareBlock(unsigned Index, int LoadSize,
BasicBlock *NextBB = (Index == (LoadCmpBlocks.size() - 1)) BasicBlock *NextBB = (Index == (LoadCmpBlocks.size() - 1))
? EndBlock ? EndBlock
: LoadCmpBlocks[Index + 1]; : LoadCmpBlocks[Index + 1];
// Early exit branch if difference found to ResultBlock, otherwise continue to // Early exit branch if difference found to ResultBlock. Otherwise, continue
// next LoadCmpBlock or EndBlock. // to next LoadCmpBlock or EndBlock.
BranchInst *CmpBr = BranchInst::Create(ResBlock.BB, NextBB, Cmp); BranchInst *CmpBr = BranchInst::Create(ResBlock.BB, NextBB, Cmp);
Builder.Insert(CmpBr); Builder.Insert(CmpBr);
// Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0 // Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0
// since early exit to ResultBlock was not taken (no difference was found in // since early exit to ResultBlock was not taken (no difference was found in
// any of the bytes) // any of the bytes).
if (Index == LoadCmpBlocks.size() - 1) { if (Index == LoadCmpBlocks.size() - 1) {
Value *Zero = ConstantInt::get(Type::getInt32Ty(CI->getContext()), 0); Value *Zero = ConstantInt::get(Type::getInt32Ty(CI->getContext()), 0);
PhiRes->addIncoming(Zero, LoadCmpBlocks[Index]); PhiRes->addIncoming(Zero, LoadCmpBlocks[Index]);
@ -2048,8 +2047,8 @@ void MemCmpExpansion::setupEndBlockPHINodes() {
Value *MemCmpExpansion::getMemCmpExpansionZeroCase(unsigned Size, Value *MemCmpExpansion::getMemCmpExpansionZeroCase(unsigned Size,
bool IsLittleEndian) { bool IsLittleEndian) {
unsigned NumBytesProcessed = 0; unsigned NumBytesProcessed = 0;
// This loop populates each of the LoadCmpBlocks with IR sequence to handle // This loop populates each of the LoadCmpBlocks with the IR sequence to
// multiple loads per block // handle multiple loads per block.
for (unsigned i = 0; i < NumBlocks; ++i) { for (unsigned i = 0; i < NumBlocks; ++i) {
emitLoadCompareBlockMultipleLoads(i, Size, NumBytesProcessed); emitLoadCompareBlockMultipleLoads(i, Size, NumBytesProcessed);
} }
@ -2074,7 +2073,7 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
unsigned Index = 0; unsigned Index = 0;
// This loop calls emitLoadCompareBlock for comparing SizeVal bytes of the two // This loop calls emitLoadCompareBlock for comparing SizeVal bytes of the two
// memcmp source. It starts with loading using the maximum load size set by // memcmp sources. It starts with loading using the maximum load size set by
// the target. It processes any remaining bytes using a load size which is the // the target. It processes any remaining bytes using a load size which is the
// next smallest power of 2. // next smallest power of 2.
while (NumBytesToBeProcessed) { while (NumBytesToBeProcessed) {
@ -2084,13 +2083,13 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
NumBytesToBeProcessed = NumBytesToBeProcessed % LoadSize; NumBytesToBeProcessed = NumBytesToBeProcessed % LoadSize;
// For each NumBlocks, populate the instruction sequence for loading and // For each NumBlocks, populate the instruction sequence for loading and
// comparing LoadSize bytes // comparing LoadSize bytes.
while (NumBlocks--) { while (NumBlocks--) {
emitLoadCompareBlock(Index, LoadSize, GEPIndex, IsLittleEndian); emitLoadCompareBlock(Index, LoadSize, GEPIndex, IsLittleEndian);
Index++; Index++;
GEPIndex++; GEPIndex++;
} }
// Get the next LoadSize to use // Get the next LoadSize to use.
LoadSize = LoadSize / 2; LoadSize = LoadSize / 2;
} }
@ -2101,7 +2100,7 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
// This function checks to see if an expansion of memcmp can be generated. // This function checks to see if an expansion of memcmp can be generated.
// It checks for constant compare size that is less than the max inline size. // It checks for constant compare size that is less than the max inline size.
// If an expansion cannot occur, returns false to leave as a library call. // If an expansion cannot occur, returns false to leave as a library call.
// Otherwise, the library call is replaced wtih new IR instruction sequence. // Otherwise, the library call is replaced with a new IR instruction sequence.
/// We want to transform: /// We want to transform:
/// %call = call signext i32 @memcmp(i8* %0, i8* %1, i64 15) /// %call = call signext i32 @memcmp(i8* %0, i8* %1, i64 15)
/// To: /// To:
@ -2176,25 +2175,24 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
NumMemCmpCalls++; NumMemCmpCalls++;
IRBuilder<> Builder(CI->getContext()); IRBuilder<> Builder(CI->getContext());
// TTI call to check if target would like to expand memcmp and get the // TTI call to check if target would like to expand memcmp. Also, get the
// MaxLoadSize // MaxLoadSize.
unsigned MaxLoadSize; unsigned MaxLoadSize;
if (!TTI->expandMemCmp(CI, MaxLoadSize)) if (!TTI->expandMemCmp(CI, MaxLoadSize))
return false; return false;
// Early exit from expansion if -Oz // Early exit from expansion if -Oz.
if (CI->getParent()->getParent()->optForMinSize()) { if (CI->getParent()->getParent()->optForMinSize())
return false; return false;
}
// Early exit from expansion if size is not a constant // Early exit from expansion if size is not a constant.
ConstantInt *SizeCast = dyn_cast<ConstantInt>(CI->getArgOperand(2)); ConstantInt *SizeCast = dyn_cast<ConstantInt>(CI->getArgOperand(2));
if (!SizeCast) { if (!SizeCast) {
NumMemCmpNotConstant++; NumMemCmpNotConstant++;
return false; return false;
} }
// Early exit from expansion if size greater than max bytes to load // Early exit from expansion if size greater than max bytes to load.
uint64_t SizeVal = SizeCast->getZExtValue(); uint64_t SizeVal = SizeCast->getZExtValue();
unsigned NumLoads = 0; unsigned NumLoads = 0;
@ -2214,14 +2212,14 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
NumMemCmpInlined++; NumMemCmpInlined++;
// MemCmpHelper object, creates and sets up basic blocks required for // MemCmpHelper object creates and sets up basic blocks required for
// expanding memcmp with size SizeVal // expanding memcmp with size SizeVal.
unsigned NumLoadsPerBlock = MemCmpNumLoadsPerBlock; unsigned NumLoadsPerBlock = MemCmpNumLoadsPerBlock;
MemCmpExpansion MemCmpHelper(CI, MaxLoadSize, NumLoadsPerBlock); MemCmpExpansion MemCmpHelper(CI, MaxLoadSize, NumLoadsPerBlock);
Value *Res = MemCmpHelper.getMemCmpExpansion(DL->isLittleEndian()); Value *Res = MemCmpHelper.getMemCmpExpansion(DL->isLittleEndian());
// Replace call with result of expansion and erarse call. // Replace call with result of expansion and erase call.
CI->replaceAllUsesWith(Res); CI->replaceAllUsesWith(Res);
CI->eraseFromParent(); CI->eraseFromParent();