Skip to content

Commit

Permalink
[inline] Heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoAfoat committed Aug 20, 2024
1 parent 4a740ee commit 2be7836
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/lib/Singleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ struct IR_CONSTDECL_FLAG

struct Enable_Parallel{
bool flag=false;
};

struct Inline_Recursion{
bool flag=false;
};
4 changes: 2 additions & 2 deletions ir/opt/Inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ bool NoRecursive::CanBeInlined(CallInst *call)
auto &&master = call->GetParent()->GetParent();
if (slave->tag == Function::Tag::ParallelBody || master->tag == Function::Tag::UnrollBody || slave->tag == Function::Tag::BuildIn)
return false;
if (InlineRecursion)
if (Singleton<Inline_Recursion>().flag)
{
static int InlineTimes = 0;
if (!master->isRecursive() && !slave->isRecursive())
return true;
if (InlineTimes < 5)
if (InlineTimes<3&&(master->Size()+slave->Size())*3<100)
{
InlineTimes++;
return true;
Expand Down
1 change: 1 addition & 0 deletions ir/opt/new_passManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void _PassManager::RunOnLevel() {
PassChangedBegin(curfunc)
}

Singleton<Inline_Recursion>().flag=true;
while (RunImpl<Inliner>(module, AM)) {
RunLevelPass(cfgSimplify, curfunc, modified)
RunImpl<DeadArgsElimination>(module, AM);
Expand Down

0 comments on commit 2be7836

Please sign in to comment.