mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Reduce array abstraction on apple platforms dealing with literals Part of the ongoing quest to reduce swift array literal abstraction penalties: make the SIL optimizer able to eliminate bridging overhead when dealing with array literals. Introduce a new classify_bridge_object SIL instruction to handle the logic of extracting platform specific bits from a Builtin.BridgeObject value that indicate whether it contains a ObjC tagged pointer object, or a normal ObjC object. This allows the SIL optimizer to eliminate these, which allows constant folding a ton of code. On the example added to test/SILOptimizer/static_arrays.swift, this results in 4x less SIL code, and also leads to a lot more commonality between linux and apple platform codegen when passing an array literal. This also introduces a couple of SIL combines for patterns that occur in the array literal passing case.
114 lines
3.8 KiB
C++
114 lines
3.8 KiB
C++
//===--- SwiftTargetInfo.h --------------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 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 declares the SwiftTargetInfo abstract base class. This class
|
|
// provides an interface to target-dependent attributes of interest to Swift.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_IRGEN_SWIFTTARGETINFO_H
|
|
#define SWIFT_IRGEN_SWIFTTARGETINFO_H
|
|
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "swift/Basic/ClusteredBitVector.h"
|
|
#include "llvm/ADT/Triple.h"
|
|
#include "IRGen.h"
|
|
|
|
namespace swift {
|
|
namespace irgen {
|
|
class IRGenModule;
|
|
|
|
class SwiftTargetInfo {
|
|
explicit SwiftTargetInfo(llvm::Triple::ObjectFormatType outputObjectFormat,
|
|
unsigned numPointerBits);
|
|
|
|
public:
|
|
|
|
/// Produces a SwiftTargetInfo object appropriate to the target.
|
|
static SwiftTargetInfo get(IRGenModule &IGM);
|
|
|
|
/// True if the ObjC runtime for the chosen platform supports tagged pointers.
|
|
bool hasObjCTaggedPointers() const;
|
|
|
|
/// True if the ObjC runtime for the chosen platform requires ISA masking.
|
|
bool hasISAMasking() const {
|
|
return ObjCUseISAMask;
|
|
}
|
|
|
|
/// True if the ObjC runtime for the chosen platform has opaque ISAs. This
|
|
/// means that even masking the ISA may not return a pointer value. The ObjC
|
|
/// runtime should be used for all accesses to get the ISA from a value.
|
|
bool hasOpaqueISAs() const {
|
|
return ObjCHasOpaqueISAs;
|
|
}
|
|
|
|
/// The target's object format type.
|
|
llvm::Triple::ObjectFormatType OutputObjectFormat;
|
|
|
|
/// The spare bit mask for pointers. Bits set in this mask are unused by
|
|
/// pointers of any alignment.
|
|
SpareBitVector PointerSpareBits;
|
|
|
|
/// The spare bit mask for (ordinary C) thin function pointers.
|
|
SpareBitVector FunctionPointerSpareBits;
|
|
|
|
/// The reserved bit mask for Objective-C pointers. Pointer values with
|
|
/// bits from this mask set are reserved by the ObjC runtime and cannot be
|
|
/// used for Swift value layout when a reference type may reference ObjC
|
|
/// objects.
|
|
SpareBitVector ObjCPointerReservedBits;
|
|
|
|
/// These bits, if set, indicate that a Builtin.BridgeObject value is holding
|
|
/// an Objective-C object.
|
|
SpareBitVector IsObjCPointerBit;
|
|
|
|
|
|
/// The alignment of heap objects. By default, assume pointer alignment.
|
|
Alignment HeapObjectAlignment;
|
|
|
|
/// The least integer value that can theoretically form a valid pointer.
|
|
/// By default, assume that there's an entire page free.
|
|
///
|
|
/// This excludes addresses in the null page(s) guaranteed to be
|
|
/// unmapped by the platform.
|
|
///
|
|
/// Changes to this must be kept in sync with swift/Runtime/Metadata.h.
|
|
uint64_t LeastValidPointerValue;
|
|
|
|
/// The maximum number of scalars that we allow to be returned directly.
|
|
unsigned MaxScalarsForDirectResult = 3;
|
|
|
|
/// Inline assembly to mark a call to objc_retainAutoreleasedReturnValue.
|
|
llvm::StringRef ObjCRetainAutoreleasedReturnValueMarker;
|
|
|
|
/// Some architectures have specialized objc_msgSend variants.
|
|
bool ObjCUseStret = true;
|
|
bool ObjCUseFPRet = false;
|
|
bool ObjCUseFP2Ret = false;
|
|
bool ObjCUseISAMask = false;
|
|
bool ObjCHasOpaqueISAs = false;
|
|
|
|
/// The value stored in a Builtin.once predicate to indicate that an
|
|
/// initialization has already happened, if known.
|
|
Optional<int64_t> OnceDonePredicateValue = None;
|
|
|
|
/// True if `swift_retain` and `swift_release` are no-ops when passed
|
|
/// "negative" pointer values.
|
|
bool SwiftRetainIgnoresNegativeValues = false;
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|