Heyu Zhu
2010-Jan-04 02:59 UTC
[LLVMdev] How to bind a register variable with a given general purpose register?
Hi everyone, There are 16 GPRs in my RISC, but in fact GPR13 is read-only and connected to output of an A/D converter. It would be very convenient if i could bind a register variable with GPR13. Because i am a newbie i don't know how my llvm backend can support that. I plan to implement it as below. A. first declare a global variable in c-code int ADC asm("GPR13"); B. If backend finds a variable is loaded from "GPR13" use GPR13 instead. C. backend can't allocate GPR13 to other variable Is it a foolish method? Is there a better one? Please give me some guidance Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100104/4fe5ac84/attachment.html>
ether
2010-Jan-04 08:36 UTC
[LLVMdev] How to bind a register variable with a given general purpose register?
hi zhu, i think you should map the peripheral registers to data memory space instead of register file, then mark that memory address as "volatile". like said the adc register was mapped to address 0xc0000, and then the corresponding c source will goes like this: //define the register #define ADCREG (*((volatile unsigned int *)0xc0000)) //read the register a = ADCREG --ether On 2010-1-4 10:59, Heyu Zhu wrote:> Hi everyone, > There are 16 GPRs in my RISC, but in fact GPR13 is read-only and > connected to output of an A/D converter. > It would be very convenient if i could bind a register variable with > GPR13. > Because i am a newbie i don't know how my llvm backend can support that. > I plan to implement it as below. > A. first declare a global variable in c-code > int ADC asm("GPR13"); > B. If backend finds a variable is loaded from "GPR13" use GPR13 instead. > C. backend can't allocate GPR13 to other variable > Is it a foolish method? Is there a better one? Please give me some > guidance > Thanks > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
ether
2010-Jan-04 11:29 UTC
[LLVMdev] 答复: [LLVMdev] How to bind a register variable with a given general purpose register?
hi zhu, i am not sure if your c frontend support "int ADC asm("GPR13");" i think you could: 1. add a attribute "GPR13"(or a more meaningful name like "adcreg") and the corresponding handler, so you code "int ADC asm("GPR13");" became "int ADC __attribute__((GPR13));" 2. add a intrinsic functions like "llvm.zhu.readadcreg()". 3. map any read to the variable marked with __attribute__((GPR13)) to llvm.zhu.readadcreg() instead of "load" instruction 4. assign gpr13 to a special register class like "gpr13class" instead of gprclass, so gpr13 will not be allocated as other gpr. 5. lower instrinisic functions "llvm.zhu.readadcreg()" to register node "gpr13" in your backend. regards --ether On 2010-1-4 18:01, Demon(Xiangyang) Zhu 朱向阳 wrote:> Hi Ether, > > The hardware had been fixed now. > If map it to memory space, it will cost another instruction cycle to execute 'a = ADCREG', > Algorithm accesses the A/D convert very frequently. To get higher precision at lower frequency > A/D output is connected to R13 directly. For the moment algorithm code is something like > assemble and difficult to maintain. I want to setup a c environment for it, but i don't know > how to bind a register variable with a given general purpose register. > > Thanks! > > ________________________________________ > 发件人: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] 代表 ether [etherzhhb at gmail.com] > 发送时间: 2010年1月4日 0:36 > 收件人: llvmdev at cs.uiuc.edu > 主题: Re: [LLVMdev] How to bind a register variable with a given general purpose register? > > hi zhu, > > i think you should map the peripheral registers to data memory space > instead of register file, then mark that memory address as "volatile". > like said the adc register was mapped to address 0xc0000, and then the > corresponding c source will goes like this: > //define the register > #define ADCREG (*((volatile unsigned int *)0xc0000)) > //read the register > a = ADCREG > > --ether > > On 2010-1-4 10:59, Heyu Zhu wrote: > >> Hi everyone, >> There are 16 GPRs in my RISC, but in fact GPR13 is read-only and >> connected to output of an A/D converter. >> It would be very convenient if i could bind a register variable with >> GPR13. >> Because i am a newbie i don't know how my llvm backend can support that. >> I plan to implement it as below. >> A. first declare a global variable in c-code >> int ADC asm("GPR13"); >> B. If backend finds a variable is loaded from "GPR13" use GPR13 instead. >> C. backend can't allocate GPR13 to other variable >> Is it a foolish method? Is there a better one? Please give me some >> guidance >> Thanks >> >> >> _______________________________________________ >> 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
Anton Korobeynikov
2010-Jan-04 12:00 UTC
[LLVMdev] How to bind a register variable with a given general purpose register?
Hello> Is it a foolish method? Is there a better one? Please give me some guidanceInline assembler is your friend. Also, do not forget to mark this register as unallocable, so codegen won't use / clobber it. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
ether
2010-Jan-04 13:37 UTC
[LLVMdev] 答复: 答复: [LLVMdev] How to bind a register variable with a given general purpose register?
or you can just add a built-in function in c frontend "readadcreg()" and emit it as llvm.zhu.readadcreg(), so you can just call the built-in function to get the adc register value. On 2010-1-4 21:27, Demon(Xiangyang) Zhu 朱向阳 wrote:> Hi Ether, > > Thank you very much. I will try it soon as your description. > > Regards > > ________________________________________ > 发件人: ether [etherzhhb at gmail.com] > 发送时间: 2010年1月4日 3:29 > 收件人: Demon(Xiangyang) Zhu 朱向阳 > 抄送: llvmdev at cs.uiuc.edu > 主题: Re: 答复: [LLVMdev] How to bind a register variable with a given general purpose register? > > hi zhu, > > i am not sure if your c frontend support "int ADC asm("GPR13");" > i think you could: > > 1. add a attribute "GPR13"(or a more meaningful name like "adcreg") and > the corresponding handler, so you code "int ADC asm("GPR13");" became > "int ADC __attribute__((GPR13));" > 2. add a intrinsic functions like "llvm.zhu.readadcreg()". > 3. map any read to the variable marked with __attribute__((GPR13)) to > llvm.zhu.readadcreg() instead of "load" instruction > 4. assign gpr13 to a special register class like "gpr13class" instead of > gprclass, so gpr13 will not be allocated as other gpr. > 5. lower instrinisic functions "llvm.zhu.readadcreg()" to register node > "gpr13" in your backend. > > regards > > --ether > > On 2010-1-4 18:01, Demon(Xiangyang) Zhu 朱向阳 wrote: > >> Hi Ether, >> >> The hardware had been fixed now. >> If map it to memory space, it will cost another instruction cycle to execute 'a = ADCREG', >> Algorithm accesses the A/D convert very frequently. To get higher precision at lower frequency >> A/D output is connected to R13 directly. For the moment algorithm code is something like >> assemble and difficult to maintain. I want to setup a c environment for it, but i don't know >> how to bind a register variable with a given general purpose register. >> >> Thanks! >> >> ________________________________________ >> 发件人: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] 代表 ether [etherzhhb at gmail.com] >> 发送时间: 2010年1月4日 0:36 >> 收件人: llvmdev at cs.uiuc.edu >> 主题: Re: [LLVMdev] How to bind a register variable with a given general purpose register? >> >> hi zhu, >> >> i think you should map the peripheral registers to data memory space >> instead of register file, then mark that memory address as "volatile". >> like said the adc register was mapped to address 0xc0000, and then the >> corresponding c source will goes like this: >> //define the register >> #define ADCREG (*((volatile unsigned int *)0xc0000)) >> //read the register >> a = ADCREG >> >> --ether >> >> On 2010-1-4 10:59, Heyu Zhu wrote: >> >> >>> Hi everyone, >>> There are 16 GPRs in my RISC, but in fact GPR13 is read-only and >>> connected to output of an A/D converter. >>> It would be very convenient if i could bind a register variable with >>> GPR13. >>> Because i am a newbie i don't know how my llvm backend can support that. >>> I plan to implement it as below. >>> A. first declare a global variable in c-code >>> int ADC asm("GPR13"); >>> B. If backend finds a variable is loaded from "GPR13" use GPR13 instead. >>> C. backend can't allocate GPR13 to other variable >>> Is it a foolish method? Is there a better one? Please give me some >>> guidance >>> Thanks >>> >>> >>> _______________________________________________ >>> 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
Kenneth Uildriks
2010-Jan-04 13:44 UTC
[LLVMdev] How to bind a register variable with a given general purpose register?
On Sun, Jan 3, 2010 at 8:59 PM, Heyu Zhu <zhu.heyu at gmail.com> wrote:> Hi everyone, > > There are 16 GPRs in my RISC, but in fact GPR13 is read-only and connected > to output of an A/D converter. > It would be very convenient if i could bind a register variable with GPR13. > > Because i am a newbie i don't know how my llvm backend can support that. > > I plan to implement it as below. > > A. first declare a global variable in c-code > int ADC asm("GPR13"); > B. If backend finds a variable is loaded from "GPR13" use GPR13 instead. > C. backend can't allocate GPR13 to other variable > > Is it a foolish method? Is there a better one? Please give me some guidance > > Thanks > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >If your end goal is to allow programs to use the output of the A/D converter, my recommendation would be to create a platform-specific intrinsic function that returns the output of the A/D converter, and have your back-end refuse to allocate GPR13 as a register. The intrinsic function would of course simply cough up the value of GPR13, which would then be available for use in the program.
Seemingly Similar Threads
- [LLVMdev] 答复: 答复: [LLVMdev] How to bind a register variable with a given general purpose register?
- [LLVMdev] 答复: [LLVMdev] How to bind a register variable with a given general purpose register?
- [LLVMdev] Problem when build LLVM
- [LLVMdev] Does mips backend support variable arguments in release version(llvm-2.6)?
- [LLVMdev] Problem when build LLVM