llvm-6502/include/llvm/Support
Bill Schmidt 34a9d4b3b9 This patch implements medium code model support for 64-bit PowerPC.
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.






git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168708 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-27 17:35:46 +00:00
..
AIXDataTypesFix.h
AlignOf.h xlc supports __attribute__((aligned(x))), use it. 2012-10-31 00:54:26 +00:00
Allocator.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
Atomic.h
BlockFrequency.h Add missing includes/class declaration. 2011-11-04 18:30:30 +00:00
BranchProbability.h Make an obviously const interface actually be marked as const. 2011-11-20 11:22:03 +00:00
CallSite.h Use the attribute builder to add attributes to call/invoke instruction. No functionality change intended. 2012-10-09 23:40:31 +00:00
Capacity.h Add missing includes/class declaration. 2011-11-04 18:30:30 +00:00
Casting.h Casting.h: Automatically handle isa<Base>(Derived). 2012-10-11 23:30:40 +00:00
CFG.h Calls and invokes with the new clang.arc.no_objc_arc_exceptions 2012-02-17 18:59:53 +00:00
circular_raw_ostream.h Use empty parens for empty function parameter list instead of '(void)'. 2012-11-15 16:51:49 +00:00
CodeGen.h Move the TLSModel information into the TargetMachine rather than hiding 2012-04-08 17:20:55 +00:00
COFF.h [yaml2obj] Fix incorrect use of signed values. 2012-08-14 22:42:31 +00:00
CommandLine.h Add missing this->. Fixes pr14238. 2012-11-05 14:57:21 +00:00
Compiler.h Add an extra slash so doxygen comments will be properly recognized. 2012-11-25 00:59:59 +00:00
ConstantFolder.h
ConstantRange.h add ConstantRange::difference (to perform set difference/relative complement) 2012-06-28 16:10:13 +00:00
CrashRecoveryContext.h
DataExtractor.h Add a relocation visitor to lib object. This works via caching relocated 2012-11-07 23:22:07 +00:00
DataFlow.h
DataStream.h Fix comment-rulers. 2012-02-06 22:41:47 +00:00
DataTypes.h.cmake Remove OpenBSD defines: 2012-08-08 18:37:39 +00:00
DataTypes.h.in Remove OpenBSD defines: 2012-08-08 18:37:39 +00:00
Debug.h Typos. 2012-07-27 21:41:59 +00:00
DebugLoc.h Pull the simple parts of DenseMapInfo<DebugLoc> inline and prune includes. 2012-07-19 15:00:34 +00:00
Disassembler.h
DOTGraphTraits.h Delete names for unused parameters in inline function definitions in headers, so LLVM users can compile with -Wunused-parameter. PR11257; based on patch by Kevin Harris. 2011-11-04 18:11:56 +00:00
Dwarf.h Add constant definitions for fission dwarf attributes, forms, etc. 2012-11-16 23:04:31 +00:00
DynamicLibrary.h Add missing includes/class declaration. 2011-11-04 18:30:30 +00:00
ELF.h This patch implements medium code model support for 64-bit PowerPC. 2012-11-27 17:35:46 +00:00
Endian.h Remove 'static' from inline functions defined in header files. 2012-06-20 08:39:33 +00:00
Errno.h
ErrorHandling.h
FEnv.h
FileOutputBuffer.h Mark unimplemented copy constructors and copy assignment operators as LLVM_DELETED_FUNCTION. 2012-09-17 06:31:17 +00:00
FileSystem.h Fix a couple of Doxygen comment issues pointed out by -Wdocumentation. 2012-09-12 16:59:47 +00:00
FileUtilities.h
Format.h Fix Doxygen issues: 2012-09-14 14:57:36 +00:00
FormattedStream.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
GCOV.h Stop casting away const qualifier needlessly. 2012-09-05 22:26:57 +00:00
GetElementPtrTypeIterator.h Fix the instcombine GEP index widening transform to work correctly for vector 2012-11-13 13:01:00 +00:00
GraphWriter.h Fixed few warnings. 2012-07-19 04:50:12 +00:00
Host.h revert r147542 after comments from Joerg Sonnenberger 2012-01-05 18:28:46 +00:00
IncludeFile.h
InstIterator.h
InstVisitor.h va_start, va_end, va_copy: InstrinsicInst subclasses and InstVisitor support. 2012-10-29 09:39:03 +00:00
IntegersSubset.h Fix the IntegersSubsetTest unit test when compiled with gcc-4.7. The issue here 2012-11-03 14:04:04 +00:00
IntegersSubsetMapping.h BranchProb: modify the definition of an edge in BranchProbabilityInfo to handle 2012-08-24 18:14:27 +00:00
IRReader.h Make SMDiagnostic a little more sane. Instead of passing around note/warning/error as a 2011-10-16 05:43:57 +00:00
LeakDetector.h
LEB128.h Fix a couple include directives that used angle brackets for llvm files. 2012-09-15 18:41:37 +00:00
LICENSE.TXT
Locale.h platform support for counting column widths and checking isprint 2012-04-17 20:03:03 +00:00
LockFileManager.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
MachO.h Remove tabs. 2012-07-19 00:01:00 +00:00
ManagedStatic.h Add support for tsan annotations (thread sanitizer, a valgrind-based tool). 2011-11-14 20:50:16 +00:00
MathExtras.h Fix Doxygen issues: 2012-09-13 12:34:29 +00:00
Memory.h Correcting enum values mentioned in comments. 2012-10-12 21:47:49 +00:00
MemoryBuffer.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
MemoryObject.h Make MemoryObject accessor members const again 2012-02-29 01:09:06 +00:00
Mutex.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
MutexGuard.h Mark unimplemented copy constructors and copy assignment operators as LLVM_DELETED_FUNCTION. 2012-09-17 06:31:17 +00:00
NoFolder.h Insertion of NoFolder functions to avoid ambiguous overload warnings or errors about whether to convert Idx to ArrayRef<Constant *> or ArrayRef<Value *> like ConstantFolder and TargetFolder. 2012-08-17 08:54:57 +00:00
OutputBuffer.h
PassNameParser.h
Path.h
PathV1.h Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164767 2012-09-27 10:14:43 +00:00
PathV2.h Fix a doxygen issue: these examples are supposed to be displayed preformatted. 2012-09-13 11:42:30 +00:00
PatternMatch.h Revert commit 149912 (lattner) and add a testcase that shows the problem (which 2012-02-10 14:26:42 +00:00
PluginLoader.h
PointerLikeTypeTraits.h
PredIteratorCache.h
PrettyStackTrace.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
Process.h Process: Add sys::Process::FileDescriptorHasColors(). 2012-07-20 18:29:38 +00:00
Program.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
raw_os_ostream.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
raw_ostream.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
Recycler.h Convert assert(0) to llvm_unreachable 2012-02-05 22:14:15 +00:00
RecyclingAllocator.h
Regex.h Fix Doxygen issues: 2012-09-14 14:57:36 +00:00
Registry.h Mark unimplemented copy constructors and copy assignment operators as LLVM_DELETED_FUNCTION. 2012-09-17 06:31:17 +00:00
RegistryParser.h
RWMutex.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
SaveAndRestore.h Move include/llvm/ADT/SaveAndRestore.h -> include/llvm/Support/SaveAndRestore.h 2012-03-01 19:45:47 +00:00
Signals.h
SMLoc.h Remove some trivial copy ctors so the classes become trivially copyable and get the optimized SmallVector implementation. 2012-07-08 19:47:51 +00:00
Solaris.h
SourceMgr.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
StreamableMemoryObject.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
StringPool.h
SwapByteOrder.h
system_error.h Add LLVM_OVERRIDE to methods that override their base classes. 2012-09-23 02:12:10 +00:00
SystemUtils.h
TargetFolder.h Move TargetData to DataLayout. 2012-10-08 16:38:25 +00:00
TargetRegistry.h When creating MCAsmBackend pass the CPU string as well. In X86AsmBackend 2012-09-18 16:08:49 +00:00
TargetSelect.h Add InitializeNativeTargetDisassembler function. 2012-03-26 21:56:56 +00:00
Threading.h Fix Doxygen issues: 2012-09-13 12:34:29 +00:00
ThreadLocal.h Remove use of GNU extension to resolve Clang warning. 2012-06-12 17:06:32 +00:00
Timer.h Use LLVM_DELETED_FUNCTION for copy constructors and copy assignment operators that aren't implemented. 2012-09-16 21:37:56 +00:00
TimeValue.h Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164767 2012-09-27 10:14:43 +00:00
ToolOutputFile.h
type_traits.h Fix some code which is invalid in C++11: an expression of enumeration type 2012-09-13 21:18:18 +00:00
Valgrind.h use llvm-config.h in public header 2011-11-28 00:49:01 +00:00
ValueHandle.h Mark unimplemented copy constructors and copy assignment operators as LLVM_DELETED_FUNCTION. 2012-09-17 06:31:17 +00:00
Win64EH.h
YAMLParser.h Allow using MemoryBuffers with yaml::Stream directly. 2012-11-19 23:21:47 +00:00