how to get and modify a local variable's value through executionEngine?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get and modify a local variable's value through executionEngine?

Dong Chen
hello guys,
recently, i successfully get and modify global variable by execution engine.
the functions i used are listed here:
 int m=1;
 EE->updateGlobalMapping(p->M->getGlobalVariable("x",true),&m);
 EE->recompileAndRelinkFunction(EntryFn);
x is the global variable in the module.
but how to modify the local variable in the module?
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Óscar Fuentes
Dong Chen <[hidden email]> writes:

> hello guys,
> recently, i successfully get and modify global variable by execution engine.
> the functions i used are listed here:
>  int m=1;
>  EE->updateGlobalMapping(p->M->getGlobalVariable("x",true),&m);
>  EE->recompileAndRelinkFunction(EntryFn);
> x is the global variable in the module.
> but how to modify the local variable in the module?

A local variable does not exists until the function that defines it is
executed, so pretending to get and modify it as you do for the global
makes no sense.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Dong Chen
hello Óscar Fuentes,
thanks for your reply, if i use the API provided by parser.h and the program *.ll i parsed contains local variable, i can get a module have local variable without defines it first.
i think that module is a structure like AST(i am not sure whether i was right), this must be a traversal method. am i right or do i misunderstand something?
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Óscar Fuentes
Dong Chen <[hidden email]> writes:

> hello Óscar Fuentes,
> thanks for your reply, if i use the API provided by parser.h and the program
> *.ll i parsed contains local variable, i can get a module have local
> variable without defines it first.
> i think that module is a structure like AST(i am not sure whether i was
> right), this must be a traversal method. am i right or do i misunderstand
> something?

Yes, you can traverse the functions and the basic blocks inside those
functions, but how do you detect a local variable? LLVM IR is in SSA
form plus memory loads/stores. A local variable, as you see it in the
original source code (C, C++ or other language) might not clearly map to
a local variable in LLVM IR, depending on how you generate the IR and/or
the passes you run on it.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Dong Chen
hi Óscar Fuentes,
i am new to llvm, so i still have several questions. thanks for you help.
(1)what is SSA form(static single assignment)?
(2)how to traverse the basic blocks? if the module is gained by parser, what will the basic blocks contain?
i will be on the line, thank you very much
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Óscar Fuentes
Dong Chen <[hidden email]> writes:

> i am new to llvm, so i still have several questions. thanks for you help.
> (1)what is SSA form(static single assignment)?

Yes.

> (2)how to traverse the basic blocks? if the module is gained by parser, what
> will the basic blocks contain?

Once the LLVM IR bytecode is loaded (or the LLVM assembler is parsed)
you have the same C++ objects that you previously generated when you
emitted the IR from your compiler. As for traversing those C++ objects
for examining the IR or transforming it, see

See http://www.llvm.org/docs/WritingAnLLVMPass.html

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Dong Chen
hi Óscar Fuentes ,
thanks for your reply, but there are still a lot of concepts i don't understand. there seems to be some document to guide you but hard to understand. can you show me some basic and easy to learn document or websites?
thank you
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Óscar Fuentes
Dong Chen <[hidden email]> writes:

> thanks for your reply, but there are still a lot of concepts i don't
> understand. there seems to be some document to guide you but hard to
> understand. can you show me some basic and easy to learn document or
> websites?

What's missing from http://www.llvm.org/docs/ ?

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: how to get and modify a local variable's value through executionEngine?

Dong Chen
hello Óscar Fuentes,
can i change a local variable's value through iterator? have you ever tried that?