Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling optimization when generating IR #579

Open
lavenzg opened this issue Nov 1, 2019 · 4 comments
Open

Disabling optimization when generating IR #579

lavenzg opened this issue Nov 1, 2019 · 4 comments
Assignees
Labels

Comments

@lavenzg
Copy link

lavenzg commented Nov 1, 2019

I tested a small program and found that some statements are optimized out when I print the IR. I can see those statements in the CAst. So I guess the optimization happens during the IR generation phase. Does anyone know how to disable them? In my case currently I need to get all IR for debugging purpose.

@msridhar
Copy link
Member

msridhar commented Nov 1, 2019

Unfortunately WALA IR invariants require this optimization, so there is no way to disable it. Hopefully with source mapping information and ASTs you can recover what you need.

@msridhar msridhar closed this as completed Nov 1, 2019
@lavenzg
Copy link
Author

lavenzg commented Nov 6, 2019

Then is it possible to prevent a variable to be optimized out? I am currently trying to converting python code to WALA IR (based on Ariadne). But I found global variable is optimized out and causes incorrect code:

g = 5

def test_global():
    global g
    g = 10
    print(g)

test_global()
print(g)

WALA IR:

23   global:global script test1.py/test_global = v43        test1.py [53:0] -> [61:8] [43=[test_global]]
24   putfield v1.< PythonLoader, LRoot, test_global, <PythonLoader,LRoot> > = v43test1.py [53:0] -> [61:8] [43=[test_global]]
25   v45 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v43 @25 exception:v46test1.py [60:0] -> [60:13] [43=[test_global]]
BB2
26   v48 = lexical:print@Lscript test1.py                   test1.py [61:0] -> [61:5]
27   v47 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v48,v40:#5 @27 exception:v49test1.py [61:0] -> [61:8] [40=[g]]
BB3

<Code body of function Lscript test1.py/test_global>
CFG:
BB0[-1..-2]
    -> BB1
BB1[0..2]
    -> BB2
BB2[-1..-2]
Instructions:
BB0
BB1
1   v6 = lexical:print@Lscript test1.py                     test1.py [58:4] -> [58:9]
2   v4 = invokeFunction < PythonLoader, LCodeBody, do()LRoot; > v6,v2:#10 @2 exception:v7test1.py [58:4] -> [58:12] [2=[g]]
BB2

The variable g should not be optimized, otherwise the output is wrong. Or is there any other way to fix this issue?

@msridhar
Copy link
Member

msridhar commented Nov 7, 2019

I don't know the Python frontend at all, but this sounds like a bug. @juliandolby?

@khatchad
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants