4ntoine / clang

AVR frontend for the LLVM project
http://clang.llvm.org/
Other
9 stars 1 forks source link

Add "section" attribute #2

Closed 4ntoine closed 10 years ago

4ntoine commented 10 years ago
__attribute__ ((section("name")))
4ntoine commented 10 years ago

Assume regular 'section' attribute is for ARM. Otherwise should revert:

def Section : InheritableAttr, TargetSpecificAttr<TargetARM>
4ntoine commented 10 years ago

Tested:

source:

#include <avr/io.h>

 __attribute__ ((section (".CSEG")))
const int i = 31;

int main()
{
    DDRB = 0x00;        //configure portB as input
    DDRC = 0xFF;        //configure portC as output

    while(1)
    {
        PORTC = PINB;
    }
    return 0;
}

generated bitcode:

; ModuleID = '/tmp/avr/Test1.c'
target datalayout = "e-p:16:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8"
target triple = "avr"

@i = constant i16 31, section ".CSEG", align 2

; Function Attrs: nounwind
define i16 @main() #0 {
entry:
  %retval = alloca i16, align 2
  store i16 0, i16* %retval
  store volatile i8 0, i8* inttoptr (i16 36 to i8*), align 1
  store volatile i8 -1, i8* inttoptr (i16 39 to i8*), align 1
  br label %while.body

while.body:                                       ; preds = %entry, %while.body
  %0 = load volatile i8* inttoptr (i16 35 to i8*), align 1
  store volatile i8 %0, i8* inttoptr (i16 40 to i8*), align 1
  br label %while.body

return:                                           ; No predecessors!
  %1 = load i16* %retval
  ret i16 %1
}

attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{!0}

!0 = metadata !{metadata !"clang version 3.6.0 (https://github.com/4ntoine/clang.git 2516492e3fe7fb4ed4aa25d733368035f6c17cde) (https://github.com/dylanmckay/llvm.git 1aea34ae240696b0c6f2903601a4a14da1244e1d)"}

seems to be ok

dylanmckay commented 10 years ago

Why is there a seperate section attribute for AVR? Can't we use the regular section attribute? It too adds the , section ".CSEG" qualifier to values, and the output seems to be the same.

4ntoine commented 10 years ago

They are almost identical.

Regular one:

def Section : InheritableAttr {
  let Spellings = [GCC<"section">, Declspec<"allocate">];
  let Args = [StringArgument<"Name">];
  let Subjects = SubjectList<[Function, GlobalVar,
                              ObjCMethod, ObjCProperty], ErrorDiag,
                             "ExpectedFunctionGlobalVarMethodOrProperty">;
  let Documentation = [SectionDocs];
}

AVR-specific:

def AVRSection : InheritableAttr, TargetSpecificAttr<TargetAVR> {
  let Spellings = [GNU<"section">];
  let Args = [StringArgument<"Name">];
  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag, "ExpectedFunctionGlobalVarMethodOrProperty">;
  let ParseKind = "Section";
  let Documentation = [SectionDocs];
}

I'm not sure about Declspec<"allocate"> and attribute usage in obj-c so it was removed. Probably should think about reverting. To be honest i've created new one and then found existing attribute with the same name

dylanmckay commented 10 years ago

Microsoft documents the allocate attribute as placing something in a specified section, so I believe the two attributes are semantically equivalent. Personally, I've never heard of it.

I'm not sure about Declspec<"allocate"> and attribute usage in obj-c so it was removed.

I'm not sure about obj-c either, but if we can use the regular Section attribute, which means touching less of clang's files and possibly supporting obj-c, it sounds like a good thing.

dylanmckay commented 10 years ago

Plus if we use the reguar Section, we don't have to handle it explicitly in AVR-LLVM and we can let the ELFObjectWriter class in LLVM handle it for us.

4ntoine commented 10 years ago

ok, agree. Reverted to use regular section attribute. But left TargetAVR declaration for future attributes