Skip to content

Commit a650d55

Browse files
committed
[Attributor][NFC] Refactorings and typos in doc
Reviewed By: sstefan1, uenoku Differential Revision: https://reviews.llvm.org/D76175
1 parent 67d67eb commit a650d55

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// automatically capture a potential dependence from Q to P. This dependence
3030
// will cause P to be reevaluated whenever Q changes in the future.
3131
//
32-
// The Attributor will only reevaluated abstract attributes that might have
32+
// The Attributor will only reevaluate abstract attributes that might have
3333
// changed since the last iteration. That means that the Attribute will not
3434
// revisit all instructions/blocks/functions in the module but only query
3535
// an update from a subset of the abstract attributes.
@@ -152,8 +152,8 @@ struct IRPosition {
152152

153153
/// The positions we distinguish in the IR.
154154
///
155-
/// The values are chosen such that the KindOrArgNo member has a value >= 1
156-
/// if it is an argument or call site argument while a value < 1 indicates the
155+
/// The values are chosen such that the KindOrArgNo member has a value >= 0
156+
/// if it is an argument or call site argument while a value < 0 indicates the
157157
/// respective kind of that value.
158158
enum Kind : int {
159159
IRP_INVALID = -6, ///< An invalid position.
@@ -273,18 +273,11 @@ struct IRPosition {
273273

274274
/// Return the associated function, if any.
275275
Function *getAssociatedFunction() const {
276-
if (auto *CB = dyn_cast<CallBase>(AnchorVal))
277-
return CB->getCalledFunction();
278276
assert(KindOrArgNo != IRP_INVALID &&
279277
"Invalid position does not have an anchor scope!");
280-
Value &V = getAnchorValue();
281-
if (isa<Function>(V))
282-
return &cast<Function>(V);
283-
if (isa<Argument>(V))
284-
return cast<Argument>(V).getParent();
285-
if (isa<Instruction>(V))
286-
return cast<Instruction>(V).getFunction();
287-
return nullptr;
278+
if (auto *CB = dyn_cast<CallBase>(AnchorVal))
279+
return CB->getCalledFunction();
280+
return getAnchorScope();
288281
}
289282

290283
/// Return the associated argument, if any.
@@ -474,7 +467,10 @@ struct IRPosition {
474467
/// The value this position is anchored at.
475468
Value *AnchorVal;
476469

477-
/// The argument number, if non-negative, or the position "kind".
470+
/// If AnchorVal is Argument or CallBase then this number should be
471+
/// non-negative and it denotes the argument or call site argument index
472+
/// respectively. Otherwise, it denotes the kind of this IRPosition according
473+
/// to Kind above.
478474
int KindOrArgNo;
479475
};
480476

@@ -2288,7 +2284,8 @@ struct DerefState : AbstractState {
22882284

22892285
/// Add accessed bytes to the map.
22902286
void addAccessedBytes(int64_t Offset, uint64_t Size) {
2291-
AccessedBytesMap[Offset] = std::max(AccessedBytesMap[Offset], Size);
2287+
uint64_t &AccessedBytes = AccessedBytesMap[Offset];
2288+
AccessedBytes = std::max(AccessedBytes, Size);
22922289

22932290
// Known bytes might increase.
22942291
computeKnownDerefBytesFromAccessedMap();

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ ChangeStatus AbstractAttribute::update(Attributor &A) {
558558
ChangeStatus
559559
IRAttributeManifest::manifestAttrs(Attributor &A, const IRPosition &IRP,
560560
const ArrayRef<Attribute> &DeducedAttrs) {
561-
Function *ScopeFn = IRP.getAssociatedFunction();
561+
Function *ScopeFn = IRP.getAnchorScope();
562562
IRPosition::Kind PK = IRP.getPositionKind();
563563

564564
// In the following some generic code that will manifest attributes in
@@ -627,8 +627,7 @@ SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) {
627627
return;
628628
case IRPosition::IRP_ARGUMENT:
629629
case IRPosition::IRP_RETURNED:
630-
IRPositions.emplace_back(
631-
IRPosition::function(*IRP.getAssociatedFunction()));
630+
IRPositions.emplace_back(IRPosition::function(*IRP.getAnchorScope()));
632631
return;
633632
case IRPosition::IRP_CALL_SITE:
634633
assert(ICS && "Expected call site!");
@@ -2528,7 +2527,7 @@ struct AAWillReturnImpl : public AAWillReturn {
25282527
void initialize(Attributor &A) override {
25292528
AAWillReturn::initialize(A);
25302529

2531-
Function *F = getAssociatedFunction();
2530+
Function *F = getAnchorScope();
25322531
if (!F || !A.isFunctionIPOAmendable(*F) || mayContainUnboundedCycle(*F, A))
25332532
indicatePessimisticFixpoint();
25342533
}
@@ -3113,7 +3112,7 @@ struct AAIsDeadArgument : public AAIsDeadFloating {
31133112

31143113
/// See AbstractAttribute::initialize(...).
31153114
void initialize(Attributor &A) override {
3116-
if (!A.isFunctionIPOAmendable(*getAssociatedFunction()))
3115+
if (!A.isFunctionIPOAmendable(*getAnchorScope()))
31173116
indicatePessimisticFixpoint();
31183117
}
31193118

@@ -3273,7 +3272,7 @@ struct AAIsDeadFunction : public AAIsDead {
32733272

32743273
/// See AbstractAttribute::initialize(...).
32753274
void initialize(Attributor &A) override {
3276-
const Function *F = getAssociatedFunction();
3275+
const Function *F = getAnchorScope();
32773276
if (F && !F->isDeclaration()) {
32783277
ToBeExploredFrom.insert(&F->getEntryBlock().front());
32793278
assumeLive(A, F->getEntryBlock());
@@ -3283,7 +3282,7 @@ struct AAIsDeadFunction : public AAIsDead {
32833282
/// See AbstractAttribute::getAsStr().
32843283
const std::string getAsStr() const override {
32853284
return "Live[#BB " + std::to_string(AssumedLiveBlocks.size()) + "/" +
3286-
std::to_string(getAssociatedFunction()->size()) + "][#TBEP " +
3285+
std::to_string(getAnchorScope()->size()) + "][#TBEP " +
32873286
std::to_string(ToBeExploredFrom.size()) + "][#KDE " +
32883287
std::to_string(KnownDeadEnds.size()) + "]";
32893288
}
@@ -3294,7 +3293,7 @@ struct AAIsDeadFunction : public AAIsDead {
32943293
"Attempted to manifest an invalid state!");
32953294

32963295
ChangeStatus HasChanged = ChangeStatus::UNCHANGED;
3297-
Function &F = *getAssociatedFunction();
3296+
Function &F = *getAnchorScope();
32983297

32993298
if (AssumedLiveBlocks.empty()) {
33003299
A.deleteAfterManifest(F);
@@ -3346,7 +3345,7 @@ struct AAIsDeadFunction : public AAIsDead {
33463345

33473346
/// See AAIsDead::isAssumedDead(BasicBlock *).
33483347
bool isAssumedDead(const BasicBlock *BB) const override {
3349-
assert(BB->getParent() == getAssociatedFunction() &&
3348+
assert(BB->getParent() == getAnchorScope() &&
33503349
"BB must be in the same anchor scope function.");
33513350

33523351
if (!getAssumed())
@@ -3361,7 +3360,7 @@ struct AAIsDeadFunction : public AAIsDead {
33613360

33623361
/// See AAIsDead::isAssumed(Instruction *I).
33633362
bool isAssumedDead(const Instruction *I) const override {
3364-
assert(I->getParent()->getParent() == getAssociatedFunction() &&
3363+
assert(I->getParent()->getParent() == getAnchorScope() &&
33653364
"Instruction must be in the same anchor scope function.");
33663365

33673366
if (!getAssumed())
@@ -3515,7 +3514,7 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
35153514
ChangeStatus Change = ChangeStatus::UNCHANGED;
35163515

35173516
LLVM_DEBUG(dbgs() << "[AAIsDead] Live [" << AssumedLiveBlocks.size() << "/"
3518-
<< getAssociatedFunction()->size() << "] BBs and "
3517+
<< getAnchorScope()->size() << "] BBs and "
35193518
<< ToBeExploredFrom.size() << " exploration points and "
35203519
<< KnownDeadEnds.size() << " known dead ends\n");
35213520

@@ -3595,7 +3594,7 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
35953594
// discovered any non-trivial dead end and (2) not ruled unreachable code
35963595
// dead.
35973596
if (ToBeExploredFrom.empty() &&
3598-
getAssociatedFunction()->size() == AssumedLiveBlocks.size() &&
3597+
getAnchorScope()->size() == AssumedLiveBlocks.size() &&
35993598
llvm::all_of(KnownDeadEnds, [](const Instruction *DeadEndI) {
36003599
return DeadEndI->isTerminator() && DeadEndI->getNumSuccessors() == 0;
36013600
}))
@@ -3935,7 +3934,7 @@ struct AAAlignImpl : AAAlign {
39353934
takeKnownMaximum(Attr.getValueAsInt());
39363935

39373936
if (getIRPosition().isFnInterfaceKind() &&
3938-
(!getAssociatedFunction() ||
3937+
(!getAnchorScope() ||
39393938
!A.isFunctionIPOAmendable(*getAssociatedFunction())))
39403939
indicatePessimisticFixpoint();
39413940
}
@@ -4736,7 +4735,7 @@ struct AAValueSimplifyArgument final : AAValueSimplifyImpl {
47364735

47374736
void initialize(Attributor &A) override {
47384737
AAValueSimplifyImpl::initialize(A);
4739-
if (!getAssociatedFunction() || getAssociatedFunction()->isDeclaration())
4738+
if (!getAnchorScope() || getAnchorScope()->isDeclaration())
47404739
indicatePessimisticFixpoint();
47414740
if (hasAttr({Attribute::InAlloca, Attribute::StructRet, Attribute::Nest},
47424741
/* IgnoreSubsumingPositions */ true))
@@ -4980,7 +4979,7 @@ struct AAHeapToStackImpl : public AAHeapToStack {
49804979
"Attempted to manifest an invalid state!");
49814980

49824981
ChangeStatus HasChanged = ChangeStatus::UNCHANGED;
4983-
Function *F = getAssociatedFunction();
4982+
Function *F = getAnchorScope();
49844983
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F);
49854984

49864985
for (Instruction *MallocCall : MallocCalls) {
@@ -5057,7 +5056,7 @@ struct AAHeapToStackImpl : public AAHeapToStack {
50575056
};
50585057

50595058
ChangeStatus AAHeapToStackImpl::updateImpl(Attributor &A) {
5060-
const Function *F = getAssociatedFunction();
5059+
const Function *F = getAnchorScope();
50615060
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F);
50625061

50635062
MustBeExecutedContextExplorer &Explorer =
@@ -7655,7 +7654,7 @@ ChangeStatus Attributor::run() {
76557654

76567655
unsigned IterationCounter = 1;
76577656

7658-
SmallVector<AbstractAttribute *, 64> ChangedAAs;
7657+
SmallVector<AbstractAttribute *, 32> ChangedAAs;
76597658
SetVector<AbstractAttribute *> Worklist, InvalidAAs;
76607659
Worklist.insert(AllAbstractAttributes.begin(), AllAbstractAttributes.end());
76617660

@@ -8306,7 +8305,7 @@ void Attributor::initializeInformationCache(Function &F) {
83068305
switch (I.getOpcode()) {
83078306
default:
83088307
assert((!ImmutableCallSite(&I)) && (!isa<CallBase>(&I)) &&
8309-
"New call site/base instruction type needs to be known int the "
8308+
"New call site/base instruction type needs to be known in the "
83108309
"Attributor.");
83118310
break;
83128311
case Instruction::Load:
@@ -8635,6 +8634,10 @@ static bool runAttributorOnFunctions(InformationCache &InfoCache,
86358634
// while we identify default attribute opportunities.
86368635
Attributor A(Functions, InfoCache, CGUpdater, DepRecInterval);
86378636

8637+
// Note: _Don't_ combine/fuse this loop with the one below because
8638+
// when A.identifyDefaultAbstractAttributes() is called for one
8639+
// function, it assumes that the information cach has been
8640+
// initialized for _all_ functions.
86388641
for (Function *F : Functions)
86398642
A.initializeInformationCache(*F);
86408643

0 commit comments

Comments
 (0)