@@ -2711,11 +2711,11 @@ void registerizeHarder(Ref ast) {
2711
2711
// Traverse each node type according to its particular control-flow semantics.
2712
2712
// TODO: switchify this
2713
2713
if (type == DEFUN) {
2714
- var jEntry = markJunction();
2714
+ int jEntry = markJunction();
2715
2715
assert(jEntry == ENTRY_JUNCTION);
2716
2716
int jExit = addJunction();
2717
2717
assert(jExit == EXIT_JUNCTION);
2718
- for (var i = 0; i < node[3].length; i++) {
2718
+ for (int i = 0; i < node[3].length; i++) {
2719
2719
buildFlowGraph(node[3][i]);
2720
2720
}
2721
2721
joinJunction(jExit);
@@ -2780,7 +2780,7 @@ void registerizeHarder(Ref ast) {
2780
2780
joinJunction(jLoop);
2781
2781
setJunction(jExit);
2782
2782
} else {
2783
- var jCond = markJunction();
2783
+ int jCond = markJunction();
2784
2784
int jLoop = addJunction();
2785
2785
int jExit = addJunction();
2786
2786
isInExpr++;
@@ -2996,7 +2996,7 @@ void registerizeHarder(Ref ast) {
2996
2996
}
2997
2997
// Does it assign a specific label value at exit?
2998
2998
if (block.kill.has(LABEL)) {
2999
- var finalNode = block->nodes.back();
2999
+ Ref finalNode = block->nodes.back();
3000
3000
if (finalNode[0] == ASSIGN && finalNode[2][1] == LABEL) {
3001
3001
// If labels are computed dynamically then all bets are off.
3002
3002
// This can happen due to indirect branching in llvm output.
@@ -3023,7 +3023,7 @@ void registerizeHarder(Ref ast) {
3023
3023
}
3024
3024
}
3025
3025
for (auto labelVal : labelledBlocks) {
3026
- var block = labelVal.second;
3026
+ Block* block = labelVal.second;
3027
3027
// Disconnect it from the graph, and create a
3028
3028
// new junction for jumps targetting this label.
3029
3029
junctions[block.entry].outblocks.erase(block.id);
@@ -3245,40 +3245,44 @@ void registerizeHarder(Ref ast) {
3245
3245
// as pairs of variables that we'd like to have share the same register
3246
3246
// (the "links").
3247
3247
3248
- var junctionVariables = {};
3248
+ struct JuncVar {
3249
+ StringSet conf, link, excl;
3250
+ IString reg;
3251
+ };
3252
+ std::unordered_map<IString, JuncVar> junctionVariables;
3249
3253
3250
- function initializeJunctionVariable( name) {
3251
- junctionVariables[name] = { conf: {}, link: {}, excl: {}, reg: null };
3252
- }
3254
+ auto initializeJunctionVariable = [&](IString name) {
3255
+ junctionVariables[name] = JuncVar(); // XXX
3256
+ };
3253
3257
3254
- for (var i = 0; i < junctions.length ; i++) {
3255
- var junc = junctions[i];
3256
- for (var name in junc.live) {
3257
- if (! junctionVariables[ name] ) initializeJunctionVariable(name);
3258
+ for (int i = 0; i < junctions.size() ; i++) {
3259
+ Junction& junc = junctions[i];
3260
+ for (auto name : junc.live) {
3261
+ if (junctionVariables.count( name) == 0 ) initializeJunctionVariable(name);
3258
3262
// It conflicts with all other names live at this junction.
3259
- for (var otherName in junc.live) {
3263
+ for (auto otherName : junc.live) {
3260
3264
if (otherName == name) continue;
3261
- junctionVariables[name].conf[ otherName] = 1 ;
3265
+ junctionVariables[name].conf.insert( otherName) ;
3262
3266
}
3263
- for (var b in junc.outblocks) {
3264
- // It conflits with any output vars of successor blocks,
3267
+ for (auto b : junc.outblocks) {
3268
+ // It conflicts with any output vars of successor blocks,
3265
3269
// if they're assigned before it goes dead in that block.
3266
- block = blocks[b];
3267
- var jSucc = junctions[block. exit];
3268
- for (var otherName in jSucc.live) {
3269
- if (junc.live[ otherName] ) continue;
3270
- if (block. lastKillLoc[otherName] < block. firstDeadLoc[name]) {
3271
- if (! junctionVariables[ otherName] ) initializeJunctionVariable(otherName);
3272
- junctionVariables[name].conf[ otherName] = 1 ;
3273
- junctionVariables[otherName].conf[ name] = 1 ;
3270
+ Block* block = blocks[b];
3271
+ Junction& jSucc = junctions[block-> exit];
3272
+ for (jSucc.live.has(otherName) ) {
3273
+ if (junc.live.has( otherName) ) continue;
3274
+ if (block-> lastKillLoc[otherName] < block-> firstDeadLoc[name]) {
3275
+ if (junctionVariables.count( otherName) == 0 ) initializeJunctionVariable(otherName);
3276
+ junctionVariables[name].conf.insert( otherName) ;
3277
+ junctionVariables[otherName].conf.insert( name) ;
3274
3278
}
3275
3279
}
3276
3280
// It links with any linkages in the outgoing blocks.
3277
- var linkName = block. link[name];
3278
- if (linkName && linkName != name) {
3279
- if (! junctionVariables[ linkName] ) initializeJunctionVariable(linkName);
3280
- junctionVariables[name].link[ linkName] = 1 ;
3281
- junctionVariables[linkName].link[ name] = 1 ;
3281
+ IString linkName = block-> link[name];
3282
+ if (!! linkName && linkName != name) {
3283
+ if (junctionVariables.count( linkName) == 0 ) initializeJunctionVariable(linkName);
3284
+ junctionVariables[name].link.insert( linkName) ;
3285
+ junctionVariables[linkName].link.insert( name) ;
3282
3286
}
3283
3287
}
3284
3288
}
@@ -3288,17 +3292,12 @@ void registerizeHarder(Ref ast) {
3288
3292
// Simple starting point: handle the most-conflicted variables first.
3289
3293
// This seems to work pretty well.
3290
3294
3291
- var sortedJunctionVariables = keys(junctionVariables);
3292
- sortedJunctionVariables.sort(function(name1, name2) {
3293
- var jv1 = junctionVariables[name1];
3294
- var jv2 = junctionVariables[name2];
3295
- if (jv1.numConfs == undefined) {
3296
- jv1.numConfs = setSize(jv1.conf);
3297
- }
3298
- if (jv2.numConfs == undefined) {
3299
- jv2.numConfs = setSize(jv2.conf);
3300
- }
3301
- return jv2.numConfs - jv1.numConfs;
3295
+ StringVec sortedJunctionVariables;
3296
+ for (auto pair : junctionVariables) {
3297
+ sortedJunctionVariables.push_back(pair->first);
3298
+ }
3299
+ std::sort(sortedJunctionVariables.begin(), sortedJunctionVariables.end(), [](const IString name1, const IString name2) {
3300
+ return junctionVariables[name2].conf.size() < junctionVariables[name1].conf.size(); //XXX
3302
3301
});
3303
3302
3304
3303
// We can now assign a register to each junction variable.
0 commit comments