Skip to content

remove some tf-specific stuff from constexpr code #19577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ WARNING(designated_init_in_cross_module_extension,none,
NOTE(designated_init_c_struct_fix,none,
"use \"self.init()\" to initialize the struct with zero values", ())

NOTE(constexpr_unknown_reason, none, "%0", (StringRef))
NOTE(constexpr_called_from, none, "when called from here", ())
NOTE(constexpr_not_evaluable, none,
"expression not evaluable as constant here", ())
Expand Down
7 changes: 1 addition & 6 deletions include/swift/SIL/GraphOperationBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
#define SWIFT_SIL_GRAPH_OPERATION_BUILDER_H

#include "swift/SIL/SILConstants.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILValue.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"

namespace swift {
class ASTContext;
class GraphOperationInst;
class SILBuilder;
class SILLocation;
class SILType;

namespace tf {

class GraphOperationBuilder {
Expand Down
9 changes: 0 additions & 9 deletions include/swift/SIL/SILConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,6 @@ struct SymbolicValueMemoryObject {
SymbolicValueMemoryObject(const SymbolicValueMemoryObject &) = delete;
void operator=(const SymbolicValueMemoryObject &) = delete;
};

/// SWIFT_ENABLE_TENSORFLOW
/// A graph operation attribute, used by GraphOperationInst.
/// Attributes have a name and a constant value.
struct GraphOperationAttribute {
Identifier name;
SymbolicValue value;
};

} // end namespace swift

#endif
9 changes: 8 additions & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/Basic/Range.h"
#include "swift/SIL/Consumption.h"
#include "swift/SIL/SILAllocated.h"
#include "swift/SIL/SILConstants.h"
#include "swift/SIL/SILDeclRef.h"
#include "swift/SIL/SILFunctionConventions.h"
#include "swift/SIL/SILLocation.h"
Expand Down Expand Up @@ -8056,6 +8057,13 @@ inline DestructureTupleInst *DestructureTupleResult::getParent() {
}

/// SWIFT_ENABLE_TENSORFLOW
/// A graph operation attribute, used by GraphOperationInst.
/// Attributes have a name and a constant value.
struct GraphOperationAttribute {
Identifier name;
SymbolicValue value;
};

/// A result for the graph_op instruction. See documentation for
/// graph_op for more information.
class GraphOperationResult final : public MultipleValueInstructionResult {
Expand All @@ -8079,7 +8087,6 @@ class GraphOperationResult final : public MultipleValueInstructionResult {
}
};

/// SWIFT_ENABLE_TENSORFLOW
/// A graph operation. This instruction will be extracted to a graph program
/// via graph program extraction passes.
class GraphOperationInst final
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/SILConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ static bool emitNoteDiagnostic(SILInstruction *badInst, UnknownReason reason,
}

auto &module = badInst->getModule();
diagnose(module.getASTContext(), loc.getSourceLoc(), diag::tf_op_misuse_note,
error)
diagnose(module.getASTContext(), loc.getSourceLoc(),
diag::constexpr_unknown_reason, error)
.highlight(loc.getSourceRange());
return true;
}
Expand Down
15 changes: 5 additions & 10 deletions lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "swift/SIL/SILVisitor.h"

using namespace swift;
using namespace tf;

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

// TODO(marcrasi): Instantiate this earlier so that its cache
// is useful. We don't right now, because instantiating one for every
// function greatly slows down or hangs compilation (e.g. compiling
// libswiftStdlibUnicodeUnittest.so slows down from <1min to >1hr).
//
ConstExprEvaluator constantEvaluator(M);

SmallVector<SymbolicValue, 1> values;
constantEvaluator.computeConstantValues({builtinInst->getArguments()[0]},
values);
Expand Down Expand Up @@ -170,13 +164,14 @@ class EmitDFDiagnostics : public SILFunctionTransform {
return;

SILModule &M = getFunction()->getModule();
ConstExprEvaluator constantEvaluator(M);
for (auto &BB : *getFunction())
for (auto &I : BB) {
diagnoseUnreachable(&I, M.getASTContext());
diagnoseStaticReports(&I, M);

// SWIFT_ENABLE_TENSORFLOW
diagnosePoundAssert(&I, M);
diagnosePoundAssert(&I, M, constantEvaluator);
}
}
};
Expand Down
1 change: 0 additions & 1 deletion lib/SILOptimizer/Mandatory/TFConstExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "llvm/Support/TrailingObjects.h"

using namespace swift;
using namespace tf;

static llvm::cl::opt<unsigned>
ConstExprLimit("constexpr-limit", llvm::cl::init(512),
Expand Down
3 changes: 0 additions & 3 deletions lib/SILOptimizer/Mandatory/TFConstExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class SILValue;
class SymbolicValue;
enum class UnknownReason;

namespace tf {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you also want to rename TFConstExpr.h to sth like ConstExpr.h?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure about what the final location and name of these files will be, so I will defer all moving/renaming until the patch review gives me a good idea of what they will be.


/// This class is the main entrypoint for evaluating constant expressions. It
/// also handles caching of previously computed constexpr results.
class ConstExprEvaluator {
Expand Down Expand Up @@ -99,6 +97,5 @@ class ConstExprEvaluator {
SmallPtrSet<SILInstruction*, 8> *arrayInsts);
};

} // end namespace tf
} // end namespace swift
#endif
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Mandatory/TFDeabstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ struct ArrayElementDecoder {
uint64_t numElements =
cast<IntegerLiteralInst>(numElementsVal)->getValue().getLimitedValue();

return !tf::ConstExprEvaluator::decodeAllocUninitializedArray(
return !ConstExprEvaluator::decodeAllocUninitializedArray(
apply, numElements, elementsAtInit, &arrayInsts);
}

Expand Down