- Nov 27, 2012
-
-
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
-
- Nov 21, 2012
-
-
Akira Hatanaka authored
llvm-svn: 168448
-
- Nov 09, 2012
-
-
Anton Korobeynikov authored
Based on the patch by Logan Chien! llvm-svn: 167633
-
- Sep 26, 2012
-
-
Craig Topper authored
llvm-svn: 164666
-
- Sep 12, 2012
-
-
Manman Ren authored
"#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)" No functional change. Update r163344. llvm-svn: 163679
-
- Sep 06, 2012
-
-
Manman Ren authored
No functional change. llvm-svn: 163344
-
- Aug 24, 2012
-
-
Roman Divacky authored
In collaboration with Adhemerval Zanella. llvm-svn: 162562
-
- Jul 21, 2012
-
-
Akira Hatanaka authored
Test case will be added later when long branch patch is checked in. llvm-svn: 160597
-
- Jun 04, 2012
-
-
Roman Divacky authored
llvm-svn: 157935
-
- Mar 26, 2012
-
-
Craig Topper authored
llvm-svn: 153429
-
- Feb 24, 2012
-
-
Jim Grosbach authored
Add support for a missed case when the symbols in a difference expression are in the same section but not the same fragment. rdar://10924681 llvm-svn: 151345
-
- Feb 11, 2012
-
-
Anton Korobeynikov authored
Patch by Kai Nacke! llvm-svn: 150307
-
- Feb 07, 2012
-
-
Craig Topper authored
llvm-svn: 149967
-
- Jan 26, 2012
-
-
James Molloy authored
Add support for the R_ARM_TARGET1 relocation, which should be given to relocations applied to all C++ constructors and destructors. This enables the linker to match concrete relocation types (absolute or relative) with whatever library or C++ support code is being linked against. llvm-svn: 149057
-
- Jan 10, 2012
-
-
Chandler Carruth authored
of several newly un-defaulted switches. This also helps optimizers (including LLVM's) recognize that every case is covered, and we should assume as much. llvm-svn: 147861
-
David Blaikie authored
llvm-svn: 147855
-
- Dec 22, 2011
-
-
Akira Hatanaka authored
ELF relocations. Patch by Jack Carter. llvm-svn: 147118
-
- Nov 15, 2011
-
-
Akira Hatanaka authored
llvm-svn: 144663
-
- Oct 25, 2011
-
-
Bruno Cardoso Lopes authored
This first patch is for expression variable kinds. Patch by Jack Carter! llvm-svn: 142934
-
- Jul 26, 2011
-
-
Evan Cheng authored
llvm-svn: 136010
-
- Jul 23, 2011
-
-
Evan Cheng authored
llvm-svn: 135833
-
- Jun 09, 2011
-
-
Roman Divacky authored
VK_PPC_{HA,LO}16 into darwin and gas variants. Darwin wants {ha,lo}16(symbol) while gnu as wants symbol@{ha,l}. llvm-svn: 132802
-
- Apr 29, 2011
-
-
Daniel Dunbar authored
that associate sections with expressions. llvm-svn: 130517
-
- Apr 15, 2011
-
-
Chris Lattner authored
Luis Felipe Strano Moraes! llvm-svn: 129558
-
- Mar 22, 2011
-
-
Owen Anderson authored
Add support for Thumb interworking addresses for symbol offsets that get constant folded very early. This fixes SPASS with -integrated-as. <rdar://problem/9165399> llvm-svn: 128037
-
- Jan 23, 2011
-
-
Rafael Espindola authored
llvm-svn: 124071
-
- Jan 13, 2011
-
-
Evan Cheng authored
in the right direction. It eliminated some hacks and will unblock codegen work. But it's far from being done. It doesn't reject illegal expressions, e.g. (FOO - :lower16:BAR). It also doesn't work in Thumb2 mode at all. llvm-svn: 123369
-
- Dec 22, 2010
-
-
Rafael Espindola authored
fixed. llvm-svn: 122448
-
Rafael Espindola authored
llvm-svn: 122427
-
Rafael Espindola authored
llvm-svn: 122405
-
- Dec 21, 2010
-
-
Rafael Espindola authored
the folding it can. llvm-svn: 122359
-
- Dec 19, 2010
-
-
Rafael Espindola authored
llvm-svn: 122167
-
Rafael Espindola authored
llvm-svn: 122165
-
Rafael Espindola authored
llvm-svn: 122160
-
- Dec 18, 2010
-
-
Rafael Espindola authored
llvm-svn: 122148
-
Rafael Espindola authored
llvm-svn: 122147
-
Rafael Espindola authored
llvm-svn: 122144
-
Rafael Espindola authored
llvm-svn: 122139
-
Rafael Espindola authored
I added a note, but suggestions on how to add a test are really welcome. llvm-svn: 122138
-
- Dec 17, 2010
-
-
Daniel Dunbar authored
IsSymbolRefDifferenceFullyResolved(). For example, we will now fold away something like: -- _a: ... L0: ... L1: ... .long (L1 - L0) / 2 -- llvm-svn: 122043
-