Skip to content
  • Chris Lattner's avatar
    Change X86_64ABIInfo to have ASTContext and TargetData ivars to · 22a931e3
    Chris Lattner authored
    avoid passing ASTContext down through all the methods it has.
    
    When classifying an argument, or argument piece, as INTEGER, check
    to see if we have a pointer at exactly the same offset in the 
    preferred type.  If so, use that pointer type instead of i64.  This
    allows us to compile A function taking a stringref into something
    like this:
    
    define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
    entry:
      %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=4]
      %0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
      store i64 %D.coerce0, i64* %0
      %1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
      store i8* %D.coerce1, i8** %1
      %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
      %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
      %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
      %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
      %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
      ret i8* %add.ptr
    }
    
    instead of this:
    
    define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
    entry:
      %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
      %0 = insertvalue %0 undef, i64 %D.coerce0, 0    ; <%0> [#uses=1]
      %1 = insertvalue %0 %0, i64 %D.coerce1, 1       ; <%0> [#uses=1]
      %2 = bitcast %struct.DeclGroup* %D to %0*       ; <%0*> [#uses=1]
      store %0 %1, %0* %2, align 1
      %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
      %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
      %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
      %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
      %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
      ret i8* %add.ptr
    }
    
    This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
    
    llvm-svn: 107123
    22a931e3
Loading