Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions source/opt/inline_exhaustive_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "source/opt/inline_exhaustive_pass.h"

#include <iterator>
#include <utility>

namespace spvtools {
Expand All @@ -27,6 +28,9 @@ Pass::Status InlineExhaustivePass::InlineExhaustive(Function* func) {
for (auto bi = func->begin(); bi != func->end(); ++bi) {
for (auto ii = bi->begin(); ii != bi->end();) {
if (IsInlinableFunctionCall(&*ii)) {
// Save instruction before the call to avoid redundant re-scanning.
Instruction* prev_inst = (ii == bi->begin()) ? nullptr : &*std::prev(ii);

// Inline call.
std::vector<std::unique_ptr<BasicBlock>> newBlocks;
std::vector<std::unique_ptr<Instruction>> newVars;
Expand All @@ -47,8 +51,8 @@ Pass::Status InlineExhaustivePass::InlineExhaustive(Function* func) {
// Insert new function variables.
if (newVars.size() > 0)
func->begin()->begin().InsertBefore(std::move(newVars));
// Restart inlining at beginning of calling block.
ii = bi->begin();
// Restart inlining at the first instruction of the inlined code.
ii = prev_inst ? ++InstructionList::iterator(prev_inst) : bi->begin();
modified = true;
} else {
++ii;
Expand Down
17 changes: 15 additions & 2 deletions source/opt/inline_opaque_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "source/opt/inline_opaque_pass.h"

#include <iterator>
#include <utility>

namespace spvtools {
Expand Down Expand Up @@ -67,6 +68,9 @@ Pass::Status InlineOpaquePass::InlineOpaque(Function* func) {
for (auto bi = func->begin(); bi != func->end(); ++bi) {
for (auto ii = bi->begin(); ii != bi->end();) {
if (IsInlinableFunctionCall(&*ii) && HasOpaqueArgsOrReturn(&*ii)) {
// Save instruction before the call to avoid redundant re-scanning.
Instruction* prev_inst = (ii == bi->begin()) ? nullptr : &*std::prev(ii);

// Inline call.
std::vector<std::unique_ptr<BasicBlock>> newBlocks;
std::vector<std::unique_ptr<Instruction>> newVars;
Expand All @@ -79,18 +83,27 @@ Pass::Status InlineOpaquePass::InlineOpaque(Function* func) {
if (newBlocks.size() > 1) UpdateSucceedingPhis(newBlocks);
// Replace old calling block with new block(s).
bi = bi.Erase();

for (auto& bb : newBlocks) {
bb->SetParent(func);
}
bi = bi.InsertBefore(&newBlocks);
// Insert new function variables.
if (newVars.size() > 0)
func->begin()->begin().InsertBefore(std::move(newVars));
// Restart inlining at beginning of calling block.
ii = bi->begin();
// Restart inlining at the first instruction of the inlined code.
ii = prev_inst ? ++InstructionList::iterator(prev_inst) : bi->begin();
modified = true;
} else {
++ii;
}
}
}

if (modified) {
FixDebugDeclares(func);
}

return (modified ? Status::SuccessWithChange : Status::SuccessWithoutChange);
}

Expand Down