|
| 1 | +#===-----------------------------------------------------------------------===// |
| 2 | +# |
| 3 | +# This source file is part of the Swift.org open source project |
| 4 | +# |
| 5 | +# Copyright (c) 2023 Apple Inc. and the Swift project authors |
| 6 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +# |
| 8 | +# See https://swift.org/LICENSE.txt for license information |
| 9 | +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +# |
| 11 | +#===-----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +atomicTypes = [ |
| 14 | + # Swift Size Alignment Builtin |
| 15 | + ("AtomicInt8Storage", "8", "1", "Builtin.Int8"), |
| 16 | + ("AtomicInt16Storage", "16", "2", "Builtin.Int16"), |
| 17 | + ("AtomicInt32Storage", "32", "4", "Builtin.Int32"), |
| 18 | + ("AtomicInt64Storage", "64", "8", "Builtin.Int64"), |
| 19 | + ("AtomicInt128Storage", "128", "16", "Builtin.Int128"), |
| 20 | +] |
| 21 | + |
| 22 | +intTypes = [ |
| 23 | + # Swift Storage Type |
| 24 | + ("Int8", "AtomicInt8Storage", "Int8"), |
| 25 | + ("Int16", "AtomicInt16Storage", "Int16"), |
| 26 | + ("Int32", "AtomicInt32Storage", "Int32"), |
| 27 | + ("Int64", "AtomicInt64Storage", "Int64"), |
| 28 | + |
| 29 | + # We handle the word type's storage in source. |
| 30 | + ("Int", "", "Word"), |
| 31 | + |
| 32 | + ("UInt8", "AtomicInt8Storage", "Int8"), |
| 33 | + ("UInt16", "AtomicInt16Storage", "Int16"), |
| 34 | + ("UInt32", "AtomicInt32Storage", "Int32"), |
| 35 | + ("UInt64", "AtomicInt64Storage", "Int64"), |
| 36 | + |
| 37 | + # We handle the word type's storage in source. |
| 38 | + ("UInt", "", "Word"), |
| 39 | +] |
| 40 | + |
| 41 | +loadOrderings = [ |
| 42 | + # Swift API name doc name LLVM name |
| 43 | + ("relaxed", "Relaxed", "relaxed", "monotonic"), |
| 44 | + ("acquiring", "Acquiring", "acquiring", "acquire"), |
| 45 | + ("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst") |
| 46 | +] |
| 47 | + |
| 48 | +storeOrderings = [ |
| 49 | + # Swift enum case, API name, doc name, LLVM name |
| 50 | + ("relaxed", "Relaxed", "relaxed", "monotonic"), |
| 51 | + ("releasing", "Releasing", "releasing", "release"), |
| 52 | + ("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst") |
| 53 | +] |
| 54 | + |
| 55 | +updateOrderings = [ |
| 56 | + # Swift enum case, API name, doc name, LLVM name, failure name |
| 57 | + ("relaxed", "Relaxed", "relaxed", "monotonic", "monotonic"), |
| 58 | + ("acquiring", "Acquiring", "acquiring", "acquire", "acquire"), |
| 59 | + ("releasing", "Releasing", "releasing", "release", "monotonic"), |
| 60 | + ("acquiringAndReleasing", "AcquiringAndReleasing", "acquiring-and-releasing", "acqrel", "acquire"), |
| 61 | + ("sequentiallyConsistent", "SequentiallyConsistent", "sequentially consistent", "seqcst", "seqcst"), |
| 62 | +] |
| 63 | + |
| 64 | +integerOperations = [ |
| 65 | + # Swift name, llvm name, operator, label, doc name |
| 66 | + ("WrappingIncrement", "add", "&+", "by", "wrapping add"), |
| 67 | + ("WrappingDecrement", "sub", "&-", "by", "wrapping subtract"), |
| 68 | + ("BitwiseAnd", "and", "&", "with", "bitwise AND"), |
| 69 | + ("BitwiseOr", "or", "|", "with", "bitwise OR"), |
| 70 | + ("BitwiseXor", "xor", "^", "with", "bitwise XOR"), |
| 71 | + |
| 72 | + # These two are handled specially in source. |
| 73 | + ("Min", "min", "", "with", "minimum"), |
| 74 | + ("Max", "max", "", "with", "maximum") |
| 75 | +] |
| 76 | + |
| 77 | +boolOperations = [ |
| 78 | + # Swift name, llvm name, operator, label, doc |
| 79 | + ("LogicalAnd", "and", "&&", "with", "logical AND"), |
| 80 | + ("LogicalOr", "or", "||", "with", "logical OR"), |
| 81 | + ("LogicalXor", "xor", "!=", "with", "logical XOR") |
| 82 | +] |
| 83 | + |
| 84 | +# LLVM doesn't support arbitrary ordering combinations yet, so for the |
| 85 | +# two-ordering cmpxchg variants we need to upgrade the success |
| 86 | +# ordering when necessary so that it is at least as "strong" as the |
| 87 | +# failure case. This function implements that mapping. |
| 88 | +# |
| 89 | +# See llvm/Support/AtomicOrdering.h |
| 90 | +def actualOrders(success, failure): |
| 91 | + def max(success, failure): |
| 92 | + if failure == "acquire": |
| 93 | + if success == "monotonic": |
| 94 | + return "acquire" |
| 95 | + if success == "release": |
| 96 | + return "acqrel" |
| 97 | + if failure == "seqcst": |
| 98 | + return "seqcst" |
| 99 | + return success |
| 100 | + actualSuccess = max(success, failure) |
| 101 | + return actualSuccess + "_" + failure |
| 102 | + |
| 103 | +def llvmToCaseName(ordering): |
| 104 | + if ordering == "monotonic": |
| 105 | + return "relaxed" |
| 106 | + if ordering == "acquire": |
| 107 | + return "acquiring" |
| 108 | + if ordering == "release": |
| 109 | + return "releasing" |
| 110 | + if ordering == "acqrel": |
| 111 | + return "acquiringAndReleasing" |
| 112 | + if ordering == "seqcst": |
| 113 | + return "sequentiallyConsistent" |
| 114 | + |
| 115 | +def atomicOperationName(intType, operation): |
| 116 | + if operation == "Min": |
| 117 | + return "umin" if intType.startswith("U") else "min" |
| 118 | + if operation == "Max": |
| 119 | + return "umax" if intType.startswith("U") else "max" |
| 120 | + return operation |
| 121 | + |
| 122 | +def lowerFirst(str): |
| 123 | + return str[:1].lower() + str[1:] if str else "" |
0 commit comments