llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.64k stars 11.84k forks source link

[AVR] Support the '__flash' attribute #30916

Closed dylanmckay closed 3 years ago

dylanmckay commented 7 years ago
Bugzilla Link 31568
Resolution FIXED
Resolved on Apr 10, 2021 03:00
Version trunk
OS All
CC @AnastasiaStulova,@asl,@dhebbeker,@benshi001

Extended Description

Support for the '__flash' keyword will need to be added in order to place data into program memory.

The parser will need to be modified to understand the keyword and then place data into the progmem address space.

Examples of LLVM IR placing variables in the program memory can be found in 'test/CodeGen/AVR/progmem.ll' in LLVM.

http://www.atmel.com/webdoc/AVRLibcReferenceManual/porting_1iar_porting_flash.html

benshi001 commented 3 years ago

fixed in https://reviews.llvm.org/rG4f173c0c42d02b14ab388a826ef0d463a07d7953

benshi001 commented 3 years ago

I have made a patch to make flash as a builtin macro attribute((addrspace(1))), along with error message if flash is not used the same way as gcc expected.

https://reviews.llvm.org/D96853

AnastasiaStulova commented 7 years ago

Clang supports an address_space attribute i.e. you could just define:

define flash attribute__((address_space(1)))

This attribute is undocumented unfortunately.

Or if you need to support __flash as a keyword you can simply map to address_spaces early in the parser. This is what we do in OpenCL for global, local, constant, generic.

dylanmckay commented 7 years ago

I don't think so, but there are parallels to this attribute in the OpenCL backend.

http://clang.llvm.org/docs/AttributeReference.html#opencl-address-spaces

asl commented 7 years ago

Ok. Do we have an attribute to specify an address space?

dylanmckay commented 7 years ago

The only thing required to place a variable into flash memory is to place it into address space '1'.

If we solely place the variable into a specific section, we won't be able to access it correctly because AVR (bring of the Harvard architecture) has separate instructions for accessing program memory, and accessing main memory.

asl commented 7 years ago

Can't you simply define flash as attribute__((section("foo"))

dylanmckay commented 7 years ago

assigned to @benshi001