summaryrefslogtreecommitdiff
path: root/tool/zjit_iongraph.html
blob: e97ac74e4ac41142468bf4216660da30f2316858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
<!-- Copyright Mozilla and licensed under Mozilla Public License Version 2.0.
     Source can be found at https://github.com/mozilla-spidermonkey/iongraph -->
<!-- Generated by `npm run build-www` on
    c08a296ff71bbcebf88104d1ae3adb64ebac6113 in aidenfoxivey/iongraph -->
<!DOCTYPE html>

<head>
  <title>iongraph</title>
  <style>/* iongraph-specific styles inspired by Tachyons */

:root {
  --ig-size-1: 1rem;
  --ig-size-2: 2rem;
  --ig-size-3: 4rem;
  --ig-size-4: 8rem;
  --ig-size-5: 16rem;

  --ig-spacing-1: .25rem;
  --ig-spacing-2: .5rem;
  --ig-spacing-3: 1rem;
  --ig-spacing-4: 2rem;
  --ig-spacing-5: 4rem;
  --ig-spacing-6: 8rem;
  --ig-spacing-7: 16rem;

  --ig-text-color: black;
  --ig-text-color-dim: #777;
  --ig-background-primary: #ffb54e;
  --ig-background-light: white;
  --ig-border-color: #0c0c0d;

  --ig-block-header-color: #0c0c0d;
  --ig-loop-header-color: #1fa411;
  --ig-movable-color: #1048af;
  --ig-rob-color: #444;
  --ig-in-worklist-color: red;

  --ig-block-selected: #ffc863;
  --ig-block-last-selected: #ffb54e;

  --ig-highlight-0: #ffb54e;
  --ig-highlight-1: #ffb5c5;
  --ig-highlight-2: #a4cbff;
  --ig-highlight-3: #8be182;
  --ig-highlight-4: #d9a4fd;

  --ig-flash-color: #ffb54e;

  /*
   * The heatmap of sample counts will effectively be sampled from a gradient:
   *
   * |----------|---------------------------------------|
   * cold     "cool"                                  hot
   *
   * The "cold" color will simply be transparent. Therefore, the "cool"
   * threshold indicates where the instruction will be fully colored and
   * noticeable to the user.
   */
  --ig-hot-color: #ff849e;
  --ig-cool-color: #ffe546;
  --ig-cool-threshold: 0.2;
}

a.ig-link-normal {
  color: inherit;
  text-decoration: inherit;
}

.ig-flex {
  display: flex;
}

.ig-flex-column {
  flex-direction: column;
}

.ig-flex-basis-0 {
  flex-basis: 0;
}

.ig-flex-grow-1 {
  flex-grow: 1;
}

.ig-flex-shrink-0 {
  flex-shrink: 0;
}

.ig-flex-shrink-1 {
  flex-shrink: 1;
}

.ig-items-center {
  align-items: center;
}

.ig-relative {
  position: relative;
}

.ig-absolute {
  position: absolute;
}

.ig-absolute-fill {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.ig-g1 {
  gap: var(--ig-spacing-1);
}

.ig-g2 {
  gap: var(--ig-spacing-2);
}

.ig-g3 {
  gap: var(--ig-spacing-3);
}

.ig-w1 {
  width: var(--ig-size-1);
}

.ig-w2 {
  width: var(--ig-size-2);
}

.ig-w3 {
  width: var(--ig-size-3);
}

.ig-w4 {
  width: var(--ig-size-4);
}

.ig-w5 {
  width: var(--ig-size-5);
}

.ig-w-100 {
  width: 100%;
}

.ig-ba {
  border-style: solid;
  border-width: 1px;
  border-color: var(--ig-border-color);
}

.ig-bt {
  border-top-style: solid;
  border-top-width: 1px;
  border-color: var(--ig-border-color);
}

.ig-br {
  border-right-style: solid;
  border-right-width: 1px;
  border-color: var(--ig-border-color);
}

.ig-bb {
  border-bottom-style: solid;
  border-bottom-width: 1px;
  border-color: var(--ig-border-color);
}

.ig-bl {
  border-left-style: solid;
  border-left-width: 1px;
  border-color: var(--ig-border-color);
}

.ig-pa1 {
  padding: var(--ig-spacing-1);
}

.ig-pa2 {
  padding: var(--ig-spacing-2);
}

.ig-pa3 {
  padding: var(--ig-spacing-3);
}

.ig-ph1 {
  padding-left: var(--ig-spacing-1);
  padding-right: var(--ig-spacing-1);
}

.ig-ph2 {
  padding-left: var(--ig-spacing-2);
  padding-right: var(--ig-spacing-2);
}

.ig-ph3 {
  padding-left: var(--ig-spacing-3);
  padding-right: var(--ig-spacing-3);
}

.ig-pv1 {
  padding-top: var(--ig-spacing-1);
  padding-bottom: var(--ig-spacing-1);
}

.ig-pv2 {
  padding-top: var(--ig-spacing-2);
  padding-bottom: var(--ig-spacing-2);
}

.ig-pv3 {
  padding-top: var(--ig-spacing-3);
  padding-bottom: var(--ig-spacing-3);
}

.ig-pt1 {
  padding-top: var(--ig-spacing-1);
}

.ig-pt2 {
  padding-top: var(--ig-spacing-2);
}

.ig-pt3 {
  padding-top: var(--ig-spacing-3);
}

.ig-pr1 {
  padding-right: var(--ig-spacing-1);
}

.ig-pr2 {
  padding-right: var(--ig-spacing-2);
}

.ig-pr3 {
  padding-right: var(--ig-spacing-3);
}

.ig-pb1 {
  padding-bottom: var(--ig-spacing-1);
}

.ig-pb2 {
  padding-bottom: var(--ig-spacing-2);
}

.ig-pb3 {
  padding-bottom: var(--ig-spacing-3);
}

.ig-pl1 {
  padding-left: var(--ig-spacing-1);
}

.ig-pl2 {
  padding-left: var(--ig-spacing-2);
}

.ig-pl3 {
  padding-left: var(--ig-spacing-3);
}

.ig-f1 {
  font-size: 3rem;
}

.ig-f2 {
  font-size: 2.25rem;
}

.ig-f3 {
  font-size: 1.5rem;
}

.ig-f4 {
  font-size: 1.25rem;
}

.ig-f5 {
  font-size: 1rem;
}

.ig-f6 {
  font-size: .875rem;
}

.ig-f7 {
  font-size: .75rem;
}

.ig-text-normal {
  color: var(--ig-text-color);
}

.ig-text-dim {
  color: var(--ig-text-color-dim);
}

.ig-tl {
  text-align: left;
}

.ig-tr {
  text-align: right;
}

.ig-tc {
  text-align: center;
}

.ig-bg-white {
  background-color: var(--ig-background-light);
}

.ig-bg-primary {
  background-color: var(--ig-background-primary);
}

.ig-overflow-hidden {
  overflow: hidden;
}

.ig-overflow-auto {
  overflow: auto;
}

.ig-overflow-x-auto {
  overflow-x: auto;
}

.ig-overflow-y-auto {
  overflow-y: auto;
}

/* Non-utility styles */

.ig-graph {
  color: var(--ig-text-color);
  position: absolute;
  left: 0;
  top: 0;
  isolation: isolate;
}

.ig-block {
  position: absolute;

  .ig-block-header {
    font-weight: bold;
    text-align: center;
    background-color: var(--ig-block-header-color);
    color: white;
    padding: 0 1em;
    border: 1px solid var(--ig-border-color);
    border-width: 1px 1px 0;
  }

  .ig-instructions {
    padding: 0.5em;
    border: 1px solid var(--ig-border-color);
    border-width: 0 1px 1px;

    table {
      border-collapse: collapse;
    }

    td,
    th {
      white-space: nowrap;
      padding: 0.1em 0.5em;
    }

    th {
      font-weight: normal;
    }
  }

  &.ig-selected {
    outline: 4px solid var(--ig-block-selected);
  }

  &.ig-last-selected {
    outline-color: var(--ig-block-last-selected);
  }
}

.ig-block-att-loopheader {
  .ig-block-header {
    background-color: var(--ig-loop-header-color);
  }
}

.ig-block-att-splitedge {
  .ig-instructions {
    border-style: dotted;
    border-width: 0 2px 2px;
  }
}

.ig-ins-num {
  text-align: right;
  cursor: pointer;
}

.ig-ins-type {
  text-align: right;
}

.ig-ins-samples {
  font-size: 0.875em;
  text-align: right;
  cursor: pointer;
}

.ig-use {
  padding: 0 0.25em;
  border-radius: 2px;
  cursor: pointer;
}

.ig-edge-label {
  position: absolute;
  font-size: 0.8em;
  line-height: 1;
  bottom: -1em;
  padding-left: 4px;
}

.ig-ins-att-RecoveredOnBailout {
  color: var(--ig-rob-color);
}

.ig-ins-att-Movable {
  color: var(--ig-movable-color);
}

.ig-ins-att-Guard {
  text-decoration: underline;
}

.ig-ins-att-InWorklist {
  color: var(--ig-in-worklist-color);
}

.ig-can-flash {
  transition: outline-color 1s ease-out;
  outline: 3px solid color-mix(in srgb, var(--ig-flash-color) 0%, transparent);
}

.ig-flash {
  transition: outline-color 0s;
  outline-color: var(--ig-flash-color);
}

.ig-hotness {
  --ig-hotness: 0;

  --ig-cold-color: color-mix(in srgb, var(--ig-cool-color) 20%, transparent);
  background-color:
    /* cool <-> hot */
    color-mix(in oklab,
      /* cold <-> cool */
      color-mix(in oklab,
        /* dead or cold */
        color-mix(in srgb, transparent, var(--ig-cold-color) clamp(0%, calc(var(--ig-hotness) * 100000000%), 100%)),
        var(--ig-cool-color) clamp(0%, calc((var(--ig-hotness) / var(--ig-cool-threshold)) * 100%), 100%)),
      var(--ig-hot-color) clamp(0%, calc(((var(--ig-hotness) - var(--ig-cool-threshold)) / (1 - var(--ig-cool-threshold))) * 100%), 100%));
}

.ig-highlight {
  --ig-highlight-color: transparent;
  background-color: var(--ig-highlight-color);
}</style>
  <style>* {
  box-sizing: border-box;
}

:root {
  font-size: 0.875rem;
}

body {
  margin: 0;
  background-color: #e5e8ea;
  /* Font, and many other styles, taken from the Firefox Profiler/ */
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Noto Sans, Liberation Sans, Cantarell, Helvetica Neue, sans-serif;
}

#container {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}

.tweaks-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 1rem;
  border: 1px solid black;
  border-width: 1px 0 0 1px;
  background-color: white;
}</style>
</head>

<body>
  <div id="reactRoot"></div>
  <script>"use strict";var iongraph=(()=>{var kt=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)kt(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ue(t))!Ge.call(e,s)&&s!==n&&kt(e,s,{get:()=>t[s],enumerable:!(o=Ve(t,s))||o.enumerable});return e};var Ye=e=>Je(kt({},"__esModule",{value:!0}),e);var Yn={};We(Yn,{renderStandaloneUI:()=>Vn,renderWebUI:()=>zn});var lt,b,Jt,Ze,D,Vt,Yt,Zt,qt,St,xt,wt,qe,J={},Xt=[],Xe=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Y=Array.isArray;function B(e,t){for(var n in t)e[n]=t[n];return e}function Pt(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Z(e,t,n){var o,s,i,a={};for(i in t)i=="key"?o=t[i]:i=="ref"?s=t[i]:a[i]=t[i];if(arguments.length>2&&(a.children=arguments.length>3?lt.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(i in e.defaultProps)a[i]===void 0&&(a[i]=e.defaultProps[i]);return it(e,a,o,s,null)}function it(e,t,n,o,s){var i={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s??++Jt,__i:-1,__u:0};return s==null&&b.vnode!=null&&b.vnode(i),i}function M(e){return e.children}function C(e,t){this.props=e,this.context=t}function z(e,t){if(t==null)return e.__?z(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?z(e):null}function Kt(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return Kt(e)}}function Ut(e){(!e.__d&&(e.__d=!0)&&D.push(e)&&!at.__r++||Vt!=b.debounceRendering)&&((Vt=b.debounceRendering)||Yt)(at)}function at(){for(var e,t,n,o,s,i,a,r=1;D.length;)D.length>r&&D.sort(Zt),e=D.shift(),r=D.length,e.__d&&(n=void 0,o=void 0,s=(o=(t=e).__v).__e,i=[],a=[],t.__P&&((n=B({},o)).__v=o.__v+1,b.vnode&&b.vnode(n),Nt(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[s]:null,i,s??z(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,ee(i,n,a),o.__e=o.__=null,n.__e!=s&&Kt(n)));at.__r=0}function Qt(e,t,n,o,s,i,a,r,c,l,u){var d,f,p,h,_,m,g,v=o&&o.__k||Xt,x=t.length;for(c=Ke(n,t,v,c,x),d=0;d<x;d++)(p=n.__k[d])!=null&&(f=p.__i==-1?J:v[p.__i]||J,p.__i=d,m=Nt(e,p,f,s,i,a,r,c,l,u),h=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&Ct(f.ref,null,p),u.push(p.ref,p.__c||h,p)),_==null&&h!=null&&(_=h),(g=!!(4&p.__u))||f.__k===p.__k?c=te(p,c,e,g):typeof p.type=="function"&&m!==void 0?c=m:h&&(c=h.nextSibling),p.__u&=-7);return n.__e=_,c}function Ke(e,t,n,o,s){var i,a,r,c,l,u=n.length,d=u,f=0;for(e.__k=new Array(s),i=0;i<s;i++)(a=t[i])!=null&&typeof a!="boolean"&&typeof a!="function"?(c=i+f,(a=e.__k[i]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?it(null,a,null,null,null):Y(a)?it(M,{children:a},null,null,null):a.constructor==null&&a.__b>0?it(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,r=null,(l=a.__i=Qe(a,n,c,d))!=-1&&(d--,(r=n[l])&&(r.__u|=2)),r==null||r.__v==null?(l==-1&&(s>u?f--:s<u&&f++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,a.__u|=4))):e.__k[i]=null;if(d)for(i=0;i<u;i++)(r=n[i])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=z(r)),oe(r,r));return o}function te(e,t,n,o){var s,i;if(typeof e.type=="function"){for(s=e.__k,i=0;s&&i<s.length;i++)s[i]&&(s[i].__=e,t=te(s[i],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=z(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function q(e,t){return t=t||[],e==null||typeof e=="boolean"||(Y(e)?e.some(function(n){q(n,t)}):t.push(e)),t}function Qe(e,t,n,o){var s,i,a,r=e.key,c=e.type,l=t[n],u=l!=null&&(2&l.__u)==0;if(l===null&&e.key==null||u&&r==l.key&&c==l.type)return n;if(o>(u?1:0)){for(s=n-1,i=n+1;s>=0||i<t.length;)if((l=t[a=s>=0?s--:i++])!=null&&(2&l.__u)==0&&r==l.key&&c==l.type)return a}return-1}function Gt(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Xe.test(t)?n:n+"px"}function rt(e,t,n,o,s){var i,a;t:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||Gt(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||Gt(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")i=t!=(t=t.replace(qt,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?o?n.u=o.u:(n.u=St,e.addEventListener(t,i?wt:xt,i)):e.removeEventListener(t,i?wt:xt,i);else{if(s=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break t}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Wt(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=St++;else if(t.t<n.u)return;return n(b.event?b.event(t):t)}}}function Nt(e,t,n,o,s,i,a,r,c,l){var u,d,f,p,h,_,m,g,v,x,S,O,H,st,G,W,yt,$=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),i=[r=t.__e=n.__e]),(u=b.__b)&&u(t);t:if(typeof $=="function")try{if(g=t.props,v="prototype"in $&&$.prototype.render,x=(u=$.contextType)&&o[u.__c],S=u?x?x.props.value:u.__:o,n.__c?m=(d=t.__c=n.__c).__=d.__E:(v?t.__c=d=new $(g,S):(t.__c=d=new C(g,S),d.constructor=$,d.render=en),x&&x.sub(d),d.props=g,d.state||(d.state={}),d.context=S,d.__n=o,f=d.__d=!0,d.__h=[],d._sb=[]),v&&d.__s==null&&(d.__s=d.state),v&&$.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=B({},d.__s)),B(d.__s,$.getDerivedStateFromProps(g,d.__s))),p=d.props,h=d.state,d.__v=t,f)v&&$.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),v&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(v&&$.getDerivedStateFromProps==null&&g!==p&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(g,S),!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(g,d.__s,S)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(d.props=g,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(F){F&&(F.__=t)}),O=0;O<d._sb.length;O++)d.__h.push(d._sb[O]);d._sb=[],d.__h.length&&a.push(d);break t}d.componentWillUpdate!=null&&d.componentWillUpdate(g,d.__s,S),v&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(p,h,_)})}if(d.context=S,d.props=g,d.__P=e,d.__e=!1,H=b.__r,st=0,v){for(d.state=d.__s,d.__d=!1,H&&H(t),u=d.render(d.props,d.state,d.context),G=0;G<d._sb.length;G++)d.__h.push(d._sb[G]);d._sb=[]}else do d.__d=!1,H&&H(t),u=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++st<25);d.state=d.__s,d.getChildContext!=null&&(o=B(B({},o),d.getChildContext())),v&&!f&&d.getSnapshotBeforeUpdate!=null&&(_=d.getSnapshotBeforeUpdate(p,h)),W=u,u!=null&&u.type===M&&u.key==null&&(W=ne(u.props.children)),r=Qt(e,Y(W)?W:[W],t,n,o,s,i,a,r,c,l),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),m&&(d.__E=d.__=null)}catch(F){if(t.__v=null,c||i!=null)if(F.then){for(t.__u|=c?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;i[i.indexOf(r)]=null,t.__e=r}else{for(yt=i.length;yt--;)Pt(i[yt]);It(t)}else t.__e=n.__e,t.__k=n.__k,F.then||It(t);b.__e(F,t,n)}else i==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=tn(n.__e,t,n,o,s,i,a,c,l);return(u=b.diffed)&&u(t),128&t.__u?void 0:r}function It(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(It)}function ee(e,t,n){for(var o=0;o<n.length;o++)Ct(n[o],n[++o],n[++o]);b.__c&&b.__c(t,e),e.some(function(s){try{e=s.__h,s.__h=[],e.some(function(i){i.call(s)})}catch(i){b.__e(i,s.__v)}})}function ne(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:Y(e)?e.map(ne):B({},e)}function tn(e,t,n,o,s,i,a,r,c){var l,u,d,f,p,h,_,m=n.props,g=t.props,v=t.type;if(v=="svg"?s="http://www.w3.org/2000/svg":v=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),i!=null){for(l=0;l<i.length;l++)if((p=i[l])&&"setAttribute"in p==!!v&&(v?p.localName==v:p.nodeType==3)){e=p,i[l]=null;break}}if(e==null){if(v==null)return document.createTextNode(g);e=document.createElementNS(s,v,g.is&&g),r&&(b.__m&&b.__m(t,i),r=!1),i=null}if(v==null)m===g||r&&e.data==g||(e.data=g);else{if(i=i&&lt.call(e.childNodes),m=n.props||J,!r&&i!=null)for(m={},l=0;l<e.attributes.length;l++)m[(p=e.attributes[l]).name]=p.value;for(l in m)if(p=m[l],l!="children"){if(l=="dangerouslySetInnerHTML")d=p;else if(!(l in g)){if(l=="value"&&"defaultValue"in g||l=="checked"&&"defaultChecked"in g)continue;rt(e,l,null,p,s)}}for(l in g)p=g[l],l=="children"?f=p:l=="dangerouslySetInnerHTML"?u=p:l=="value"?h=p:l=="checked"?_=p:r&&typeof p!="function"||m[l]===p||rt(e,l,p,m[l],s);if(u)r||d&&(u.__html==d.__html||u.__html==e.innerHTML)||(e.innerHTML=u.__html),t.__k=[];else if(d&&(e.innerHTML=""),Qt(t.type=="template"?e.content:e,Y(f)?f:[f],t,n,o,v=="foreignObject"?"http://www.w3.org/1999/xhtml":s,i,a,i?i[0]:n.__k&&z(n,0),r,c),i!=null)for(l=i.length;l--;)Pt(i[l]);r||(l="value",v=="progress"&&h==null?e.removeAttribute("value"):h!=null&&(h!==e[l]||v=="progress"&&!h||v=="option"&&h!=m[l])&&rt(e,l,h,m[l],s),l="checked",_!=null&&_!=e[l]&&rt(e,l,_,m[l],s))}return e}function Ct(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(s){b.__e(s,n)}}function oe(e,t,n){var o,s;if(b.unmount&&b.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ct(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(i){b.__e(i,t)}o.base=o.__P=null}if(o=e.__k)for(s=0;s<o.length;s++)o[s]&&oe(o[s],t,n||typeof e.type!="function");n||Pt(e.__e),e.__c=e.__=e.__e=void 0}function en(e,t,n){return this.constructor(e,n)}function Lt(e,t,n){var o,s,i,a;t==document&&(t=document.documentElement),b.__&&b.__(e,t),s=(o=typeof n=="function")?null:n&&n.__k||t.__k,i=[],a=[],Nt(t,e=(!o&&n||t).__k=Z(M,null,[e]),s||J,J,t.namespaceURI,!o&&n?[n]:s?null:t.firstChild?lt.call(t.childNodes):null,i,!o&&n?n:s?s.__e:t.firstChild,o,a),ee(i,e,a)}lt=Xt.slice,b={__e:function(e,t,n,o){for(var s,i,a;t=t.__;)if((s=t.__c)&&!s.__)try{if((i=s.constructor)&&i.getDerivedStateFromError!=null&&(s.setState(i.getDerivedStateFromError(e)),a=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(e,o||{}),a=s.__d),a)return s.__E=s}catch(r){e=r}throw e}},Jt=0,Ze=function(e){return e!=null&&e.constructor==null},C.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=B({},this.state),typeof e=="function"&&(e=e(B({},n),this.props)),e&&B(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Ut(this))},C.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Ut(this))},C.prototype.render=M,D=[],Yt=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Zt=function(e,t){return e.__v.__b-t.__v.__b},at.__r=0,qt=/(PointerCapture)$|Capture$/i,St=0,xt=Wt(!1),wt=Wt(!0),qe=0;var X,w,Et,se,ut=0,pe=[],I=b,re=I.__b,ie=I.__r,ae=I.diffed,le=I.__c,ce=I.unmount,ue=I.__;function $t(e,t){I.__h&&I.__h(w,e,ut||t),ut=0;var n=w.__H||(w.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function N(e){return ut=1,fe(me,e)}function fe(e,t,n){var o=$t(X++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):me(void 0,t),function(r){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,r);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=w,!w.__f)){var s=function(r,c,l){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(f){return!!f.__c});if(u.every(function(f){return!f.__N}))return!i||i.call(this,r,c,l);var d=o.__c.props!==r;return u.forEach(function(f){if(f.__N){var p=f.__[0];f.__=f.__N,f.__N=void 0,p!==f.__[0]&&(d=!0)}}),i&&i.call(this,r,c,l)||d};w.__f=!0;var i=w.shouldComponentUpdate,a=w.componentWillUpdate;w.componentWillUpdate=function(r,c,l){if(this.__e){var u=i;i=void 0,s(r,c,l),i=u}a&&a.call(this,r,c,l)},w.shouldComponentUpdate=s}return o.__N||o.__}function L(e,t){var n=$t(X++,3);!I.__s&&_e(n.__H,t)&&(n.__=e,n.u=t,w.__H.__h.push(n))}function dt(e){return ut=5,he(function(){return{current:e}},[])}function he(e,t){var n=$t(X++,7);return _e(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function nn(){for(var e;e=pe.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ct),e.__H.__h.forEach(Tt),e.__H.__h=[]}catch(t){e.__H.__h=[],I.__e(t,e.__v)}}I.__b=function(e){w=null,re&&re(e)},I.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ue&&ue(e,t)},I.__r=function(e){ie&&ie(e),X=0;var t=(w=e.__c).__H;t&&(Et===w?(t.__h=[],w.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ct),t.__h.forEach(Tt),t.__h=[],X=0)),Et=w},I.diffed=function(e){ae&&ae(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(pe.push(t)!==1&&se===I.requestAnimationFrame||((se=I.requestAnimationFrame)||on)(nn)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Et=w=null},I.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ct),n.__h=n.__h.filter(function(o){return!o.__||Tt(o)})}catch(o){t.some(function(s){s.__h&&(s.__h=[])}),t=[],I.__e(o,n.__v)}}),le&&le(e,t)},I.unmount=function(e){ce&&ce(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ct(o)}catch(s){t=s}}),n.__H=void 0,t&&I.__e(t,n.__v))};var de=typeof requestAnimationFrame=="function";function on(e){var t,n=function(){clearTimeout(o),de&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);de&&(t=requestAnimationFrame(n))}function ct(e){var t=w,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),w=t}function Tt(e){var t=w;e.__c=e.__(),w=t}function _e(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function me(e,t){return typeof t=="function"?t(e):t}function an(e,t){for(var n in t)e[n]=t[n];return e}function ge(e,t){for(var n in e)if(n!=="__source"&&!(n in t))return!0;for(var o in t)if(o!=="__source"&&e[o]!==t[o])return!0;return!1}function ve(e,t){this.props=e,this.context=t}(ve.prototype=new C).isPureReactComponent=!0,ve.prototype.shouldComponentUpdate=function(e,t){return ge(this.props,e)||ge(this.state,t)};var be=b.__b;b.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),be&&be(e)};var co=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.forward_ref")||3911;var ln=b.__e;b.__e=function(e,t,n,o){if(e.then){for(var s,i=t;i=i.__;)if((s=i.__c)&&s.__c)return t.__e==null&&(t.__e=n.__e,t.__k=n.__k),s.__c(e,t)}ln(e,t,n,o)};var ye=b.unmount;function Pe(e,t,n){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(o){typeof o.__c=="function"&&o.__c()}),e.__c.__H=null),(e=an({},e)).__c!=null&&(e.__c.__P===n&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(o){return Pe(o,t,n)})),e}function Ne(e,t,n){return e&&n&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(o){return Ne(o,t,n)}),e.__c&&e.__c.__P===t&&(e.__e&&n.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=n)),e}function Mt(){this.__u=0,this.o=null,this.__b=null}function Ce(e){var t=e.__.__c;return t&&t.__a&&t.__a(e)}function pt(){this.i=null,this.l=null}b.unmount=function(e){var t=e.__c;t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),ye&&ye(e)},(Mt.prototype=new C).__c=function(e,t){var n=t.__c,o=this;o.o==null&&(o.o=[]),o.o.push(n);var s=Ce(o.__v),i=!1,a=function(){i||(i=!0,n.__R=null,s?s(r):r())};n.__R=a;var r=function(){if(!--o.__u){if(o.state.__a){var c=o.state.__a;o.__v.__k[0]=Ne(c,c.__c.__P,c.__c.__O)}var l;for(o.setState({__a:o.__b=null});l=o.o.pop();)l.forceUpdate()}};o.__u++||32&t.__u||o.setState({__a:o.__b=o.__v.__k[0]}),e.then(a,a)},Mt.prototype.componentWillUnmount=function(){this.o=[]},Mt.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),o=this.__v.__k[0].__c;this.__v.__k[0]=Pe(this.__b,n,o.__O=o.__P)}this.__b=null}var s=t.__a&&Z(M,null,e.fallback);return s&&(s.__u&=-33),[Z(M,null,t.__a?null:e.children),s]};var ke=function(e,t,n){if(++n[1]===n[0]&&e.l.delete(t),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(n=e.i;n;){for(;n.length>3;)n.pop()();if(n[1]<n[0])break;e.i=n=n[2]}};(pt.prototype=new C).__a=function(e){var t=this,n=Ce(t.__v),o=t.l.get(e);return o[0]++,function(s){var i=function(){t.props.revealOrder?(o.push(s),ke(t,e,o)):s()};n?n(i):i()}},pt.prototype.render=function(e){this.i=null,this.l=new Map;var t=q(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&t.reverse();for(var n=t.length;n--;)this.l.set(t[n],this.i=[1,0,this.i]);return e.children},pt.prototype.componentDidUpdate=pt.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,n){ke(e,n,t)})};var cn=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,un=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,dn=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,pn=/[A-Z0-9]/g,fn=typeof document<"u",hn=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};function Le(e,t,n){return t.__k==null&&(t.textContent=""),Lt(e,t),typeof n=="function"&&n(),e?e.__c:null}C.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(C.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var xe=b.event;function _n(){}function mn(){return this.cancelBubble}function gn(){return this.defaultPrevented}b.event=function(e){return xe&&(e=xe(e)),e.persist=_n,e.isPropagationStopped=mn,e.isDefaultPrevented=gn,e.nativeEvent=e};var Ee,vn={enumerable:!1,configurable:!0,get:function(){return this.class}},we=b.vnode;b.vnode=function(e){typeof e.type=="string"&&function(t){var n=t.props,o=t.type,s={},i=o.indexOf("-")===-1;for(var a in n){var r=n[a];if(!(a==="value"&&"defaultValue"in n&&r==null||fn&&a==="children"&&o==="noscript"||a==="class"||a==="className")){var c=a.toLowerCase();a==="defaultValue"&&"value"in n&&n.value==null?a="value":a==="download"&&r===!0?r="":c==="translate"&&r==="no"?r=!1:c[0]==="o"&&c[1]==="n"?c==="ondoubleclick"?a="ondblclick":c!=="onchange"||o!=="input"&&o!=="textarea"||hn(n.type)?c==="onfocus"?a="onfocusin":c==="onblur"?a="onfocusout":dn.test(a)&&(a=c):c=a="oninput":i&&un.test(a)?a=a.replace(pn,"-$&").toLowerCase():r===null&&(r=void 0),c==="oninput"&&s[a=c]&&(a="oninputCapture"),s[a]=r}}o=="select"&&s.multiple&&Array.isArray(s.value)&&(s.value=q(n.children).forEach(function(l){l.props.selected=s.value.indexOf(l.props.value)!=-1})),o=="select"&&s.defaultValue!=null&&(s.value=q(n.children).forEach(function(l){l.props.selected=s.multiple?s.defaultValue.indexOf(l.props.value)!=-1:s.defaultValue==l.props.value})),n.class&&!n.className?(s.class=n.class,Object.defineProperty(s,"className",vn)):(n.className&&!n.class||n.class&&n.className)&&(s.class=s.className=n.className),t.props=s}(e),e.$$typeof=cn,we&&we(e)};var Ie=b.__r;b.__r=function(e){Ie&&Ie(e),Ee=e.__c};var Se=b.diffed;b.diffed=function(e){Se&&Se(e);var t=e.props,n=e.__e;n!=null&&e.type==="textarea"&&"value"in t&&t.value!==n.value&&(n.value=t.value==null?"":t.value),Ee=null};function Te(e){return!!e.__k&&(Lt(null,e),!0)}function Bt(e){return{render:function(t){Le(t,e)},unmount:function(){Te(e)}}}function Ot(...e){let t=[];for(let n of e)if(typeof n=="string")t.push(n);else for(let[o,s]of Object.entries(n))s&&t.push(o);return t.join(" ")}function R(e,t,n={}){let o=t,s=[],i={get(){return o},set(a){o=a;for(let r of s)r(o)},valueOf(){return o},toString(){return String(o)},[Symbol.toPrimitive](a){return a==="string"?String(o):o},onChange(a){s.push(a)},initial:t,name:e,min:n.min??0,max:n.max??100,step:n.step??1};return(n.tweaksObject??Ht).add(i)}var ft=class{constructor(t){this.container=t.container,this.tweaks=[],this.callbacks=[]}add(t){let n=this.tweaks.find(l=>l.name===t.name);if(n)return n;this.tweaks.push(t);let o=document.createElement("div");this.container.appendChild(o),o.style.display="flex",o.style.alignItems="center",o.style.justifyContent="end",o.style.gap="0.5rem";let s=t.name.replace(/[a-zA-Z0-9]/g,"_"),i=document.createElement("label");o.appendChild(i),i.innerText=t.name,i.htmlFor=`tweak-${s}-input`;let a=document.createElement("input");o.appendChild(a),a.type="number",a.value=String(t),a.id=`tweak-${s}-input`,a.style.width="4rem",a.addEventListener("input",()=>{t.set(a.valueAsNumber)});let r=document.createElement("input");o.appendChild(r),r.type="range",r.value=String(t),r.min=String(t.min),r.max=String(t.max),r.step=t.step===0?"any":String(t.step),r.addEventListener("input",()=>{t.set(r.valueAsNumber)});let c=document.createElement("button");return o.appendChild(c),c.innerText="Reset",c.disabled=t.get()===t.initial,c.addEventListener("click",()=>{t.set(t.initial)}),t.onChange(l=>{a.value=String(l),r.value=String(l),c.disabled=t.get()===t.initial;for(let u of this.callbacks)u(t)}),t}onTweak(t){this.callbacks.push(t)}},$e=document.createElement("div");$e.classList.add("tweaks-panel");var Ht=new ft({container:$e});Ht.onTweak(e=>{window.dispatchEvent(new CustomEvent("tweak",{detail:e}))});window.tweaks=Ht;var bn=document.createElement("div"),yn=new ft({container:bn}),Me=R("Test Value",3,{tweaksObject:yn});Me.set(4);Me=4;function Dt(e,t,n){return Math.max(t,Math.min(n,e))}function ht(e,t,n,o){return(e-t)*Math.pow(n,o)+t}function y(e,t,n=!1){if(!e)if(n)console.error(t??"Assertion failed");else throw new Error(t??"Assertion failed")}function E(e,t){return y(e,t),e}var Ae=R("Debug?",0,{min:0,max:1}),T=20,K=44,P=16,A=60,j=12,Q=36,Be=16,tt=16,kn=R("Layout Iterations",2,{min:0,max:6}),Oe=R("Nearly Straight Threshold",30,{min:0,max:200}),xn=R("Nearly Straight Iterations",8,{min:0,max:10}),He=R("Stop At Pass",30,{min:0,max:30}),wn=1.5,In=.01,Sn=1,Pn=.1,_t=40;function mt(e){return e.attributes.includes("loopheader")}function Nn(e){return e.loopHeight!==void 0}function V(e){if(y(e),Nn(e))return e;throw new Error("Block is not a pseudo LoopHeader")}var gt=1,De=2,Rt=4,et=0,At=1,jt=new Proxy(console,{get(e,t){let n=e[t];return typeof n!="function"?n:+Ae?n.bind(e):()=>{}}}),vt=class{constructor(t,n,o={}){let s=n.mir.blocks;this.viewport=t;let i=t.getBoundingClientRect();this.viewportSize={x:i.width,y:i.height},this.graphContainer=document.createElement("div"),this.graphContainer.classList.add("ig-graph"),this.graphContainer.style.transformOrigin="top left",this.viewport.appendChild(this.graphContainer),this.pass=n,this.blocks=s,this.blocksInOrder=[...s].sort((u,d)=>u.id-d.id),this.blocksByID=new Map,this.blocksByPtr=new Map,this.insPtrsByID=new Map,this.insIDsByPtr=new Map,this.loops=[],this.sampleCounts=o.sampleCounts,this.maxSampleCounts=[0,0],this.heatmapMode=et;for(let[u,d]of this.sampleCounts?.totalLineHits??[])this.maxSampleCounts[et]=Math.max(this.maxSampleCounts[et],d);for(let[u,d]of this.sampleCounts?.selfLineHits??[])this.maxSampleCounts[At]=Math.max(this.maxSampleCounts[At],d);this.size={x:0,y:0},this.numLayers=0,this.zoom=1,this.translation={x:0,y:0},this.animating=!1,this.targetZoom=1,this.targetTranslation={x:0,y:0},this.startMousePos={x:0,y:0},this.lastMousePos={x:0,y:0},this.selectedBlockPtrs=new Set,this.lastSelectedBlockPtr=0,this.nav={visited:[],currentIndex:-1,siblings:[]},this.highlightedInstructions=[],this.instructionPalette=o.instructionPalette??[0,1,2,3,4].map(u=>`var(--ig-highlight-${u})`);let a=new Map;for(let u of n.lir.blocks)a.set(u.id,u);for(let u of s){y(u.ptr,"blocks must always have non-null ptrs"),this.blocksByID.set(u.id,u),this.blocksByPtr.set(u.ptr,u);for(let f of u.instructions)this.insPtrsByID.set(f.id,f.ptr),this.insIDsByPtr.set(f.ptr,f.id);if(u.lir=a.get(u.id)??null,u.lir)for(let f of u.lir.instructions)this.insPtrsByID.set(f.id,f.ptr),this.insIDsByPtr.set(f.ptr,f.id);let d=this.renderBlock(u);if(u.el=d,u.layer=-1,u.loopID=-1,u.attributes.includes("loopheader")){let f=u;f.loopHeight=0,f.parentLoop=null,f.outgoingEdges=[]}}for(let u of s)u.size={x:u.el.clientWidth,y:u.el.clientHeight};for(let u of s)if(u.preds=u.predecessors.map(d=>E(this.blocksByID.get(d))),u.succs=u.successors.map(d=>E(this.blocksByID.get(d))),mt(u)){let d=u.preds.filter(f=>f.attributes.includes("backedge"));y(d.length===1),u.backedge=d[0]}let[r,c,l]=this.layout();this.render(r,c,l),this.addEventListeners()}layout(){let t=this.blocks.filter(i=>i.predecessors.length===0);for(let i of t){let a=i;a.loopHeight=0,a.parentLoop=null,a.outgoingEdges=[],Object.defineProperty(a,"backedge",{get(){throw new Error("Accessed .backedge on a pseudo loop header! Don't do that.")},configurable:!0})}for(let i of t)this.findLoops(i),this.layer(i);let n=this.makeLayoutNodes();this.straightenEdges(n);let o=this.finagleJoints(n),s=this.verticalize(n,o);return[n,s,o]}findLoops(t,n=null){if(n===null&&(n=[t.id]),!(t.loopID>=0)){if(mt(t)){y(t.loopDepth===n.length);let o=n[n.length-1],s=V(this.blocksByID.get(o));t.parentLoop=s,n=[...n,t.id]}if(t.loopDepth<n.length-1?n=n.slice(0,t.loopDepth+1):t.loopDepth>=n.length&&(t.loopDepth=n.length-1),t.loopID=n[t.loopDepth],!t.attributes.includes("backedge"))for(let o of t.succs)this.findLoops(o,n)}}layer(t,n=0){if(t.attributes.includes("backedge")){t.layer=t.succs[0].layer;return}if(n<=t.layer)return;t.layer=Math.max(t.layer,n),this.numLayers=Math.max(t.layer+1,this.numLayers);let o=V(this.blocksByID.get(t.loopID));for(;o;)o.loopHeight=Math.max(o.loopHeight,t.layer-o.layer+1),o=o.parentLoop;for(let s of t.succs)s.loopDepth<t.loopDepth?V(this.blocksByID.get(t.loopID)).outgoingEdges.push(s):this.layer(s,n+1);if(mt(t))for(let s of t.outgoingEdges)this.layer(s,n+t.loopHeight)}makeLayoutNodes(){function t(r,c,l){r.dstNodes[c]=l,l.srcNodes.includes(r)||l.srcNodes.push(r)}let n;{let r={};for(let c of this.blocks)r[c.layer]||(r[c.layer]=[]),r[c.layer].push(c);n=Object.entries(r).map(([c,l])=>[Number(c),l]).sort((c,l)=>c[0]-l[0]).map(([c,l])=>l)}let o=0,s=n.map(()=>[]),i=[],a=new Map;for(let[r,c]of n.entries()){let l=[];for(let p of c)for(let h=i.length-1;h>=0;h--){let _=i[h];_.dstBlock===p&&(l.unshift(_),i.splice(h,1))}let u=new Map;for(let p of i){let h,_=u.get(p.dstBlock.id);if(_)t(p.src,p.srcPort,_),h=_;else{let m={id:o++,pos:{x:T,y:T},size:{x:0,y:0},block:null,srcNodes:[],dstNodes:[],dstBlock:p.dstBlock,jointOffsets:[],flags:0};t(p.src,p.srcPort,m),s[r].push(m),u.set(p.dstBlock.id,m),h=m}p.src=h,p.srcPort=0}let d=[];for(let p of c){let h=V(this.blocksByID.get(p.loopID));for(;mt(h);){let _=d.find(g=>g.loopID===h.id);_?_.block=p:d.push({loopID:h.id,block:p});let m=h.parentLoop;if(!m)break;h=m}}let f=[];for(let p of c){let h={id:o++,pos:{x:T,y:T},size:p.size,block:p,srcNodes:[],dstNodes:[],jointOffsets:[],flags:0};for(let _ of l)_.dstBlock===p&&t(_.src,_.srcPort,h);s[r].push(h),p.layoutNode=h;for(let _ of d.filter(m=>m.block===p)){let m=V(this.blocksByID.get(_.loopID)).backedge,g={id:o++,pos:{x:T,y:T},size:{x:0,y:0},block:null,srcNodes:[],dstNodes:[],dstBlock:m,jointOffsets:[],flags:0},v=a.get(m);v?t(g,0,v):(g.flags|=Rt,t(g,0,m.layoutNode)),s[r].push(g),a.set(m,g)}if(p.attributes.includes("backedge"))t(p.layoutNode,0,p.succs[0].layoutNode);else for(let[_,m]of p.succs.entries())m.attributes.includes("backedge")?f.push({src:h,srcPort:_,dstBlock:m}):i.push({src:h,srcPort:_,dstBlock:m})}for(let p of f){let h=E(a.get(p.dstBlock));t(p.src,p.srcPort,h)}}{let r=[];for(let l of Ln(s))l.srcNodes.length===0&&r.push(l);let c=new Set;for(let l of r){let u=l;for(;u.block===null&&u.srcNodes.length===0;)Cn(u),c.add(u),y(u.dstNodes.length===1),u=u.dstNodes[0]}for(let l of s)for(let u=l.length-1;u>=0;u--)c.has(l[u])&&l.splice(u,1)}for(let r of s){for(let c=0;c<r.length&&r[c].block===null;c++)r[c].flags|=gt;for(let c=r.length-1;c>=0&&r[c].block===null;c--)r[c].flags|=De}for(let r of s)for(let c of r){c.block?y(c.dstNodes.length===c.block.successors.length,`expected node ${c.id} for block ${c.block.id} to have ${c.block.successors.length} destination nodes, but got ${c.dstNodes.length} instead`):y(c.dstNodes.length===1,`expected dummy node ${c.id} to have only one destination node, but got ${c.dstNodes.length} instead`);for(let l=0;l<c.dstNodes.length;l++)y(c.dstNodes[l]!==void 0,`dst slot ${l} of node ${c.id} was undefined`)}return s}straightenEdges(t){let n=f=>{for(let p=0;p<f.length-1;p++){let h=f[p],_=f[p+1],m=h.block===null&&_.block!==null,g=h.pos.x+h.size.x+(m?P:0)+K;_.pos.x=Math.max(_.pos.x,g)}},o=()=>{for(let f of t)for(let p of f){if(p.block===null)continue;let h=p.block.loopID!==null?V(this.blocksByID.get(p.block.loopID)):null;if(h){let _=h.layoutNode;p.pos.x=Math.max(p.pos.x,_.pos.x)}}},s=()=>{let f=new Map;for(let p of Ft(t)){let h=p.dstBlock,_=p.pos.x;f.set(h,Math.max(f.get(h)??0,_))}for(let p of Ft(t)){let h=p.dstBlock,_=f.get(h);y(_,`no position for backedge ${h.id}`),p.pos.x=_}for(let p of t)n(p)},i=()=>{let f=new Map;for(let p of t){let h=0,_=0;for(;h<p.length;h++)if(!(p[h].flags&gt)){_=p[h].pos.x;break}for(h-=1,_-=K+P;h>=0;h--){let m=p[h];y(m.block===null&&m.flags&gt);let g=_;for(let v of m.srcNodes){let x=v.pos.x+v.dstNodes.indexOf(m)*A;x<g&&(g=x)}m.pos.x=g,_=m.pos.x-K,f.set(m.dstBlock,Math.min(f.get(m.dstBlock)??1/0,g))}}for(let p of Ft(t)){if(!(p.flags&gt))continue;let h=f.get(p.dstBlock);y(h,`no position for run to block ${p.dstBlock.id}`),p.pos.x=h}},a=()=>{for(let f=0;f<t.length-1;f++){let p=t[f];n(p);let h=-1;for(let _ of p)for(let[m,g]of _.dstNodes.entries()){let v=t[f+1].indexOf(g);if(v>h&&g.srcNodes[0]===_){let x=P+A*m,S=P,O=g.pos.x;g.pos.x=Math.max(g.pos.x,_.pos.x+x-S),g.pos.x!==O&&(h=v)}}}},r=()=>{for(let f of t){for(let p=f.length-1;p>=0;p--){let h=f[p];if(!h.block||h.block.attributes.includes("backedge"))continue;let _=[];for(let m of h.srcNodes){let g=P+m.dstNodes.indexOf(h)*A,v=P;_.push(m.pos.x+g-(h.pos.x+v))}for(let[m,g]of h.dstNodes.entries()){if(g.block===null&&g.dstBlock.attributes.includes("backedge"))continue;let v=P+m*A,x=P;_.push(g.pos.x+x-(h.pos.x+v))}if(!_.includes(0)){_=_.filter(m=>m>0).sort((m,g)=>m-g);for(let m of _){let g=!1;for(let v=p+1;v<f.length;v++){let x=f[v];if(x.flags&De)continue;let S=h.pos.x+m,O=h.pos.x+m+h.size.x,H=x.pos.x-K,st=x.pos.x+x.size.x+K;O>=H&&S<=st&&(g=!0)}if(!g){h.pos.x+=m;break}}}}n(f)}},c=()=>{for(let f=t.length-1;f>=0;f--){let p=t[f];n(p);for(let h of p)for(let _ of h.srcNodes){if(_.block!==null)continue;Math.abs(_.pos.x-h.pos.x)<=Oe&&(_.pos.x=Math.max(_.pos.x,h.pos.x),h.pos.x=Math.max(_.pos.x,h.pos.x))}}},l=()=>{for(let f=0;f<t.length;f++){let p=t[f];n(p);for(let h of p){if(h.dstNodes.length===0)continue;let _=h.dstNodes[0];if(_.block!==null)continue;Math.abs(_.pos.x-h.pos.x)<=Oe&&(_.pos.x=Math.max(_.pos.x,h.pos.x),h.pos.x=Math.max(_.pos.x,h.pos.x))}}};function u(f,p){let h=[];for(let _=0;_<p;_++)for(let m of f)h.push(m);return h}let d=[...u([a,o,s],kn),s,...u([c,l],xn),r,s,i];y(d.length<=(He.initial??1/0),`STOP_AT_PASS was too small - should be at least ${d.length}`),jt.group("Running passes");for(let[f,p]of d.entries())f<He&&(jt.log(p.name??p.toString()),p());jt.groupEnd()}finagleJoints(t){let n=[];for(let o of t){let s=[];for(let l of o)if(l.jointOffsets=new Array(l.dstNodes.length).fill(0),!l.block?.attributes.includes("backedge"))for(let[u,d]of l.dstNodes.entries()){let f=l.pos.x+P+A*u,p=d.pos.x+P;Math.abs(p-f)<2*j||s.push({x1:f,x2:p,src:l,srcPort:u,dst:d})}s.sort((l,u)=>l.x1-u.x1);let i=[],a=[];t:for(let l of s){let u=l.x2-l.x1>=0?i:a,d=null;for(let f=u.length-1;f>=0;f--){let p=u[f],h=!1;for(let _ of p){if(l.dst===_.dst){p.push(l);continue t}let m=Math.min(l.x1,l.x2),g=Math.max(l.x1,l.x2),v=Math.min(_.x1,_.x2),x=Math.max(_.x1,_.x2);if(g>=v&&m<=x){h=!0;break}}if(h)break;d=p}d?d.push(l):u.push([l])}let r=Math.max(0,i.length+a.length-1)*Be,c=-r/2;for(let l of[...i.reverse(),...a]){for(let u of l)u.src.jointOffsets[u.srcPort]=c;c+=Be}n.push(r)}return y(n.length===t.length),n}verticalize(t,n){let o=new Array(t.length),s=T;for(let i=0;i<t.length;i++){let a=t[i],r=0;for(let c of a)c.pos.y=s,r=Math.max(r,c.size.y);o[i]=r,s+=r+Q+n[i]+Q}return o}renderBlock(t){let n=document.createElement("div");this.graphContainer.appendChild(n),n.classList.add("ig-block","ig-bg-white");for(let r of t.attributes)n.classList.add(`ig-block-att-${r}`);n.setAttribute("data-ig-block-ptr",`${t.ptr}`),n.setAttribute("data-ig-block-id",`${t.id}`);let o="";t.attributes.includes("loopheader")?o=" (loop header)":t.attributes.includes("backedge")?o=" (backedge)":t.attributes.includes("splitedge")&&(o=" (split edge)");let s=document.createElement("div");s.classList.add("ig-block-header"),s.innerText=`Block ${t.id}${o}`,n.appendChild(s);let i=document.createElement("div");i.classList.add("ig-instructions"),n.appendChild(i);let a=document.createElement("table");if(t.lir){a.innerHTML=`
        <colgroup>
          <col style="width: 1px">
          <col style="width: auto">
          ${this.sampleCounts?`
            <col style="width: 1px">
            <col style="width: 1px">
          `:""}
        </colgroup>
        ${this.sampleCounts?`
          <thead>
            <tr>
              <th></th>
              <th></th>
              <th class="ig-f6">Total</th>
              <th class="ig-f6">Self</th>
            </tr>
          </thead>
        `:""}
      `;for(let r of t.lir.instructions)a.appendChild(this.renderLIRInstruction(r))}else{a.innerHTML=`
        <colgroup>
          <col style="width: 1px">
          <col style="width: auto">
          <col style="width: 1px">
        </colgroup>
      `;for(let r of t.instructions)a.appendChild(this.renderMIRInstruction(r))}if(i.appendChild(a),t.successors.length===2)for(let[r,c]of[1,0].entries()){let l=document.createElement("div");l.innerText=`${c}`,l.classList.add("ig-edge-label"),l.style.left=`${P+A*r}px`,n.appendChild(l)}return s.addEventListener("pointerdown",r=>{r.preventDefault(),r.stopPropagation()}),s.addEventListener("click",r=>{r.stopPropagation(),r.shiftKey||this.selectedBlockPtrs.clear(),this.setSelection([],t.ptr)}),n}render(t,n,o){for(let c of t)for(let l of c)if(l.block!==null){let u=l.block;u.el.style.left=`${l.pos.x}px`,u.el.style.top=`${l.pos.y}px`}let s=0,i=0;for(let c of t)for(let l of c)s=Math.max(s,l.pos.x+l.size.x+T),i=Math.max(i,l.pos.y+l.size.y+T);let a=document.createElementNS("http://www.w3.org/2000/svg","svg");this.graphContainer.appendChild(a);let r=(c,l)=>{for(let u of c)s=Math.max(s,u+T);for(let u of l)i=Math.max(i,u+T)};for(let c=0;c<t.length;c++){let l=t[c];for(let u of l){u.block||y(u.dstNodes.length===1,`dummy nodes must have exactly one destination, but dummy ${u.id} had ${u.dstNodes.length}`),y(u.dstNodes.length===u.jointOffsets.length,"must have a joint offset for each destination");for(let[d,f]of u.dstNodes.entries()){let p=u.pos.x+P+A*d,h=u.pos.y+u.size.y;if(u.block?.attributes.includes("backedge")){let _=u.block.succs[0],m=u.pos.x,g=u.pos.y+tt,v=_.layoutNode.pos.x+_.size.x,x=_.layoutNode.pos.y+tt,S=Bn(m,g,v,x);a.appendChild(S),r([m,v],[g,x])}else if(u.flags&Rt){let _=E(f.block),m=u.pos.x+P,g=u.pos.y+tt+j,v=_.layoutNode.pos.x+_.size.x,x=_.layoutNode.pos.y+tt,S=$n(m,g,v,x);a.appendChild(S),r([m,v],[g,x])}else if(f.block===null&&f.dstBlock.attributes.includes("backedge")){let _=f.pos.x+P,m=f.pos.y+(f.flags&Rt?tt+j:0);if(u.block===null){let g=h-Q,v=Tn(p,h,_,m,g,!1);a.appendChild(v),r([p,_],[h,m,g])}else{let g=h-u.size.y+n[c]+Q+o[c]/2+u.jointOffsets[d],v=Mn(p,h,_,m,g);a.appendChild(v),r([p,_],[h,m,g])}}else{let _=f.pos.x+P,m=f.pos.y,g=h-u.size.y+n[c]+Q+o[c]/2+u.jointOffsets[d],v=En(p,h,_,m,g,f.block!==null);a.appendChild(v),r([p,_],[h,m,g])}}}}if(a.setAttribute("width",`${s}`),a.setAttribute("height",`${i}`),this.size={x:s,y:i},+Ae)for(let c of t)for(let l of c){let u=document.createElement("div");u.innerHTML=`${l.id}<br>&lt;- ${l.srcNodes.map(d=>d.id)}<br>-&gt; ${l.dstNodes.map(d=>d.id)}<br>${l.flags}`,u.style.position="absolute",u.style.border="1px solid black",u.style.backgroundColor="white",u.style.left=`${l.pos.x}px`,u.style.top=`${l.pos.y}px`,u.style.whiteSpace="nowrap",this.graphContainer.appendChild(u)}this.updateHighlightedInstructions(),this.updateHotness()}renderMIRInstruction(t){let n=t.opcode.replace("->","\u2192").replace("<-","\u2190"),o=document.createElement("tr");o.classList.add("ig-ins","ig-ins-mir","ig-can-flash",...t.attributes.map(r=>`ig-ins-att-${r}`)),o.setAttribute("data-ig-ins-ptr",`${t.ptr}`),o.setAttribute("data-ig-ins-id",`${t.id}`);let s=document.createElement("td");s.classList.add("ig-ins-num"),s.innerText=`v${t.id}`,o.appendChild(s);let i=document.createElement("td");i.innerHTML=n.replace(/(v)(\d+)/g,(r,c,l)=>`<span class="ig-use ig-highlightable" data-ig-use="${l}">${c}${l}</span>`),o.appendChild(i);let a=document.createElement("td");return a.classList.add("ig-ins-type"),a.innerText=t.type==="None"?"":t.type,o.appendChild(a),s.addEventListener("pointerdown",r=>{r.preventDefault(),r.stopPropagation()}),s.addEventListener("click",()=>{this.toggleInstructionHighlight(t.ptr)}),i.querySelectorAll(".ig-use").forEach(r=>{r.addEventListener("pointerdown",c=>{c.preventDefault(),c.stopPropagation()}),r.addEventListener("click",c=>{let l=parseInt(E(r.getAttribute("data-ig-use")),10);this.jumpToInstruction(l,{zoom:1})})}),o}renderLIRInstruction(t){let n=t.opcode.replace("->","\u2192").replace("<-","\u2190"),o=document.createElement("tr");o.classList.add("ig-ins","ig-ins-lir","ig-hotness"),o.setAttribute("data-ig-ins-ptr",`${t.ptr}`),o.setAttribute("data-ig-ins-id",`${t.id}`);let s=document.createElement("td");s.classList.add("ig-ins-num"),s.innerText=String(t.id),o.appendChild(s);let i=document.createElement("td");if(i.innerText=n,o.appendChild(i),this.sampleCounts){let a=this.sampleCounts?.totalLineHits.get(t.id)??0,r=this.sampleCounts?.selfLineHits.get(t.id)??0,c=document.createElement("td");c.classList.add("ig-ins-samples"),c.classList.toggle("ig-text-dim",a===0),c.innerText=`${a}`,c.title="Color by total count",o.appendChild(c);let l=document.createElement("td");l.classList.add("ig-ins-samples"),l.classList.toggle("ig-text-dim",r===0),l.innerText=`${r}`,l.title="Color by self count",o.appendChild(l);for(let[u,d]of[c,l].entries())d.addEventListener("pointerdown",f=>{f.preventDefault(),f.stopPropagation()}),d.addEventListener("click",()=>{y(u===et||u===At),this.heatmapMode=u,this.updateHotness()})}return s.addEventListener("pointerdown",a=>{a.preventDefault(),a.stopPropagation()}),s.addEventListener("click",()=>{this.toggleInstructionHighlight(t.ptr)}),o}renderSelection(){this.graphContainer.querySelectorAll(".ig-block").forEach(t=>{let n=parseInt(E(t.getAttribute("data-ig-block-ptr")),10);t.classList.toggle("ig-selected",this.selectedBlockPtrs.has(n)),t.classList.toggle("ig-last-selected",this.lastSelectedBlockPtr===n)})}removeNonexistentHighlights(){this.highlightedInstructions=this.highlightedInstructions.filter(t=>this.graphContainer.querySelector(`.ig-ins[data-ig-ins-ptr="${t.ptr}"]`))}updateHighlightedInstructions(){for(let t of this.highlightedInstructions)y(this.highlightedInstructions.filter(n=>n.ptr===t.ptr).length===1,`instruction ${t.ptr} was highlighted more than once`);this.graphContainer.querySelectorAll(".ig-ins, .ig-use").forEach(t=>{On(t)});for(let t of this.highlightedInstructions){let n=this.instructionPalette[t.paletteColor%this.instructionPalette.length],o=this.graphContainer.querySelector(`.ig-ins[data-ig-ins-ptr="${t.ptr}"]`);if(o){Re(o,n);let s=this.insIDsByPtr.get(t.ptr);this.graphContainer.querySelectorAll(`.ig-use[data-ig-use="${s}"]`).forEach(i=>{Re(i,n)})}}}updateHotness(){this.graphContainer.querySelectorAll(".ig-ins-lir").forEach(t=>{y(t.classList.contains("ig-hotness"));let n=parseInt(E(t.getAttribute("data-ig-ins-id")),10),o=0;this.sampleCounts&&(o=((this.heatmapMode===et?this.sampleCounts.totalLineHits:this.sampleCounts.selfLineHits).get(n)??0)/this.maxSampleCounts[this.heatmapMode]),t.style.setProperty("--ig-hotness",`${o}`)})}addEventListeners(){this.viewport.addEventListener("wheel",n=>{n.preventDefault();let o=this.zoom;if(n.ctrlKey){o=Math.max(Pn,Math.min(Sn,this.zoom*Math.pow(wn,-n.deltaY*In)));let i=o/this.zoom-1;this.zoom=o;let{x:a,y:r}=this.viewport.getBoundingClientRect(),c=n.clientX-a-this.translation.x,l=n.clientY-r-this.translation.y;this.translation.x-=c*i,this.translation.y-=l*i}else this.translation.x-=n.deltaX,this.translation.y-=n.deltaY;let s=this.clampTranslation(this.translation,o);this.translation.x=s.x,this.translation.y=s.y,this.animating=!1,this.updatePanAndZoom()}),this.viewport.addEventListener("pointerdown",n=>{n.pointerType==="mouse"&&!(n.button===0||n.button===1)||(n.preventDefault(),this.viewport.setPointerCapture(n.pointerId),this.startMousePos={x:n.clientX,y:n.clientY},this.lastMousePos={x:n.clientX,y:n.clientY},this.animating=!1)}),this.viewport.addEventListener("pointermove",n=>{if(!this.viewport.hasPointerCapture(n.pointerId))return;let o=n.clientX-this.lastMousePos.x,s=n.clientY-this.lastMousePos.y;this.translation.x+=o,this.translation.y+=s,this.lastMousePos={x:n.clientX,y:n.clientY};let i=this.clampTranslation(this.translation,this.zoom);this.translation.x=i.x,this.translation.y=i.y,this.animating=!1,this.updatePanAndZoom()}),this.viewport.addEventListener("pointerup",n=>{this.viewport.releasePointerCapture(n.pointerId);let o=2,s=this.startMousePos.x-n.clientX,i=this.startMousePos.y-n.clientY;Math.abs(s)<=o&&Math.abs(i)<=o&&this.setSelection([]),this.animating=!1}),new ResizeObserver(n=>{y(n.length===1);let o=n[0].contentRect;this.viewportSize.x=o.width,this.viewportSize.y=o.height}).observe(this.viewport)}setSelection(t,n=0){this.setSelectionRaw(t,n),n?this.nav={visited:[n],currentIndex:0,siblings:[n]}:this.nav={visited:[],currentIndex:-1,siblings:[]}}setSelectionRaw(t,n){this.selectedBlockPtrs.clear();for(let o of[...t,n])this.blocksByPtr.has(o)&&this.selectedBlockPtrs.add(o);this.lastSelectedBlockPtr=this.blocksByPtr.has(n)?n:0,this.renderSelection()}navigate(t){let n=this.lastSelectedBlockPtr;if(t==="down"||t==="up")if(n){let o=E(this.blocksByPtr.get(n)),s=(t==="down"?o.successors:o.predecessors).map(a=>E(this.blocksByID.get(a)).ptr);o.ptr!==this.nav.visited[this.nav.currentIndex]&&(this.nav.visited=[o.ptr],this.nav.currentIndex=0);let i=this.nav.currentIndex+(t==="down"?1:-1);if(0<=i&&i<this.nav.visited.length)this.nav.currentIndex=i,this.nav.siblings=s;else{let a=s[0];a!==void 0&&(t==="down"?(this.nav.visited.push(a),this.nav.currentIndex+=1,y(this.nav.currentIndex===this.nav.visited.length-1)):(this.nav.visited.unshift(a),y(this.nav.currentIndex===0)),this.nav.siblings=s)}this.setSelectionRaw([],this.nav.visited[this.nav.currentIndex])}else{let o=this.blocksInOrder,s=o.filter(c=>c.predecessors.length===0),i=o.filter(c=>c.successors.length===0),a=t==="down"?s:i,r=a[0];y(r),this.setSelectionRaw([],r.ptr),this.nav={visited:[r.ptr],currentIndex:0,siblings:a.map(c=>c.ptr)}}else if(n!==void 0){let o=this.nav.siblings.indexOf(n);y(o>=0,"currently selected node should be in siblings array");let s=o+(t==="right"?1:-1);0<=s&&s<this.nav.siblings.length&&this.setSelectionRaw([],this.nav.siblings[s])}y(this.nav.visited.length===0||this.nav.siblings.includes(this.nav.visited[this.nav.currentIndex]),"expected currently visited node to be in the siblings array"),y(this.lastSelectedBlockPtr===0||this.nav.siblings.includes(this.lastSelectedBlockPtr),"expected currently selected block to be in siblings array")}toggleInstructionHighlight(t,n){this.removeNonexistentHighlights();let o=this.highlightedInstructions.findIndex(i=>i.ptr===t),s=o>=0;if(n!==void 0&&(s=!n),s)o>=0&&this.highlightedInstructions.splice(o,1);else if(o<0){let i=0;for(;;){if(this.highlightedInstructions.find(a=>a.paletteColor===i)){i+=1;continue}break}this.highlightedInstructions.push({ptr:t,paletteColor:i})}this.updateHighlightedInstructions()}clampTranslation(t,n){let o=_t-this.size.x*n,s=this.viewportSize.x-_t,i=_t-this.size.y*n,a=this.viewportSize.y-_t,r=Dt(t.x,o,s),c=Dt(t.y,i,a);return{x:r,y:c}}updatePanAndZoom(){let t=this.clampTranslation(this.translation,this.zoom);this.graphContainer.style.transform=`translate(${t.x}px, ${t.y}px) scale(${this.zoom})`}graph2viewport(t,n=this.translation,o=this.zoom){return{x:t.x*o+n.x,y:t.y*o+n.y}}viewport2graph(t,n=this.translation,o=this.zoom){return{x:(t.x-n.x)/o,y:(t.y-n.y)/o}}async goToGraphCoordinates(t,{zoom:n=this.zoom,animate:o=!0}){let s={x:-t.x*n,y:-t.y*n};if(!o){this.animating=!1,this.translation.x=s.x,this.translation.y=s.y,this.zoom=n,this.updatePanAndZoom(),await new Promise(a=>setTimeout(a,0));return}if(this.targetTranslation=s,this.targetZoom=n,this.animating)return;this.animating=!0;let i=performance.now();for(;this.animating;){let a=await new Promise(h=>requestAnimationFrame(h)),r=(a-i)/1e3;i=a;let c=1,l=.01,u=1e-6,d=this.targetTranslation.x-this.translation.x,f=this.targetTranslation.y-this.translation.y,p=this.targetZoom-this.zoom;if(this.translation.x=ht(this.translation.x,this.targetTranslation.x,u,r),this.translation.y=ht(this.translation.y,this.targetTranslation.y,u,r),this.zoom=ht(this.zoom,this.targetZoom,u,r),this.updatePanAndZoom(),Math.abs(d)<=c&&Math.abs(f)<=c&&Math.abs(p)<=l){this.translation.x=this.targetTranslation.x,this.translation.y=this.targetTranslation.y,this.zoom=this.targetZoom,this.animating=!1,this.updatePanAndZoom();break}}await new Promise(a=>setTimeout(a,0))}jumpToBlock(t,{zoom:n=this.zoom,animate:o=!0,viewportPos:s}={}){let i=this.blocksByPtr.get(t);if(!i)return Promise.resolve();let a;return s?a={x:i.layoutNode.pos.x-s.x/n,y:i.layoutNode.pos.y-s.y/n}:a=this.graphPosToCenterRect(i.layoutNode.pos,i.layoutNode.size,n),this.goToGraphCoordinates(a,{zoom:n,animate:o})}async jumpToInstruction(t,{zoom:n=this.zoom,animate:o=!0}){let s=this.graphContainer.querySelector(`.ig-ins[data-ig-ins-id="${t}"]`);if(!s)return;let i=s.getBoundingClientRect(),a=this.graphContainer.getBoundingClientRect(),r=(i.x-a.x)/this.zoom,c=(i.y-a.y)/this.zoom,l=i.width/this.zoom,u=i.height/this.zoom,d=this.graphPosToCenterRect({x:r,y:c},{x:l,y:u},n);s.classList.add("ig-flash"),await this.goToGraphCoordinates(d,{zoom:n,animate:o}),s.classList.remove("ig-flash")}graphPosToCenterRect(t,n,o){let s=this.viewportSize.x/o,i=this.viewportSize.y/o,a=Math.max(20/o,(s-n.x)/2),r=Math.max(20/o,(i-n.y)/2),c=t.x-a,l=t.y-r;return{x:c,y:l}}exportState(){let t={translation:this.translation,zoom:this.zoom,heatmapMode:this.heatmapMode,highlightedInstructions:this.highlightedInstructions,selectedBlockPtrs:this.selectedBlockPtrs,lastSelectedBlockPtr:this.lastSelectedBlockPtr,viewportPosOfSelectedBlock:void 0};return this.lastSelectedBlockPtr&&(t.viewportPosOfSelectedBlock=this.graph2viewport(E(this.blocksByPtr.get(this.lastSelectedBlockPtr)).layoutNode.pos)),t}restoreState(t,n){this.translation.x=t.translation.x,this.translation.y=t.translation.y,this.zoom=t.zoom,this.heatmapMode=t.heatmapMode,this.highlightedInstructions=t.highlightedInstructions,this.setSelection(Array.from(t.selectedBlockPtrs),t.lastSelectedBlockPtr),this.updatePanAndZoom(),this.updateHotness(),this.updateHighlightedInstructions(),n.preserveSelectedBlockPosition&&this.jumpToBlock(this.lastSelectedBlockPtr,{zoom:this.zoom,animate:!1,viewportPos:t.viewportPosOfSelectedBlock})}};function Cn(e){for(let t of e.dstNodes){let n=t.srcNodes.indexOf(e);y(n!==-1),t.srcNodes.splice(n,1)}}function*Ft(e){for(let t of e)for(let n of t)n.block===null&&(yield n)}function*Ln(e){for(let t of e)for(let n of t)n.block===null&&n.dstBlock.attributes.includes("backedge")&&(yield n)}function En(e,t,n,o,s,i,a=1){let r=j;y(t+r<=s&&s<o-r,`downward arrow: x1 = ${e}, y1 = ${t}, x2 = ${n}, y2 = ${o}, ym = ${s}, r = ${r} `,!0),a%2===1&&(e+=.5,n+=.5,s+=.5);let c="";if(c+=`M ${e} ${t} `,Math.abs(n-e)<2*r)c+=`C ${e} ${t+(o-t)/3} ${n} ${t+2*(o-t)/3} ${n} ${o} `;else{let d=Math.sign(n-e);c+=`L ${e} ${s-r} `,c+=`A ${r} ${r} 0 0 ${d>0?0:1} ${e+r*d} ${s} `,c+=`L ${n-r*d} ${s} `,c+=`A ${r} ${r} 0 0 ${d>0?1:0} ${n} ${s+r} `,c+=`L ${n} ${o} `}let l=document.createElementNS("http://www.w3.org/2000/svg","g"),u=document.createElementNS("http://www.w3.org/2000/svg","path");if(u.setAttribute("d",c),u.setAttribute("fill","none"),u.setAttribute("stroke","black"),u.setAttribute("stroke-width",`${a} `),l.appendChild(u),i){let d=bt(n,o,180);l.appendChild(d)}return l}function Tn(e,t,n,o,s,i,a=1){let r=j;y(o+r<=s&&s<=t-r,`upward arrow: x1 = ${e}, y1 = ${t}, x2 = ${n}, y2 = ${o}, ym = ${s}, r = ${r} `,!0),a%2===1&&(e+=.5,n+=.5,s+=.5);let c="";if(c+=`M ${e} ${t} `,Math.abs(n-e)<2*r)c+=`C ${e} ${t+(o-t)/3} ${n} ${t+2*(o-t)/3} ${n} ${o} `;else{let d=Math.sign(n-e);c+=`L ${e} ${s+r} `,c+=`A ${r} ${r} 0 0 ${d>0?1:0} ${e+r*d} ${s} `,c+=`L ${n-r*d} ${s} `,c+=`A ${r} ${r} 0 0 ${d>0?0:1} ${n} ${s-r} `,c+=`L ${n} ${o} `}let l=document.createElementNS("http://www.w3.org/2000/svg","g"),u=document.createElementNS("http://www.w3.org/2000/svg","path");if(u.setAttribute("d",c),u.setAttribute("fill","none"),u.setAttribute("stroke","black"),u.setAttribute("stroke-width",`${a} `),l.appendChild(u),i){let d=bt(n,o,0);l.appendChild(d)}return l}function $n(e,t,n,o,s=1){let i=j;y(t-i>=o&&e-i>=n,`to backedge: x1 = ${e}, y1 = ${t}, x2 = ${n}, y2 = ${o}, r = ${i} `,!0),s%2===1&&(e+=.5,o+=.5);let a="";a+=`M ${e} ${t} `,a+=`A ${i} ${i} 0 0 0 ${e-i} ${o} `,a+=`L ${n} ${o} `;let r=document.createElementNS("http://www.w3.org/2000/svg","g"),c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",a),c.setAttribute("fill","none"),c.setAttribute("stroke","black"),c.setAttribute("stroke-width",`${s} `),r.appendChild(c);let l=bt(n,o,270);return r.appendChild(l),r}function Mn(e,t,n,o,s,i=1){let a=j;y(t+a<=s&&e<=n&&o<=t,`block to backedge dummy: x1 = ${e}, y1 = ${t}, x2 = ${n}, y2 = ${o}, ym = ${s}, r = ${a} `,!0),i%2===1&&(e+=.5,n+=.5,s+=.5);let r="";r+=`M ${e} ${t} `,r+=`L ${e} ${s-a} `,r+=`A ${a} ${a} 0 0 0 ${e+a} ${s} `,r+=`L ${n-a} ${s} `,r+=`A ${a} ${a} 0 0 0 ${n} ${s-a} `,r+=`L ${n} ${o} `;let c=document.createElementNS("http://www.w3.org/2000/svg","g"),l=document.createElementNS("http://www.w3.org/2000/svg","path");return l.setAttribute("d",r),l.setAttribute("fill","none"),l.setAttribute("stroke","black"),l.setAttribute("stroke-width",`${i} `),c.appendChild(l),c}function Bn(e,t,n,o,s=1){y(n<e&&o===t,`x1 = ${e}, y1 = ${t}, x2 = ${n}, y2 = ${o} `,!0),s%2===1&&(t+=.5,o+=.5);let i="";i+=`M ${e} ${t} `,i+=`L ${n} ${o} `;let a=document.createElementNS("http://www.w3.org/2000/svg","g"),r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",i),r.setAttribute("fill","none"),r.setAttribute("stroke","black"),r.setAttribute("stroke-width",`${s} `),a.appendChild(r);let c=bt(n,o,270);return a.appendChild(c),a}function bt(e,t,n,o=5){let s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",`M 0 0 L ${-o} ${o*1.5} L ${o} ${o*1.5} Z`),s.setAttribute("transform",`translate(${e}, ${t}) rotate(${n})`),s}function Re(e,t){e.classList.add("ig-highlight"),e.style.setProperty("--ig-highlight-color",t)}function On(e){e.classList.remove("ig-highlight"),e.style.setProperty("--ig-highlight-color","transparent")}var je=Object.prototype.hasOwnProperty;function nt(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&nt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(je.call(e,n)&&++o&&!je.call(t,n)||!(n in t)||!nt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}var Hn=0,So=Array.isArray;function k(e,t,n,o,s,i){t||(t={});var a,r,c=t;if("ref"in c)for(r in c={},t)r=="ref"?a=t[r]:c[r]=t[r];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Hn,__i:-1,__u:0,__source:s,__self:i};if(typeof e=="function"&&(a=e.defaultProps))for(r in a)c[r]===void 0&&(c[r]=a[r]);return b.vnode&&b.vnode(l),l}function zt({func:e,pass:t=0,sampleCounts:n}){let o=dt(null),s=dt(null),[i,a]=N(t),[r,c]=N([null,null,null,null]),[l,u]=N([]);L(()=>{a(t)},[t]),L(()=>{{let f=[null,null,null,null],p=null;for(let[h,_]of e.passes.entries())_.mir.blocks.length>0&&(f[0]===null&&(f[0]=h),_.lir.blocks.length===0&&(f[1]=h)),_.lir.blocks.length>0&&(p?.lir.blocks.length===0&&(f[2]=h),f[3]=h),p=_;c(f)}{let f=[],p=null;for(let[h,_]of e.passes.entries()){if(p===null){p=_;continue}nt(p.mir,_.mir)&&nt(p.lir,_.lir)&&f.push(h),p=_}u(f)}},[e]);function d(f){if(o.current){let p=s.current?.exportState();if(o.current.innerHTML="",s.current=null,f)try{s.current=new vt(o.current,f,{sampleCounts:n}),p&&s.current.restoreState(p,{preserveSelectedBlockPosition:!0})}catch(h){o.current.innerHTML="An error occurred while laying out the graph. See console.",console.error(h)}}}return L(()=>{let f=e.passes[i];d(f);let p=()=>{d(f)};return window.addEventListener("tweak",p),()=>{window.removeEventListener("tweak",p)}},[e,i,n]),L(()=>{let f=p=>{switch(p.key){case"w":case"s":s.current?.navigate(p.key==="s"?"down":"up"),s.current?.jumpToBlock(s.current.lastSelectedBlockPtr);break;case"a":case"d":s.current?.navigate(p.key==="d"?"right":"left"),s.current?.jumpToBlock(s.current.lastSelectedBlockPtr);break;case"f":a(h=>{for(let _=h+1;_<e.passes.length;_++)if(!l.includes(_))return _;return h});break;case"r":a(h=>{for(let _=h-1;_>=0;_--)if(!l.includes(_))return _;return h});break;case"1":case"2":case"3":case"4":{let h=["1","2","3","4"].indexOf(p.key),_=r[h];typeof _=="number"&&a(_)}break;case"c":{let h=s.current?.blocksByPtr.get(s.current?.lastSelectedBlockPtr??-1);h&&o.current&&s.current?.jumpToBlock(h.ptr,{zoom:1})}break}};return window.addEventListener("keydown",f),()=>{window.removeEventListener("keydown",f)}},[e,r,l]),k("div",{className:"ig-absolute ig-absolute-fill ig-flex",children:[k("div",{className:"ig-w5 ig-br ig-flex-shrink-0 ig-overflow-y-auto ig-bg-white",children:e.passes.map((f,p)=>k("div",{children:k("a",{href:"#",className:Ot("ig-link-normal ig-pv1 ig-ph2 ig-flex ig-g2",{"ig-bg-primary":i===p}),onClick:h=>{h.preventDefault(),a(p)},children:[k("div",{className:"ig-w1 ig-tr ig-f6 ig-text-dim",style:{paddingTop:"0.08rem"},children:p}),k("div",{className:Ot({"ig-text-dim":l.includes(p)}),children:f.name})]})},p))}),k("div",{ref:o,className:"ig-flex-grow-1 ig-overflow-hidden",style:{position:"relative"}})]})}function ot(e){e.version===void 0&&(e.version=0);for(let t of e.functions)Dn(t,e.version);return e.version=1,e}function Dn(e,t){for(let n of e.passes){for(let o of n.mir.blocks)Rn(o,t);for(let o of n.lir.blocks)jn(o,t)}return e}function Rn(e,t){t===0&&(e.ptr=(e.id??e.number)+1,e.id=e.number);for(let n of e.instructions)An(n,t);return e}function An(e,t){return t===0&&(e.ptr=e.id),e}function jn(e,t){t===0&&(e.ptr=e.id??e.number,e.id=e.number);for(let n of e.instructions)Fn(n,t);return e}function Fn(e,t){return t===0&&(e.ptr=e.id,e.mirPtr=null),e}function zn(e){Bt(e).render(k(Gn,{}))}function Vn(e,t){let n=Bt(e),o=ot(t);n.render(k(Wn,{ionjson:o}))}var U=new URL(window.location.toString()).searchParams,Un=U.has("func")?parseInt(U.get("func"),10):void 0,Fe=U.has("pass")?parseInt(U.get("pass"),10):void 0;function ze(e){let[[t,n],o]=N([null,""]),[s,i]=N(Un??0);L(()=>{e.ionjson&&(o([e.ionjson,JSON.stringify(e.ionjson)]),e.funcSelected(e.ionjson.functions[s]??null))},[]),L(()=>{e.ionjson&&(o([e.ionjson,JSON.stringify(e.ionjson)]),e.funcSelected(e.ionjson.functions[s]??null))},[e.ionjson]),L(()=>{t&&e.funcSelected(t.functions[s]??null)},[s]);async function a(l){let u=l.target;if(!u.files?.length)return;let d=u.files[0],f=JSON.parse(await d.text()),p=ot(f);o([p,JSON.stringify(p)]),i(0),e.funcSelected(p.functions[0]??null)}let r=t?.functions.length??0,c=0<=s&&s<r;return k("div",{className:"ig-bb ig-flex ig-bg-white",children:[k("div",{className:"ig-pv2 ig-ph3 ig-flex ig-g2 ig-items-center ig-br",children:[e.browse&&k("div",{children:k("input",{type:"file",onChange:a})}),r>1&&k("div",{children:["Function ",k("input",{type:"number",min:"1",max:r,value:s+1,className:"ig-w3",onChange:l=>{let u=parseInt(l.target.value,10),d=Math.max(0,Math.min(r-1,u-1));i(isNaN(d)?0:d)}})," / ",r]}),t&&r===0&&k("div",{children:"No functions to display."})]}),k("div",{className:"ig-flex-grow-1 ig-pv2 ig-ph3 ig-flex ig-g2 ig-items-center",children:[c&&k("div",{children:t?.functions[s].name??""}),k("div",{className:"ig-flex-grow-1"}),e.export&&k("div",{children:k("button",{disabled:!c,onClick:()=>{Jn(t?.functions[s].name??"",n,{funcIndex:s})},children:"Export"})})]})]})}function Gn(){let[e,t]=N(),[n,o]=N(null),[s,i]=N();return L(()=>{(async()=>{let a=U.get("file");if(a){let c=await(await fetch(a)).json(),l;c.functions?l=ot(c):l=ot({functions:[c]}),t(l)}})(),(async()=>{let a=U.get("sampleCounts");if(a){let c=await(await fetch(a)).json();i({selfLineHits:new Map(c.selfLineHits),totalLineHits:new Map(c.totalLineHits)})}})()},[]),k("div",{className:"ig-absolute ig-absolute-fill ig-flex ig-flex-column",children:[k(ze,{browse:!0,export:!0,ionjson:e,funcSelected:a=>o(a)}),n&&k("div",{className:"ig-relative ig-flex-basis-0 ig-flex-grow-1 ig-overflow-hidden",children:k(zt,{func:n,pass:Fe,sampleCounts:s})})]})}function Wn(e){let[t,n]=N(null);return k("div",{className:"ig-absolute ig-absolute-fill ig-flex ig-flex-column",children:[k(ze,{ionjson:e.ionjson,funcSelected:o=>n(o)}),t&&k("div",{className:"ig-relative ig-flex-basis-0 ig-flex-grow-1 ig-overflow-hidden",children:k(zt,{func:t,pass:Fe})})]})}async function Jn(e,t,n={}){let o=t;if(n.funcIndex!==void 0){let u={version:1,functions:[JSON.parse(t).functions[n.funcIndex]]};o=JSON.stringify(u)}let i=(await(await fetch("./standalone.html")).text()).replace(/\{\{\s*IONJSON\s*\}\}/,o),a=URL.createObjectURL(new Blob([i],{type:"text/html;charset=utf-8"})),r=document.createElement("a");r.href=a,r.download=`iongraph-${e}.html`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(a)}return Ye(Yn);})();
</script>
  <script>window.__exportedIonJSON = {{ IONJSON }}</script>
  <script>
    iongraph.renderStandaloneUI(window.reactRoot, window.__exportedIonJSON);
  </script>
</body>