Skip to content

Commit bc303e0

Browse files
committed
Update to LLVM 9.0
1 parent 188bfbb commit bc303e0

19 files changed

+123
-439
lines changed

.travis.yml

+15-12
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,43 @@ matrix:
55
include:
66
- os: osx
77
language: objective-c
8-
osx_image: xcode10.2
8+
osx_image: xcode11.5
99
before_install:
1010
- export PATH=/usr/local/opt/llvm/bin:"${PATH}"
1111
- brew update
12-
- brew install llvm
12+
- brew install llvm@9
13+
- echo 'export PATH="/usr/local/opt/llvm@9/bin:$PATH"' >> /Users/travis/.bash_profile
14+
- source /Users/travis/.bash_profile
1315
- sudo swift utils/make-pkgconfig.swift
1416
script:
1517
- swift test -Xlinker -w
1618
- os: linux
1719
language: generic
1820
sudo: required
19-
dist: trusty
21+
dist: focal
2022
env:
21-
- LLVM_API_VERSION=8
23+
- LLVM_API_VERSION=9
2224
before_install:
2325
- export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:"${PKG_CONFIG_PATH}"
2426
- wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
25-
- sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-${LLVM_API_VERSION} main"
27+
- sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${LLVM_API_VERSION} main"
2628
- sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
2729
- sudo apt-get update
28-
- sudo apt-get install -y llvm-${LLVM_API_VERSION} libc++1
30+
- sudo apt-get install -y binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata zlib1g-dev
31+
- sudo apt-get install -y llvm-${LLVM_API_VERSION} llvm-${LLVM_API_VERSION}-dev libc++1 libtinfo5 libncurses5
2932
- sudo cp /usr/lib/x86_64-linux-gnu/libc++.so.1.0 /usr/lib/
3033
- sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so
3134
- sudo rm -rf /usr/local/clang-*/bin/llvm-config
32-
- ls -l /usr/bin/llvm-config*
3335
- sudo rm -f /usr/bin/llvm-config
3436
- sudo ln -s /usr/bin/llvm-config-${LLVM_API_VERSION} /usr/bin/llvm-config
37+
- ls /usr/lib/llvm-9/include/llvm-c
3538
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
36-
- wget https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz
37-
- tar xzf swift-5.0-RELEASE-ubuntu14.04.tar.gz
38-
- export PATH=${PWD}/swift-5.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
39-
- sudo ./swift-5.0-RELEASE-ubuntu14.04/usr/bin/swift utils/make-pkgconfig.swift
39+
- wget https://swift.org/builds/swift-5.2.5-release/ubuntu1804/swift-5.2.5-RELEASE/swift-5.2.5-RELEASE-ubuntu18.04.tar.gz
40+
- tar xzf swift-5.2.5-RELEASE-ubuntu18.04.tar.gz
41+
- export PATH=${PWD}/swift-5.2.5-RELEASE-ubuntu18.04/usr/bin:"${PATH}"
42+
- sudo ./swift-5.2.5-RELEASE-ubuntu18.04/usr/bin/swift utils/make-pkgconfig.swift
4043
script:
41-
- ./swift-5.0-RELEASE-ubuntu14.04/usr/bin/swift test
44+
- sudo ./swift-5.2.5-RELEASE-ubuntu18.04/usr/bin/swift test
4245
notifications:
4346
slack:
4447
secure: ek/+U+e44bqP8+QCHojy2LhrN9iwY3N/TNNqNG5FZrp09Vidrd5KXWJOXFxlGrpeWdgTpi089YbEdTfxpcDIudUqDqLwPzS7wePiG2cEC1OT6l3yrhI4AvOe7EsNSOX8gzkuEnmrZVHwLLGe7JeR7JIQKoHMZsBcPYDnO8kRP0Ei3zOh47YUn75SE87egAgZOVBDbZYO3GWRa4WX64s8gaQYQ9a7EoUY0oX9rQ48FJs3rmEIhvIXdcOj9bGX7+o0j7l+IFial/Qh+B6bp4XkZU/tUVP6cuNVI1vxE1weVGCBhgt5wLhXTMewzoE5D1IgMZHVuzIBcDbBthSzQRttLSlYar6xTjXtRtOnb8tqZMWfUj3HBYCFYqtz7PGnZ3IflEVsPJW6tgSsoeB6egjzb8APP9mvhm8+zb1jQG1dqXLWErMjWqhlyPVPmHrxU2w/OLWLAJPY94GVmLnSuOw2pSz41spuEY80JcVVzoRbAOQWrwAujq2S3k93yvKpGq4eaT72Mt8g1CyZesByvzcLk99LEJSpqOIxUqXBd4RwHhay/sq8LllyyqY8ORsxEgwQluOAjEhATO/t/HUsu2ndn1k38U1c4HqXW7FDs1hffYEzZ/PGxciCS6Vt1bfST+iq34pzqpanENQCnX6mSR+D+M7mHlCWdsUihmxEcs5knuM=

Sources/LLVM/AddressSpace.swift

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#if SWIFT_PACKAGE
2+
import cllvm
3+
#endif
4+
5+
/// An address space is an identifier for a target-specific range of address values. An address space is a
6+
/// fundamental part of the type of a pointer value and the type of operations that manipulate memory.
7+
///
8+
/// LLVM affords a default address space (numbered zero) and places a number of assumptions on pointer
9+
/// values within that address space:
10+
/// - The pointer must have a fixed integral value
11+
/// - The null pointer has a bit-value of 0
12+
///
13+
/// These assumptions are not guaranteed to hold in any other address space. In particular, a target may
14+
/// allow pointers in non-default address spaces to have *non-integral* types. Non-integral pointer types
15+
/// represent pointers that have an unspecified bitwise representation; that is, the integral representation may
16+
/// be target dependent or have an unstable value. Further, outside of the default address space, it is not
17+
/// always the case that the `null` pointer value, especially as returned by
18+
/// `IRType.constPointerNull()` has a bit value of 0. e.g. A non-default address space may use
19+
/// an offset-based or segment-based addressing mode in which 0 is a valid, addressable pointer value.
20+
///
21+
/// Target-Level Address Space Overrides
22+
/// ====================================
23+
///
24+
/// A target may choose to override the default address space for code, data, and local allocations through the
25+
/// data layout string. This has multiple uses. For example, the address space of an `alloca` is *only*
26+
/// configurable via the data layout string, because it is a target-dependent property. There are also
27+
/// use-cases for overriding language standards e.g. the C standard requires the address-of operator applied
28+
/// to values on the stack to result in a pointer in the default address space. However, many OpenCL-based
29+
/// targets consider the stack to be a private region, and place such pointers in a non-default address space.
30+
///
31+
/// Care must be taken when interacting with these non-standard targets. The IR printer currently does not
32+
/// print anything when the default address space is attached to an instruction or value, and values will still
33+
/// report being assigned to that space. However, these values are still subject to the backend's interpretation
34+
/// of the data layout string overrides and as such may not always reside in the default address space when
35+
/// it comes time to codegen them.
36+
///
37+
/// Restrictions
38+
/// ============
39+
///
40+
/// There are currently a number of artificial restrictions on values and operations that have non-default
41+
/// address spaces:
42+
/// - A `bitcast` between two pointer values residing in different address spaces, even if those two
43+
/// values have the same size, is always an illegal operation. Use an `addrspacecast` instead or
44+
/// always use `IRBuilder.buildPointerCast(of:to:name:)` to get the correct operation.
45+
/// - The so-called "null pointer" has a bit value that may differ from address space to address space. This
46+
/// exposes bugs in optimizer passes and lowerings that did not consider this possibility.
47+
/// - A pointer value may not necessarily "round-trip" when converted between address spaces, even if
48+
/// annotated `nonnull` and `dereferenceable`. This is especially true of non-integral pointer types.
49+
/// - Though the zero address space is the default, many backends and some errant passes interpret this to
50+
/// mean a "lack of address space" and may miscompile code with pointers in mixed address spaces.
51+
/// - A number of intriniscs that operate on memory currently do not support a non-default address space.
52+
/// - The address space is ultimately an integer value and in theory an address space identifier may take on
53+
/// any value. In practice, LLVM guarantees only 24 bits of precision, though higher address space
54+
/// identifiers may succeed in being properly represented.
55+
public struct AddressSpace: Equatable {
56+
let rawValue: Int
57+
58+
/// LLVM's default address space.
59+
public static let zero = AddressSpace(0)
60+
61+
/// Creates and initializes an address space with the given identifier.
62+
/// - Parameter identifier: The raw, integral address space identifier.
63+
public init(_ identifier: Int) {
64+
self.rawValue = identifier
65+
}
66+
}

Sources/LLVM/AttachedMetadata.swift

+3
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ public class AttachedMetadata {
336336
/// attribute may only be applied to pointer typed parameters. This is not
337337
/// checked or enforced by LLVM; if the parameter or return pointer is null,
338338
/// the behavior is undefined.
339+
///
340+
/// Note that the concept of a "null" pointer is address space dependent. it is
341+
/// not necessarily the 0 bit-pattern.
339342
case nonnull = 11
340343
/// Dereferenceable metadata.
341344
///

Sources/LLVM/DIBuilder.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -664,17 +664,17 @@ extension DIBuilder {
664664
/// - pointee: Type pointed by this pointer.
665665
/// - size: The size of the pointer value.
666666
/// - alignment: The alignment of the pointer.
667-
/// - addressSpace: DWARF address space.
667+
/// - addressSpace: The address space the pointer type reside in.
668668
/// - name: The name of the pointer type.
669669
public func buildPointerType(
670670
pointee: DIType, size: Size, alignment: Alignment = .zero,
671-
addressSpace: UInt32 = 0, name: String = ""
671+
addressSpace: AddressSpace = .zero, name: String = ""
672672
) -> DIType {
673673
let radix = UInt32(self.module.dataLayout.intPointerType().width)
674674
guard let ty = LLVMDIBuilderCreatePointerType(
675675
self.llvm, pointee.asMetadata(),
676676
size.valueInBits(radix: UInt64(radix)), alignment.rawValue * radix,
677-
addressSpace, name, name.count)
677+
UInt32(addressSpace.rawValue), name, name.count)
678678
else {
679679
fatalError("Failed to allocate metadata")
680680
}

Sources/LLVM/IRBuilder.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,9 @@ extension IRBuilder {
10381038
/// choose to align the allocation on any convenient boundary compatible with
10391039
/// the type.
10401040
///
1041+
/// The returned value is allocated in the address space specified in the data layout string for the target. If
1042+
/// no such value is specified, the value is allocated in the default address space.
1043+
///
10411044
/// - parameter type: The sized type used to determine the amount of stack
10421045
/// memory to allocate.
10431046
/// - parameter count: An optional number of slots to allocate, to simulate a
@@ -1277,6 +1280,9 @@ extension IRBuilder {
12771280
/// `bitcast` instruction. Note that if the address space conversion is legal
12781281
/// then both result and operand refer to the same memory location.
12791282
///
1283+
/// This instruction must be used in lieu of a `bitcast` even if the cast is between
1284+
/// types of the same size.
1285+
///
12801286
/// The address spaces of the value and the destination pointer types must
12811287
/// be distinct.
12821288
public func buildAddrSpaceCast(_ val: IRValue, type: IRType, name: String = "") -> IRValue {
@@ -1791,7 +1797,7 @@ extension IRBuilder {
17911797
/// variable resides.
17921798
///
17931799
/// - returns: A value representing the newly inserted global variable.
1794-
public func addGlobal(_ name: String, type: IRType, addressSpace: Int? = nil) -> Global {
1800+
public func addGlobal(_ name: String, type: IRType, addressSpace: AddressSpace = .zero) -> Global {
17951801
return self.module.addGlobal(name, type: type, addressSpace: addressSpace)
17961802
}
17971803

@@ -1803,7 +1809,7 @@ extension IRBuilder {
18031809
/// variable resides.
18041810
///
18051811
/// - returns: A value representing the newly inserted global variable.
1806-
public func addGlobal(_ name: String, initializer: IRValue, addressSpace: Int? = nil) -> Global {
1812+
public func addGlobal(_ name: String, initializer: IRValue, addressSpace: AddressSpace = .zero) -> Global {
18071813
return self.module.addGlobal(name, initializer: initializer, addressSpace: addressSpace)
18081814
}
18091815

Sources/LLVM/IRMetadata.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public struct MDNode: IRMetadata {
438438
public init(in context: Context = .global, operands: [IRMetadata]) {
439439
var operands = operands.map { $0.asMetadata() as Optional }
440440
self.llvm = operands.withUnsafeMutableBufferPointer { buf in
441-
return LLVMMDNodeInContext2(context.llvm, buf.baseAddress!, UInt32(buf.count))
441+
return LLVMMDNodeInContext2(context.llvm, buf.baseAddress!, buf.count)
442442
}
443443
}
444444

Sources/LLVM/IRType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal func convertType(_ type: LLVMTypeRef) -> IRType {
8181
case LLVMPointerTypeKind:
8282
let pointee = convertType(LLVMGetElementType(type))
8383
let addressSpace = Int(LLVMGetPointerAddressSpace(type))
84-
return PointerType(pointee: pointee, addressSpace: addressSpace)
84+
return PointerType(pointee: pointee, addressSpace: AddressSpace(addressSpace))
8585
case LLVMVectorTypeKind:
8686
let elementType = convertType(LLVMGetElementType(type))
8787
let count = Int(LLVMGetVectorSize(type))

Sources/LLVM/IRValue.swift

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public enum IRValueKind {
107107
/// The value is a constant floating pointer value.
108108
case constantFloat
109109
/// The value is a constant pointer to null.
110+
///
111+
/// Note that this pointer is a zero bit-value pointer. Its semantics are dependent upon the address space.
110112
case constantPointerNull
111113
/// The value is a constant none-token value.
112114
case constantTokenNone

Sources/LLVM/MetadataAttributes.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,6 @@ public struct DIFlags : OptionSet {
496496
public static let bitField = DIFlags(rawValue: LLVMDIFlagBitField.rawValue)
497497
/// Denotes a `noreturn` function.
498498
public static let noReturn = DIFlags(rawValue: LLVMDIFlagNoReturn.rawValue)
499-
/// Denotes the subprogram for main.
500-
public static let mainSubprogram = DIFlags(rawValue: LLVMDIFlagMainSubprogram.rawValue)
501499
/// Denotes a parameter that is passed by value according to the target's
502500
/// calling convention.
503501
public static let passByValue = DIFlags(rawValue: LLVMDIFlagTypePassByValue.rawValue)
@@ -508,9 +506,8 @@ public struct DIFlags : OptionSet {
508506
public static let enumClass = DIFlags(rawValue: LLVMDIFlagEnumClass.rawValue)
509507
/// Denotes a thunk function.
510508
public static let thunk = DIFlags(rawValue: LLVMDIFlagThunk.rawValue)
511-
/// Denotes a class that has a trivial default constructor and is trivially
512-
/// copiable.
513-
public static let trivial = DIFlags(rawValue: LLVMDIFlagTrivial.rawValue)
509+
/// Denotes a class that has a non-trivial default constructor or is not trivially copiable.
510+
public static let nonTrivial = DIFlags(rawValue: LLVMDIFlagNonTrivial.rawValue)
514511
/// Denotes an indirect virtual base class.
515512
public static let indirectVirtualBase = DIFlags(rawValue: LLVMDIFlagIndirectVirtualBase.rawValue)
516513
/// The mask for `public`, `private`, and `protected` accessibility.

Sources/LLVM/Module.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,9 @@ extension Module {
502502
/// variable resides.
503503
///
504504
/// - returns: A value representing the newly inserted global variable.
505-
public func addGlobal(_ name: String, type: IRType, addressSpace: Int? = nil) -> Global {
506-
let val: LLVMValueRef
507-
if let addressSpace = addressSpace {
508-
val = LLVMAddGlobalInAddressSpace(llvm, type.asLLVM(), name, UInt32(addressSpace))
509-
} else {
510-
val = LLVMAddGlobal(llvm, type.asLLVM(), name)
505+
public func addGlobal(_ name: String, type: IRType, addressSpace: AddressSpace = .zero) -> Global {
506+
guard let val = LLVMAddGlobalInAddressSpace(llvm, type.asLLVM(), name, UInt32(addressSpace.rawValue)) else {
507+
fatalError()
511508
}
512509
return Global(llvm: val)
513510
}
@@ -520,7 +517,7 @@ extension Module {
520517
/// variable resides.
521518
///
522519
/// - returns: A value representing the newly inserted global variable.
523-
public func addGlobal(_ name: String, initializer: IRValue, addressSpace: Int? = nil) -> Global {
520+
public func addGlobal(_ name: String, initializer: IRValue, addressSpace: AddressSpace = .zero) -> Global {
524521
let global = addGlobal(name, type: initializer.type)
525522
global.initializer = initializer
526523
return global

Sources/LLVM/ObjectFile.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public final class MachOUniversalBinaryFile: BinaryFile {
184184
public func objectFile(for architecture: Triple.Architecture) throws -> Slice {
185185
var error: UnsafeMutablePointer<Int8>?
186186
let archName = architecture.rawValue
187-
let archFile: LLVMBinaryRef = LLVMUniversalBinaryCopyObjectForArchitecture(self.llvm, archName, archName.count, &error)
187+
let archFile: LLVMBinaryRef = LLVMMachOUniversalBinaryCopyObjectForArch(self.llvm, archName, archName.count, &error)
188188
if let error = error {
189189
defer { LLVMDisposeMessage(error) }
190190
throw BinaryFileError.couldNotCreate(String(cString: error))

Sources/LLVM/PassManager.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ public enum Pass {
212212
/// Return a new pass object which transforms invoke instructions into calls,
213213
/// if the callee can *not* unwind the stack.
214214
case pruneEH
215-
215+
/// This transformation attempts to discovery `alloca` allocations of aggregates that can be
216+
/// broken down into component scalar values.
216217
case scalarReplacementOfAggregates
217218
/// This pass removes any function declarations (prototypes) that are not used.
218219
case stripDeadPrototypes

Sources/LLVM/PointerType.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public struct PointerType: IRType {
1616
/// Retrieves the type of the value being pointed to.
1717
public let pointee: IRType
1818
/// Retrieves the address space where the pointed-to object resides.
19-
public let addressSpace: Int
19+
public let addressSpace: AddressSpace
2020

2121
/// Creates a `PointerType` from a pointee type and an optional address space.
2222
///
2323
/// - parameter pointee: The type of the pointed-to object.
2424
/// - parameter addressSpace: The optional address space where the pointed-to
2525
/// object resides.
2626
/// - note: The context of this type is taken from it's pointee
27-
public init(pointee: IRType, addressSpace: Int = 0) {
27+
public init(pointee: IRType, addressSpace: AddressSpace = .zero) {
2828
// FIXME: This class of invalid reference is not caught by Module.verify(),
2929
// only `lli`.
3030
if pointee is VoidType {
@@ -40,7 +40,7 @@ public struct PointerType: IRType {
4040

4141
/// Retrieves the underlying LLVM type object.
4242
public func asLLVM() -> LLVMTypeRef {
43-
return LLVMPointerType(pointee.asLLVM(), UInt32(addressSpace))
43+
return LLVMPointerType(pointee.asLLVM(), UInt32(addressSpace.rawValue))
4444
}
4545
}
4646

Sources/LLVM/TargetData.swift

+6-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TargetData {
1717
/// Computes the byte offset of the indexed struct element for a target.
1818
///
1919
/// - parameter element: The index of the element in the given structure to
20-
// compute.
20+
/// compute.
2121
/// - parameter type: The type of the structure to compute the offset with.
2222
///
2323
/// - returns: The offset of the given element within the structure.
@@ -66,17 +66,9 @@ public class TargetData {
6666
/// - addressSpace: The address space in which to derive the type.
6767
/// - returns: An IntegerType that is the same size as the pointer type
6868
/// on this target.
69-
public func intPointerType(context: Context? = nil, addressSpace: Int? = nil) -> IntType {
70-
let type: LLVMTypeRef
71-
switch (context, addressSpace) {
72-
case let (context?, addressSpace?):
73-
type = LLVMIntPtrTypeForASInContext(context.llvm, llvm, UInt32(addressSpace))
74-
case let (nil, addressSpace?):
75-
type = LLVMIntPtrTypeForAS(llvm, UInt32(addressSpace))
76-
case let (context?, nil):
77-
type = LLVMIntPtrTypeInContext(context.llvm, llvm)
78-
case (nil, nil):
79-
type = LLVMIntPtrType(llvm)
69+
public func intPointerType(context: Context = .global, addressSpace: AddressSpace = .zero) -> IntType {
70+
guard let type = LLVMIntPtrTypeForASInContext(context.llvm, llvm, UInt32(addressSpace.rawValue)) else {
71+
fatalError()
8072
}
8173
return convertType(type) as! IntType // Guaranteed to succeed
8274
}
@@ -137,12 +129,8 @@ public class TargetData {
137129
/// - parameter addressSpace: The address space in which to compute
138130
/// pointer size.
139131
/// - returns: The size of a pointer in the target address space.
140-
public func pointerSize(addressSpace: Int? = nil) -> Size {
141-
if let addressSpace = addressSpace {
142-
return Size(UInt64(LLVMPointerSizeForAS(llvm, UInt32(addressSpace))))
143-
} else {
144-
return Size(UInt64(LLVMPointerSize(llvm)))
145-
}
132+
public func pointerSize(addressSpace: AddressSpace = .zero) -> Size {
133+
return Size(UInt64(LLVMPointerSizeForAS(llvm, UInt32(addressSpace.rawValue))))
146134
}
147135

148136
/// Returns the offset in bytes between successive objects of the

Sources/cllvm/shim.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <llvm-c/LinkTimeOptimizer.h>
1919
#include <llvm-c/lto.h>
2020
#include <llvm-c/Object.h>
21-
#include <llvm-c/OptRemarks.h>
2221
#include <llvm-c/OrcBindings.h>
2322
#include <llvm-c/Support.h>
2423
#include <llvm-c/Target.h>

0 commit comments

Comments
 (0)