Alireza.Moshtaghi at microchip.com
2007-Sep-14 00:22 UTC
[LLVMdev] Embedded C Language Extensions
Cool, Let me list the things that I can think of for now : (Please feel free to add/modify/eliminate/prioritize/etc) 1) I am still reading the LLVM docs, could you give me pointers to stuff that is more relevant to this discussion so I get faster start. 2) As far as the Embedded C language extensions, for now, I am more interested in the address space, and after that work on the Fixed point and I/O registers. 3) As far as things related to the Address Space, the ISO report leaves some stuff to the implementation; we have to decide what we want to do about them: Eg: --how many Address Spaces do we want to support in the LLVM IR --what address space names do we want to add to the front-end --how best to model nested address spaces (if we want to support this in IR) --do we want to provide some kind of support (type inference stuff) for things like Automatic pointers that I mentioned earlier (in case some one wants to use them). I agree that this is against C language fundamentals, however, people are asking for them more and more and some compilers are actually trying to support them in weird ways, I think we can handle them in LLVM much better than how others do. But again, this is probably at the bottom of our list anyways! A. -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Chris Lattner Sent: Thursday, September 13, 2007 3:46 PM To: LLVM Developers Mailing List Subject: Re: [LLVMdev] PointerTypes with AddressSpace On Thu, 13 Sep 2007 Alireza.Moshtaghi at microchip.com wrote:> I think it all boils down to whether you think it is time toincorporate> these extensions into LLVM IR and how long do you think it will taketo> do so?Sure, any time is good. The reason we don't have this now is primarily because noone has stepped up to contribute it. If you're like to start this, I'd be happy to help with the design issues. -Chris> -----Original Message----- > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Chris Lattner > Sent: Wednesday, September 12, 2007 11:07 PM > To: LLVM Developers Mailing List > Subject: Re: [LLVMdev] PointerTypes with AddressSpace > > > On Sep 12, 2007, at 6:41 PM, <Alireza.Moshtaghi at microchip.com> > <Alireza.Moshtaghi at microchip.com> wrote: > >> Chris, >> Extending LLVM IR to support PointerTypes that take an address >> space is >> what I was hoping to avoid. However, if we want to do things right, >> that >> is probably the way to go. Now that we got here, let me write some >> of my >> thoughts on this and solicit your input: > > Okay, I agree that it's the right way to go. Also, being able to > eventually the Embedded C specification as Christopher points out > seems very useful :). > >> --- 1) Syntax extension: >> In our existing compiler for 8-bit microcontrollers, we have >> introduced >> rom and ram qualifiers (with ram being the default one) that can be >> applied to any type for example: >> rom int a; //integer in program memory >> rom int *a; //ram pointer to integer in rom >> int * rom a; //rom pointer to integer in ram >> rom int * rom a; //rom pointer to integer in rom >> Is something similar to the above what you also envision? > > As far as C syntax goes, I have no preference. I think that > following Embedded C makes the most sense. > >> --- 2) Automatic pointers: >> This is what we don't have in our existing compiler, but many >> people are >> asking for it. Would it be possible in LLVM to treat pointers as >> general >> all the way to code generation, and then decide its Address Space >> based >> on the following criteria? (we should be able to do so in an LLVMpass>> because at code generation time we have the full view of the program) >> -- a) Address Space of the pointer is the Address Space of the >> variable >> eg: ptr = &var; //AddSp of ptr becomes AddSp of var >> -- b) Address Space of the pointer is the address Space of thepointer>> eg: ptr1 = ptr2; //AddSp of ptr1 becomes AddSp of ptr2 >> -- c) Conflicts inside functions are not resolvable and should >> generate >> diagnostic. >> eg: >> void f(void){ >> generalPtr = romPtr; >> //some code >> generalPtr = ramPtr; // non resolvable conflict >> } > > This basically amounts to type inference. If you want this, it would > have to be implemented in the front-end, not in at the LLVM level > (you lose too much to give useful error reports etc). > > Type inference is very nice, but it is not in the spirit of C at > all. C is very explicit (to a fault perhaps). > >> -- d) Conflicts at the function interface will spawn a new function >> eg: >> void inc(int *a){ >> (*a)++; >> } >> void g(void){ >> inc(romPointer); // this will spawn an f with rom pointer >> inc(ramPointer); // this will spawn an f with ram pointer >> } >> >> In the case of (2) we still need rom and ram qualifiers to declare >> variables in the intended Address Space, however the impact on the >> front >> end will probably be reduced. >> A combination of (1) and (2) would probably be ideal. > > This again is a front-end issue. It sounds like you want generic > functions ala C++ templates. If you go down this path, you are > basically designing your own c-like language, you're not doing a > simple C extension (which is what Embedded C is). > > Regardless of whether you choose to make your own language or use > Embedded C, the LLVM support should be the same though. > > -Chris > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-Chris -- http://nondot.org/sabre/ http://llvm.org/ _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
My $0.02 On Sep 13, 2007, at 5:22 PM, <Alireza.Moshtaghi at microchip.com> <Alireza.Moshtaghi at microchip.com> wrote:> Eg: > --how many Address Spaces do we want to support in the LLVM IR > --what address space names do we want to add to the front-endI think that the name of the address spaces will need to be target specific, based on the target's front end. I'd guess that these would get mapped into a set of numbered address spaces that LLVM supports in the IR (and the target specific code generator). The number of address spaces that LLVM supports in the IR is mainly an encoding efficiency issue. I'd start with only a few (4 perhaps), as I believe that it should not be difficult to expand the number supported if a target appeared that needed them.> --how best to model nested address spaces (if we want to support > this in > IR)Supporting nested address spaces is simply a matter of constraining transformations that may be applied. I think that this is mostly a front end issue (correct me if I'm wrong Chris), and if there are parts that need to be dealt with in LLVM they can be added after basic address space support is available.> --do we want to provide some kind of support (type inference stuff) > for > things like Automatic pointers that I mentioned earlier (in case some > one wants to use them). I agree that this is against C language > fundamentals, however, people are asking for them more and more and > some > compilers are actually trying to support them in weird ways, I > think we > can handle them in LLVM much better than how others do. But again, > this > is probably at the bottom of our list anyways!I think that this is something that can be tackled after the basic address space support is in place. Here are some questions/suggestions that might help guide where to look through the code base and think about the design: * Where does the address space information need to be stored in the IR? Globals, function parameters that are pointers, alloca's, malloc's, GEP's? * What changes are required so that the address space info is preserved in the IR by existing passes? * Where is the address space information consumed in the back end? My guess is instruction selection, which means that the DAG node form of LD/ST will need to carry address space information. * What changes are required so that the address space info is preserved in the DAG nodes given existing transformations? Perhaps take a look at how other pointer attributes (volatile/ noalias) weave their way through the data flow to get an idea of these further attributes might be handled. Chris can most likely help answer those questions above and probably issues I haven't thought of as well =) -- Christopher Lamb
We'll have to introduce local load / store instructions. These look just like normal load / store except for the additional address space index bit. Alternatively, just add the address space information to load / store. I can see advantages to either approaches. Evan On Sep 13, 2007, at 6:56 PM, Christopher Lamb wrote:> > I think that this is something that can be tackled after the basic > address space support is in place. > > Here are some questions/suggestions that might help guide where to > look through the code base and think about the design: > * Where does the address space information need to be stored in the > IR? > Globals, function parameters that are pointers, alloca's, malloc's, > GEP's? > * What changes are required so that the address space info is > preserved in the IR by existing passes? > * Where is the address space information consumed in the back end? > My guess is instruction selection, which means that the DAG node > form of LD/ST will need to carry address space information. > * What changes are required so that the address space info is > preserved in the DAG nodes given existing transformations? > > Perhaps take a look at how other pointer attributes (volatile/ > noalias) weave their way through the data flow to get an idea of > these further attributes might be handled. > > Chris can most likely help answer those questions above and probably > issues I haven't thought of as well =) > > -- > Christopher Lamb > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev