Skip to content
Open
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 compiler/include/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ extern bool fReportGpuTransformTime;
extern bool fPermitUnhandledModuleErrors;

extern bool fDebugSymbols;
extern bool fDebugSafeOptOnly;
extern bool optimizeCCode;
extern bool specializeCCode;

Expand Down
8 changes: 7 additions & 1 deletion compiler/main/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,14 @@ static void setDebugSymbols(const ArgumentDescription* desc, const char* arg_unu
static void setDebugSafeOptOnly(const ArgumentDescription* desc, const char* arg_unused) {
// --no-copy-propagation
fNoCopyPropagation = true;
// Dead code elimination (DCE) is made up of many different parts
// (dead var, dead expr, dead func, etc). DCE is needed by other parts of
// the compiler for proper compilation, so we can't fully disable it here.
// However, when debugging, we want to minimize the amount of code that
// is removed, so we disable as much of it as possible, controlled
// via fDebugSafeOptOnly directly
// --no-dead-code-elimination
fNoDeadCodeElimination = true;
// fNoDeadCodeElimination = true;
// --no-loop-invariant-code-motion
fNoLoopInvariantCodeMotion = true;
// --no-inline
Expand Down
12 changes: 12 additions & 0 deletions compiler/optimizations/deadCodeElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void deadVariableElimination(FnSymbol* fn) {
if (!isVarSymbol(sym))
continue;

// when debugging, we're only interested in compiler temps
if (fDebugSafeOptOnly && !sym->hasFlag(FLAG_TEMP))
continue;

// A method must have a _this symbol, even if it is not used.
if (sym == fn->_this)
continue;
Expand Down Expand Up @@ -151,6 +155,9 @@ void deadVariableElimination(FnSymbol* fn) {
// Removes expression statements that have no effect.
//
void deadExpressionElimination(FnSymbol* fn) {
// when debugging, skip this
if (fDebugSafeOptOnly) return;

std::vector<BaseAST*> asts;

collect_asts(fn, asts);
Expand Down Expand Up @@ -404,6 +411,9 @@ static bool isDeadModule(ModuleSymbol* mod) {

// Eliminates all dead modules
static void deadModuleElimination() {
// when debugging, skip this
if (fDebugSafeOptOnly) return;

deadModuleCount = 0;

forv_Vec(ModuleSymbol, mod, allModules) {
Expand Down Expand Up @@ -465,6 +475,8 @@ static bool removeVoidFunction(FnSymbol* fn) {
}

static void deadFunctionElimination() {
// when debugging, skip this
if (fDebugSafeOptOnly) return;
// skip minimal modules, since many key functions are stubbed out and then get
// removed, which breaks later passes
if (fMinimalModules) return;
Expand Down
4 changes: 2 additions & 2 deletions compiler/optimizations/inlineFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ static void simplifyBody(FnSymbol* fn) {
removeUnnecessaryGotos(fn);

#if DEBUG_CP < 2 // That is, disabled if DEBUG_CP >= 2
if (fNoCopyPropagation == false) {
if (!fNoCopyPropagation) {
singleAssignmentRefPropagation(fn);
localCopyPropagation(fn);
}
#endif

if (fNoDeadCodeElimination == false) {
if (!fNoDeadCodeElimination) {
deadVariableElimination(fn);
deadExpressionElimination(fn);
}
Expand Down