aboutsummaryrefslogtreecommitdiff
path: root/source/opt/ir_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/ir_context.cpp')
-rw-r--r--source/opt/ir_context.cpp35
1 files changed, 22 insertions, 13 deletions
diff --git a/source/opt/ir_context.cpp b/source/opt/ir_context.cpp
index 03afe6e8..5b0beeb2 100644
--- a/source/opt/ir_context.cpp
+++ b/source/opt/ir_context.cpp
@@ -30,7 +30,8 @@ static const int kSpvDecorateBuiltinInIdx = 2;
static const int kEntryPointInterfaceInIdx = 3;
static const int kEntryPointFunctionIdInIdx = 1;
-// Constants for OpenCL.DebugInfo.100 extension instructions.
+// Constants for OpenCL.DebugInfo.100 / NonSemantic.Shader.DebugInfo.100
+// extension instructions.
static const uint32_t kDebugFunctionOperandFunctionIndex = 13;
static const uint32_t kDebugGlobalVariableOperandVariableIndex = 11;
@@ -105,7 +106,7 @@ void IRContext::InvalidateAnalyses(IRContext::Analysis analyses_to_invalidate) {
analyses_to_invalidate |= kAnalysisDebugInfo;
}
- // The dominator analysis hold the psuedo entry and exit nodes from the CFG.
+ // The dominator analysis hold the pseudo entry and exit nodes from the CFG.
// Also if the CFG change the dominators many changed as well, so the
// dominator analysis should be invalidated as well.
if (analyses_to_invalidate & kAnalysisCFG) {
@@ -170,7 +171,9 @@ Instruction* IRContext::KillInst(Instruction* inst) {
KillOperandFromDebugInstructions(inst);
if (AreAnalysesValid(kAnalysisDefUse)) {
- get_def_use_mgr()->ClearInst(inst);
+ analysis::DefUseManager* def_use_mgr = get_def_use_mgr();
+ def_use_mgr->ClearInst(inst);
+ for (auto& l_inst : inst->dbg_line_insts()) def_use_mgr->ClearInst(&l_inst);
}
if (AreAnalysesValid(kAnalysisInstrToBlockMapping)) {
instr_to_block_.erase(inst);
@@ -217,6 +220,8 @@ Instruction* IRContext::KillInst(Instruction* inst) {
void IRContext::CollectNonSemanticTree(
Instruction* inst, std::unordered_set<Instruction*>* to_kill) {
if (!inst->HasResultId()) return;
+ // Debug[No]Line result id is not used, so we are done
+ if (inst->IsDebugLineInst()) return;
std::vector<Instruction*> work_list;
std::unordered_set<Instruction*> seen;
work_list.push_back(inst);
@@ -312,7 +317,7 @@ bool IRContext::IsConsistent() {
#else
if (AreAnalysesValid(kAnalysisDefUse)) {
analysis::DefUseManager new_def_use(module());
- if (*get_def_use_mgr() != new_def_use) {
+ if (!CompareAndPrintDifferences(*get_def_use_mgr(), new_def_use)) {
return false;
}
}
@@ -437,8 +442,7 @@ void IRContext::KillOperandFromDebugInstructions(Instruction* inst) {
if (opcode == SpvOpVariable || IsConstantInst(opcode)) {
for (auto it = module()->ext_inst_debuginfo_begin();
it != module()->ext_inst_debuginfo_end(); ++it) {
- if (it->GetOpenCL100DebugOpcode() !=
- OpenCLDebugInfo100DebugGlobalVariable)
+ if (it->GetCommonDebugOpcode() != CommonDebugInfoDebugGlobalVariable)
continue;
auto& operand = it->GetOperand(kDebugGlobalVariableOperandVariableIndex);
if (operand.words[0] == id) {
@@ -619,9 +623,8 @@ void IRContext::AddCombinatorsForCapability(uint32_t capability) {
void IRContext::AddCombinatorsForExtension(Instruction* extension) {
assert(extension->opcode() == SpvOpExtInstImport &&
"Expecting an import of an extension's instruction set.");
- const char* extension_name =
- reinterpret_cast<const char*>(&extension->GetInOperand(0).words[0]);
- if (!strcmp(extension_name, "GLSL.std.450")) {
+ const std::string extension_name = extension->GetInOperand(0).AsString();
+ if (extension_name == "GLSL.std.450") {
combinator_ops_[extension->result_id()] = {GLSLstd450Round,
GLSLstd450RoundEven,
GLSLstd450Trunc,
@@ -930,7 +933,7 @@ void IRContext::EmitErrorMessage(std::string message, Instruction* inst) {
while (line_inst != nullptr) { // Stop at the beginning of the basic block.
if (!line_inst->dbg_line_insts().empty()) {
line_inst = &line_inst->dbg_line_insts().back();
- if (line_inst->opcode() == SpvOpNoLine) {
+ if (line_inst->IsNoLine()) {
line_inst = nullptr;
}
break;
@@ -940,11 +943,11 @@ void IRContext::EmitErrorMessage(std::string message, Instruction* inst) {
uint32_t line_number = 0;
uint32_t col_number = 0;
- char* source = nullptr;
+ std::string source;
if (line_inst != nullptr) {
Instruction* file_name =
get_def_use_mgr()->GetDef(line_inst->GetSingleWordInOperand(0));
- source = reinterpret_cast<char*>(&file_name->GetInOperand(0).words[0]);
+ source = file_name->GetInOperand(0).AsString();
// Get the line number and column number.
line_number = line_inst->GetSingleWordInOperand(1);
@@ -953,7 +956,7 @@ void IRContext::EmitErrorMessage(std::string message, Instruction* inst) {
message +=
"\n " + inst->PrettyPrint(SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES);
- consumer()(SPV_MSG_ERROR, source, {line_number, col_number, 0},
+ consumer()(SPV_MSG_ERROR, source.c_str(), {line_number, col_number, 0},
message.c_str());
}
@@ -1034,5 +1037,11 @@ bool IRContext::CheckCFG() {
return true;
}
+
+bool IRContext::IsReachable(const opt::BasicBlock& bb) {
+ auto enclosing_function = bb.GetParent();
+ return GetDominatorAnalysis(enclosing_function)
+ ->Dominates(enclosing_function->entry().get(), &bb);
+}
} // namespace opt
} // namespace spvtools