Skip to content

Commit 82643cb

Browse files
committed
[MERGE chakra-core#1028] Kill 'caller' fields when entering and leaving an inlinee
Merge pull request chakra-core#1028 from rajatd:caller Function.caller should only be copy-propped when it is invoked from the same call chain. As such, it cannot be copy-propped from a parent function into an inlinee or from an inlinee to outside the inlinee.
2 parents 0ee5494 + 7330307 commit 82643cb

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

lib/Backend/GlobOpt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ GlobOpt::Optimize()
277277
if (!func->DoGlobOpt())
278278
{
279279
this->lengthEquivBv = nullptr;
280-
argumentsEquivBv = nullptr;
280+
this->argumentsEquivBv = nullptr;
281+
this->callerEquivBv = nullptr;
281282

282283
// Still need to run the dead store phase to calculate the live reg on back edge
283284
this->BackwardPass(Js::DeadStorePhase);
@@ -287,7 +288,8 @@ GlobOpt::Optimize()
287288

288289
{
289290
this->lengthEquivBv = this->func->m_symTable->m_propertyEquivBvMap->Lookup(Js::PropertyIds::length, nullptr); // Used to kill live "length" properties
290-
argumentsEquivBv = func->m_symTable->m_propertyEquivBvMap->Lookup(Js::PropertyIds::arguments, nullptr); // Used to kill live "arguments" properties
291+
this->argumentsEquivBv = func->m_symTable->m_propertyEquivBvMap->Lookup(Js::PropertyIds::arguments, nullptr); // Used to kill live "arguments" properties
292+
this->callerEquivBv = func->m_symTable->m_propertyEquivBvMap->Lookup(Js::PropertyIds::caller, nullptr); // Used to kill live "caller" properties
291293

292294
// The backward phase needs the glob opt's allocator to allocate the propertyTypeValueMap
293295
// in GlobOpt::EnsurePropertyTypeValue and ranges of instructions where int overflow may be ignored.

lib/Backend/GlobOpt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ class GlobOpt
12061206

12071207
BVSparse<JitArenaAllocator> * lengthEquivBv;
12081208
BVSparse<JitArenaAllocator> * argumentsEquivBv;
1209+
BVSparse<JitArenaAllocator> * callerEquivBv;
12091210

12101211
GlobOptBlockData blockData;
12111212

lib/Backend/GlobOptFields.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,10 @@ GlobOpt::ProcessFieldKills(IR::Instr *instr, BVSparse<JitArenaAllocator> *bv, bo
539539
case Js::OpCode::InlineeEnd:
540540
Assert(!instr->UsesAllFields());
541541

542-
// Kill all live 'arguments' fields, as 'inlineeFunction.arguments' cannot be copy-propped across different instances of
543-
// the same inlined function.
542+
// Kill all live 'arguments' and 'caller' fields, as 'inlineeFunction.arguments' and 'inlineeFunction.caller'
543+
// cannot be copy-propped across different instances of the same inlined function.
544544
KillLiveFields(argumentsEquivBv, bv);
545+
KillLiveFields(callerEquivBv, bv);
545546
break;
546547

547548
case Js::OpCode::CallDirect:

test/Optimizer/copyprop.baseline

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
startvalue: 0
22
d = -9
3+
function v9() {
4+
return func3();
5+
}
6+
function v9() {
7+
return func3();
8+
}

test/Optimizer/copyprop.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,18 @@ testcycle2();
7878
// run JITted code
7979
testcycle2();
8080

81+
var func3 = function () {
82+
return func3.caller;
83+
}
84+
85+
function v9() {
86+
return func3();
87+
}
88+
function v14() {
89+
func3(1);
90+
var v15 = v9();
91+
WScript.Echo(v15);
92+
}
93+
v14();
94+
v14();
95+

0 commit comments

Comments
 (0)