Skip to content

[6.0][region-isolation] Move logging in front of NDEBUG to make it easier to triage with no asserts compilers #75829

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

Closed
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
2 changes: 0 additions & 2 deletions include/swift/SIL/SILBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ public SwiftObjectHeader {

void printAsOperand(raw_ostream &OS, bool PrintType = true);

#ifndef NDEBUG
/// Print the ID of the block, bbN.
void dumpID(bool newline = true) const;

Expand All @@ -571,7 +570,6 @@ public SwiftObjectHeader {

/// Print the ID of the block with \p Ctx, bbN.
void printID(SILPrintContext &Ctx, bool newline = true) const;
#endif

/// getSublistAccess() - returns pointer to member of instruction list
static InstListType SILBasicBlock::*getSublistAccess() {
Expand Down
6 changes: 0 additions & 6 deletions include/swift/SILOptimizer/Analysis/RegionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ class RegionAnalysisValueMap;

namespace regionanalysisimpl {

#ifndef NDEBUG
/// Global bool set only when asserts are enabled to ease debugging by causing
/// unknown pattern errors to cause an assert so we drop into the debugger.
extern bool AbortOnUnknownPatternMatchError;
#endif

static inline bool shouldAbortOnUnknownPatternMatchError() {
#ifndef NDEBUG
return AbortOnUnknownPatternMatchError;
#else
return false;
#endif
}

using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
Expand Down
13 changes: 1 addition & 12 deletions include/swift/SILOptimizer/Utils/PartitionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
#include "swift/SILOptimizer/Utils/RegionIsolation.h"
#include "swift/SILOptimizer/Utils/SILIsolationInfo.h"

#include "llvm/ADT/MapVector.h"
Expand All @@ -36,18 +37,6 @@ namespace swift {

namespace PartitionPrimitives {

#ifndef NDEBUG
extern bool REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING;
#define REGIONBASEDISOLATION_VERBOSE_LOG(...) \
do { \
if (PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING) { \
LLVM_DEBUG(__VA_ARGS__); \
} \
} while (0);
#else
#define REGIONBASEDISOLATION_VERBOSE_LOG(...)
#endif

struct Element {
unsigned num;

Expand Down
61 changes: 61 additions & 0 deletions include/swift/SILOptimizer/Utils/RegionIsolation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//===--- RegionIsolation.h ------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file This file just declares some command line options that are used for
/// the various parts of region analysis based diagnostics.
///
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SILOPTIMIZER_UTILS_REGIONANALYSIS_H
#define SWIFT_SILOPTIMIZER_UTILS_REGIONANALYSIS_H

namespace swift {

namespace regionisolation {

enum class LoggingFlag {
Off = 0,
Normal = 0x1,
Verbose = 0x3,
};

extern LoggingFlag ENABLE_LOGGING;

#ifdef REGIONBASEDISOLATION_LOG
#error "REGIONBASEDISOLATION_LOG already defined?!"
#endif

#ifdef REGIONBASEDISOLATION_VERBOSE_LOG
#error "REGIONBASEDISOLATION_VERBOSE_LOG already defined?!"
#endif

#define REGIONBASEDISOLATION_LOG(...) \
do { \
if (swift::regionisolation::ENABLE_LOGGING != \
swift::regionisolation::LoggingFlag::Off) { \
__VA_ARGS__; \
} \
} while (0);

#define REGIONBASEDISOLATION_VERBOSE_LOG(...) \
do { \
if (swift::regionisolation::ENABLE_LOGGING == \
swift::regionisolation::LoggingFlag::Verbose) { \
__VA_ARGS__; \
} \
} while (0);

} // namespace regionisolation

} // namespace swift

#endif
6 changes: 6 additions & 0 deletions include/swift/SILOptimizer/Utils/SILIsolationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class SILIsolationInfo {
return isolatedValue;
}

SILValue maybeGetIsolatedValue() const {
if (kind != Task && kind != Actor)
return SILValue();
return getIsolatedValue();
}

/// Return the specific SILValue for the actor that our isolated value is
/// isolated to if one exists.
ActorInstance getActorInstance() const {
Expand Down
14 changes: 12 additions & 2 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3227,20 +3227,30 @@ void SILBasicBlock::print(SILPrintContext &Ctx) const {
SILPrinter(Ctx).print(this);
}

#ifndef NDEBUG
void SILBasicBlock::dumpID(bool newline) const {
#ifndef NDEBUG
printID(llvm::errs(), newline);
#else
llvm::errs() << "NOASSERTS" << (newline ? "\n" : "");
#endif
}

void SILBasicBlock::printID(llvm::raw_ostream &OS, bool newline) const {
#ifndef NDEBUG
SILPrintContext Ctx(OS);
printID(Ctx, newline);
#else
llvm::errs() << "NOASSERTS" << (newline ? "\n" : "");
#endif
}

void SILBasicBlock::printID(SILPrintContext &Ctx, bool newline) const {
#ifndef NDEBUG
SILPrinter(Ctx).printID(this, newline);
}
#else
llvm::errs() << "NOASSERTS" << (newline ? "\n" : "");
#endif
}

/// Pretty-print the SILFunction to errs.
void SILFunction::dump(bool Verbose) const {
Expand Down
Loading