mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-30 23:10:05 +00:00
2d2a512691
* Move ProcessFunction* function from pass to the context. There are a few functions that are used to traverse the call tree. They currently live in the Pass class, but they have nothing to do with a pass, and may be needed outside of a pass. They would be better in the ir context, or in a specific call tree class if we ever have a need for it. * Don't inline recursive functions. Inlining does not check if a function is recursive or not. This has been fine as long as the shader was a Vulkan shader, which forbid recursive functions. However, not all shaders are vulkan, so either we limit inlining to Vulkan shaders or we teach it to look for recursive functions. I prefer to keep the passes as general as is reasonable. The change does not require much new code in inlining and gives a reason to refactor some other code. The changes are to add a member function to the Function class that checks if that function is recursive or not. Then this is used in inlining to not inlining a function call if it calls a recursive function. * Add id to function analysis There are a few places that build a map from ids to Function whose result is that id. I decided to add an analysis to the context for this to reduce that code, and simplify some of the functions. * Add missing file.
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
// Copyright (c) 2017 The Khronos Group Inc.
|
|
// Copyright (c) 2017 Valve Corporation
|
|
// Copyright (c) 2017 LunarG Inc.
|
|
//
|
|
// 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
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// 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.
|
|
|
|
#include "source/opt/pass.h"
|
|
|
|
#include "source/opt/iterator.h"
|
|
|
|
namespace spvtools {
|
|
namespace opt {
|
|
|
|
namespace {
|
|
|
|
const uint32_t kTypePointerTypeIdInIdx = 1;
|
|
|
|
} // namespace
|
|
|
|
Pass::Pass() : consumer_(nullptr), context_(nullptr), already_run_(false) {}
|
|
|
|
Pass::Status Pass::Run(IRContext* ctx) {
|
|
if (already_run_) {
|
|
return Status::Failure;
|
|
}
|
|
already_run_ = true;
|
|
|
|
context_ = ctx;
|
|
Pass::Status status = Process();
|
|
context_ = nullptr;
|
|
|
|
if (status == Status::SuccessWithChange) {
|
|
ctx->InvalidateAnalysesExceptFor(GetPreservedAnalyses());
|
|
}
|
|
assert(ctx->IsConsistent());
|
|
return status;
|
|
}
|
|
|
|
uint32_t Pass::GetPointeeTypeId(const Instruction* ptrInst) const {
|
|
const uint32_t ptrTypeId = ptrInst->type_id();
|
|
const Instruction* ptrTypeInst = get_def_use_mgr()->GetDef(ptrTypeId);
|
|
return ptrTypeInst->GetSingleWordInOperand(kTypePointerTypeIdInIdx);
|
|
}
|
|
|
|
} // namespace opt
|
|
} // namespace spvtools
|