20
20
#include " llvm/ADT/SmallVector.h"
21
21
#include " llvm/IR/Attributes.h"
22
22
#include " llvm/IR/BasicBlock.h"
23
- #include " llvm/IR/CallSite.h"
24
23
#include " llvm/IR/Constant.h"
25
24
#include " llvm/IR/Constants.h"
26
25
#include " llvm/IR/DataLayout.h"
@@ -52,22 +51,28 @@ using namespace llvm;
52
51
#define DEBUG_TYPE " functioncomparator"
53
52
54
53
int FunctionComparator::cmpNumbers (uint64_t L, uint64_t R) const {
55
- if (L < R) return -1 ;
56
- if (L > R) return 1 ;
54
+ if (L < R)
55
+ return -1 ;
56
+ if (L > R)
57
+ return 1 ;
57
58
return 0 ;
58
59
}
59
60
60
61
int FunctionComparator::cmpOrderings (AtomicOrdering L, AtomicOrdering R) const {
61
- if ((int )L < (int )R) return -1 ;
62
- if ((int )L > (int )R) return 1 ;
62
+ if ((int )L < (int )R)
63
+ return -1 ;
64
+ if ((int )L > (int )R)
65
+ return 1 ;
63
66
return 0 ;
64
67
}
65
68
66
69
int FunctionComparator::cmpAPInts (const APInt &L, const APInt &R) const {
67
70
if (int Res = cmpNumbers (L.getBitWidth (), R.getBitWidth ()))
68
71
return Res;
69
- if (L.ugt (R)) return 1 ;
70
- if (R.ugt (L)) return -1 ;
72
+ if (L.ugt (R))
73
+ return 1 ;
74
+ if (R.ugt (L))
75
+ return -1 ;
71
76
return 0 ;
72
77
}
73
78
@@ -166,21 +171,21 @@ int FunctionComparator::cmpRangeMetadata(const MDNode *L,
166
171
return 0 ;
167
172
}
168
173
174
+ // FIXME(CallSite): the parameters should be CallBase
169
175
int FunctionComparator::cmpOperandBundlesSchema (const Instruction *L,
170
176
const Instruction *R) const {
171
- ImmutableCallSite LCS (L);
172
- ImmutableCallSite RCS (R);
177
+ const CallBase * LCS = cast<CallBase> (L);
178
+ const CallBase * RCS = cast<CallBase> (R);
173
179
174
- assert (LCS && RCS && " Must be calls or invokes!" );
175
- assert (LCS.isCall () == RCS.isCall () && " Can't compare otherwise!" );
180
+ assert (LCS->getOpcode () == RCS->getOpcode () && " Can't compare otherwise!" );
176
181
177
182
if (int Res =
178
- cmpNumbers (LCS. getNumOperandBundles (), RCS. getNumOperandBundles ()))
183
+ cmpNumbers (LCS-> getNumOperandBundles (), RCS-> getNumOperandBundles ()))
179
184
return Res;
180
185
181
- for (unsigned i = 0 , e = LCS. getNumOperandBundles (); i != e; ++i) {
182
- auto OBL = LCS. getOperandBundleAt (i);
183
- auto OBR = RCS. getOperandBundleAt (i);
186
+ for (unsigned i = 0 , e = LCS-> getNumOperandBundles (); i != e; ++i) {
187
+ auto OBL = LCS-> getOperandBundleAt (i);
188
+ auto OBR = RCS-> getOperandBundleAt (i);
184
189
185
190
if (int Res = OBL.getTagName ().compare (OBR.getTagName ()))
186
191
return Res;
@@ -361,12 +366,12 @@ int FunctionComparator::cmpConstants(const Constant *L,
361
366
if (LBA->getFunction () == RBA->getFunction ()) {
362
367
// They are BBs in the same function. Order by which comes first in the
363
368
// BB order of the function. This order is deterministic.
364
- Function* F = LBA->getFunction ();
369
+ Function * F = LBA->getFunction ();
365
370
BasicBlock *LBB = LBA->getBasicBlock ();
366
371
BasicBlock *RBB = RBA->getBasicBlock ();
367
372
if (LBB == RBB)
368
373
return 0 ;
369
- for (BasicBlock &BB : F->getBasicBlockList ()) {
374
+ for (BasicBlock &BB : F->getBasicBlockList ()) {
370
375
if (&BB == LBB) {
371
376
assert (&BB != RBB);
372
377
return -1 ;
@@ -561,7 +566,8 @@ int FunctionComparator::cmpOperations(const Instruction *L,
561
566
if (int Res = cmpNumbers (LI->getSyncScopeID (),
562
567
cast<LoadInst>(R)->getSyncScopeID ()))
563
568
return Res;
564
- return cmpRangeMetadata (LI->getMetadata (LLVMContext::MD_range),
569
+ return cmpRangeMetadata (
570
+ LI->getMetadata (LLVMContext::MD_range),
565
571
cast<LoadInst>(R)->getMetadata (LLVMContext::MD_range));
566
572
}
567
573
if (const StoreInst *SI = dyn_cast<StoreInst>(L)) {
@@ -579,11 +585,11 @@ int FunctionComparator::cmpOperations(const Instruction *L,
579
585
}
580
586
if (const CmpInst *CI = dyn_cast<CmpInst>(L))
581
587
return cmpNumbers (CI->getPredicate (), cast<CmpInst>(R)->getPredicate ());
582
- if (auto CSL = CallSite ( const_cast <Instruction * >(L) )) {
583
- auto CSR = CallSite ( const_cast <Instruction * >(R) );
584
- if (int Res = cmpNumbers (CSL. getCallingConv (), CSR. getCallingConv ()))
588
+ if (auto *CBL = dyn_cast<CallBase >(L)) {
589
+ auto *CBR = cast<CallBase >(R);
590
+ if (int Res = cmpNumbers (CBL-> getCallingConv (), CBR-> getCallingConv ()))
585
591
return Res;
586
- if (int Res = cmpAttrs (CSL. getAttributes (), CSR. getAttributes ()))
592
+ if (int Res = cmpAttrs (CBL-> getAttributes (), CBR-> getAttributes ()))
587
593
return Res;
588
594
if (int Res = cmpOperandBundlesSchema (L, R))
589
595
return Res;
@@ -626,8 +632,8 @@ int FunctionComparator::cmpOperations(const Instruction *L,
626
632
if (int Res = cmpNumbers (CXI->isVolatile (),
627
633
cast<AtomicCmpXchgInst>(R)->isVolatile ()))
628
634
return Res;
629
- if (int Res = cmpNumbers (CXI-> isWeak (),
630
- cast<AtomicCmpXchgInst>(R)->isWeak ()))
635
+ if (int Res =
636
+ cmpNumbers (CXI-> isWeak (), cast<AtomicCmpXchgInst>(R)->isWeak ()))
631
637
return Res;
632
638
if (int Res =
633
639
cmpOrderings (CXI->getSuccessOrdering (),
@@ -648,7 +654,7 @@ int FunctionComparator::cmpOperations(const Instruction *L,
648
654
cast<AtomicRMWInst>(R)->isVolatile ()))
649
655
return Res;
650
656
if (int Res = cmpOrderings (RMWI->getOrdering (),
651
- cast<AtomicRMWInst>(R)->getOrdering ()))
657
+ cast<AtomicRMWInst>(R)->getOrdering ()))
652
658
return Res;
653
659
return cmpNumbers (RMWI->getSyncScopeID (),
654
660
cast<AtomicRMWInst>(R)->getSyncScopeID ());
@@ -685,8 +691,8 @@ int FunctionComparator::cmpGEPs(const GEPOperator *GEPL,
685
691
if (GEPL->accumulateConstantOffset (DL, OffsetL) &&
686
692
GEPR->accumulateConstantOffset (DL, OffsetR))
687
693
return cmpAPInts (OffsetL, OffsetR);
688
- if (int Res = cmpTypes (GEPL-> getSourceElementType (),
689
- GEPR->getSourceElementType ()))
694
+ if (int Res =
695
+ cmpTypes (GEPL-> getSourceElementType (), GEPR->getSourceElementType ()))
690
696
return Res;
691
697
692
698
if (int Res = cmpNumbers (GEPL->getNumOperands (), GEPR->getNumOperands ()))
@@ -839,8 +845,8 @@ int FunctionComparator::compareSignature() const {
839
845
// Visit the arguments so that they get enumerated in the order they're
840
846
// passed in.
841
847
for (Function::const_arg_iterator ArgLI = FnL->arg_begin (),
842
- ArgRI = FnR->arg_begin (),
843
- ArgLE = FnL->arg_end ();
848
+ ArgRI = FnR->arg_begin (),
849
+ ArgLE = FnL->arg_end ();
844
850
ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
845
851
if (cmpValues (&*ArgLI, &*ArgRI) != 0 )
846
852
llvm_unreachable (" Arguments repeat!" );
@@ -907,9 +913,7 @@ class HashAccumulator64 {
907
913
// Initialize to random constant, so the state isn't zero.
908
914
HashAccumulator64 () { Hash = 0x6acaa36bef8325c5ULL ; }
909
915
910
- void add (uint64_t V) {
911
- Hash = hashing::detail::hash_16_bytes (Hash, V);
912
- }
916
+ void add (uint64_t V) { Hash = hashing::detail::hash_16_bytes (Hash, V); }
913
917
914
918
// No finishing is required, because the entire hash value is used.
915
919
uint64_t getHash () { return Hash; }
0 commit comments