Skip to content

Commit bb26134

Browse files
authored
remove some tf-specific stuff from constexpr code (#19577)
1 parent 0f8e798 commit bb26134

File tree

9 files changed

+18
-33
lines changed

9 files changed

+18
-33
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ 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_unknown_reason, none, "%0", (StringRef))
224225
NOTE(constexpr_called_from, none, "when called from here", ())
225226
NOTE(constexpr_not_evaluable, none,
226227
"expression not evaluable as constant here", ())

include/swift/SIL/GraphOperationBuilder.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@
2020
#define SWIFT_SIL_GRAPH_OPERATION_BUILDER_H
2121

2222
#include "swift/SIL/SILConstants.h"
23+
#include "swift/SIL/SILInstruction.h"
2324
#include "swift/SIL/SILValue.h"
2425
#include "llvm/ADT/SmallVector.h"
2526
#include "llvm/ADT/StringRef.h"
2627

2728
namespace swift {
28-
class ASTContext;
29-
class GraphOperationInst;
30-
class SILBuilder;
31-
class SILLocation;
32-
class SILType;
33-
3429
namespace tf {
3530

3631
class GraphOperationBuilder {

include/swift/SIL/SILConstants.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,6 @@ struct SymbolicValueMemoryObject {
444444
SymbolicValueMemoryObject(const SymbolicValueMemoryObject &) = delete;
445445
void operator=(const SymbolicValueMemoryObject &) = delete;
446446
};
447-
448-
/// SWIFT_ENABLE_TENSORFLOW
449-
/// A graph operation attribute, used by GraphOperationInst.
450-
/// Attributes have a name and a constant value.
451-
struct GraphOperationAttribute {
452-
Identifier name;
453-
SymbolicValue value;
454-
};
455-
456447
} // end namespace swift
457448

458449
#endif

include/swift/SIL/SILInstruction.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/Basic/Range.h"
3232
#include "swift/SIL/Consumption.h"
3333
#include "swift/SIL/SILAllocated.h"
34+
#include "swift/SIL/SILConstants.h"
3435
#include "swift/SIL/SILDeclRef.h"
3536
#include "swift/SIL/SILFunctionConventions.h"
3637
#include "swift/SIL/SILLocation.h"
@@ -8056,6 +8057,13 @@ inline DestructureTupleInst *DestructureTupleResult::getParent() {
80568057
}
80578058

80588059
/// SWIFT_ENABLE_TENSORFLOW
8060+
/// A graph operation attribute, used by GraphOperationInst.
8061+
/// Attributes have a name and a constant value.
8062+
struct GraphOperationAttribute {
8063+
Identifier name;
8064+
SymbolicValue value;
8065+
};
8066+
80598067
/// A result for the graph_op instruction. See documentation for
80608068
/// graph_op for more information.
80618069
class GraphOperationResult final : public MultipleValueInstructionResult {
@@ -8079,7 +8087,6 @@ class GraphOperationResult final : public MultipleValueInstructionResult {
80798087
}
80808088
};
80818089

8082-
/// SWIFT_ENABLE_TENSORFLOW
80838090
/// A graph operation. This instruction will be extracted to a graph program
80848091
/// via graph program extraction passes.
80858092
class GraphOperationInst final

lib/SIL/SILConstants.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ static bool emitNoteDiagnostic(SILInstruction *badInst, UnknownReason reason,
800800
}
801801

802802
auto &module = badInst->getModule();
803-
diagnose(module.getASTContext(), loc.getSourceLoc(), diag::tf_op_misuse_note,
804-
error)
803+
diagnose(module.getASTContext(), loc.getSourceLoc(),
804+
diag::constexpr_unknown_reason, error)
805805
.highlight(loc.getSourceRange());
806806
return true;
807807
}

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/SIL/SILVisitor.h"
2626

2727
using namespace swift;
28-
using namespace tf;
2928

3029
template<typename...T, typename...U>
3130
static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
@@ -118,19 +117,14 @@ static void diagnoseStaticReports(const SILInstruction *I,
118117
// SWIFT_ENABLE_TENSORFLOW
119118
/// \brief Emit a diagnostic for `poundAssert` builtins whose condition is
120119
/// false or whose condition cannot be evaluated.
121-
static void diagnosePoundAssert(const SILInstruction *I, SILModule &M) {
120+
static void diagnosePoundAssert(const SILInstruction *I,
121+
SILModule &M,
122+
ConstExprEvaluator &constantEvaluator) {
122123
auto *builtinInst = dyn_cast<BuiltinInst>(I);
123124
if (!builtinInst ||
124125
builtinInst->getBuiltinKind() != BuiltinValueKind::PoundAssert)
125126
return;
126127

127-
// TODO(marcrasi): Instantiate this earlier so that its cache
128-
// is useful. We don't right now, because instantiating one for every
129-
// function greatly slows down or hangs compilation (e.g. compiling
130-
// libswiftStdlibUnicodeUnittest.so slows down from <1min to >1hr).
131-
//
132-
ConstExprEvaluator constantEvaluator(M);
133-
134128
SmallVector<SymbolicValue, 1> values;
135129
constantEvaluator.computeConstantValues({builtinInst->getArguments()[0]},
136130
values);
@@ -170,13 +164,14 @@ class EmitDFDiagnostics : public SILFunctionTransform {
170164
return;
171165

172166
SILModule &M = getFunction()->getModule();
167+
ConstExprEvaluator constantEvaluator(M);
173168
for (auto &BB : *getFunction())
174169
for (auto &I : BB) {
175170
diagnoseUnreachable(&I, M.getASTContext());
176171
diagnoseStaticReports(&I, M);
177172

178173
// SWIFT_ENABLE_TENSORFLOW
179-
diagnosePoundAssert(&I, M);
174+
diagnosePoundAssert(&I, M, constantEvaluator);
180175
}
181176
}
182177
};

lib/SILOptimizer/Mandatory/TFConstExpr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "llvm/Support/TrailingObjects.h"
2626

2727
using namespace swift;
28-
using namespace tf;
2928

3029
static llvm::cl::opt<unsigned>
3130
ConstExprLimit("constexpr-limit", llvm::cl::init(512),

lib/SILOptimizer/Mandatory/TFConstExpr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class SILValue;
3838
class SymbolicValue;
3939
enum class UnknownReason;
4040

41-
namespace tf {
42-
4341
/// This class is the main entrypoint for evaluating constant expressions. It
4442
/// also handles caching of previously computed constexpr results.
4543
class ConstExprEvaluator {
@@ -99,6 +97,5 @@ class ConstExprEvaluator {
9997
SmallPtrSet<SILInstruction*, 8> *arrayInsts);
10098
};
10199

102-
} // end namespace tf
103100
} // end namespace swift
104101
#endif

lib/SILOptimizer/Mandatory/TFDeabstraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ struct ArrayElementDecoder {
14741474
uint64_t numElements =
14751475
cast<IntegerLiteralInst>(numElementsVal)->getValue().getLimitedValue();
14761476

1477-
return !tf::ConstExprEvaluator::decodeAllocUninitializedArray(
1477+
return !ConstExprEvaluator::decodeAllocUninitializedArray(
14781478
apply, numElements, elementsAtInit, &arrayInsts);
14791479
}
14801480

0 commit comments

Comments
 (0)