Commit graph

103 commits

Author SHA1 Message Date
Johan Engelen
bb24fb2816 Add LTO support (full and thin), with -flto=thin|full.
LTO needs linker support: I am only aware of support on OS X and Linux (through the LLVMgold plugin).

Resolves #693
2016-11-09 14:30:13 +01:00
Martin
8276269ab1 Create static libs in -od directory for LDMD only
Let LDC treat relative output paths as relative to the current working
directory again (as it always used to until a few weeks ago). It's more
intuitive and avoids breaking build systems/scripts using LDC directly.

Only LDMD continues to prepend the -od directory to the relative output
path, for DMD compatibility.

Fixes issue #1819.
2016-10-14 21:47:27 +02:00
Martin
a8c6293865 Create output directories recursively
Fixes issue #1819.
2016-10-09 23:21:35 +02:00
Martin
8f2665d7bb Windows: Support .res and .def files in command-line 2016-09-27 01:34:05 +02:00
Martin
b1a6315ee4 Don't reverse order of object file names
Make sure the overall order corresponds to the user's command-line order
of object and source files. The only exception being singleObj builds,
for which the single object file for all source files is always the first
entry in the object files list (which is forwarded to the linker in that
order). This is done so that we can easily get hold of the name when
emitting the single object file later in the `ldc::CodeGenerator` dtor.
It should also clearly define the linking order (affecting comdat
selections etc.) for special singleObj builds.

Also reuse some more code (wrt. output filenames) from DMD's main().
2016-09-27 01:34:05 +02:00
Martin
d85986be3d Infer output names from first object file alone (ignore root module) 2016-09-07 09:53:35 +02:00
Martin
6c03a3d725 Streamline output filenames and -singleObj behavior some more with DMD 2016-09-07 09:53:35 +02:00
Martin
aed881350a Refactor output filename generation/validation 2016-09-07 09:53:35 +02:00
Martin
24cecc268c Streamline main() with DMD's (ddmd/mars.d) 2016-08-27 20:40:26 +02:00
kinke
dbc9733a05 Merge pull request #1649 from JohanEngelen/warningfix1
Fix a few clang warnings [NFC]
2016-07-28 00:46:53 +02:00
Johan Engelen
c6ba2dc29b Fix a few clang warnings. [NFC] 2016-07-27 20:21:02 +02:00
Johan Engelen
0fcd50fb0d Do the check that gExePath is not a directory (before deleting it) also in release builds. 2016-07-27 19:47:51 +02:00
Rainer Schuetze
9f85baee90 use *W-functions if UNICODE #defined on windows 2016-06-28 08:29:49 +02:00
Johan Engelen
33a54a9900 [PGO] Fix ldc-profile-rt.lib linking on Windows. 2016-06-20 17:28:35 +02:00
Johan Engelen
20c9f3fbec [PGO] Fix profile-rt linking: put it before Phobos. 2016-06-20 17:28:32 +02:00
Johan Engelen
e0d9c58443 [PGO] Add PGO to LDC. Supported for LLVM >= 3.7
Add the commandline options -fprofile-instr-generate[=filename] and -profile-instr-use=filename
-fprofile-instr-generate
-- Add instrumentation on branches, switches, and function entry; uses LLVM's InstrProf pass.
-- Link to profile runtime that writes instrumentation counters to a file.
-fprofile-instr-use
-- Read profile data from a file and apply branch weights to branches and switches, and annotate functions with entrycount in LLVM IR.
-- Functions with low or high entrycount are marked with 'cold' or 'inlinehint'.

The only statement type without PGO yet is "try-finally".

A new pragma, `pragma(LDC_profile_instr, [ true | false ])`, is added to selectively disable/enable instrumentation of functions (granularity = whole functions).

The runtime library ldc-profile-rt is a copy of LLVM compiler-rt lib/profile. It has to be exactly in-sync with the LLVM version, and thus we need a copy for each PGO-supported LLVM (>=3.7).
import ldc.profile for a D interface to ldc-profile-rt (for example to reset execution counts after a program startup phase).

The instrumentation data is mainly passed on to LLVM: function-entry counts and branch counts/probabilities. LDC marks functions as hot when "execution count is 30% of the maximum function execution count", and marks functions as cold if their count is 1% of maximum function execution count.

The source of LLVM's llvm-profdata tool is hereby included in LDCs repository (different source for each LLVM version), and the binary is included in the install bin folder.
The executable is named "ldc-profdata" to avoid clashing with llvm-profdata on the same machine. This is needed because profdata executable has to be in-sync with the LLVM version used to build LDC.

Maintenance burden: for trunk LLVM, we have to keep ldc-profile-rt and llvm-profdata in sync. There is no diff with upstream; but because of active development there are the occasional API changes.
2016-06-20 17:28:22 +02:00
Johan Engelen
ef91385223 Making bitcode file argument errors fatal. 2016-06-10 12:47:46 +02:00
Johan Engelen
404d483c2a Bitcode cmd arguments: fix compilation for LLVM < 3.8, and disable for LLVM 3.5. 2016-06-10 12:43:31 +02:00
Johan Engelen
d9b267a4be Accept LLVM bitcode files (*.bc) on the commandline and add the code to the first source file on the cmdline (the first emitted module). 2016-06-05 16:07:14 +02:00
Johan Engelen
4515033381 Merge pull request #1470 from JohanEngelen/random_file
Use random output filenames for `-run`.
2016-05-10 13:08:18 +02:00
Johan Engelen
ac23473525 Use random output filenames for -run.
The temporary files created should be unique for parallel processes (e.g. in a test suite where LDC is called in parallel with perhaps same input).
These files will be deleted after execution so their name is not relevant. For better linking errors, the new filenames are created by appending random characters to their name.
2016-05-09 20:14:00 +02:00
Kai Nacke
0b2d7e7969 Merge remote-tracking branch 'origin/ltsmaster' 2016-04-30 16:35:00 -04:00
Kai Nacke
1cfb6d46ee Do not use -Xlinker for linker options starting with -shared or -static.
This is part of fixing the CMAKE_EXE_LINKER_FLAGS problem of the 1.0 build.
2016-04-30 16:11:02 +02:00
Kai Nacke
ee8c6b106b Fix merge errors 2016-04-23 14:58:39 +02:00
Kai Nacke
e55823fd09 Merge remote-tracking branch 'origin/ltsmaster' 2016-04-23 11:19:20 +02:00
Joakim
ee8a832c49 Add a handful of fixes for Android 2016-04-19 22:09:14 +05:30
Kai Nacke
d4dc52d4aa Fix compile errors caused by D frontend
- scope is now _scope
- targetTriple requires -> instead of .
- factory method createTypeIdentifier() instead of new TypeIdentifier()
2016-03-03 21:41:46 +01:00
Kai Nacke
24adf155ff Revert "Revert "Merge branch 'ltsmaster'""
This reverts commit 1653911600.
2016-03-03 21:12:53 +01:00
Kai Nacke
1653911600 Revert "Merge branch 'ltsmaster'"
This reverts commit dcb781004b, reversing
changes made to 3c6f09faf0.
2016-03-03 13:14:39 +01:00
Kai Nacke
dcb781004b Merge branch 'ltsmaster' 2016-03-03 07:50:17 +01:00
Kai Nacke
5243b44ccd AArch32/64: gcc does not support -m32/-m64.
Currently we want to pass -m64 to gcc which aborts the compiler.
2016-03-01 22:51:16 +01:00
Johan Engelen
acdcc4a8c1 Merge branch 'master' into merge-2.069 2016-02-13 20:12:17 +01:00
Martin
241dc9135f Fix error message formatting 2016-02-02 22:31:54 +01:00
Johan Engelen
29ce4012af dmd2 --> ddmd. Merge (almost all of) our changes to dmd source into the new D source of dmd 2.069.2.
Also adds the CMake infrastructure to compile and link the D source files.

The build is partially broken:
- A few files in Phobos and druntime do not build
- MSVC build is broken because of unresolved symbols involving reals
2016-01-28 19:03:58 +01:00
Kai Nacke
8df1f7ec1a Add more support for xBSD type OS.
Use the same code for FreeBSD, NetBSD, OpenBSD and DragonFly BSD.
2016-01-22 22:10:33 +01:00
David Nadlinger
880483b564 Merge pull request #1247 from nrTQgc/netbsd
NetBSD support (compiler parts)
2016-01-19 20:45:29 +01:00
Nick Tolstokulakov
556e3a691f netbsd changes 2016-01-18 18:33:46 +00:00
Kai Nacke
4e932cb8f1 Add missing libraries for OpenSolaris.
The libraries -lsocket and -lnsl were missing.
Both are required to compile a "Hello World" style program.
2016-01-17 09:49:07 +01:00
Johan Engelen
54e9a69b29 [Windows] Add diagnostics about missing ComSpec environment variable while setting up an MSVC environment during linking. If ComSpec is not defined, assume "cmd.exe". 2015-12-19 17:02:49 +01:00
David Nadlinger
57546e1723 driver: Add -static option for creating fully static binaries 2015-11-29 20:16:19 +01:00
David Nadlinger
51afced357 Also clang-tidy driver/ 2015-11-02 11:30:40 +02:00
David Nadlinger
44b0f7b615 driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code
with other LLVM projects. The DMD code we use will soon all
be in D anyway.
2015-11-02 00:28:01 +02:00
Martin
2d959ea540 Make use of C++11 range-based for
Should be available now that support for LLVM < 3.5 has been dropped.
2015-11-01 14:49:04 +01:00
Martin
60d676e2a1 Drop support for LLVM < 3.5
This allows to clean up the code a little.
2015-10-30 22:24:05 +01:00
Martin
7b28517a5c Windows: don't convert encoding when writing linker response file
LLVM assumes UTF-8 input, but our args mainly come from the LDC command
line (+ some from the config file and some implicit ASCII ones).

LDC doesn't use UTF-16 on Windows, so afaik, the command-line args are
encoded in the current codepage and so should just be written untouched
into the response file.
writeFileWithEncoding()'s default encoding is UTF-8, meaning no
conversion.

Also check for errors when trying to create and write the response file,
and refactor the executeAndWait() part.
2015-10-18 04:00:34 +02:00
Martin
eff81f9c46 Windows: also quote & escape args containing double quotes, but no space
And print a more detailed part of the command line if the tool fails.
2015-10-18 02:21:31 +02:00
Martin
b20148e2db Windows: use a temporary response file for the linker (issue #1160) 2015-10-18 00:42:21 +02:00
Martin
6dfbfe60e9 Windows: fix command line when invoking linker batch file
This command line sent to CreateProcess():

"C:\LDC\bin\amd64.bat" 1 2 "3" 4

is internally transformed to:

C:\Windows\system32\cmd.exe /c "C:\LDC\bin\amd64.bat" 1 2 "3" 4

Now guess what - cmd.exe treats the command string after /c or /k in a
very special way if it begins with double quotes and is followed by other
quoted args. In this example, it tries to invoke:

C:\LDC\bin\amd64.bat" 1 2 "3

Another example:

C:\Windows\system32\cmd.exe /c "C:\L D C\bin\amd64.bat" 1 2 "3" 4
=> C:\L

The fix seems to be enclosing the whole command with additional double
quotes (but no additional escaping of the command!) and using /s for
cmd.exe:

C:\Windows\system32\cmd.exe /s /c ""C:\L D C\bin\amd64.bat" 1 2 "3" 4"

So the command is quoted, but not escaped, i.e., no regular argument to
cmd.exe, so we can't use LLVM's executeAndWait() to launch the cmd.exe
process. :/

Additionally, LLVM's arg-quoting code is not public, so we can't use it
to quote & escape the regular args inside the command.

I therefore implemented a simple quoteArgs() variant which should
suffice for our use cases.
2015-10-18 00:42:20 +02:00
Rainer Schuetze
8b5cee7a7c issue #1161: return status if lib invocation 2015-10-17 15:27:37 +02:00
Martin
c480e9b41b MSVC: detect VS install dir properly and add batch file helper for x86 2015-10-01 01:57:38 +02:00