Skip to content
  1. Dec 12, 2012
  2. Dec 11, 2012
    • Bill Schmidt's avatar
      This patch implements the general dynamic TLS model for 64-bit PowerPC. · c56f1d34
      Bill Schmidt authored
      Given a thread-local symbol x with global-dynamic access, the generated
      code to obtain x's address is:
      
           Instruction                            Relocation            Symbol
        addis ra,r2,x@got@tlsgd@ha           R_PPC64_GOT_TLSGD16_HA       x
        addi  r3,ra,x@got@tlsgd@l            R_PPC64_GOT_TLSGD16_L        x
        bl __tls_get_addr(x@tlsgd)           R_PPC64_TLSGD                x
                                             R_PPC64_REL24           __tls_get_addr
        nop
        <use address in r3>
      
      The implementation borrows from the medium code model work for introducing
      special forms of ADDIS and ADDI into the DAG representation.  This is made
      slightly more complicated by having to introduce a call to the external
      function __tls_get_addr.  Using the full call machinery is overkill and,
      more importantly, makes it difficult to add a special relocation.  So I've
      introduced another opcode GET_TLS_ADDR to represent the function call, and
      surrounded it with register copies to set up the parameter and return value.
      
      Most of the code is pretty straightforward.  I ran into one peculiarity
      when I introduced a new PPC opcode BL8_NOP_ELF_TLSGD, which is just like
      BL8_NOP_ELF except that it takes another parameter to represent the symbol
      ("x" above) that requires a relocation on the call.  Something in the 
      TblGen machinery causes BL8_NOP_ELF and BL8_NOP_ELF_TLSGD to be treated
      identically during the emit phase, so this second operand was never
      visited to generate relocations.  This is the reason for the slightly
      messy workaround in PPCMCCodeEmitter.cpp:getDirectBrEncoding().
      
      Two new tests are included to demonstrate correct external assembly and
      correct generation of relocations using the integrated assembler.
      
      Comments welcome!
      
      Thanks,
      Bill
      
      llvm-svn: 169910
      c56f1d34
    • Eli Bendersky's avatar
      Remove the RelaxAll overrule in MCAssembler::fixupNeedsRelaxation, · 0f74f173
      Eli Bendersky authored
      because that method is only getting called for MCInstFragment. These
      fragments aren't even generated when RelaxAll is set, which is why the
      flag reference here is superfluous. Removing it simplifies the code
      with no harmful effects.
      
      An assertion is added higher up to make sure this path is never
      reached.
      
      llvm-svn: 169886
      0f74f173
  3. Dec 10, 2012
  4. Dec 08, 2012
  5. Dec 07, 2012
  6. Dec 06, 2012
  7. Dec 05, 2012
  8. Dec 04, 2012
    • Bill Schmidt's avatar
      This patch introduces initial-exec model support for thread-local storage · ca4a0c9d
      Bill Schmidt authored
      on 64-bit PowerPC ELF.
      
      The patch includes code to handle external assembly and MC output with the
      integrated assembler.  It intentionally does not support the "old" JIT.
      
      For the initial-exec TLS model, the ABI requires the following to calculate
      the address of external thread-local variable x:
      
       Code sequence            Relocation                  Symbol
        ld 9,x@got@tprel(2)      R_PPC64_GOT_TPREL16_DS      x
        add 9,9,x@tls            R_PPC64_TLS                 x
      
      The register 9 is arbitrary here.  The linker will replace x@got@tprel
      with the offset relative to the thread pointer to the generated GOT
      entry for symbol x.  It will replace x@tls with the thread-pointer
      register (13).
      
      The two test cases verify correct assembly output and relocation output
      as just described.
      
      PowerPC-specific selection node variants are added for the two
      instructions above:  LD_GOT_TPREL and ADD_TLS.  These are inserted
      when an initial-exec global variable is encountered by
      PPCTargetLowering::LowerGlobalTLSAddress(), and later lowered to
      machine instructions LDgotTPREL and ADD8TLS.  LDgotTPREL is a pseudo
      that uses the same LDrs support added for medium code model's LDtocL,
      with a different relocation type.
      
      The rest of the processing is straightforward.
      
      llvm-svn: 169281
      ca4a0c9d
    • Chandler Carruth's avatar
      Sort includes for all of the .h files under the 'lib' tree. These were · 802d7555
      Chandler Carruth authored
      missed in the first pass because the script didn't yet handle include
      guards.
      
      Note that the script is now able to handle all of these headers without
      manual edits. =]
      
      llvm-svn: 169224
      802d7555
  9. Dec 03, 2012
    • Chandler Carruth's avatar
      Use the new script to sort the includes of every file under lib. · ed0881b2
      Chandler Carruth authored
      Sooooo many of these had incorrect or strange main module includes.
      I have manually inspected all of these, and fixed the main module
      include to be the nearest plausible thing I could find. If you own or
      care about any of these source files, I encourage you to take some time
      and check that these edits were sensible. I can't have broken anything
      (I strictly added headers, and reordered them, never removed), but they
      may not be the headers you'd really like to identify as containing the
      API being implemented.
      
      Many forward declarations and missing includes were added to a header
      files to allow them to parse cleanly when included first. The main
      module rule does in fact have its merits. =]
      
      llvm-svn: 169131
      ed0881b2
  10. Dec 01, 2012
  11. Nov 30, 2012
  12. Nov 28, 2012
  13. Nov 27, 2012
    • Bill Schmidt's avatar
      This patch implements medium code model support for 64-bit PowerPC. · 34627e34
      Bill Schmidt authored
      The default for 64-bit PowerPC is small code model, in which TOC entries
      must be addressable using a 16-bit offset from the TOC pointer.  Additionally,
      only TOC entries are addressed via the TOC pointer.
      
      With medium code model, TOC entries and data sections can all be addressed
      via the TOC pointer using a 32-bit offset.  Cooperation with the linker
      allows 16-bit offsets to be used when these are sufficient, reducing the
      number of extra instructions that need to be executed.  Medium code model
      also does not generate explicit TOC entries in ".section toc" for variables
      that are wholly internal to the compilation unit.
      
      Consider a load of an external 4-byte integer.  With small code model, the
      compiler generates:
      
      	ld 3, .LC1@toc(2)
      	lwz 4, 0(3)
      
      	.section	.toc,"aw",@progbits
      .LC1:
      	.tc ei[TC],ei
      
      With medium model, it instead generates:
      
      	addis 3, 2, .LC1@toc@ha
      	ld 3, .LC1@toc@l(3)
      	lwz 4, 0(3)
      
      	.section	.toc,"aw",@progbits
      .LC1:
      	.tc ei[TC],ei
      
      Here .LC1@toc@ha is a relocation requesting the upper 16 bits of the
      32-bit offset of ei's TOC entry from the TOC base pointer.  Similarly,
      .LC1@toc@l is a relocation requesting the lower 16 bits.  Note that if
      the linker determines that ei's TOC entry is within a 16-bit offset of
      the TOC base pointer, it will replace the "addis" with a "nop", and
      replace the "ld" with the identical "ld" instruction from the small
      code model example.
      
      Consider next a load of a function-scope static integer.  For small code
      model, the compiler generates:
      
      	ld 3, .LC1@toc(2)
      	lwz 4, 0(3)
      
      	.section	.toc,"aw",@progbits
      .LC1:
      	.tc test_fn_static.si[TC],test_fn_static.si
      	.type	test_fn_static.si,@object
      	.local	test_fn_static.si
      	.comm	test_fn_static.si,4,4
      
      For medium code model, the compiler generates:
      
      	addis 3, 2, test_fn_static.si@toc@ha
      	addi 3, 3, test_fn_static.si@toc@l
      	lwz 4, 0(3)
      
      	.type	test_fn_static.si,@object
      	.local	test_fn_static.si
      	.comm	test_fn_static.si,4,4
      
      Again, the linker may replace the "addis" with a "nop", calculating only
      a 16-bit offset when this is sufficient.
      
      Note that it would be more efficient for the compiler to generate:
      
      	addis 3, 2, test_fn_static.si@toc@ha
              lwz 4, test_fn_static.si@toc@l(3)
      
      The current patch does not perform this optimization yet.  This will be
      addressed as a peephole optimization in a later patch.
      
      For the moment, the default code model for 64-bit PowerPC will remain the
      small code model.  We plan to eventually change the default to medium code
      model, which matches current upstream GCC behavior.  Note that the different
      code models are ABI-compatible, so code compiled with different models will
      be linked and execute correctly.
      
      I've tested the regression suite and the application/benchmark test suite in
      two ways:  Once with the patch as submitted here, and once with additional
      logic to force medium code model as the default.  The tests all compile
      cleanly, with one exception.  The mandel-2 application test fails due to an
      unrelated ABI compatibility with passing complex numbers.  It just so happens
      that small code model was incredibly lucky, in that temporary values in 
      floating-point registers held the expected values needed by the external
      library routine that was called incorrectly.  My current thought is to correct
      the ABI problems with _Complex before making medium code model the default,
      to avoid introducing this "regression."
      
      Here are a few comments on how the patch works, since the selection code
      can be difficult to follow:
      
      The existing logic for small code model defines three pseudo-instructions:
      LDtoc for most uses, LDtocJTI for jump table addresses, and LDtocCPT for
      constant pool addresses.  These are expanded by SelectCodeCommon().  The
      pseudo-instruction approach doesn't work for medium code model, because
      we need to generate two instructions when we match the same pattern.
      Instead, new logic in PPCDAGToDAGISel::Select() intercepts the TOC_ENTRY
      node for medium code model, and generates an ADDIStocHA followed by either
      a LDtocL or an ADDItocL.  These new node types correspond naturally to
      the sequences described above.
      
      The addis/ld sequence is generated for the following cases:
       * Jump table addresses
       * Function addresses
       * External global variables
       * Tentative definitions of global variables (common linkage)
      
      The addis/addi sequence is generated for the following cases:
       * Constant pool entries
       * File-scope static global variables
       * Function-scope static variables
      
      Expanding to the two-instruction sequences at select time exposes the
      instructions to subsequent optimization, particularly scheduling.
      
      The rest of the processing occurs at assembly time, in
      PPCAsmPrinter::EmitInstruction.  Each of the instructions is converted to
      a "real" PowerPC instruction.  When a TOC entry needs to be created, this
      is done here in the same manner as for the existing LDtoc, LDtocJTI, and
      LDtocCPT pseudo-instructions (I factored out a new routine to handle this).
      
      I had originally thought that if a TOC entry was needed for LDtocL or
      ADDItocL, it would already have been generated for the previous ADDIStocHA.
      However, at higher optimization levels, the ADDIStocHA may appear in a 
      different block, which may be assembled textually following the block
      containing the LDtocL or ADDItocL.  So it is necessary to include the
      possibility of creating a new TOC entry for those two instructions.
      
      Note that for LDtocL, we generate a new form of LD called LDrs.  This
      allows specifying the @toc@l relocation for the offset field of the LD
      instruction (i.e., the offset is replaced by a SymbolLo relocation).
      When the peephole optimization described above is added, we will need
      to do similar things for all immediate-form load and store operations.
      
      The seven "mcm-n.ll" test cases are kept separate because otherwise the
      intermingling of various TOC entries and so forth makes the tests fragile
      and hard to understand.
      
      The above assumes use of an external assembler.  For use of the
      integrated assembler, new relocations are added and used by
      PPCELFObjectWriter.  Testing is done with "mcm-obj.ll", which tests for
      proper generation of the various relocations for the same sequences
      tested with the external assembler.
      
      llvm-svn: 168708
      34627e34
  14. Nov 25, 2012
  15. Nov 24, 2012
  16. Nov 23, 2012
  17. Nov 21, 2012
  18. Nov 14, 2012
  19. Nov 09, 2012
  20. Nov 05, 2012
  21. Nov 01, 2012
Loading