@@ -1753,13 +1753,13 @@ void MemCmpExpansion::emitLoadCompareByteBlock(unsigned Index, int GEPIndex) {
1753
1753
1754
1754
Builder.SetInsertPoint (LoadCmpBlocks[Index]);
1755
1755
Type *LoadSizeType = Type::getInt8Ty (CI->getContext ());
1756
- // Cast source to LoadSizeType*
1756
+ // Cast source to LoadSizeType*.
1757
1757
if (Source1->getType () != LoadSizeType)
1758
1758
Source1 = Builder.CreateBitCast (Source1, LoadSizeType->getPointerTo ());
1759
1759
if (Source2->getType () != LoadSizeType)
1760
1760
Source2 = Builder.CreateBitCast (Source2, LoadSizeType->getPointerTo ());
1761
1761
1762
- // Get the base address using the GEPIndex
1762
+ // Get the base address using the GEPIndex.
1763
1763
if (GEPIndex != 0 ) {
1764
1764
Source1 = Builder.CreateGEP (LoadSizeType, Source1,
1765
1765
ConstantInt::get (LoadSizeType, GEPIndex));
@@ -1777,16 +1777,15 @@ void MemCmpExpansion::emitLoadCompareByteBlock(unsigned Index, int GEPIndex) {
1777
1777
PhiRes->addIncoming (Diff, LoadCmpBlocks[Index]);
1778
1778
1779
1779
if (Index < (LoadCmpBlocks.size () - 1 )) {
1780
- // Early exit branch if difference found to EndBlock, otherwise continue to
1781
- // next LoadCmpBlock
1782
-
1780
+ // Early exit branch if difference found to EndBlock. Otherwise, continue to
1781
+ // next LoadCmpBlock,
1783
1782
Value *Cmp = Builder.CreateICmp (ICmpInst::ICMP_NE, Diff,
1784
1783
ConstantInt::get (Diff->getType (), 0 ));
1785
1784
BranchInst *CmpBr =
1786
1785
BranchInst::Create (EndBlock, LoadCmpBlocks[Index + 1 ], Cmp);
1787
1786
Builder.Insert (CmpBr);
1788
1787
} else {
1789
- // The last block has an unconditional branch to EndBlock
1788
+ // The last block has an unconditional branch to EndBlock.
1790
1789
BranchInst *CmpBr = BranchInst::Create (EndBlock);
1791
1790
Builder.Insert (CmpBr);
1792
1791
}
@@ -1826,21 +1825,21 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
1826
1825
Value *Source1 = CI->getArgOperand (0 );
1827
1826
Value *Source2 = CI->getArgOperand (1 );
1828
1827
1829
- // Cast source to LoadSizeType*
1828
+ // Cast source to LoadSizeType*.
1830
1829
if (Source1->getType () != LoadSizeType)
1831
1830
Source1 = Builder.CreateBitCast (Source1, LoadSizeType->getPointerTo ());
1832
1831
if (Source2->getType () != LoadSizeType)
1833
1832
Source2 = Builder.CreateBitCast (Source2, LoadSizeType->getPointerTo ());
1834
1833
1835
- // Get the base address using the GEPIndex
1834
+ // Get the base address using the GEPIndex.
1836
1835
if (GEPIndex != 0 ) {
1837
1836
Source1 = Builder.CreateGEP (LoadSizeType, Source1,
1838
1837
ConstantInt::get (LoadSizeType, GEPIndex));
1839
1838
Source2 = Builder.CreateGEP (LoadSizeType, Source2,
1840
1839
ConstantInt::get (LoadSizeType, GEPIndex));
1841
1840
}
1842
1841
1843
- // Load LoadSizeType from the base address
1842
+ // Load LoadSizeType from the base address.
1844
1843
Value *LoadSrc1 = Builder.CreateLoad (LoadSizeType, Source1);
1845
1844
Value *LoadSrc2 = Builder.CreateLoad (LoadSizeType, Source2);
1846
1845
if (LoadSizeType != MaxLoadType) {
@@ -1863,10 +1862,10 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
1863
1862
return OutList;
1864
1863
};
1865
1864
1866
- // Pair wise OR the XOR results
1865
+ // Pairwise OR the XOR results.
1867
1866
OrList = pairWiseOr (XorList);
1868
1867
1869
- // Pair wise OR the OR results until one result left
1868
+ // Pairwise OR the OR results until one result left.
1870
1869
while (OrList.size () != 1 ) {
1871
1870
OrList = pairWiseOr (OrList);
1872
1871
}
@@ -1876,14 +1875,14 @@ void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
1876
1875
BasicBlock *NextBB = (Index == (LoadCmpBlocks.size () - 1 ))
1877
1876
? EndBlock
1878
1877
: LoadCmpBlocks[Index + 1 ];
1879
- // Early exit branch if difference found to ResultBlock, otherwise continue to
1880
- // next LoadCmpBlock or EndBlock.
1878
+ // Early exit branch if difference found to ResultBlock. Otherwise,
1879
+ // continue to next LoadCmpBlock or EndBlock.
1881
1880
BranchInst *CmpBr = BranchInst::Create (ResBlock.BB , NextBB, Cmp);
1882
1881
Builder.Insert (CmpBr);
1883
1882
1884
1883
// Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0
1885
1884
// since early exit to ResultBlock was not taken (no difference was found in
1886
- // any of the bytes)
1885
+ // any of the bytes).
1887
1886
if (Index == LoadCmpBlocks.size () - 1 ) {
1888
1887
Value *Zero = ConstantInt::get (Type::getInt32Ty (CI->getContext ()), 0 );
1889
1888
PhiRes->addIncoming (Zero, LoadCmpBlocks[Index]);
@@ -1915,21 +1914,21 @@ void MemCmpExpansion::emitLoadCompareBlock(unsigned Index, int LoadSize,
1915
1914
Value *Source2 = CI->getArgOperand (1 );
1916
1915
1917
1916
Builder.SetInsertPoint (LoadCmpBlocks[Index]);
1918
- // Cast source to LoadSizeType*
1917
+ // Cast source to LoadSizeType*.
1919
1918
if (Source1->getType () != LoadSizeType)
1920
1919
Source1 = Builder.CreateBitCast (Source1, LoadSizeType->getPointerTo ());
1921
1920
if (Source2->getType () != LoadSizeType)
1922
1921
Source2 = Builder.CreateBitCast (Source2, LoadSizeType->getPointerTo ());
1923
1922
1924
- // Get the base address using the GEPIndex
1923
+ // Get the base address using the GEPIndex.
1925
1924
if (GEPIndex != 0 ) {
1926
1925
Source1 = Builder.CreateGEP (LoadSizeType, Source1,
1927
1926
ConstantInt::get (LoadSizeType, GEPIndex));
1928
1927
Source2 = Builder.CreateGEP (LoadSizeType, Source2,
1929
1928
ConstantInt::get (LoadSizeType, GEPIndex));
1930
1929
}
1931
1930
1932
- // Load LoadSizeType from the base address
1931
+ // Load LoadSizeType from the base address.
1933
1932
Value *LoadSrc1 = Builder.CreateLoad (LoadSizeType, Source1);
1934
1933
Value *LoadSrc2 = Builder.CreateLoad (LoadSizeType, Source2);
1935
1934
@@ -1961,14 +1960,14 @@ void MemCmpExpansion::emitLoadCompareBlock(unsigned Index, int LoadSize,
1961
1960
BasicBlock *NextBB = (Index == (LoadCmpBlocks.size () - 1 ))
1962
1961
? EndBlock
1963
1962
: LoadCmpBlocks[Index + 1 ];
1964
- // Early exit branch if difference found to ResultBlock, otherwise continue to
1965
- // next LoadCmpBlock or EndBlock.
1963
+ // Early exit branch if difference found to ResultBlock. Otherwise, continue
1964
+ // to next LoadCmpBlock or EndBlock.
1966
1965
BranchInst *CmpBr = BranchInst::Create (ResBlock.BB , NextBB, Cmp);
1967
1966
Builder.Insert (CmpBr);
1968
1967
1969
1968
// Add a phi edge for the last LoadCmpBlock to Endblock with a value of 0
1970
1969
// since early exit to ResultBlock was not taken (no difference was found in
1971
- // any of the bytes)
1970
+ // any of the bytes).
1972
1971
if (Index == LoadCmpBlocks.size () - 1 ) {
1973
1972
Value *Zero = ConstantInt::get (Type::getInt32Ty (CI->getContext ()), 0 );
1974
1973
PhiRes->addIncoming (Zero, LoadCmpBlocks[Index]);
@@ -2048,8 +2047,8 @@ void MemCmpExpansion::setupEndBlockPHINodes() {
2048
2047
Value *MemCmpExpansion::getMemCmpExpansionZeroCase (unsigned Size ,
2049
2048
bool IsLittleEndian) {
2050
2049
unsigned NumBytesProcessed = 0 ;
2051
- // This loop populates each of the LoadCmpBlocks with IR sequence to handle
2052
- // multiple loads per block
2050
+ // This loop populates each of the LoadCmpBlocks with the IR sequence to
2051
+ // handle multiple loads per block.
2053
2052
for (unsigned i = 0 ; i < NumBlocks; ++i) {
2054
2053
emitLoadCompareBlockMultipleLoads (i, Size , NumBytesProcessed);
2055
2054
}
@@ -2074,7 +2073,7 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
2074
2073
2075
2074
unsigned Index = 0 ;
2076
2075
// This loop calls emitLoadCompareBlock for comparing SizeVal bytes of the two
2077
- // memcmp source . It starts with loading using the maximum load size set by
2076
+ // memcmp sources . It starts with loading using the maximum load size set by
2078
2077
// the target. It processes any remaining bytes using a load size which is the
2079
2078
// next smallest power of 2.
2080
2079
while (NumBytesToBeProcessed) {
@@ -2084,13 +2083,13 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
2084
2083
NumBytesToBeProcessed = NumBytesToBeProcessed % LoadSize;
2085
2084
2086
2085
// For each NumBlocks, populate the instruction sequence for loading and
2087
- // comparing LoadSize bytes
2086
+ // comparing LoadSize bytes.
2088
2087
while (NumBlocks--) {
2089
2088
emitLoadCompareBlock (Index, LoadSize, GEPIndex, IsLittleEndian);
2090
2089
Index++;
2091
2090
GEPIndex++;
2092
2091
}
2093
- // Get the next LoadSize to use
2092
+ // Get the next LoadSize to use.
2094
2093
LoadSize = LoadSize / 2 ;
2095
2094
}
2096
2095
@@ -2101,7 +2100,7 @@ Value *MemCmpExpansion::getMemCmpExpansion(bool IsLittleEndian) {
2101
2100
// This function checks to see if an expansion of memcmp can be generated.
2102
2101
// It checks for constant compare size that is less than the max inline size.
2103
2102
// If an expansion cannot occur, returns false to leave as a library call.
2104
- // Otherwise, the library call is replaced wtih new IR instruction sequence.
2103
+ // Otherwise, the library call is replaced with a new IR instruction sequence.
2105
2104
// / We want to transform:
2106
2105
// / %call = call signext i32 @memcmp(i8* %0, i8* %1, i64 15)
2107
2106
// / To:
@@ -2176,25 +2175,24 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
2176
2175
NumMemCmpCalls++;
2177
2176
IRBuilder<> Builder (CI->getContext ());
2178
2177
2179
- // TTI call to check if target would like to expand memcmp and get the
2180
- // MaxLoadSize
2178
+ // TTI call to check if target would like to expand memcmp. Also, get the
2179
+ // MaxLoadSize.
2181
2180
unsigned MaxLoadSize;
2182
2181
if (!TTI->expandMemCmp (CI, MaxLoadSize))
2183
2182
return false ;
2184
2183
2185
- // Early exit from expansion if -Oz
2186
- if (CI->getParent ()->getParent ()->optForMinSize ()) {
2184
+ // Early exit from expansion if -Oz.
2185
+ if (CI->getParent ()->getParent ()->optForMinSize ())
2187
2186
return false ;
2188
- }
2189
2187
2190
- // Early exit from expansion if size is not a constant
2188
+ // Early exit from expansion if size is not a constant.
2191
2189
ConstantInt *SizeCast = dyn_cast<ConstantInt>(CI->getArgOperand (2 ));
2192
2190
if (!SizeCast) {
2193
2191
NumMemCmpNotConstant++;
2194
2192
return false ;
2195
2193
}
2196
2194
2197
- // Early exit from expansion if size greater than max bytes to load
2195
+ // Early exit from expansion if size greater than max bytes to load.
2198
2196
uint64_t SizeVal = SizeCast->getZExtValue ();
2199
2197
2200
2198
unsigned NumLoads = 0 ;
@@ -2214,14 +2212,14 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
2214
2212
2215
2213
NumMemCmpInlined++;
2216
2214
2217
- // MemCmpHelper object, creates and sets up basic blocks required for
2218
- // expanding memcmp with size SizeVal
2215
+ // MemCmpHelper object creates and sets up basic blocks required for
2216
+ // expanding memcmp with size SizeVal.
2219
2217
unsigned NumLoadsPerBlock = MemCmpNumLoadsPerBlock;
2220
2218
MemCmpExpansion MemCmpHelper (CI, MaxLoadSize, NumLoadsPerBlock);
2221
2219
2222
2220
Value *Res = MemCmpHelper.getMemCmpExpansion (DL->isLittleEndian ());
2223
2221
2224
- // Replace call with result of expansion and erarse call.
2222
+ // Replace call with result of expansion and erase call.
2225
2223
CI->replaceAllUsesWith (Res);
2226
2224
CI->eraseFromParent ();
2227
2225
0 commit comments