summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-inline.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-10-10 15:59:45 -0700
committerGitHub <noreply@github.com>2022-10-10 15:59:45 -0700
commit768e62f6c7541439e2edc18dad5fb3846d2e05f9 (patch)
tree8c68424ee65905b77d3ecb4c7659c5fdcc6ab948 /source/slang/slang-ir-inline.cpp
parent8487678d6504459935fec07886d2e53ed688ac2f (diff)
Support multi-level break + single-return conversion + general inline. (#2436)
* Support multi-level break. * Single return. * Add test for inlining `void` return-type functions. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-inline.cpp')
-rw-r--r--source/slang/slang-ir-inline.cpp47
1 files changed, 5 insertions, 42 deletions
diff --git a/source/slang/slang-ir-inline.cpp b/source/slang/slang-ir-inline.cpp
index 77691d169..70d98d10c 100644
--- a/source/slang/slang-ir-inline.cpp
+++ b/source/slang/slang-ir-inline.cpp
@@ -2,6 +2,7 @@
#include "slang-ir-inline.h"
#include "slang-ir-ssa-simplification.h"
+#include "slang-ir-single-return.h"
// This file provides general facilities for inlining function calls.
@@ -320,48 +321,9 @@ struct InliningPassBase
// For now, our inlining pass only handles the case where
// the callee is a "single-return" function, which means the callee
// function contains only one return at the end of the body.
- if (isSingleReturnFunc(callee))
- {
- inlineSingleReturnFuncBody(callSite, &env, &builder);
- }
- else
- {
- // Running into any non-trivial function to be inlined
- // is currently an internal compiler error.
- //
- SLANG_UNIMPLEMENTED_X("general case of inlining");
- }
- }
-
- /// Check if `func` represents a simple callee that has only a single `return`.
- bool isSingleReturnFunc(IRFunc* func)
- {
- auto firstBlock = func->getFirstBlock();
-
- // If the body block is decorated (for some reason), then the function is non-trivial.
- //
- if( firstBlock->getFirstDecoration() )
- return false;
-
- // If the body has more than one returns, we cannot inline it now.
- bool returnFound = false;
- for (auto block : func->getBlocks())
- {
- for (auto inst : block->getChildren())
- {
- if (inst->getOp() == kIROp_Return)
- {
- // If the return is not at the end of the block, we cannot handle it.
- if (inst != block->getTerminator())
- return false;
- // If there is already a return found, this function cannot be simple.
- if (returnFound)
- return false;
- returnFound = true;
- }
- }
- }
- return true;
+
+ convertFuncToSingleReturnForm(m_module, callSite.callee);
+ inlineSingleReturnFuncBody(callSite, &env, &builder);
}
// When instructions are cloned, with cloneInst no sourceLoc information is copied over by default.
@@ -527,6 +489,7 @@ struct InliningPassBase
//
call->removeAndDeallocate();
}
+
};
/// An inlining pass that inlines calls to `[unsafeForceInlineEarly]` functions