Commit Graph

132 Commits

Author SHA1 Message Date
Jonas Maebe
c4ae040258 + support for writing LLVM function-level inline assembly blocks
git-svn-id: trunk@34891 -
2016-11-13 16:06:29 +00:00
Jonas Maebe
1c23218375 * pass the parameter list directly to getparas()
git-svn-id: trunk@34888 -
2016-11-13 16:06:20 +00:00
Jonas Maebe
bdfd588b47 * free the temporary assembler writer created for writing the code of pure
assembler routines

git-svn-id: trunk@34887 -
2016-11-13 16:06:17 +00:00
Jonas Maebe
af297e849c + function-level LLVM inline assembly decorator
git-svn-id: trunk@34855 -
2016-11-09 19:51:30 +00:00
Jonas Maebe
646385e966 * support for overriding the line ending character in external assembler
writer decorators (for LLVM function-level inline assembly: there
    newline has to be replaced by the character sequence '\0A')

git-svn-id: trunk@34854 -
2016-11-09 19:51:27 +00:00
Jonas Maebe
74a49b5f91 * restructured the the TExternalAssembler constructors so that the
hack for the Jasmin descendent is no longer needed

git-svn-id: trunk@34852 -
2016-11-09 19:51:20 +00:00
Jonas Maebe
999cb7de6d + LLVM 3.7 support in the LLVM IR writer
git-svn-id: trunk@34550 -
2016-09-20 21:44:06 +00:00
Jonas Maebe
7ebbb744e9 * also specify sret attribute at the caller side
git-svn-id: trunk@34302 -
2016-08-13 14:47:42 +00:00
Jonas Maebe
819f0c39fa * specify the "byval" attribute also at the caller side
git-svn-id: trunk@34301 -
2016-08-13 14:47:39 +00:00
Jonas Maebe
687adbefd7 + support for LOC_VOID parameters in llvm for empty records (fixes
tests/test/tnoext4.)

git-svn-id: trunk@34136 -
2016-07-15 14:35:17 +00:00
Jonas Maebe
14ab43626f * don't write initialisation values for AB_EXTERNAL_INDIRECT
git-svn-id: trunk@33956 -
2016-06-12 09:20:51 +00:00
Jonas Maebe
44839ba0c0 * handle AB_INDIRECT and AB_EXTERNAL_INDIRECT in the llvm assembler writer
git-svn-id: trunk@33721 -
2016-05-20 20:51:28 +00:00
Jonas Maebe
4fff9645af * use tasmbind for llvm aliases and derive llvm flags from that
git-svn-id: trunk@33720 -
2016-05-20 20:51:25 +00:00
nickysn
e1f21fb1e3 + handle the asd_cpu directive (commented out, but without producing an internal
error) on all the remaining external assemblers, so it is safe to emit on all
  platforms

git-svn-id: trunk@33122 -
2016-02-26 20:50:41 +00:00
Jonas Maebe
e3f8f8c974 * fixed position of "weak" linkage flag
git-svn-id: trunk@32915 -
2016-01-10 17:22:14 +00:00
Jonas Maebe
5959f45694 * emit custom Objective-C names in the LLVM assembler writer
git-svn-id: trunk@32912 -
2016-01-10 17:22:06 +00:00
Jonas Maebe
53bf43983a + support for emitting weak symbols with the high level typed constant builder
git-svn-id: trunk@32883 -
2016-01-07 22:06:06 +00:00
Jonas Maebe
58ae32e2d1 * factored out writing the LLVM linkage flags, take into account version
differences and also write them for procdefs

git-svn-id: trunk@32882 -
2016-01-07 22:06:00 +00:00
Jonas Maebe
110a5642c0 - removed ait_weak/tai_weak, and replaced it with the previously existing
asd_weak_reference/asd_weak_definition directives

git-svn-id: trunk@32879 -
2016-01-07 22:05:38 +00:00
Jonas Maebe
c452e70f74 + support for a reference without base or symbol, if the offset is 0
(for @ptrtype(0)^.field expressions)

git-svn-id: trunk@32777 -
2015-12-28 15:06:15 +00:00
Jonas Maebe
b4fe4789d6 + support for constant call parameters on LLVM
o reduces the size of the generated LLVM IR, but mainly important for LLVM
     intrinsics such as llvm.memcpy.*(), as llc complains if some of their
     parameters are not constants (you could work around it by first running
     opt or by using clang with optimizations so that the constants, which
     were loaded in registers until now, were propagated to the intrinsics
     by the time llc saw them)

git-svn-id: trunk@32776 -
2015-12-28 15:06:07 +00:00
Jonas Maebe
787caf4dda * treat records with {$packrecords c} the same as other records for LLVM
o while in principle LLVM can layout those the same as we do, this would
     require special treatment in case some fields are not initialised in
     a typed record declaration (because then we have to emit padding only
     for the skipped fields, and not for any padding between them)
   o exception: records we create to represent parameters, as those have to
     match the ABI definitions exactly for them to be treated as expected

git-svn-id: trunk@32714 -
2015-12-25 21:05:22 +00:00
Jonas Maebe
2342ee467b * don't write the parameter names for external function declarations in llvm,
because the names we assign to parameter locations are no longer valid after
    a module has been compiled (they are tasmsymbols), and they're not necessary
    for declarations either; this also avoids generating calleeside parameter
    information for imported routines just to write the external declaration
    (the callerside information will already be available from when the routines
     were called)

git-svn-id: trunk@32518 -
2015-11-24 20:10:28 +00:00
Jonas Maebe
1284032765 + llvm blockaddress() intrinsic (supported as of LLVM 3.5.1)
git-svn-id: trunk@32409 -
2015-11-21 12:36:55 +00:00
Jonas Maebe
91e8f4c439 + custom section name support for llvm
git-svn-id: trunk@32400 -
2015-11-21 12:36:26 +00:00
Jonas Maebe
1675c27e59 * fixed writing of procvardef records (they're also written as tck_record)
git-svn-id: trunk@32298 -
2015-11-12 22:00:25 +00:00
Jonas Maebe
75012405fa * add some llvm function flags
o in particular, mark fpc_setjmp as "returns_twice" so calls to it are
     never converted into tail calls

git-svn-id: trunk@31659 -
2015-09-12 23:34:04 +00:00
Jonas Maebe
2741b37f28 * only specify the "unnamed_addr" flag for initialised data if its symbol is
a tasmlabel, since otherwise the address needs to remain unique

git-svn-id: trunk@31654 -
2015-09-12 23:33:46 +00:00
Jonas Maebe
7a08319d2e * converted taillvmdecl properties to a set
git-svn-id: trunk@31653 -
2015-09-12 23:33:42 +00:00
Jonas Maebe
839482751d * when generating code for a pure assembler routine with LLVM, instantiate
a code and temp generator for the architectural target instead of for LLVM
  * write the code for pure assembler routines using a GNU-style external
    assembler writer for the target, with a decorator to wrap it in
    LLVM module-level assembly statements

git-svn-id: trunk@31633 -
2015-09-12 23:32:31 +00:00
Jonas Maebe
5c69d57674 + TLLVMModuleInlineAssemblyDecorator to decorate inline module-level
assembly

git-svn-id: trunk@31632 -
2015-09-12 23:32:28 +00:00
Jonas Maebe
c80fb6a20e * explicitly specify whether an llvm specification is a definition (= locally
defined) or a declaration (external symbol), instead of deriving it from
    from the bind of the tasmsymbol. The reason is that with module-level
    inline assembly, some locally implemented functions (in pure assembler)
    won't have an LLVM IR body

git-svn-id: trunk@31629 -
2015-09-12 23:32:17 +00:00
Jonas Maebe
991e1f49bd * store a pointer to the used tasminfo record in every assembler writer, so
that we can use assembler writers with different conventions from the
    currently set target_asm (e.g. an x86 assembler writer for inline assembly
    in LLVM IR)

git-svn-id: trunk@31628 -
2015-09-12 23:32:13 +00:00
Jonas Maebe
b3d0197f98 * factored out the output file handling (mostly writing data) from the
external assembler writer, so we can reuse the archtecture-specific
    writers to write inline assembly in LLVM IR files

git-svn-id: trunk@31625 -
2015-09-12 23:32:01 +00:00
Jonas Maebe
1cdaf8e332 * don't write external linkage for aliases: llvm 3.6 has a bug that rejects
linkage types for aliases (or its documentation hasn't been updated), and
    external linkage is the default so it doesn't matter for earlier versions

git-svn-id: trunk@31284 -
2015-08-05 21:05:52 +00:00
Jonas Maebe
7a8b5fd6c5 * several fixes for emitting aggregate typed constants with C/ABI packing:
o don't emit explicit padding bytes (LLVM adds them)
   o don't mark them in LLVM as packed either

git-svn-id: trunk@31187 -
2015-07-03 20:04:15 +00:00
Jonas Maebe
54dd25b448 * support llvm aliases for defs other than procdef
git-svn-id: trunk@31052 -
2015-06-13 22:48:14 +00:00
Jonas Maebe
4eea652576 * fixed writing non-default linkage and visibility of llvm alias declarations
git-svn-id: trunk@31051 -
2015-06-13 22:48:11 +00:00
Jonas Maebe
d546e74d1c * don't write newlines after nested taillvm instructions (since they're
embedded in the middle of another instruction)

git-svn-id: trunk@30779 -
2015-05-03 16:50:55 +00:00
Jonas Maebe
72277f5098 * store the used tabstractprocdef when generating an llvm call instruction,
because due to aliasing symbols a single symbol may be called using
    different procdefs (e.g. FPC_ANSISTR_UNIQUE in the system unit is defined
    as an alias for a function and called as a procedure). This means we have
    to insert extra type conversions for llvm, which requires both the source
    and destination type

git-svn-id: trunk@30776 -
2015-05-03 16:50:43 +00:00
Jonas Maebe
e2cf90ad8a * add type declarations for structure types in the llvm code so that we can
handle recursive record references (rec= record prec: ^rec)
   o llvm unfortunately does not support recursive references to array types
     or function pointers, so those will currently still result in endless
     recursion when the compiler tries to write them out. Solving those
     will require a lot of typecasting in the generated code

git-svn-id: trunk@30675 -
2015-04-19 21:37:46 +00:00
Jonas Maebe
c8e44e4a7c * keep track of whether we're in an inline assembly block in the llvm
assembler writer, and for now skip writing labels if we are (they
    will have to emitted as part of an actual inline assembly block,
    not as llvm-style labels)

git-svn-id: trunk@30672 -
2015-04-19 21:37:37 +00:00
Jonas Maebe
07141e92d3 + support for llvm "undef" operand
git-svn-id: trunk@30669 -
2015-04-19 21:37:27 +00:00
Jonas Maebe
a8cefa8fcd - removed aggas.pas leftovers
git-svn-id: trunk@30498 -
2015-04-08 19:08:33 +00:00
Jeppe Johansen
e2272c8a7e Added aitconst_gs for AVR pointer references to Flash.
git-svn-id: trunk@30419 -
2015-04-04 10:29:11 +00:00
Jonas Maebe
bc7ba58798 * fixed compilation after removal of ait_set, ait_thumb_set and ait_symbol_pair
git-svn-id: branches/hlcgllvm@30243 -
2015-03-15 21:10:47 +00:00
Jonas Maebe
935c0c86aa * write all ait_const's of value 0 as 'zeroinitializer' so they also work
for pointer constants

git-svn-id: branches/hlcgllvm@30126 -
2015-03-07 21:43:47 +00:00
Jonas Maebe
6677e698cd * record the alignment in taillvmdecl, as it can be different from the
default

git-svn-id: branches/hlcgllvm@28752 -
2014-10-06 20:53:17 +00:00
Jonas Maebe
cc4482d6f8 - removed tck_simple_procvar2proc, instead use
procdef.getcopyas(procvardef,pc_address_only) as the def if we want to
    specify that we're interested in the address of a procedure/procvar of
    object

git-svn-id: branches/hlcgllvm@28476 -
2014-08-19 20:22:11 +00:00
Jonas Maebe
575911dcb0 + support for (section-based) threadvars for LLVM
git-svn-id: branches/hlcgllvm@28352 -
2014-08-10 13:18:46 +00:00
Jonas Maebe
099588aaf5 * don't write comments in the LLVM IR about ait_section/ait_align elements,
as these can appear in the middle of aggregate constants and hence
    otherwise break the definition

git-svn-id: branches/hlcgllvm@28326 -
2014-08-06 18:04:36 +00:00
Jonas Maebe
bfe431913d * fixed writing hex-encoded characters in string constants
git-svn-id: branches/hlcgllvm@28209 -
2014-07-12 22:42:20 +00:00
Jonas Maebe
39074edf10 - removed the globalsymbolmangleprefix/suffix constants that were added for
llvm
  * instead, add LLVM-specific name mangling based on the asmsymbol's bind
    and typ whenever we write out its name

git-svn-id: branches/hlcgllvm@28166 -
2014-07-05 15:44:16 +00:00
Jonas Maebe
eef6f05697 * specify the asm section type when creating an LLVM declaration
o in case it's a read-only section, mark the data as "constant"

git-svn-id: branches/hlcgllvm@28155 -
2014-07-04 20:30:24 +00:00
Jonas Maebe
394dfdd220 * ensure that all initialised items have a type (and only one):
o remove the accompanying tdef operands from tai operands, because such
     tai operands should have a tdef already
   o check that every queued tai is a tai_simpletypedconst (which have a
     type)
   o wrap queued bitcast/getelementptr tai instances with a
     tai_simpletypedconst

git-svn-id: branches/hlcgllvm@28154 -
2014-07-04 19:24:20 +00:00
Jonas Maebe
5cf52bb957 * fixed writing nested conversion operations such as bitcast (missing
opening bracket)

git-svn-id: branches/hlcgllvm@28142 -
2014-07-03 22:28:28 +00:00
Jonas Maebe
9f39188253 * moved the tai_*typedconst classes to aasmcnst to make use of def-related
helpers in a cleaner way (defutils would not belong in the uses clause of
    aasmtai)

git-svn-id: branches/hlcgllvm@28132 -
2014-07-02 17:24:50 +00:00
Jonas Maebe
2af0b46792 - removed unused variables
git-svn-id: branches/hlcgllvm@28131 -
2014-07-02 17:24:47 +00:00
Jonas Maebe
3511aa4878 * don't write a tab character before an instruction that's a nested operand
git-svn-id: branches/hlcgllvm@28126 -
2014-07-01 16:31:03 +00:00
Jonas Maebe
1a77bc952e * immediate write out partial string respresentations of instructions
rather than first concatenating everything, because in case of
    instructions that have other tai as operands we have to ensure that
    all previous output is flushed before the tai-operand is evaluated
    (and written/flushed)

git-svn-id: branches/hlcgllvm@28125 -
2014-07-01 16:31:00 +00:00
Jonas Maebe
0c10cbe63b + support for tai_symbol (in nested typed constant expressions)
git-svn-id: branches/hlcgllvm@28122 -
2014-07-01 16:30:52 +00:00
Jonas Maebe
f89b2e2b26 + support for tai_string (in nested typed constant expressions)
git-svn-id: branches/hlcgllvm@28121 -
2014-07-01 16:30:49 +00:00
Jonas Maebe
204adf82c7 * handle tai_const instances as operands to other tai
git-svn-id: branches/hlcgllvm@28120 -
2014-07-01 16:30:46 +00:00
Jonas Maebe
f8f7c30f14 * support non-taillvm tai instances as operands to taillvm instances
git-svn-id: branches/hlcgllvm@28119 -
2014-07-01 16:30:43 +00:00
Jonas Maebe
da3e931d68 + support for tai_realconst in llvm assembler writer
git-svn-id: branches/hlcgllvm@28114 -
2014-07-01 16:30:27 +00:00
Jonas Maebe
8043254461 * factored out generating string representations of floating point numbers
in the llvm assembler writer

git-svn-id: branches/hlcgllvm@28113 -
2014-07-01 16:30:24 +00:00
Jonas Maebe
1e7d9c9f0e + support for instruction operands that are tai themselves in the llvm
backend (required for inserting bitcasts/ptrtoint/... operations inside
    typed constant declarations)
   o taillvm constructors for creating bitcast-style and getlementptr
     operations that accept a tai as their source/base operand

git-svn-id: branches/hlcgllvm@28112 -
2014-07-01 16:30:22 +00:00
Jonas Maebe
7ebb1b813f + basic support infrastructure in the llvm assembler writer to write out
typed constant data
   o llvm declarations now get an extra "initdata" list that contains the
     typed constant data associated with this declaration (if any)

git-svn-id: branches/hlcgllvm@28111 -
2014-07-01 16:30:19 +00:00
Jonas Maebe
1fdb16b615 * fixed indentation
git-svn-id: branches/hlcgllvm@28110 -
2014-07-01 16:30:16 +00:00
Jonas Maebe
1047cdadcb * factored out writing of a single tai, so this routine can call itself
recursively when writing out typed constant data
   o basic support for tai_const

git-svn-id: branches/hlcgllvm@28109 -
2014-07-01 16:30:13 +00:00
Jonas Maebe
b0ff41406a * grouped all tai_real* types into a single tai_realconst type,
to free up space for more ait_* types in taitype (can't have
    more than 32 because they have to fit in a small set)
   o factored out writing of floating point numbers as an array of
     byte in the external assemblers

git-svn-id: branches/hlcgllvm@28105 -
2014-07-01 16:29:58 +00:00
Jonas Maebe
0fd172ddf6 * ignore global labels with a comment for now, they're generated for
function symbol aliases

git-svn-id: branches/hlcgllvm@27014 -
2014-03-06 21:42:17 +00:00
Jonas Maebe
6dcfd73d21 + support for a_call_name() on the llvm target:
o make use of the fact that callparanodes always first load everything
     in temporary parameters (allocated via paramanager.createtempparaloc)
     -> we pass those temporary paralocs to the llvm call nodes and ignore
     the "real" locations with physical registers
   o all function results are forced to memory before handing them back
     to the generic code generator to avoid having to deal with special
     result locations and llvm<->pascal type differences (llvm removes
     the extra temp stores/loads while optimising)
   o ideally, the llvm code generator should share the common code with
      the generic code generator for a_load_ref_cgpara() at some point in
      the future

git-svn-id: branches/hlcgllvm@27013 -
2014-03-06 21:42:14 +00:00
Jonas Maebe
b82053ef40 * reworked handling of defined/declared symbols in llvm: we now automatically
generate declarations when external symbols are referred in a taillvm
    instruction
  * added "declared" field to tasmsymbol for llvm to make avoid declaring a
    symbol multiple times (harmless, but unnecessary)
  * all kinds of declarations/definitions are now handled using the new
    taillvmdecl, the old separate types have been removed

git-svn-id: branches/hlcgllvm@27010 -
2014-03-06 21:42:03 +00:00
Jonas Maebe
02ca215272 * reworked and fixed llvm procdef handling (except for variadic C functions):
o handle parameters and function results divided over multiple paralocs,
     including generating fake recorddefs that represent
   o fixed zero/sign extension handling
   o properly handle difference between procdefs as printed for the
    implementation, an alias declaration or a procvar definition

git-svn-id: branches/hlcgllvm@27009 -
2014-03-06 21:42:00 +00:00
Jonas Maebe
dad45d63b1 * improved symbol alias handling (pass in old sym instead of name, add
pointer add end of aliased procdef)

git-svn-id: branches/hlcgllvm@27008 -
2014-03-06 21:41:56 +00:00
Jonas Maebe
358b346bbc * fixed writing of constant operands outside the longint range
git-svn-id: branches/hlcgllvm@27005 -
2014-03-06 21:41:46 +00:00
Jonas Maebe
227ff0ea48 * llvm requires that single precision constants are exactly representable
using single precision -> convert them to single precision in the code
    generator

git-svn-id: branches/hlcgllvm@27001 -
2014-03-06 21:41:32 +00:00
Jonas Maebe
9902864cce * don't output alignments for reference operands to bitcast & co
git-svn-id: branches/hlcgllvm@26984 -
2014-03-06 21:40:29 +00:00
Jonas Maebe
9c674ff444 * made internalerror unique
git-svn-id: branches/hlcgllvm@26982 -
2014-03-06 21:40:21 +00:00
Jonas Maebe
0cc581825f * enabled darwin/ppc64 for the llvm target
git-svn-id: branches/hlcgllvm@26072 -
2013-11-12 19:22:50 +00:00
Jonas Maebe
5409d4321e + basic llvm bitcode (textual format) writer:
o no support yet for many ait_* types, although eventually most of them
     shouldn't be generated at all for the llvm target
   o no support yet for calling "opt" (which optimises llvm bitcode) before
     calling llc (which translates llvm bitcode into native code) -- compile
     with -s and manually call "opt" with -std-compile-opts, -O1, -O2 or -O3
     if you want to experiment
   o override the assembler writer with the llvm one when compiling an llvm-
     targeting compiler
   o override the assembler file extension with .ll when compiling an llvm-
     targeting compiler

git-svn-id: branches/hlcgllvm@26054 -
2013-11-11 11:16:25 +00:00