Skip to content

Commit 43e8809

Browse files
authored
Add C and JS APIs to control more pass options (#6713)
Add functions to: * Set and get the trapsNeverHappen, closedWorld, generateStackIR and optimizeStackIR flags * Manage the list of passes to skip.
1 parent 53b7dd1 commit 43e8809

13 files changed

+170
-0
lines changed

src/binaryen-c.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5373,6 +5373,18 @@ bool BinaryenGetDebugInfo(void) { return globalPassOptions.debugInfo; }
53735373

53745374
void BinaryenSetDebugInfo(bool on) { globalPassOptions.debugInfo = on != 0; }
53755375

5376+
bool BinaryenGetTrapsNeverHappen(void) {
5377+
return globalPassOptions.trapsNeverHappen;
5378+
}
5379+
5380+
void BinaryenSetTrapsNeverHappen(bool on) {
5381+
globalPassOptions.trapsNeverHappen = on;
5382+
}
5383+
5384+
bool BinaryenGetClosedWorld(void) { return globalPassOptions.closedWorld; }
5385+
5386+
void BinaryenSetClosedWorld(bool on) { globalPassOptions.closedWorld = on; }
5387+
53765388
bool BinaryenGetLowMemoryUnused(void) {
53775389
return globalPassOptions.lowMemoryUnused;
53785390
}
@@ -5393,6 +5405,22 @@ bool BinaryenGetFastMath(void) { return globalPassOptions.fastMath; }
53935405

53945406
void BinaryenSetFastMath(bool value) { globalPassOptions.fastMath = value; }
53955407

5408+
bool BinaryenGetGenerateStackIR(void) {
5409+
return globalPassOptions.generateStackIR;
5410+
}
5411+
5412+
void BinaryenSetGenerateStackIR(bool on) {
5413+
globalPassOptions.generateStackIR = on;
5414+
}
5415+
5416+
bool BinaryenGetOptimizeStackIR(void) {
5417+
return globalPassOptions.optimizeStackIR;
5418+
}
5419+
5420+
void BinaryenSetOptimizeStackIR(bool on) {
5421+
globalPassOptions.optimizeStackIR = on;
5422+
}
5423+
53965424
const char* BinaryenGetPassArgument(const char* key) {
53975425
assert(key);
53985426
const auto& args = globalPassOptions.arguments;
@@ -5415,6 +5443,18 @@ void BinaryenSetPassArgument(const char* key, const char* value) {
54155443

54165444
void BinaryenClearPassArguments(void) { globalPassOptions.arguments.clear(); }
54175445

5446+
bool BinaryenHasPassToSkip(const char* pass) {
5447+
assert(pass);
5448+
return globalPassOptions.passesToSkip.count(pass);
5449+
}
5450+
5451+
void BinaryenAddPassToSkip(const char* pass) {
5452+
assert(pass);
5453+
globalPassOptions.passesToSkip.insert(pass);
5454+
}
5455+
5456+
void BinaryenClearPassesToSkip(void) { globalPassOptions.passesToSkip.clear(); }
5457+
54185458
BinaryenIndex BinaryenGetAlwaysInlineMaxSize(void) {
54195459
return globalPassOptions.inlining.alwaysInlineMaxSize;
54205460
}

src/binaryen-c.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,6 +2925,24 @@ BINARYEN_API bool BinaryenGetDebugInfo(void);
29252925
// Applies to all modules, globally.
29262926
BINARYEN_API void BinaryenSetDebugInfo(bool on);
29272927

2928+
// Gets whether no traps can be considered reached at runtime when optimizing.
2929+
// Applies to all modules, globally.
2930+
BINARYEN_API bool BinaryenGetTrapsNeverHappen(void);
2931+
2932+
// Enables or disables whether no traps can be considered reached at
2933+
// runtime when optimizing. Applies to all modules, globally.
2934+
BINARYEN_API void BinaryenSetTrapsNeverHappen(bool on);
2935+
2936+
// Gets whether considering that the code outside of the module does
2937+
// not inspect or interact with GC and function references. Applies to
2938+
// all modules, globally.
2939+
BINARYEN_API bool BinaryenGetClosedWorld(void);
2940+
2941+
// Enables or disables whether considering that the code outside of
2942+
// the module does not inspect or interact with GC and function
2943+
// references. Applies to all modules, globally.
2944+
BINARYEN_API void BinaryenSetClosedWorld(bool on);
2945+
29282946
// Gets whether the low 1K of memory can be considered unused when optimizing.
29292947
// Applies to all modules, globally.
29302948
BINARYEN_API bool BinaryenGetLowMemoryUnused(void);
@@ -2950,6 +2968,22 @@ BINARYEN_API bool BinaryenGetFastMath(void);
29502968
// Applies to all modules, globally.
29512969
BINARYEN_API void BinaryenSetFastMath(bool value);
29522970

2971+
// Gets whether to generate StackIR during binary writing.
2972+
// Applies to all modules, globally.
2973+
BINARYEN_API bool BinaryenGetGenerateStackIR(void);
2974+
2975+
// Enable or disable StackIR generation during binary writing.
2976+
// Applies to all modules, globally.
2977+
BINARYEN_API void BinaryenSetGenerateStackIR(bool on);
2978+
2979+
// Gets whether to optimize StackIR during binary writing.
2980+
// Applies to all modules, globally.
2981+
BINARYEN_API bool BinaryenGetOptimizeStackIR(void);
2982+
2983+
// Enable or disable StackIR optimization during binary writing.
2984+
// Applies to all modules, globally.
2985+
BINARYEN_API void BinaryenSetOptimizeStackIR(bool on);
2986+
29532987
// Gets the value of the specified arbitrary pass argument.
29542988
// Applies to all modules, globally.
29552989
BINARYEN_API const char* BinaryenGetPassArgument(const char* name);
@@ -2962,6 +2996,18 @@ BINARYEN_API void BinaryenSetPassArgument(const char* name, const char* value);
29622996
// Applies to all modules, globally.
29632997
BINARYEN_API void BinaryenClearPassArguments();
29642998

2999+
// Gets whether a pass is in the set of passes to skip.
3000+
// Applies to all modules, globally.
3001+
BINARYEN_API bool BinaryenHasPassToSkip(const char* pass);
3002+
3003+
// Add a pass to the set of passes to skip.
3004+
// Applies to all modules, globally.
3005+
BINARYEN_API void BinaryenAddPassToSkip(const char* pass);
3006+
3007+
// Clears the set of passes to skip.
3008+
// Applies to all modules, globally.
3009+
BINARYEN_API void BinaryenClearPassesToSkip(void);
3010+
29653011
// Gets the function size at which we always inline.
29663012
// Applies to all modules, globally.
29673013
BINARYEN_API BinaryenIndex BinaryenGetAlwaysInlineMaxSize(void);

src/js/binaryen.js-post.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,6 +3412,30 @@ Module['setDebugInfo'] = function(on) {
34123412
Module['_BinaryenSetDebugInfo'](on);
34133413
};
34143414

3415+
// Gets whether no traps can be considered reached at runtime when optimizing.
3416+
Module['getTrapsNeverHappen'] = function() {
3417+
return Boolean(Module['_BinaryenGetTrapsNeverHappen']());
3418+
};
3419+
3420+
// Enables or disables whether no traps can be considered reached at
3421+
// runtime when optimizing.
3422+
Module['setTrapsNeverHappen'] = function(on) {
3423+
Module['_BinaryenSetTrapsNeverHappen'](on);
3424+
};
3425+
3426+
// Gets whether considering that the code outside of the module does
3427+
// not inspect or interact with GC and function references.
3428+
Module['getClosedWorld'] = function() {
3429+
return Boolean(Module['_BinaryenGetClosedWorld']());
3430+
};
3431+
3432+
// Enables or disables whether considering that the code outside of
3433+
// the module does not inspect or interact with GC and function
3434+
// references.
3435+
Module['setClosedWorld'] = function(on) {
3436+
Module['_BinaryenSetClosedWorld'](on);
3437+
};
3438+
34153439
// Gets whether the low 1K of memory can be considered unused when optimizing.
34163440
Module['getLowMemoryUnused'] = function() {
34173441
return Boolean(Module['_BinaryenGetLowMemoryUnused']());
@@ -3445,6 +3469,26 @@ Module['setFastMath'] = function(value) {
34453469
Module['_BinaryenSetFastMath'](value);
34463470
};
34473471

3472+
// Gets whether to generate StackIR during binary writing.
3473+
Module['getGenerateStackIR'] = function() {
3474+
return Boolean(Module['_BinaryenGetGenerateStackIR']());
3475+
};
3476+
3477+
// Enable or disable StackIR generation during binary writing.
3478+
Module['setGenerateStackIR'] = function(value) {
3479+
Module['_BinaryenSetGenerateStackIR'](value);
3480+
};
3481+
3482+
// Gets whether to optimize StackIR during binary writing.
3483+
Module['getOptimizeStackIR'] = function() {
3484+
return Boolean(Module['_BinaryenGetOptimizeStackIR']());
3485+
};
3486+
3487+
// Enable or disable StackIR optimisation during binary writing.
3488+
Module['setOptimizeStackIR'] = function(value) {
3489+
Module['_BinaryenSetOptimizeStackIR'](value);
3490+
};
3491+
34483492
// Gets the value of the specified arbitrary pass argument.
34493493
Module['getPassArgument'] = function(key) {
34503494
return preserveStack(() => {
@@ -3464,6 +3508,23 @@ Module['clearPassArguments'] = function() {
34643508
Module['_BinaryenClearPassArguments']();
34653509
};
34663510

3511+
// Gets whether a pass is in the set of passes to skip.
3512+
Module['hasPassToSkip'] = function(pass) {
3513+
return preserveStack(() => {
3514+
return Boolean(Module['_BinaryenHasPassToSkip'](strToStack(pass)));
3515+
});
3516+
};
3517+
3518+
// Add a pass to the set of passes to skip.
3519+
Module['addPassToSkip'] = function (pass) {
3520+
preserveStack(() => { Module['_BinaryenAddPassToSkip'](strToStack(pass)) });
3521+
};
3522+
3523+
// Clears the set of passes to skip.
3524+
Module['clearPassesToSkip'] = function() {
3525+
Module['_BinaryenClearPassesToSkip']();
3526+
};
3527+
34673528
// Gets the function size at which we always inline.
34683529
Module['getAlwaysInlineMaxSize'] = function() {
34693530
return Module['_BinaryenGetAlwaysInlineMaxSize']();

test/binaryen.js/closed-world.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
console.log("// closedWorld=" + binaryen.getClosedWorld());
2+
binaryen.setClosedWorld(true);
3+
assert(binaryen.getClosedWorld() == true);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// closedWorld=false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
console.log("// generateStackIR=" + binaryen.getGenerateStackIR());
2+
binaryen.setGenerateStackIR(true);
3+
assert(binaryen.getGenerateStackIR() == true);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// generateStackIR=false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
console.log("// optimizeStackIR=" + binaryen.getOptimizeStackIR());
2+
binaryen.setOptimizeStackIR(true);
3+
assert(binaryen.getOptimizeStackIR() == true);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// optimizeStackIR=false

test/binaryen.js/passes-to-skip.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
assert(!binaryen.hasPassToSkip("thePass"));
2+
3+
binaryen.addPassToSkip("thePass");
4+
assert(binaryen.hasPassToSkip("thePass"));
5+
6+
binaryen.clearPassesToSkip();
7+
assert(!binaryen.hasPassToSkip("thePass"));

0 commit comments

Comments
 (0)