68
68
#include " llvm/IR/DataLayout.h"
69
69
#include " llvm/IR/DebugLoc.h"
70
70
#include " llvm/IR/DerivedTypes.h"
71
+ #include " llvm/IR/DiagnosticInfo.h"
71
72
#include " llvm/IR/Dominators.h"
72
73
#include " llvm/IR/Function.h"
73
74
#include " llvm/IR/GlobalAlias.h"
82
83
#include " llvm/IR/Metadata.h"
83
84
#include " llvm/IR/Module.h"
84
85
#include " llvm/IR/ModuleSummaryIndexYAML.h"
86
+ #include " llvm/IR/PassManager.h"
85
87
#include " llvm/Support/Casting.h"
86
88
#include " llvm/Support/CommandLine.h"
87
89
#include " llvm/Support/Errc.h"
@@ -451,21 +453,21 @@ struct VirtualCallSite {
451
453
452
454
void
453
455
emitRemark (const StringRef OptName, const StringRef TargetName,
454
- function_ref<OptimizationRemarkEmitter &(Function * )> OREGetter) {
456
+ function_ref<OptimizationRemarkEmitter &(Function & )> OREGetter) {
455
457
Function *F = CB.getCaller ();
456
458
DebugLoc DLoc = CB.getDebugLoc ();
457
459
BasicBlock *Block = CB.getParent ();
458
460
459
461
using namespace ore ;
460
- OREGetter (F).emit (OptimizationRemark (DEBUG_TYPE, OptName, DLoc, Block)
461
- << NV (" Optimization" , OptName)
462
- << " : devirtualized a call to "
463
- << NV (" FunctionName" , TargetName));
462
+ OREGetter (* F).emit (OptimizationRemark (DEBUG_TYPE, OptName, DLoc, Block)
463
+ << NV (" Optimization" , OptName)
464
+ << " : devirtualized a call to "
465
+ << NV (" FunctionName" , TargetName));
464
466
}
465
467
466
468
void replaceAndErase (
467
469
const StringRef OptName, const StringRef TargetName, bool RemarksEnabled,
468
- function_ref<OptimizationRemarkEmitter &(Function * )> OREGetter,
470
+ function_ref<OptimizationRemarkEmitter &(Function & )> OREGetter,
469
471
Value *New) {
470
472
if (RemarksEnabled)
471
473
emitRemark (OptName, TargetName, OREGetter);
@@ -573,22 +575,21 @@ struct DevirtModule {
573
575
function_ref<AAResults &(Function &)> AARGetter;
574
576
function_ref<DominatorTree &(Function &)> LookupDomTree;
575
577
576
- ModuleSummaryIndex *ExportSummary;
577
- const ModuleSummaryIndex *ImportSummary;
578
+ ModuleSummaryIndex *const ExportSummary;
579
+ const ModuleSummaryIndex *const ImportSummary;
578
580
579
- IntegerType *Int8Ty;
580
- PointerType *Int8PtrTy;
581
- IntegerType *Int32Ty;
582
- IntegerType *Int64Ty;
583
- IntegerType *IntPtrTy;
581
+ IntegerType *const Int8Ty;
582
+ PointerType *const Int8PtrTy;
583
+ IntegerType *const Int32Ty;
584
+ IntegerType *const Int64Ty;
585
+ IntegerType *const IntPtrTy;
584
586
// / Sizeless array type, used for imported vtables. This provides a signal
585
587
// / to analyzers that these imports may alias, as they do for example
586
588
// / when multiple unique return values occur in the same vtable.
587
- ArrayType *Int8Arr0Ty;
588
-
589
- bool RemarksEnabled;
590
- function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter;
589
+ ArrayType *const Int8Arr0Ty;
591
590
591
+ const bool RemarksEnabled;
592
+ function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter;
592
593
MapVector<VTableSlot, VTableSlotInfo> CallSlots;
593
594
594
595
// Calls that have already been optimized. We may add a call to multiple
@@ -612,7 +613,7 @@ struct DevirtModule {
612
613
PatternList FunctionsToSkip;
613
614
614
615
DevirtModule (Module &M, function_ref<AAResults &(Function &)> AARGetter,
615
- function_ref<OptimizationRemarkEmitter &(Function * )> OREGetter,
616
+ function_ref<OptimizationRemarkEmitter &(Function & )> OREGetter,
616
617
function_ref<DominatorTree &(Function &)> LookupDomTree,
617
618
ModuleSummaryIndex *ExportSummary,
618
619
const ModuleSummaryIndex *ImportSummary)
@@ -740,7 +741,7 @@ struct DevirtModule {
740
741
// arguments. For testing purposes only.
741
742
static bool
742
743
runForTesting (Module &M, function_ref<AAResults &(Function &)> AARGetter,
743
- function_ref<OptimizationRemarkEmitter &(Function * )> OREGetter,
744
+ function_ref<OptimizationRemarkEmitter &(Function & )> OREGetter,
744
745
function_ref<DominatorTree &(Function &)> LookupDomTree);
745
746
};
746
747
@@ -787,8 +788,8 @@ PreservedAnalyses WholeProgramDevirtPass::run(Module &M,
787
788
auto AARGetter = [&](Function &F) -> AAResults & {
788
789
return FAM.getResult <AAManager>(F);
789
790
};
790
- auto OREGetter = [&](Function * F) -> OptimizationRemarkEmitter & {
791
- return FAM.getResult <OptimizationRemarkEmitterAnalysis>(* F);
791
+ auto OREGetter = [&](Function & F) -> OptimizationRemarkEmitter & {
792
+ return FAM.getResult <OptimizationRemarkEmitterAnalysis>(F);
792
793
};
793
794
auto LookupDomTree = [&FAM](Function &F) -> DominatorTree & {
794
795
return FAM.getResult <DominatorTreeAnalysis>(F);
@@ -832,8 +833,8 @@ typeIDVisibleToRegularObj(StringRef TypeID,
832
833
// function for the base type and thus only contains a reference to the
833
834
// type info (_ZTI). To catch this case we query using the type info
834
835
// symbol corresponding to the TypeID.
835
- std::string typeInfo = (" _ZTI" + TypeID).str ();
836
- return IsVisibleToRegularObj (typeInfo );
836
+ std::string TypeInfo = (" _ZTI" + TypeID).str ();
837
+ return IsVisibleToRegularObj (TypeInfo );
837
838
}
838
839
839
840
static bool
@@ -842,7 +843,7 @@ skipUpdateDueToValidation(GlobalVariable &GV,
842
843
SmallVector<MDNode *, 2 > Types;
843
844
GV.getMetadata (LLVMContext::MD_type, Types);
844
845
845
- for (auto Type : Types)
846
+ for (auto * Type : Types)
846
847
if (auto *TypeID = dyn_cast<MDString>(Type->getOperand (1 ).get ()))
847
848
return typeIDVisibleToRegularObj (TypeID->getString (),
848
849
IsVisibleToRegularObj);
@@ -912,9 +913,9 @@ void llvm::getVisibleToRegularObjVtableGUIDs(
912
913
ModuleSummaryIndex &Index,
913
914
DenseSet<GlobalValue::GUID> &VisibleToRegularObjSymbols,
914
915
function_ref<bool (StringRef)> IsVisibleToRegularObj) {
915
- for (const auto &typeID : Index.typeIdCompatibleVtableMap ()) {
916
- if (typeIDVisibleToRegularObj (typeID .first , IsVisibleToRegularObj))
917
- for (const TypeIdOffsetVtableInfo &P : typeID .second )
916
+ for (const auto &TypeID : Index.typeIdCompatibleVtableMap ()) {
917
+ if (typeIDVisibleToRegularObj (TypeID .first , IsVisibleToRegularObj))
918
+ for (const TypeIdOffsetVtableInfo &P : TypeID .second )
918
919
VisibleToRegularObjSymbols.insert (P.VTableVI .getGUID ());
919
920
}
920
921
}
@@ -957,15 +958,15 @@ void llvm::runWholeProgramDevirtOnIndex(
957
958
958
959
void llvm::updateIndexWPDForExports (
959
960
ModuleSummaryIndex &Summary,
960
- function_ref<bool (StringRef, ValueInfo)> isExported ,
961
+ function_ref<bool (StringRef, ValueInfo)> IsExported ,
961
962
std::map<ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap) {
962
963
for (auto &T : LocalWPDTargetsMap) {
963
964
auto &VI = T.first ;
964
965
// This was enforced earlier during trySingleImplDevirt.
965
966
assert (VI.getSummaryList ().size () == 1 &&
966
967
" Devirt of local target has more than one copy" );
967
968
auto &S = VI.getSummaryList ()[0 ];
968
- if (!isExported (S->modulePath (), VI))
969
+ if (!IsExported (S->modulePath (), VI))
969
970
continue ;
970
971
971
972
// It's been exported by a cross module import.
@@ -997,7 +998,7 @@ static Error checkCombinedSummaryForTesting(ModuleSummaryIndex *Summary) {
997
998
998
999
bool DevirtModule::runForTesting (
999
1000
Module &M, function_ref<AAResults &(Function &)> AARGetter,
1000
- function_ref<OptimizationRemarkEmitter &(Function * )> OREGetter,
1001
+ function_ref<OptimizationRemarkEmitter &(Function & )> OREGetter,
1001
1002
function_ref<DominatorTree &(Function &)> LookupDomTree) {
1002
1003
std::unique_ptr<ModuleSummaryIndex> Summary =
1003
1004
std::make_unique<ModuleSummaryIndex>(/* HaveGVs=*/ false );
@@ -1071,7 +1072,7 @@ void DevirtModule::buildTypeIdentifierMap(
1071
1072
}
1072
1073
1073
1074
for (MDNode *Type : Types) {
1074
- auto TypeID = Type->getOperand (1 ).get ();
1075
+ auto * TypeID = Type->getOperand (1 ).get ();
1075
1076
1076
1077
uint64_t Offset =
1077
1078
cast<ConstantInt>(
@@ -1120,7 +1121,7 @@ bool DevirtModule::tryFindVirtualCallTargets(
1120
1121
1121
1122
// Save the symbol used in the vtable to use as the devirtualization
1122
1123
// target.
1123
- auto GV = dyn_cast<GlobalValue>(C);
1124
+ auto * GV = dyn_cast<GlobalValue>(C);
1124
1125
assert (GV);
1125
1126
TargetsForSlot.push_back ({GV, &TM});
1126
1127
}
@@ -1284,7 +1285,7 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
1284
1285
Apply (P.second );
1285
1286
}
1286
1287
1287
- static bool AddCalls (VTableSlotInfo &SlotInfo, const ValueInfo &Callee) {
1288
+ static bool addCalls (VTableSlotInfo &SlotInfo, const ValueInfo &Callee) {
1288
1289
// We can't add calls if we haven't seen a definition
1289
1290
if (Callee.getSummaryList ().empty ())
1290
1291
return false ;
@@ -1359,7 +1360,7 @@ bool DevirtModule::trySingleImplDevirt(
1359
1360
if (ValueInfo TheFnVI = ExportSummary->getValueInfo (TheFn->getGUID ()))
1360
1361
// Any needed promotion of 'TheFn' has already been done during
1361
1362
// LTO unit split, so we can ignore return value of AddCalls.
1362
- AddCalls (SlotInfo, TheFnVI);
1363
+ addCalls (SlotInfo, TheFnVI);
1363
1364
1364
1365
Res->TheKind = WholeProgramDevirtResolution::SingleImpl;
1365
1366
Res->SingleImplName = std::string (TheFn->getName ());
@@ -1400,7 +1401,7 @@ bool DevirtIndex::trySingleImplDevirt(MutableArrayRef<ValueInfo> TargetsForSlot,
1400
1401
DevirtTargets.insert (TheFn);
1401
1402
1402
1403
auto &S = TheFn.getSummaryList ()[0 ];
1403
- bool IsExported = AddCalls (SlotInfo, TheFn);
1404
+ bool IsExported = addCalls (SlotInfo, TheFn);
1404
1405
if (IsExported)
1405
1406
ExportedGUIDs.insert (TheFn.getGUID ());
1406
1407
@@ -1597,7 +1598,7 @@ bool DevirtModule::tryEvaluateFunctionsWithArgs(
1597
1598
// TODO: Skip for now if the vtable symbol was an alias to a function,
1598
1599
// need to evaluate whether it would be correct to analyze the aliasee
1599
1600
// function for this optimization.
1600
- auto Fn = dyn_cast<Function>(Target.Fn );
1601
+ auto * Fn = dyn_cast<Function>(Target.Fn );
1601
1602
if (!Fn)
1602
1603
return false ;
1603
1604
@@ -1836,11 +1837,11 @@ bool DevirtModule::tryVirtualConstProp(
1836
1837
// TODO: Skip for now if the vtable symbol was an alias to a function,
1837
1838
// need to evaluate whether it would be correct to analyze the aliasee
1838
1839
// function for this optimization.
1839
- auto Fn = dyn_cast<Function>(TargetsForSlot[0 ].Fn );
1840
+ auto * Fn = dyn_cast<Function>(TargetsForSlot[0 ].Fn );
1840
1841
if (!Fn)
1841
1842
return false ;
1842
1843
// This only works if the function returns an integer.
1843
- auto RetType = dyn_cast<IntegerType>(Fn->getReturnType ());
1844
+ auto * RetType = dyn_cast<IntegerType>(Fn->getReturnType ());
1844
1845
if (!RetType)
1845
1846
return false ;
1846
1847
unsigned BitWidth = RetType->getBitWidth ();
@@ -1871,7 +1872,7 @@ bool DevirtModule::tryVirtualConstProp(
1871
1872
// TODO: Skip for now if the vtable symbol was an alias to a function,
1872
1873
// need to evaluate whether it would be correct to analyze the aliasee
1873
1874
// function for this optimization.
1874
- auto Fn = dyn_cast<Function>(Target.Fn );
1875
+ auto * Fn = dyn_cast<Function>(Target.Fn );
1875
1876
if (!Fn)
1876
1877
return false ;
1877
1878
@@ -1992,11 +1993,11 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
1992
1993
1993
1994
// Build an anonymous global containing the before bytes, followed by the
1994
1995
// original initializer, followed by the after bytes.
1995
- auto NewInit = ConstantStruct::getAnon (
1996
+ auto * NewInit = ConstantStruct::getAnon (
1996
1997
{ConstantDataArray::get (M.getContext (), B.Before .Bytes ),
1997
1998
B.GV ->getInitializer (),
1998
1999
ConstantDataArray::get (M.getContext (), B.After .Bytes )});
1999
- auto NewGV =
2000
+ auto * NewGV =
2000
2001
new GlobalVariable (M, NewInit->getType (), B.GV ->isConstant (),
2001
2002
GlobalVariable::PrivateLinkage, NewInit, " " , B.GV );
2002
2003
NewGV->setSection (B.GV ->getSection ());
@@ -2009,7 +2010,7 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
2009
2010
2010
2011
// Build an alias named after the original global, pointing at the second
2011
2012
// element (the original initializer).
2012
- auto Alias = GlobalAlias::create (
2013
+ auto * Alias = GlobalAlias::create (
2013
2014
B.GV ->getInitializer ()->getType (), 0 , B.GV ->getLinkage (), " " ,
2014
2015
ConstantExpr::getInBoundsGetElementPtr (
2015
2016
NewInit->getType (), NewGV,
@@ -2270,7 +2271,7 @@ void DevirtModule::importResolution(VTableSlot Slot, VTableSlotInfo &SlotInfo) {
2270
2271
}
2271
2272
2272
2273
void DevirtModule::removeRedundantTypeTests () {
2273
- auto True = ConstantInt::getTrue (M.getContext ());
2274
+ auto * True = ConstantInt::getTrue (M.getContext ());
2274
2275
for (auto &&U : NumUnsafeUsesForTypeTest) {
2275
2276
if (U.second == 0 ) {
2276
2277
U.first ->replaceAllUsesWith (True);
@@ -2490,18 +2491,17 @@ bool DevirtModule::run() {
2490
2491
// Generate remarks for each devirtualized function.
2491
2492
for (const auto &DT : DevirtTargets) {
2492
2493
GlobalValue *GV = DT.second ;
2493
- auto F = dyn_cast<Function>(GV);
2494
+ auto * F = dyn_cast<Function>(GV);
2494
2495
if (!F) {
2495
- auto A = dyn_cast<GlobalAlias>(GV);
2496
+ auto * A = dyn_cast<GlobalAlias>(GV);
2496
2497
assert (A && isa<Function>(A->getAliasee ()));
2497
2498
F = dyn_cast<Function>(A->getAliasee ());
2498
2499
assert (F);
2499
2500
}
2500
2501
2501
2502
using namespace ore ;
2502
- OREGetter (F).emit (OptimizationRemark (DEBUG_TYPE, " Devirtualized" , F)
2503
- << " devirtualized "
2504
- << NV (" FunctionName" , DT.first ));
2503
+ OREGetter (*F).emit (OptimizationRemark (DEBUG_TYPE, " Devirtualized" , F)
2504
+ << " devirtualized " << NV (" FunctionName" , DT.first ));
2505
2505
}
2506
2506
}
2507
2507
0 commit comments