-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFC] Refactor -opt-enable and -opt-disable (#5516)
Refactored -opt-enable and -opt-disable. - Added `hlsl::option::OptimizationToggles` to manage the toggles instead of checking a `std::map`. - All the options are moved into `hlsl::options::TOGGLE_*` constants, where each constant contains both the option's name and whether it's default on or off. + Previously, every check had to be either `toggles.count("my-flag") && toggles.find("my-flag")->second` for default off, and `!toggles.count("my-flag") || toggles.map.find("my-flag")->second` for default on. + Now, a check is simply `toggles.IsEnabled(TOGGLE_MY_FLAG)`.
- Loading branch information
Showing
9 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// DxcOptToggles.h // | ||
// Copyright (C) Microsoft Corporation. All rights reserved. // | ||
// This file is distributed under the University of Illinois Open Source // | ||
// License. See LICENSE.TXT for details. // | ||
// // | ||
// Helper code for representing -opt-disable, -opt-enable, -opt-select // | ||
// options // | ||
// // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#ifndef LLVM_HLSL_DXC_OPT_TOGGLES_H | ||
#define LLVM_HLSL_DXC_OPT_TOGGLES_H | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include <map> | ||
#include <set> | ||
#include <string> | ||
|
||
namespace hlsl { | ||
|
||
namespace options { | ||
|
||
struct Toggle { | ||
llvm::StringRef Name; | ||
bool Default = false; | ||
Toggle(llvm::StringRef Name, bool Default) : Name(Name), Default(Default) {} | ||
}; | ||
|
||
enum { | ||
DEFAULT_ON = 1, | ||
DEFAULT_OFF = 0, | ||
}; | ||
|
||
static const Toggle TOGGLE_GVN = {"gvn", DEFAULT_ON}; | ||
static const Toggle TOGGLE_LICM = {"licm", DEFAULT_ON}; | ||
static const Toggle TOGGLE_SINK = {"sink", DEFAULT_ON}; | ||
static const Toggle TOGGLE_LIFETIME_MARKERS = {"lifetime-markers", DEFAULT_ON}; | ||
static const Toggle TOGGLE_PARTIAL_LIFETIME_MARKERS = { | ||
"partial-lifetime-markers", DEFAULT_OFF}; | ||
static const Toggle TOGGLE_STRUCTURIZE_LOOP_EXITS_FOR_UNROLL = { | ||
"structurize-loop-exits-for-unroll", DEFAULT_ON}; | ||
static const Toggle TOGGLE_DEBUG_NOPS = {"debug-nops", DEFAULT_ON}; | ||
static const Toggle TOGGLE_STRUCTURIZE_RETURNS = {"structurize-returns", DEFAULT_OFF}; | ||
|
||
struct OptimizationToggles { | ||
// Optimization pass enables, disables and selects | ||
std::map<std::string, bool> Toggles; // OPT_opt_enable & OPT_opt_disable | ||
std::map<std::string, std::string> Selects; // OPT_opt_select | ||
|
||
void Set(Toggle Opt, bool Value) { | ||
Toggles[Opt.Name] = Value; | ||
} | ||
bool IsSet(Toggle Opt) const { | ||
return Toggles.find(Opt.Name) != Toggles.end(); | ||
} | ||
bool IsEnabled(Toggle Opt) const { | ||
auto It = Toggles.find(Opt.Name); | ||
const bool Found = It != Toggles.end(); | ||
if (Found) | ||
return It->second; | ||
return Opt.Default; | ||
} | ||
}; | ||
|
||
} // namespace options | ||
} // namespace hlsl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters