Skip to content

Commit 9dfb04d

Browse files
authored
[NFC][WPD] code style fixes (#155454)
1 parent 17a49c4 commit 9dfb04d

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "llvm/IR/DataLayout.h"
6969
#include "llvm/IR/DebugLoc.h"
7070
#include "llvm/IR/DerivedTypes.h"
71+
#include "llvm/IR/DiagnosticInfo.h"
7172
#include "llvm/IR/Dominators.h"
7273
#include "llvm/IR/Function.h"
7374
#include "llvm/IR/GlobalAlias.h"
@@ -82,6 +83,7 @@
8283
#include "llvm/IR/Metadata.h"
8384
#include "llvm/IR/Module.h"
8485
#include "llvm/IR/ModuleSummaryIndexYAML.h"
86+
#include "llvm/IR/PassManager.h"
8587
#include "llvm/Support/Casting.h"
8688
#include "llvm/Support/CommandLine.h"
8789
#include "llvm/Support/Errc.h"
@@ -451,21 +453,21 @@ struct VirtualCallSite {
451453

452454
void
453455
emitRemark(const StringRef OptName, const StringRef TargetName,
454-
function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter) {
456+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter) {
455457
Function *F = CB.getCaller();
456458
DebugLoc DLoc = CB.getDebugLoc();
457459
BasicBlock *Block = CB.getParent();
458460

459461
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));
464466
}
465467

466468
void replaceAndErase(
467469
const StringRef OptName, const StringRef TargetName, bool RemarksEnabled,
468-
function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter,
470+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
469471
Value *New) {
470472
if (RemarksEnabled)
471473
emitRemark(OptName, TargetName, OREGetter);
@@ -573,22 +575,21 @@ struct DevirtModule {
573575
function_ref<AAResults &(Function &)> AARGetter;
574576
function_ref<DominatorTree &(Function &)> LookupDomTree;
575577

576-
ModuleSummaryIndex *ExportSummary;
577-
const ModuleSummaryIndex *ImportSummary;
578+
ModuleSummaryIndex *const ExportSummary;
579+
const ModuleSummaryIndex *const ImportSummary;
578580

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;
584586
/// Sizeless array type, used for imported vtables. This provides a signal
585587
/// to analyzers that these imports may alias, as they do for example
586588
/// 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;
591590

591+
const bool RemarksEnabled;
592+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter;
592593
MapVector<VTableSlot, VTableSlotInfo> CallSlots;
593594

594595
// Calls that have already been optimized. We may add a call to multiple
@@ -612,7 +613,7 @@ struct DevirtModule {
612613
PatternList FunctionsToSkip;
613614

614615
DevirtModule(Module &M, function_ref<AAResults &(Function &)> AARGetter,
615-
function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter,
616+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
616617
function_ref<DominatorTree &(Function &)> LookupDomTree,
617618
ModuleSummaryIndex *ExportSummary,
618619
const ModuleSummaryIndex *ImportSummary)
@@ -740,7 +741,7 @@ struct DevirtModule {
740741
// arguments. For testing purposes only.
741742
static bool
742743
runForTesting(Module &M, function_ref<AAResults &(Function &)> AARGetter,
743-
function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter,
744+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
744745
function_ref<DominatorTree &(Function &)> LookupDomTree);
745746
};
746747

@@ -787,8 +788,8 @@ PreservedAnalyses WholeProgramDevirtPass::run(Module &M,
787788
auto AARGetter = [&](Function &F) -> AAResults & {
788789
return FAM.getResult<AAManager>(F);
789790
};
790-
auto OREGetter = [&](Function *F) -> OptimizationRemarkEmitter & {
791-
return FAM.getResult<OptimizationRemarkEmitterAnalysis>(*F);
791+
auto OREGetter = [&](Function &F) -> OptimizationRemarkEmitter & {
792+
return FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
792793
};
793794
auto LookupDomTree = [&FAM](Function &F) -> DominatorTree & {
794795
return FAM.getResult<DominatorTreeAnalysis>(F);
@@ -832,8 +833,8 @@ typeIDVisibleToRegularObj(StringRef TypeID,
832833
// function for the base type and thus only contains a reference to the
833834
// type info (_ZTI). To catch this case we query using the type info
834835
// 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);
837838
}
838839

839840
static bool
@@ -842,7 +843,7 @@ skipUpdateDueToValidation(GlobalVariable &GV,
842843
SmallVector<MDNode *, 2> Types;
843844
GV.getMetadata(LLVMContext::MD_type, Types);
844845

845-
for (auto Type : Types)
846+
for (auto *Type : Types)
846847
if (auto *TypeID = dyn_cast<MDString>(Type->getOperand(1).get()))
847848
return typeIDVisibleToRegularObj(TypeID->getString(),
848849
IsVisibleToRegularObj);
@@ -912,9 +913,9 @@ void llvm::getVisibleToRegularObjVtableGUIDs(
912913
ModuleSummaryIndex &Index,
913914
DenseSet<GlobalValue::GUID> &VisibleToRegularObjSymbols,
914915
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)
918919
VisibleToRegularObjSymbols.insert(P.VTableVI.getGUID());
919920
}
920921
}
@@ -957,15 +958,15 @@ void llvm::runWholeProgramDevirtOnIndex(
957958

958959
void llvm::updateIndexWPDForExports(
959960
ModuleSummaryIndex &Summary,
960-
function_ref<bool(StringRef, ValueInfo)> isExported,
961+
function_ref<bool(StringRef, ValueInfo)> IsExported,
961962
std::map<ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap) {
962963
for (auto &T : LocalWPDTargetsMap) {
963964
auto &VI = T.first;
964965
// This was enforced earlier during trySingleImplDevirt.
965966
assert(VI.getSummaryList().size() == 1 &&
966967
"Devirt of local target has more than one copy");
967968
auto &S = VI.getSummaryList()[0];
968-
if (!isExported(S->modulePath(), VI))
969+
if (!IsExported(S->modulePath(), VI))
969970
continue;
970971

971972
// It's been exported by a cross module import.
@@ -997,7 +998,7 @@ static Error checkCombinedSummaryForTesting(ModuleSummaryIndex *Summary) {
997998

998999
bool DevirtModule::runForTesting(
9991000
Module &M, function_ref<AAResults &(Function &)> AARGetter,
1000-
function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter,
1001+
function_ref<OptimizationRemarkEmitter &(Function &)> OREGetter,
10011002
function_ref<DominatorTree &(Function &)> LookupDomTree) {
10021003
std::unique_ptr<ModuleSummaryIndex> Summary =
10031004
std::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
@@ -1071,7 +1072,7 @@ void DevirtModule::buildTypeIdentifierMap(
10711072
}
10721073

10731074
for (MDNode *Type : Types) {
1074-
auto TypeID = Type->getOperand(1).get();
1075+
auto *TypeID = Type->getOperand(1).get();
10751076

10761077
uint64_t Offset =
10771078
cast<ConstantInt>(
@@ -1120,7 +1121,7 @@ bool DevirtModule::tryFindVirtualCallTargets(
11201121

11211122
// Save the symbol used in the vtable to use as the devirtualization
11221123
// target.
1123-
auto GV = dyn_cast<GlobalValue>(C);
1124+
auto *GV = dyn_cast<GlobalValue>(C);
11241125
assert(GV);
11251126
TargetsForSlot.push_back({GV, &TM});
11261127
}
@@ -1284,7 +1285,7 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
12841285
Apply(P.second);
12851286
}
12861287

1287-
static bool AddCalls(VTableSlotInfo &SlotInfo, const ValueInfo &Callee) {
1288+
static bool addCalls(VTableSlotInfo &SlotInfo, const ValueInfo &Callee) {
12881289
// We can't add calls if we haven't seen a definition
12891290
if (Callee.getSummaryList().empty())
12901291
return false;
@@ -1359,7 +1360,7 @@ bool DevirtModule::trySingleImplDevirt(
13591360
if (ValueInfo TheFnVI = ExportSummary->getValueInfo(TheFn->getGUID()))
13601361
// Any needed promotion of 'TheFn' has already been done during
13611362
// LTO unit split, so we can ignore return value of AddCalls.
1362-
AddCalls(SlotInfo, TheFnVI);
1363+
addCalls(SlotInfo, TheFnVI);
13631364

13641365
Res->TheKind = WholeProgramDevirtResolution::SingleImpl;
13651366
Res->SingleImplName = std::string(TheFn->getName());
@@ -1400,7 +1401,7 @@ bool DevirtIndex::trySingleImplDevirt(MutableArrayRef<ValueInfo> TargetsForSlot,
14001401
DevirtTargets.insert(TheFn);
14011402

14021403
auto &S = TheFn.getSummaryList()[0];
1403-
bool IsExported = AddCalls(SlotInfo, TheFn);
1404+
bool IsExported = addCalls(SlotInfo, TheFn);
14041405
if (IsExported)
14051406
ExportedGUIDs.insert(TheFn.getGUID());
14061407

@@ -1597,7 +1598,7 @@ bool DevirtModule::tryEvaluateFunctionsWithArgs(
15971598
// TODO: Skip for now if the vtable symbol was an alias to a function,
15981599
// need to evaluate whether it would be correct to analyze the aliasee
15991600
// function for this optimization.
1600-
auto Fn = dyn_cast<Function>(Target.Fn);
1601+
auto *Fn = dyn_cast<Function>(Target.Fn);
16011602
if (!Fn)
16021603
return false;
16031604

@@ -1836,11 +1837,11 @@ bool DevirtModule::tryVirtualConstProp(
18361837
// TODO: Skip for now if the vtable symbol was an alias to a function,
18371838
// need to evaluate whether it would be correct to analyze the aliasee
18381839
// function for this optimization.
1839-
auto Fn = dyn_cast<Function>(TargetsForSlot[0].Fn);
1840+
auto *Fn = dyn_cast<Function>(TargetsForSlot[0].Fn);
18401841
if (!Fn)
18411842
return false;
18421843
// 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());
18441845
if (!RetType)
18451846
return false;
18461847
unsigned BitWidth = RetType->getBitWidth();
@@ -1871,7 +1872,7 @@ bool DevirtModule::tryVirtualConstProp(
18711872
// TODO: Skip for now if the vtable symbol was an alias to a function,
18721873
// need to evaluate whether it would be correct to analyze the aliasee
18731874
// function for this optimization.
1874-
auto Fn = dyn_cast<Function>(Target.Fn);
1875+
auto *Fn = dyn_cast<Function>(Target.Fn);
18751876
if (!Fn)
18761877
return false;
18771878

@@ -1992,11 +1993,11 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
19921993

19931994
// Build an anonymous global containing the before bytes, followed by the
19941995
// original initializer, followed by the after bytes.
1995-
auto NewInit = ConstantStruct::getAnon(
1996+
auto *NewInit = ConstantStruct::getAnon(
19961997
{ConstantDataArray::get(M.getContext(), B.Before.Bytes),
19971998
B.GV->getInitializer(),
19981999
ConstantDataArray::get(M.getContext(), B.After.Bytes)});
1999-
auto NewGV =
2000+
auto *NewGV =
20002001
new GlobalVariable(M, NewInit->getType(), B.GV->isConstant(),
20012002
GlobalVariable::PrivateLinkage, NewInit, "", B.GV);
20022003
NewGV->setSection(B.GV->getSection());
@@ -2009,7 +2010,7 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
20092010

20102011
// Build an alias named after the original global, pointing at the second
20112012
// element (the original initializer).
2012-
auto Alias = GlobalAlias::create(
2013+
auto *Alias = GlobalAlias::create(
20132014
B.GV->getInitializer()->getType(), 0, B.GV->getLinkage(), "",
20142015
ConstantExpr::getInBoundsGetElementPtr(
20152016
NewInit->getType(), NewGV,
@@ -2270,7 +2271,7 @@ void DevirtModule::importResolution(VTableSlot Slot, VTableSlotInfo &SlotInfo) {
22702271
}
22712272

22722273
void DevirtModule::removeRedundantTypeTests() {
2273-
auto True = ConstantInt::getTrue(M.getContext());
2274+
auto *True = ConstantInt::getTrue(M.getContext());
22742275
for (auto &&U : NumUnsafeUsesForTypeTest) {
22752276
if (U.second == 0) {
22762277
U.first->replaceAllUsesWith(True);
@@ -2490,18 +2491,17 @@ bool DevirtModule::run() {
24902491
// Generate remarks for each devirtualized function.
24912492
for (const auto &DT : DevirtTargets) {
24922493
GlobalValue *GV = DT.second;
2493-
auto F = dyn_cast<Function>(GV);
2494+
auto *F = dyn_cast<Function>(GV);
24942495
if (!F) {
2495-
auto A = dyn_cast<GlobalAlias>(GV);
2496+
auto *A = dyn_cast<GlobalAlias>(GV);
24962497
assert(A && isa<Function>(A->getAliasee()));
24972498
F = dyn_cast<Function>(A->getAliasee());
24982499
assert(F);
24992500
}
25002501

25012502
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));
25052505
}
25062506
}
25072507

0 commit comments

Comments
 (0)