Hi, If x is a local variable, it will be stored on the stack. So you need an alloca for it: %x = alloca i8 ; <i8*> Then you can just perform a store: Store i8* %x, i8 0 Cheers, James> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of leledumbo > Sent: 20 October 2010 14:39 > To: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] Re : How to assign a constant to a register? > > > > from what you say, I assume you have some kind of representation(AST> or a > > lower-level intermediate representation) from which you generateLLVM> > assembly. > > Is this representation in SSA form? > > Yes, the representation is an AST. It's not in SSA yet, as it's a > direct > representation of the input. I'm confused for this node: > :> / \ > x 0 > > where x is a local variable. > > > If it is, you might want to do a "copy propagation" transformation > that > > replaces > > the uses of all variables that are assigned a constant value bytheir> > definitions. > > I'll consider it, it would useful for constant expression. > > -- > View this message in context: http://old.nabble.com/How-to-assign-a- > constant-to-a-register--tp29987387p30009972.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
> If x is a local variable, it will be stored on the stack. So you need an > alloca for it:Aha, I remember this in Kaleidoscope tutorial. So, after the alloca %x can be modified freely (e.g. without adding suffix)? -- View this message in context: http://old.nabble.com/How-to-assign-a-constant-to-a-register--tp29987387p30016496.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Hi, After the alloca, %x is of type i8* (i.e. a pointer to whatever type x is in your HLL). It can be mutated using the 'store' instruction. Note that if you want to read its value, you will have to perform a 'load' to a temporary - for example to increment 'x' by one: Load i8 %x.tmp1, i8* %x Add i8 %x.tmp2, i8 %x.tmp1, i8 1 Store i8* %x, %x.tmp2 Think of the LLVM architecture as like a load/store RISC machine, apart from it has infinite registers and each register can only be written to once. Cheers, James> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of leledumbo > Sent: 21 October 2010 07:20 > To: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] Re : How to assign a constant to a register? > > > > If x is a local variable, it will be stored on the stack. So youneed> an > > alloca for it: > > Aha, I remember this in Kaleidoscope tutorial. So, after the alloca %x > can > be modified freely (e.g. without adding suffix)? > -- > View this message in context: http://old.nabble.com/How-to-assign-a- > constant-to-a-register--tp29987387p30016496.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Matthieu Wipliez
2010-Oct-21 08:13 UTC
[LLVMdev] Re : Re : How to assign a constant to a register?
Yes, because an alloca allocates stack memory for %x, so this means that %x is a pointer, not a register in SSA form. So you need to use "load" and "store" to access the contents of the variable and to modify it respectively (as shown in the "Memory in LLVM" section: http://llvm.org/docs/tutorial/LangImpl7.html#memory ) Using local registers is less verbose (because you do not have all those load/store operations), and is not too hard to generate if you already have a representation in SSA form. On the other hand, using loads and stores does not require the SSA form, and the code will use registers anyway once the mem2reg pass is run. Matthieu ----- Message d'origine ----> De : leledumbo <leledumbo_cool at yahoo.co.id> > À : llvmdev at cs.uiuc.edu > Envoyé le : Jeu 21 octobre 2010, 8h 19min 53s > Objet : Re: [LLVMdev] Re : How to assign a constant to a register? > > > > If x is a local variable, it will be stored on the stack. So you need an > > alloca for it: > > Aha, I remember this in Kaleidoscope tutorial. So, after the alloca %x can > be modified freely (e.g. without adding suffix)? > -- > View this message in context: >http://old.nabble.com/How-to-assign-a-constant-to-a-register--tp29987387p30016496.html > > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Seemingly Similar Threads
- [LLVMdev] Re : How to assign a constant to a register?
- [LLVMdev] How to assign a constant to a register?
- [LLVMdev] How to assign a constant to a register?
- [LLVMdev] Bls: Compiling LLVM 2.7 with MinGW GCC 4.5.0
- [LLVMdev] Bls: Compiling LLVM 2.7 with MinGW GCC 4.5.0