mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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).
55 lines
1.7 KiB
C++
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
|