compiler construction - Static Single Assignment for variables in different scopes -


i student learning compilers, , confused problem in ssa form.

as in many languages, c, there exists many scopes. variable in current scope may modified in other scopes, example, value of global variables can changed after calling function, makes optimization incorrect. furthermore, variable in current scope can modified using pointers.

what should deal such circumstance?

the simple, conservative solution problem describing involves never keeping copies of value if may change in ways difficult or impossible reason about.

so mean that? consider following c fragment:

void bar(void); int unsafe;  void foo(void) {     unsafe++; // 1     bar();     printf("%d\n", unsafe); // 2 } 

assume code compiled using compiler performs no interprocedural optimization or analysis. clearly, then, impossible compiler know whether or not call bar mutate unsafe. such, compiler must not keep copy of unsafe live across call bar. instead, value should read , written memory @ point #1, , read memory @ point #2.

bottom line: if cannot definitively prove it's safe keep copy of global variable live during portion of program's execution, must read and/or written memory every time accessed.

a similar problem arises pointers local variables, suggested:

void qux(void) {     int x;     int *px = &x;     x = 10;     *px = 100;     printf("%d\n", x); } 

a naïve compiler, failing detect x aliased, may incorrectly output 10 instead of 100. conservative solution similar here: if have local variable address taken, never keep copy around -- spill stack frame , load/store value needed. besides, have anyway in order x have address in first place!

notice there's nothing specific ssa form here. problems, , solutions, similar regardless of whether intermediate representation in ssa form or not.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -