Skip to content

Commit 4213bc7

Browse files
committed
[llvm][NFC][CallSite] Removed CallSite from some implementation details.
Reviewers: craig.topper, dblaikie Subscribers: hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78256
1 parent 71303b7 commit 4213bc7

File tree

4 files changed

+49
-47
lines changed

4 files changed

+49
-47
lines changed

llvm/lib/Transforms/Utils/FunctionComparator.cpp

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/IR/Attributes.h"
2222
#include "llvm/IR/BasicBlock.h"
23-
#include "llvm/IR/CallSite.h"
2423
#include "llvm/IR/Constant.h"
2524
#include "llvm/IR/Constants.h"
2625
#include "llvm/IR/DataLayout.h"
@@ -52,22 +51,28 @@ using namespace llvm;
5251
#define DEBUG_TYPE "functioncomparator"
5352

5453
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;
5758
return 0;
5859
}
5960

6061
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;
6366
return 0;
6467
}
6568

6669
int FunctionComparator::cmpAPInts(const APInt &L, const APInt &R) const {
6770
if (int Res = cmpNumbers(L.getBitWidth(), R.getBitWidth()))
6871
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;
7176
return 0;
7277
}
7378

@@ -166,21 +171,21 @@ int FunctionComparator::cmpRangeMetadata(const MDNode *L,
166171
return 0;
167172
}
168173

174+
// FIXME(CallSite): the parameters should be CallBase
169175
int FunctionComparator::cmpOperandBundlesSchema(const Instruction *L,
170176
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);
173179

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!");
176181

177182
if (int Res =
178-
cmpNumbers(LCS.getNumOperandBundles(), RCS.getNumOperandBundles()))
183+
cmpNumbers(LCS->getNumOperandBundles(), RCS->getNumOperandBundles()))
179184
return Res;
180185

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);
184189

185190
if (int Res = OBL.getTagName().compare(OBR.getTagName()))
186191
return Res;
@@ -361,12 +366,12 @@ int FunctionComparator::cmpConstants(const Constant *L,
361366
if (LBA->getFunction() == RBA->getFunction()) {
362367
// They are BBs in the same function. Order by which comes first in the
363368
// BB order of the function. This order is deterministic.
364-
Function* F = LBA->getFunction();
369+
Function *F = LBA->getFunction();
365370
BasicBlock *LBB = LBA->getBasicBlock();
366371
BasicBlock *RBB = RBA->getBasicBlock();
367372
if (LBB == RBB)
368373
return 0;
369-
for(BasicBlock &BB : F->getBasicBlockList()) {
374+
for (BasicBlock &BB : F->getBasicBlockList()) {
370375
if (&BB == LBB) {
371376
assert(&BB != RBB);
372377
return -1;
@@ -561,7 +566,8 @@ int FunctionComparator::cmpOperations(const Instruction *L,
561566
if (int Res = cmpNumbers(LI->getSyncScopeID(),
562567
cast<LoadInst>(R)->getSyncScopeID()))
563568
return Res;
564-
return cmpRangeMetadata(LI->getMetadata(LLVMContext::MD_range),
569+
return cmpRangeMetadata(
570+
LI->getMetadata(LLVMContext::MD_range),
565571
cast<LoadInst>(R)->getMetadata(LLVMContext::MD_range));
566572
}
567573
if (const StoreInst *SI = dyn_cast<StoreInst>(L)) {
@@ -579,11 +585,11 @@ int FunctionComparator::cmpOperations(const Instruction *L,
579585
}
580586
if (const CmpInst *CI = dyn_cast<CmpInst>(L))
581587
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()))
585591
return Res;
586-
if (int Res = cmpAttrs(CSL.getAttributes(), CSR.getAttributes()))
592+
if (int Res = cmpAttrs(CBL->getAttributes(), CBR->getAttributes()))
587593
return Res;
588594
if (int Res = cmpOperandBundlesSchema(L, R))
589595
return Res;
@@ -626,8 +632,8 @@ int FunctionComparator::cmpOperations(const Instruction *L,
626632
if (int Res = cmpNumbers(CXI->isVolatile(),
627633
cast<AtomicCmpXchgInst>(R)->isVolatile()))
628634
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()))
631637
return Res;
632638
if (int Res =
633639
cmpOrderings(CXI->getSuccessOrdering(),
@@ -648,7 +654,7 @@ int FunctionComparator::cmpOperations(const Instruction *L,
648654
cast<AtomicRMWInst>(R)->isVolatile()))
649655
return Res;
650656
if (int Res = cmpOrderings(RMWI->getOrdering(),
651-
cast<AtomicRMWInst>(R)->getOrdering()))
657+
cast<AtomicRMWInst>(R)->getOrdering()))
652658
return Res;
653659
return cmpNumbers(RMWI->getSyncScopeID(),
654660
cast<AtomicRMWInst>(R)->getSyncScopeID());
@@ -685,8 +691,8 @@ int FunctionComparator::cmpGEPs(const GEPOperator *GEPL,
685691
if (GEPL->accumulateConstantOffset(DL, OffsetL) &&
686692
GEPR->accumulateConstantOffset(DL, OffsetR))
687693
return cmpAPInts(OffsetL, OffsetR);
688-
if (int Res = cmpTypes(GEPL->getSourceElementType(),
689-
GEPR->getSourceElementType()))
694+
if (int Res =
695+
cmpTypes(GEPL->getSourceElementType(), GEPR->getSourceElementType()))
690696
return Res;
691697

692698
if (int Res = cmpNumbers(GEPL->getNumOperands(), GEPR->getNumOperands()))
@@ -839,8 +845,8 @@ int FunctionComparator::compareSignature() const {
839845
// Visit the arguments so that they get enumerated in the order they're
840846
// passed in.
841847
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();
844850
ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
845851
if (cmpValues(&*ArgLI, &*ArgRI) != 0)
846852
llvm_unreachable("Arguments repeat!");
@@ -907,9 +913,7 @@ class HashAccumulator64 {
907913
// Initialize to random constant, so the state isn't zero.
908914
HashAccumulator64() { Hash = 0x6acaa36bef8325c5ULL; }
909915

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); }
913917

914918
// No finishing is required, because the entire hash value is used.
915919
uint64_t getHash() { return Hash; }

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6084,9 +6084,9 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I) {
60846084
SI->getPointerOperand() == I;
60856085

60866086
// A call to null is undefined.
6087-
if (auto CS = CallSite(Use))
6088-
return !NullPointerIsDefined(CS->getFunction()) &&
6089-
CS.getCalledValue() == I;
6087+
if (auto *CB = dyn_cast<CallBase>(Use))
6088+
return !NullPointerIsDefined(CB->getFunction()) &&
6089+
CB->getCalledValue() == I;
60906090
}
60916091
return false;
60926092
}

llvm/lib/Transforms/Utils/ValueMapper.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "llvm/ADT/SmallVector.h"
2222
#include "llvm/IR/Argument.h"
2323
#include "llvm/IR/BasicBlock.h"
24-
#include "llvm/IR/CallSite.h"
2524
#include "llvm/IR/Constant.h"
2625
#include "llvm/IR/Constants.h"
2726
#include "llvm/IR/DebugInfoMetadata.h"
@@ -888,17 +887,17 @@ void Mapper::remapInstruction(Instruction *I) {
888887
return;
889888

890889
// If the instruction's type is being remapped, do so now.
891-
if (auto CS = CallSite(I)) {
890+
if (auto *CB = dyn_cast<CallBase>(I)) {
892891
SmallVector<Type *, 3> Tys;
893-
FunctionType *FTy = CS.getFunctionType();
892+
FunctionType *FTy = CB->getFunctionType();
894893
Tys.reserve(FTy->getNumParams());
895894
for (Type *Ty : FTy->params())
896895
Tys.push_back(TypeMapper->remapType(Ty));
897-
CS.mutateFunctionType(FunctionType::get(
896+
CB->mutateFunctionType(FunctionType::get(
898897
TypeMapper->remapType(I->getType()), Tys, FTy->isVarArg()));
899898

900-
LLVMContext &C = CS->getContext();
901-
AttributeList Attrs = CS.getAttributes();
899+
LLVMContext &C = CB->getContext();
900+
AttributeList Attrs = CB->getAttributes();
902901
for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
903902
if (Attrs.hasAttribute(i, Attribute::ByVal)) {
904903
Type *Ty = Attrs.getAttribute(i, Attribute::ByVal).getValueAsType();
@@ -910,7 +909,7 @@ void Mapper::remapInstruction(Instruction *I) {
910909
C, i, Attribute::getWithByValType(C, TypeMapper->remapType(Ty)));
911910
}
912911
}
913-
CS.setAttributes(Attrs);
912+
CB->setAttributes(Attrs);
914913
return;
915914
}
916915
if (auto *AI = dyn_cast<AllocaInst>(I))

llvm/tools/opt/AnalysisWrappers.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//===----------------------------------------------------------------------===//
1818

1919
#include "llvm/Analysis/CallGraph.h"
20-
#include "llvm/IR/CallSite.h"
2120
#include "llvm/IR/Module.h"
2221
#include "llvm/Pass.h"
2322
#include "llvm/Support/raw_ostream.h"
@@ -40,11 +39,11 @@ namespace {
4039
Instruction *UI = dyn_cast<Instruction>(U);
4140
if (!UI) continue;
4241

43-
CallSite CS(cast<Value>(UI));
44-
if (!CS) continue;
42+
CallBase *CB = dyn_cast<CallBase>(UI);
43+
if (!CB)
44+
continue;
4545

46-
for (CallSite::arg_iterator AI = CS.arg_begin(),
47-
E = CS.arg_end(); AI != E; ++AI) {
46+
for (auto AI = CB->arg_begin(), E = CB->arg_end(); AI != E; ++AI) {
4847
if (!isa<Constant>(*AI)) continue;
4948

5049
if (!PrintedFn) {

0 commit comments

Comments
 (0)