2016-08-31 23:37:13 +00:00
|
|
|
// Copyright (c) 2016 Google Inc.
|
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2016-08-31 23:37:13 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-08-31 23:37:13 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-08-31 23:37:13 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "test/opt/pass_fixture.h"
|
|
|
|
#include "test/opt/pass_utils.h"
|
2016-08-31 23:37:13 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
|
|
|
namespace opt {
|
2016-08-31 23:37:13 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A pass turning all none debug line instructions into Nop.
|
2018-07-11 13:24:49 +00:00
|
|
|
class NopifyPass : public Pass {
|
2016-08-31 23:37:13 +00:00
|
|
|
public:
|
|
|
|
const char* name() const override { return "NopifyPass"; }
|
2018-07-12 13:08:45 +00:00
|
|
|
Status Process() override {
|
2016-09-12 16:39:44 +00:00
|
|
|
bool modified = false;
|
2018-07-12 13:08:45 +00:00
|
|
|
context()->module()->ForEachInst(
|
2018-07-11 13:24:49 +00:00
|
|
|
[&modified](Instruction* inst) {
|
2016-09-12 16:39:44 +00:00
|
|
|
inst->ToNop();
|
|
|
|
modified = true;
|
|
|
|
},
|
|
|
|
/* run_on_debug_line_insts = */ false);
|
|
|
|
return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange;
|
2016-08-31 23:37:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using PassTestForLineDebugInfo = PassTest<::testing::Test>;
|
|
|
|
|
|
|
|
// This test's purpose to show our implementation choice: line debug info is
|
|
|
|
// preserved even if the following instruction is killed. It serves as a guard
|
|
|
|
// of potential behavior changes.
|
|
|
|
TEST_F(PassTestForLineDebugInfo, KeepLineDebugInfo) {
|
|
|
|
// clang-format off
|
|
|
|
const char* text =
|
|
|
|
"OpCapability Shader "
|
|
|
|
"%1 = OpExtInstImport \"GLSL.std.450\" "
|
|
|
|
"OpMemoryModel Logical GLSL450 "
|
|
|
|
"OpEntryPoint Vertex %2 \"main\" "
|
|
|
|
"%3 = OpString \"minimal.vert\" "
|
|
|
|
"OpNoLine "
|
|
|
|
"OpLine %3 10 10 "
|
|
|
|
"%void = OpTypeVoid "
|
|
|
|
"OpLine %3 100 100 "
|
|
|
|
"%5 = OpTypeFunction %void "
|
|
|
|
"%2 = OpFunction %void None %5 "
|
|
|
|
"OpLine %3 1 1 "
|
|
|
|
"OpNoLine "
|
|
|
|
"OpLine %3 2 2 "
|
|
|
|
"OpLine %3 3 3 "
|
|
|
|
"%6 = OpLabel "
|
|
|
|
"OpLine %3 4 4 "
|
|
|
|
"OpNoLine "
|
|
|
|
"OpReturn "
|
|
|
|
"OpLine %3 4 4 "
|
|
|
|
"OpNoLine "
|
|
|
|
"OpFunctionEnd ";
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
const char* result_keep_nop =
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpLine %3 10 10\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpLine %3 100 100\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpLine %3 1 1\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpLine %3 2 2\n"
|
|
|
|
"OpLine %3 3 3\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpLine %3 4 4\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpNop\n"
|
|
|
|
"OpLine %3 4 4\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpNop\n";
|
|
|
|
SinglePassRunAndCheck<NopifyPass>(text, result_keep_nop,
|
|
|
|
/* skip_nop = */ false);
|
|
|
|
const char* result_skip_nop =
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpLine %3 10 10\n"
|
|
|
|
"OpLine %3 100 100\n"
|
|
|
|
"OpLine %3 1 1\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpLine %3 2 2\n"
|
|
|
|
"OpLine %3 3 3\n"
|
|
|
|
"OpLine %3 4 4\n"
|
|
|
|
"OpNoLine\n"
|
|
|
|
"OpLine %3 4 4\n"
|
|
|
|
"OpNoLine\n";
|
|
|
|
SinglePassRunAndCheck<NopifyPass>(text, result_skip_nop,
|
|
|
|
/* skip_nop = */ true);
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace opt
|
|
|
|
} // namespace spvtools
|