Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Debug/ExecutionContext.cpp
//===- ExecutionContext.cpp - Debug Execution Context Support -------------===// | //===- ExecutionContext.cpp - Debug Execution Context Support -------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "mlir/Debug/ExecutionContext.h" | #include "mlir/Debug/ExecutionContext.h" | ||||
#include "llvm/ADT/ScopeExit.h" | #include "llvm/ADT/ScopeExit.h" | ||||
#include "llvm/Support/FormatVariadic.h" | |||||
#include <cstddef> | #include <cstddef> | ||||
using namespace mlir; | using namespace mlir; | ||||
using namespace mlir::tracing; | using namespace mlir::tracing; | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// ExecutionContext | // ActionActiveStack | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
static const thread_local ActionActiveStack *actionStack = nullptr; | void ActionActiveStack::print(raw_ostream &os, bool withContext) const { | ||||
os << "ActionActiveStack depth " << getDepth() << "\n"; | |||||
void ExecutionContext::setCallback(CallbackTy callback) { | const ActionActiveStack *current = this; | ||||
onBreakpointControlExecutionCallback = callback; | int count = 0; | ||||
while (current) { | |||||
llvm::errs() << llvm::formatv("#{0,3}: ", count++); | |||||
current->action.print(llvm::errs()); | |||||
llvm::errs() << "\n"; | |||||
ArrayRef<IRUnit> context = current->action.getContextIRUnits(); | |||||
if (withContext && !context.empty()) { | |||||
llvm::errs() << "Context:\n"; | |||||
llvm::interleave( | |||||
current->action.getContextIRUnits(), | |||||
[&](const IRUnit &unit) { | |||||
llvm::errs() << " - "; | |||||
unit.print(llvm::errs()); | |||||
rriddle: llvm::interleave? | |||||
}, | |||||
[&]() { llvm::errs() << "\n"; }); | |||||
llvm::errs() << "\n"; | |||||
} | |||||
current = current->parent; | |||||
} | } | ||||
} | |||||
//===----------------------------------------------------------------------===// | |||||
// ExecutionContext | |||||
//===----------------------------------------------------------------------===// | |||||
static const LLVM_THREAD_LOCAL ActionActiveStack *actionStack = nullptr; | |||||
void ExecutionContext::registerObserver(Observer *observer) { | void ExecutionContext::registerObserver(Observer *observer) { | ||||
observers.push_back(observer); | observers.push_back(observer); | ||||
} | } | ||||
void ExecutionContext::operator()(llvm::function_ref<void()> transform, | void ExecutionContext::operator()(llvm::function_ref<void()> transform, | ||||
const Action &action) { | const Action &action) { | ||||
// Update the top of the stack with the current action. | // Update the top of the stack with the current action. | ||||
Show All 32 Lines | void ExecutionContext::operator()(llvm::function_ref<void()> transform, | ||||
// Try to find a breakpoint that would hit on this action. | // Try to find a breakpoint that would hit on this action. | ||||
// Right now there is no way to collect them all, we stop at the first one. | // Right now there is no way to collect them all, we stop at the first one. | ||||
for (auto *breakpointManager : breakpoints) { | for (auto *breakpointManager : breakpoints) { | ||||
breakpoint = breakpointManager->match(action); | breakpoint = breakpointManager->match(action); | ||||
if (breakpoint) | if (breakpoint) | ||||
break; | break; | ||||
} | } | ||||
info.setBreakpoint(breakpoint); | |||||
bool shouldExecuteAction = true; | bool shouldExecuteAction = true; | ||||
// If we have a breakpoint, or if `depthToBreak` was previously set and the | // If we have a breakpoint, or if `depthToBreak` was previously set and the | ||||
// current depth matches, we invoke the user-provided callback. | // current depth matches, we invoke the user-provided callback. | ||||
if (breakpoint || (depthToBreak && depth <= depthToBreak)) | if (breakpoint || (depthToBreak && depth <= depthToBreak)) | ||||
shouldExecuteAction = handleUserInput(); | shouldExecuteAction = handleUserInput(); | ||||
// Notify the observers about the current action. | // Notify the observers about the current action. | ||||
Show All 15 Lines |
llvm::interleave?