Files
swift-mirror/lib/SILOptimizer/Mandatory/PhiStorageOptimizer.h
Nate Chandler 48f4b5aac4 [AddressLowering] Allow use-projection into phi.
Resolves numerous regressions when enabling AddressLowering early in the
pipeline.

Previously, if a value incoming into a phi had storage which itself was
a use-projection out of some other storage, PhiStorageOptimizer bailed
out.  The result was unnecessary "moves" (i.e. `copy_addr [take] [init]`
instructions).

Here, this bailout is removed.  In order to do this, it is necessary to
find (1) all values whose storage recursively project out of an incoming
value (such a value may have storage which is either a use _or_ a def
projection) and (2) the block which dominates the defs of all these
values.

Together, these values are used to compute liveness to determine
interference.  Previously, the live region was that between the uses of
an incoming value and its defining block.  Now, it is that between the
uses of any of the values found in (1) and the dominating block found in
(2).
2023-10-23 16:18:57 -07:00

55 lines
1.7 KiB
C++

//===--- PhiStorageOptimizer.h - Phi storage optimizer --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// This file defines PhiStorageOptimizer, a utility for use with the
/// mandatory AddressLowering pass.
///
//===----------------------------------------------------------------------===//
#include "AddressLowering.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILBasicBlock.h"
#include "swift/SIL/SILValue.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
namespace swift {
class DominanceInfo;
class CoalescedPhi {
friend class PhiStorageOptimizer;
SmallVector<Operand *, 4> coalescedOperands;
CoalescedPhi(const CoalescedPhi &) = delete;
CoalescedPhi &operator=(const CoalescedPhi &) = delete;
public:
CoalescedPhi() = default;
CoalescedPhi(CoalescedPhi &&) = default;
CoalescedPhi &operator=(CoalescedPhi &&) = default;
void coalesce(PhiValue phi, const ValueStorageMap &valueStorageMap,
DominanceInfo *domInfo);
bool empty() const { return coalescedOperands.empty(); }
ArrayRef<Operand *> getCoalescedOperands() const { return coalescedOperands; }
SILInstruction::OperandValueRange getCoalescedValues() const {
return SILInstruction::getOperandValues(getCoalescedOperands());
}
};
} // namespace swift