Presentation is loading. Please wait.

Presentation is loading. Please wait.

Not referenced literal

Similar presentations


Presentation on theme: "Not referenced literal"— Presentation transcript:

1 Not referenced literal
Kei Hasegawa

2 Example void g(char*); int f(void) { } char a[] = "hello"; g(&a[0]);
return sizeof "world"; }

3 3 address code of `f' a[0] := 'h' a[1] := 'e' a[2] := 'l' a[3] := 'l'
a[4] := 'o' a[5] := '\0' t1 := &a param t1 call g return 6

4 Optimization of symbol table
Eliminate "hello", "world" from symbol table because of not referenced. This kind of elimination should be applied to constants 1.234L : long double type constant which may be located at memory. Of cause, should be appied to local variables and medium variables if not referenced.

5 Elimination not referenced literal is not so easy.
void f() { use literal1; use literal2; ... } void g() { not use any literal; } If all literals are eliminated, ... Backend generator has address descriptor for literal1, literal2, ... int x = 1; // If this is allocated at the same address where literali was allocated at the same address, ... Because backend generator doesn't know about literali elimination, backend generator does nothing for above declaration.

6 If a function is declared with static or inline, not so simple.
inline void f(void){ printf("`f' called\n"); } Code generation or inline substitution of `f' is skipped until `f' is referenced. void g(void){ ... } If eliminate "`f' called\n" because `g' doesn't reference to `f', ... void h(void){ ... f(); ... } h: ... t0 := &"`f' called\n" param t0 call printf As a result of inline substitution, "`f' called\n" is referenced but it doesn't exist in symbol table. Avoid this, it's necessary to judge a literal is referenced by some function which declared with static or inline. set<usr*> referenced_by_static_inline_function; // Simple but it works

7 Variables with initial value also reference literal like 3 address code.
char* p = "hello"; char a[] = "world"; void f(void){ ... } In code generation of `f', it's not correct to eliminate "hello". It's ok to eliminate "world" becase initial value of `a' are 'w', 'o', 'r', 'l', 'd', '\0'.

8 If a literal is referenced at the table which is different from symbol table, it cannot be eliminated simply. For optimization, constants are referenced at the another table map<string, vector<usr*> >& usrs = scope::root::m_usrs; for ( IT p = usrs.begin() ; p != usrs.end() ; ){ vector<usr*>& v = p->second; usr* u = v.back(); if (erasable(u, code) ) { // `code' is vector<3 address code> IT q = p++; usrs.erase(q); delete u; // NG. `u' may be constant<int> and it is referenced at the another table . } else ++p;


Download ppt "Not referenced literal"

Similar presentations


Ads by Google