Skip to content

Commit d9ae2ec

Browse files
committed
Merge branch 'tensorflow' of github.com:apple/swift into autodiff-3
# Conflicts: # lib/SILOptimizer/Mandatory/TFDifferentiation.cpp
2 parents c39323e + dd79e4f commit d9ae2ec

27 files changed

+1910
-1088
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ WARNING(designated_init_in_cross_module_extension,none,
221221
NOTE(designated_init_c_struct_fix,none,
222222
"use \"self.init()\" to initialize the struct with zero values", ())
223223

224+
NOTE(constexpr_called_from, none, "when called from here", ())
225+
NOTE(constexpr_not_evaluable, none,
226+
"expression not evaluable as constant here", ())
224227

225228
// SWIFT_ENABLE_TENSORFLOW
226229
// TensorFlow Support Diagnostics.
@@ -263,7 +266,6 @@ ERROR(tf_op_misuse, none,
263266
NOTE(tf_op_misuse_note, none,
264267
"%0", (StringRef))
265268

266-
267269
// Control flow diagnostics.
268270
ERROR(missing_return,none,
269271
"missing return in a %select{function|closure}1 expected to return %0",

include/swift/SIL/SILConstants.h

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ class SILValue;
2626
class SILBuilder;
2727
class SerializedSILLoader;
2828

29-
struct APIntSymbolicValue;
3029
struct APFloatSymbolicValue;
31-
struct EnumWithPayloadSymbolicValue;
30+
struct APIntSymbolicValue;
3231
struct ArraySymbolicValue;
3332
struct DerivedAddressValue;
33+
struct EnumWithPayloadSymbolicValue;
3434
struct SymbolicValueMemoryObject;
35+
struct UnknownSymbolicValue;
3536

3637
/// When we fail to constant fold a value, this captures a reason why,
3738
/// allowing the caller to produce a specific diagnostic. The "Unknown"
@@ -56,7 +57,6 @@ enum class UnknownReason {
5657
Trap,
5758
};
5859

59-
6060
/// This is the symbolic value tracked for each SILValue in a scope. We
6161
/// support multiple representational forms for the constant node in order to
6262
/// avoid pointless memory bloat + copying. This is intended to be a
@@ -66,6 +66,7 @@ enum class UnknownReason {
6666
/// symbolic values (e.g. to save memory). It provides a simpler public
6767
/// interface though.
6868
class SymbolicValue {
69+
private:
6970
enum RepresentationKind {
7071
/// This value is an alloc stack that is has not (yet) been initialized
7172
/// by flow-sensitive analysis.
@@ -133,11 +134,9 @@ class SymbolicValue {
133134
};
134135

135136
union {
136-
/// When the value is Unknown, this contains the value that was the
137+
/// When the value is Unknown, this contains information about the
137138
/// unfoldable part of the computation.
138-
///
139-
/// TODO: make this a more rich representation.
140-
SILNode *unknown;
139+
UnknownSymbolicValue *unknown;
141140

142141
/// This is always a SILType with an object category. This is the value
143142
/// of the underlying instance type, not the MetatypeType.
@@ -217,7 +216,6 @@ class SymbolicValue {
217216
} aux;
218217

219218
public:
220-
221219
/// This enum is used to indicate the sort of value held by a SymbolicValue
222220
/// independent of its concrete representation. This is the public
223221
/// interface to SymbolicValue.
@@ -270,25 +268,21 @@ class SymbolicValue {
270268
return kind != Unknown && kind != UninitMemory;
271269
}
272270

273-
static SymbolicValue getUnknown(SILNode *node, UnknownReason reason) {
274-
assert(node && "node must be present");
275-
SymbolicValue result;
276-
result.representationKind = RK_Unknown;
277-
result.value.unknown = node;
278-
result.aux.unknown_reason = reason;
279-
return result;
280-
}
271+
static SymbolicValue getUnknown(SILNode *node, UnknownReason reason,
272+
llvm::ArrayRef<SourceLoc> callStack,
273+
llvm::BumpPtrAllocator &allocator);
281274

282-
bool isUnknown() const {
283-
return getKind() == Unknown;
284-
}
275+
/// Return true if this represents an unknown result.
276+
bool isUnknown() const { return getKind() == Unknown; }
285277

286-
/// Return information about an unknown result, including the SIL node that
287-
/// is a problem, and the reason it is an issue.
288-
std::pair<SILNode *, UnknownReason> getUnknownValue() const {
289-
assert(representationKind == RK_Unknown);
290-
return { value.unknown, aux.unknown_reason };
291-
}
278+
/// Return the call stack for an unknown result.
279+
ArrayRef<SourceLoc> getUnknownCallStack() const;
280+
281+
/// Return the node that triggered an unknown result.
282+
SILNode *getUnknownNode() const;
283+
284+
/// Return the reason an unknown result was generated.
285+
UnknownReason getUnknownReason() const;
292286

293287
static SymbolicValue getUninitMemory() {
294288
SymbolicValue result;
@@ -381,7 +375,6 @@ class SymbolicValue {
381375

382376
SymbolicValue getEnumPayloadValue() const;
383377

384-
385378
/// Return a symbolic value that represents the address of a memory object.
386379
static SymbolicValue getAddress(SymbolicValueMemoryObject *memoryObject) {
387380
SymbolicValue result;
@@ -405,11 +398,12 @@ class SymbolicValue {
405398
SymbolicValueMemoryObject *getAddressValueMemoryObject() const;
406399

407400
/// Produce an array of elements.
408-
401+
409402
static SymbolicValue getArray(ArrayRef<SymbolicValue> elements,
410403
CanType elementType,
411404
llvm::BumpPtrAllocator &allocator);
412-
static SymbolicValue getArrayAddress(SymbolicValueMemoryObject *memoryObject){
405+
static SymbolicValue
406+
getArrayAddress(SymbolicValueMemoryObject *memoryObject) {
413407
SymbolicValue result;
414408
result.representationKind = RK_ArrayAddress;
415409
result.value.directAddress = memoryObject;
@@ -439,7 +433,7 @@ class SymbolicValue {
439433
void dump() const;
440434
};
441435

442-
static_assert(sizeof(SymbolicValue) == 2*sizeof(void*),
436+
static_assert(sizeof(SymbolicValue) == 2 * sizeof(void *),
443437
"SymbolicValue should stay small and POD");
444438

445439
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, SymbolicValue val) {
@@ -465,12 +459,11 @@ struct SymbolicValueMemoryObject {
465459
SymbolicValue value;
466460

467461
SymbolicValueMemoryObject(Type type, SymbolicValue value)
468-
: type(type), value(value) {}
469-
SymbolicValueMemoryObject(const SymbolicValueMemoryObject&) = delete;
470-
void operator=(const SymbolicValueMemoryObject&) = delete;
462+
: type(type), value(value) {}
463+
SymbolicValueMemoryObject(const SymbolicValueMemoryObject &) = delete;
464+
void operator=(const SymbolicValueMemoryObject &) = delete;
471465
};
472466

473-
474467
/// SWIFT_ENABLE_TENSORFLOW
475468
/// A graph operation attribute, used by GraphOperationInst.
476469
/// Attributes have a name and a constant value.

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ PASS(TFPartitionTest, "tf-partition",
283283
"Partition accelerator operations out of mainline control flow")
284284
PASS(TFXLACFGCanonicalize, "tf-xla-cfg-canonicalize",
285285
"Canonicalize the control flow graph into SESE region for XLA")
286+
PASS(TFLowerGraph, "tf-lower-graph",
287+
"Lower the given control flow graph into a TF graph")
286288
// SWIFT_ENABLE_TENSORFLOW End
287289
PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
288290
"SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")

0 commit comments

Comments
 (0)