Skip to content

Commit fad8747

Browse files
committed
Adjust test cases.
Swift SVN r17964
1 parent d3f2e38 commit fad8747

File tree

921 files changed

+60288
-21288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

921 files changed

+60288
-21288
lines changed

docs/Hacking on Swift.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
Hacking on Swift
24
================
35

docs/tools/swift.pod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ swift - the amazingly new programming language
66

77
=head1 SYNOPSIS
88

9-
B<swift> [B<-c>|B<-S>|B<-i>] B<-sdk=>I<SDK-path> B<-g>
10-
[B<-O0>|B<-O1>|B<-O2>|B<-O3>]
9+
B<swift> [B<-emit-object>|B<-emit-assembly>|B<-emit-library>|B<-i>]
10+
[-help]
1111
B<-o> I<output-file>
1212
I<input-filenames>
1313

14+
The full list of supported options is available via "swift -help".
15+
1416
=head1 DESCRIPTION
1517

1618
B<Swift> is a new, high performance systems programming language. It has a clean

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 116 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SwiftTargetInfo.cpp --------------------------------------------*-===//
1+
//===--- SwiftTargetInfo.cpp ----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -19,63 +19,137 @@
1919
#include "IRGenModule.h"
2020
#include "llvm/ADT/Triple.h"
2121
#include "llvm/IR/DataLayout.h"
22-
#include "swift/IRGen/Options.h"
22+
#include "swift/ABI/System.h"
23+
#include "swift/AST/IRGenOptions.h"
2324

2425
using namespace swift;
2526
using namespace irgen;
2627

27-
/// Creates a generic SwiftTargetInfo with conservative values that should
28-
/// be valid for any platform absent more specific information.
29-
static SwiftTargetInfo getGenericSwiftTargetInfo(IRGenModule &IGM) {
30-
auto pointerSize = IGM.DataLayout.getPointerSizeInBits();
31-
32-
// Assume no spare bits in pointers.
33-
llvm::BitVector pointerSpareBits(pointerSize, false);
34-
// Assume all bit patterns are reserved by the ObjC runtime.
35-
llvm::BitVector objcReservedBits(pointerSize, true);
36-
// Assume no special alignment of heap objects.
37-
Alignment heapObjectAlignment(1);
38-
// Assume only zero is an invalid pointer.
39-
uint64_t leastValidPointerValue = 1;
40-
41-
return SwiftTargetInfo(std::move(pointerSpareBits),
42-
std::move(objcReservedBits),
43-
heapObjectAlignment,
44-
leastValidPointerValue);
28+
/// Initialize a bit vector to be equal to the given bit-mask.
29+
static void setToMask(llvm::BitVector &bits, uint64_t mask) {
30+
// This is a ridiculously inefficient way of doing this.
31+
for (unsigned i = 0, e = bits.size(); i != e; ++i) {
32+
if (mask & (1ULL << i)) {
33+
bits.set(i);
34+
} else {
35+
bits.reset(i);
36+
}
37+
}
4538
}
4639

47-
/// Creates SwiftTargetInfo for X86-64 platforms.
48-
static SwiftTargetInfo getX86_64SwiftTargetInfo(IRGenModule &IGM) {
49-
// User space only uses the low 47 bits of a pointer.
50-
// FIXME: In kernel mode, the highest bit is occupied.
51-
llvm::BitVector pointerSpareBits(47, false);
52-
pointerSpareBits.resize(64, true);
40+
/// Configures target-specific information for arm64 platforms.
41+
static void configureARM64(IRGenModule &IGM, const llvm::Triple &triple,
42+
SwiftTargetInfo &target) {
43+
setToMask(target.PointerSpareBits,
44+
SWIFT_ABI_ARM64_SWIFT_SPARE_BITS_MASK);
45+
setToMask(target.ObjCPointerReservedBits,
46+
SWIFT_ABI_ARM64_OBJC_RESERVED_BITS_MASK);
5347

54-
// Objective-C reserves the lowest and highest bits for tagged pointers.
55-
llvm::BitVector objcReservedBits(64, false);
56-
objcReservedBits[0] = true;
57-
objcReservedBits[63] = true;
48+
if (triple.isOSDarwin()) {
49+
target.LeastValidPointerValue =
50+
SWIFT_ABI_DARWIN_ARM64_LEAST_VALID_POINTER;
51+
}
52+
53+
// CGPoint and CGRect are both returned in registers.
54+
target.MaxScalarsForDirectResult = 4;
55+
56+
// arm64 has no special objc_msgSend variants, not even stret.
57+
target.ObjCUseStret = false;
58+
59+
// arm64 requires marker assembly for objc_retainAutoreleasedReturnValue.
60+
target.ObjCRetainAutoreleasedReturnValueMarker =
61+
"mov\tfp, fp\t\t; marker for objc_retainAutoreleaseReturnValue";
62+
}
63+
64+
/// Configures target-specific information for x86-64 platforms.
65+
static void configureX86_64(IRGenModule &IGM, const llvm::Triple &triple,
66+
SwiftTargetInfo &target) {
67+
setToMask(target.PointerSpareBits,
68+
SWIFT_ABI_X86_64_SWIFT_SPARE_BITS_MASK);
69+
setToMask(target.ObjCPointerReservedBits,
70+
SWIFT_ABI_X86_64_OBJC_RESERVED_BITS_MASK);
5871

59-
// Heap objects are 16-byte-aligned.
60-
Alignment heapObjectAlignment(16);
72+
if (triple.isOSDarwin()) {
73+
target.LeastValidPointerValue =
74+
SWIFT_ABI_DARWIN_X86_64_LEAST_VALID_POINTER;
75+
}
76+
77+
// On simulator targets, use null instead of &_objc_empty_vtable.
78+
if (triple.isiOS())
79+
target.ObjCUseNullForEmptyVTable = true;
6180

62-
// The null 4K page is always unmapped.
63-
// FIXME: Are additional null pages always unmapped on some platforms?
64-
uint64_t leastValidPointerValue = 4096;
81+
// x86-64 has every objc_msgSend variant known to humankind.
82+
target.ObjCUseFPRet = true;
83+
target.ObjCUseFP2Ret = true;
84+
}
85+
86+
/// Configures target-specific information for 32-bit x86 platforms.
87+
static void configureX86(IRGenModule &IGM, const llvm::Triple &triple,
88+
SwiftTargetInfo &target) {
89+
// On simulator targets, use null instead of &_objc_empty_vtable.
90+
if (triple.isiOS())
91+
target.ObjCUseNullForEmptyVTable = true;
6592

66-
return SwiftTargetInfo(std::move(pointerSpareBits),
67-
std::move(objcReservedBits),
68-
heapObjectAlignment,
69-
leastValidPointerValue);
93+
// x86 uses objc_msgSend_fpret but not objc_msgSend_fp2ret.
94+
target.ObjCUseFPRet = true;
95+
}
96+
97+
/// Configures target-specific information for 32-bit arm platforms.
98+
static void configureARM(IRGenModule &IGM, const llvm::Triple &triple,
99+
SwiftTargetInfo &target) {
100+
// ARM requires marker assembly for objc_retainAutoreleasedReturnValue.
101+
target.ObjCRetainAutoreleasedReturnValueMarker =
102+
"mov\tr7, r7\t\t@ marker for objc_retainAutoreleaseReturnValue";
103+
}
104+
105+
/// Configure a default target.
106+
SwiftTargetInfo::SwiftTargetInfo(unsigned numPointerBits)
107+
: PointerSpareBits(numPointerBits, false),
108+
ObjCPointerReservedBits(numPointerBits, true),
109+
HeapObjectAlignment(numPointerBits / 8),
110+
LeastValidPointerValue(SWIFT_ABI_DEFAULT_LEAST_VALID_POINTER)
111+
{
112+
setToMask(PointerSpareBits,
113+
SWIFT_ABI_DEFAULT_SWIFT_SPARE_BITS_MASK);
114+
setToMask(ObjCPointerReservedBits,
115+
SWIFT_ABI_DEFAULT_OBJC_RESERVED_BITS_MASK);
70116
}
71117

72118
SwiftTargetInfo SwiftTargetInfo::get(IRGenModule &IGM) {
73119
llvm::Triple triple(IGM.Opts.Triple);
120+
auto pointerSize = IGM.DataLayout.getPointerSizeInBits();
121+
122+
/// Prepare generic target information.
123+
SwiftTargetInfo target(pointerSize);
74124

75125
switch (triple.getArch()) {
76126
case llvm::Triple::x86_64:
77-
return getX86_64SwiftTargetInfo(IGM);
127+
configureX86_64(IGM, triple, target);
128+
break;
129+
130+
case llvm::Triple::x86:
131+
configureX86(IGM, triple, target);
132+
break;
133+
134+
case llvm::Triple::arm:
135+
configureARM(IGM, triple, target);
136+
break;
137+
138+
case llvm::Triple::arm64:
139+
configureARM64(IGM, triple, target);
140+
break;
141+
78142
default:
79-
return getGenericSwiftTargetInfo(IGM);
143+
// FIXME: Complain here? Default target info is unlikely to be correct.
144+
break;
145+
}
146+
147+
// The JIT does not support absolute symbols, so we have to use null
148+
// for &objc_empty_vtable.
149+
if (IGM.Opts.UseJIT) {
150+
target.ObjCUseNullForEmptyVTable = true;
80151
}
81-
}
152+
153+
return target;
154+
}
155+

lib/IRGen/SwiftTargetInfo.h

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,52 @@ namespace irgen {
2626
class IRGenModule;
2727

2828
class SwiftTargetInfo {
29+
explicit SwiftTargetInfo(unsigned numPointerBits);
30+
2931
public:
30-
SwiftTargetInfo(llvm::BitVector &&pointerSpareBits,
31-
llvm::BitVector &&objcPointerReservedBits,
32-
Alignment heapObjectAlignment,
33-
uint64_t leastValidPointerValue)
34-
: PointerSpareBits(std::move(pointerSpareBits)),
35-
ObjCPointerReservedBits(std::move(objcPointerReservedBits)),
36-
HeapObjectAlignment(heapObjectAlignment),
37-
LeastValidPointerValue(leastValidPointerValue)
38-
{}
39-
32+
4033
/// Produces a SwiftTargetInfo object appropriate to the target.
4134
static SwiftTargetInfo get(IRGenModule &IGM);
4235

4336
/// The spare bit mask for pointers. Bits set in this mask are unused by
4437
/// pointers of any alignment.
45-
const llvm::BitVector PointerSpareBits;
38+
llvm::BitVector PointerSpareBits;
4639

4740
/// The reserved bit mask for Objective-C pointers. Pointer values with
4841
/// bits from this mask set are reserved by the ObjC runtime and cannot be
4942
/// used for Swift value layout when a reference type may reference ObjC
5043
/// objects.
51-
const llvm::BitVector ObjCPointerReservedBits;
44+
llvm::BitVector ObjCPointerReservedBits;
5245

53-
/// The alignment of heap objects.
54-
const Alignment HeapObjectAlignment;
46+
/// The alignment of heap objects. By default, assume pointer alignment.
47+
Alignment HeapObjectAlignment;
5548

5649
/// The least integer value that can theoretically form a valid pointer.
57-
/// This excludes addresses in the null page(s) guaranteed to be unmapped by
58-
/// the platform.
59-
const uint64_t LeastValidPointerValue;
50+
/// By default, assume that there's an entire page free.
51+
///
52+
/// This excludes addresses in the null page(s) guaranteed to be
53+
/// unmapped by the platform.
54+
///
55+
/// Changes to this must be kept in sync with swift/Runtime/Metadata.h.
56+
uint64_t LeastValidPointerValue;
57+
58+
/// The maximum number of scalars that we allow to be returned directly.
59+
/// FIXME Until rdar://14679857, this must be set such that
60+
/// NSRect and NSPoint structs are returned correctly.
61+
unsigned MaxScalarsForDirectResult = 3;
62+
63+
/// Inline assembly to mark a call to objc_retainAutoreleasedReturnValue.
64+
llvm::StringRef ObjCRetainAutoreleasedReturnValueMarker;
65+
66+
/// Some architectures have specialized objc_msgSend variants.
67+
bool ObjCUseStret = true;
68+
bool ObjCUseFPRet = false;
69+
bool ObjCUseFP2Ret = false;
70+
bool ObjCUseNullForEmptyVTable = false;
6071
};
6172

6273
}
6374
}
6475

65-
#endif
76+
#endif
77+

0 commit comments

Comments
 (0)