Commit Graph

98 Commits

Author SHA1 Message Date
Steven Wu 9278019eb3 [Driver] Make clang/cc conforms to UNIX standard
Summary:
This is basically reverting r261774 with a tweak for clang-cl. UNIX
standard states:
When c99 encounters a compilation error that causes an object file not
to be created, it shall write a diagnostic to standard error and
continue to compile other source code operands, but it shall not perform
the link phase and it shall return a non-zero exit status

The same goes for c89 or cc. And they are all alias or shims pointing to
clang on Darwin.

The original commit was intended for CUDA so the error message doesn't
get emit twice for both host and device. It seems that the clang driver
has been changed to model the CUDA dependency differently. Now the
driver behaves the same without this commit.

rdar://problem/32223263

Reviewers: thakis, dexonsmith, tra

Reviewed By: tra

Subscribers: jlebar, cfe-commits

Differential Revision: https://reviews.llvm.org/D39502

llvm-svn: 317860
2017-11-10 01:32:47 +00:00
Hamza Sood 8c01d47e52 Testing commit access.
llvm-svn: 315231
2017-10-09 19:07:09 +00:00
Jonas Hahnfeld bbf56fb621 [OpenMP] Fix passing of -m arguments correctly
The recent fix in D38258 was wrong: getAuxTriple() only returns
non-null values for the CUDA toolchain. That is why the now added
test for PPC and X86 failed.

Differential Revision: https://reviews.llvm.org/D38372

llvm-svn: 314902
2017-10-04 13:32:59 +00:00
Jonas Hahnfeld 102c333d9a [OpenMP] Fix translation of target args
ToolChain::TranslateArgs() returns nullptr if no changes are performed.
This would currently mean that OpenMPArgs are lost. Patch fixes this
by falling back to simply using OpenMPArgs in that case.

Differential Revision: https://reviews.llvm.org/D38259

llvm-svn: 314330
2017-09-27 18:12:36 +00:00
Jonas Hahnfeld 85f19958e9 [OpenMP] Fix memory leak when translating arguments
Parsing the argument after -Xopenmp-target allocates memory that needs
to be freed. Associate it with the final DerivedArgList after we know
which one will be used.

Differential Revision: https://reviews.llvm.org/D38257

llvm-svn: 314328
2017-09-27 18:12:31 +00:00
Alexander Kornienko 9707aa74d6 Update users of llvm::sys::ExecuteAndWait etc.
Summary: Clang part of https://reviews.llvm.org/D37563

Reviewers: bkramer

Subscribers: vsk, cfe-commits

Differential Revision: https://reviews.llvm.org/D37564

llvm-svn: 313156
2017-09-13 17:03:58 +00:00
Gheorghe-Teodor Bercea bcfdd7861e Non-functional change. Fix previous patch D34784.
llvm-svn: 310282
2017-08-07 18:43:37 +00:00
Gheorghe-Teodor Bercea 47e0cf378c [OpenMP] Add flag for specifying the target device architecture for OpenMP device offloading
Summary:
OpenMP has the ability to offload target regions to devices which may have different architectures.

A new -fopenmp-target-arch flag is introduced to specify the device architecture.

In this patch I use the new flag to specify the compute capability of the underlying NVIDIA architecture for the OpenMP offloading CUDA tool chain.

Only a host-offloading test is provided since full device offloading capability will only be available when [[ https://reviews.llvm.org/D29654 | D29654 ]] lands.

Reviewers: hfinkel, Hahnfeld, carlo.bertolli, caomhin, ABataev

Reviewed By: hfinkel

Subscribers: guansong, cfe-commits

Tags: #openmp

Differential Revision: https://reviews.llvm.org/D34784

llvm-svn: 310263
2017-08-07 15:39:11 +00:00
Benjamin Kramer 43c0f486b0 [Driver] Actually report errors during parsing instead of stopping when there's an error somewhere.
This is a more principled version of r303756. That change was both very
brittle about the state of the Diags object going into the driver and
also broke tooling in funny ways.

In particular it prevented tools from capturing diagnostics properly and
made the compilation database logic fail to provide arguments to the
tool, falling back to scanning directories for JSON files.

llvm-svn: 306822
2017-06-30 13:21:27 +00:00
Samuel Antao 31fef98993 [Driver][OpenMP] Add logic for offloading-specific argument translation.
Summary:
This patch includes support for argument translation that is specific of a given offloading kind. Additionally, it implements the translation for OpenMP device kinds in the gcc tool chain.

With this patch, it is possible to compile a functional OpenMP application with offloading capabilities with no separate compilation.

Reviewers: echristo, tra, jlebar, rsmith, ABataev, hfinkel

Subscribers: whchung, mehdi_amini, cfe-commits, Hahnfeld, andreybokhanko, arpith-jacob, carlo.bertolli, caomhin

Differential Revision: https://reviews.llvm.org/D21848

llvm-svn: 285320
2016-10-27 17:39:44 +00:00
Mehdi Amini c50b1a263b Turn ArchName/BoundArch in Driver from raw pointer to StringRef (NFC)
llvm-svn: 283605
2016-10-07 21:27:26 +00:00
Nikolay Haustov 9c366cdf2a [Driver] Add method to redirect output of Compilation.
Summary:
Currently output of child process, however in my use case, it
needs to be captured and presented to the user.

Add Redirect method to Compilation and use existing infrastructure
for redirecting output of commands.

Reviewers: tstellarAMD

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21224

llvm-svn: 273997
2016-06-28 08:00:42 +00:00
Samuel Antao c1ffba5062 [CUDA][OpenMP] Create generic offload toolchains
Summary:
This patch introduces the concept of offloading tool chain and offloading kind. Each tool chain may have associated an offloading kind that marks it as used in a given programming model that requires offloading. 

It also adds the logic to iterate on the tool chains based on the kind. Currently, only CUDA is supported, but in general a programming model (an offloading kind) may have associated multiple tool chains that require supporting offloading.

This patch does not add tests - its goal is to keep the existing functionality.

This patch is the first of a series of three that attempts to make the current support of CUDA more generic and easier to extend to other programming models, namely OpenMP. It tries to capture the suggestions/improvements/concerns on the initial proposal in  http://lists.llvm.org/pipermail/cfe-dev/2016-February/047547.html. It only tackles the more consensual part of the proposal, i.e.does not address the problem of intermediate files bundling yet.

Reviewers: ABataev, jlebar, echristo, hfinkel, tra

Subscribers: guansong, Hahnfeld, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin

Differential Revision: http://reviews.llvm.org/D18170

llvm-svn: 272571
2016-06-13 18:10:57 +00:00
Justin Lebar 8671c441c3 Bail on compilation as soon as a job fails.
Summary:
(Re-land of r260448, which was reverted in r260522 due to a test failure
in Driver/output-file-cleanup.c that only showed up in fresh builds.)

Previously we attempted to be smart; if one job failed, we'd run all
jobs that didn't depend on the failing job.

Problem is, this doesn't work well for e.g. CUDA compilation without
-save-temps.  In this case, the device-side and host-side Assemble
actions (which actually are responsible for preprocess, compile,
backend, and assemble, since we're not saving temps) are necessarily
distinct.  So our clever heuristic doesn't help us, and we repeat every
error message once for host and once for each device arch.

The main effect of this change, other than fixing CUDA, is that if you
pass multiple cc files to one instance of clang and you get a compile
error, we'll stop when the first cc1 job fails.

Reviewers: echristo

Subscribers: cfe-commits, jhen, echristo, tra, rafael

Differential Revision: http://reviews.llvm.org/D17217

llvm-svn: 261774
2016-02-24 21:49:28 +00:00
Nico Weber 5a459f8249 Rename Action::begin() to Action::input_begin().
Also introduce inputs() that reutnrs an llvm::iterator_range.
Iterating over A->inputs() is much less mysterious than
iterating over *A.  No intended behavior change.

llvm-svn: 261674
2016-02-23 19:30:43 +00:00
Rafael Espindola 932b31982a Revert "Bail on compilation as soon as a job fails."
This reverts commit r260448.

It was causing Driver/output-file-cleanup.c to fail.

llvm-svn: 260522
2016-02-11 14:13:17 +00:00
Justin Lebar 4022d52959 Bail on compilation as soon as a job fails.
Previously we attempted to be smart; if one job failed, we'd run all
jobs that didn't depend on the failing job.

Problem is, this doesn't work well for e.g. CUDA compilation without
-save-temps.  In this case, the device-side and host-side Assemble
actions (which actually are responsible for preprocess, compile,
backend, and assemble, since we're not saving temps) are necessarily
distinct.  So our clever heuristic doesn't help us, and we repeat every
error message once for host and once for each device arch.

The main effect of this change, other than fixing CUDA, is that if you
pass multiple cc files to one instance of clang and you get a compile
error, we'll stop when the first cc1 job fails.

Reviewers: tra, echristo

Subscribers: jhen, cfe-commits

Differential Revision: http://reviews.llvm.org/D16514

llvm-svn: 260448
2016-02-10 22:17:00 +00:00
Justin Lebar 41094615fb Move ownership of Action objects into Compilation.
Summary:
This makes constructing Action graphs which are DAGs much simpler.  It
also just simplifies in general the ownership semantics of Actions.

Depends on D15910.

Reviewers: echristo

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D15911

llvm-svn: 257407
2016-01-11 23:07:27 +00:00
Artem Belevich 5e2a3ecd48 [CUDA] use -aux-triple to pass target triple of opposite side of compilation
Clang needs to know target triple for both sides of compilation so that
preprocessor macros and target builtins from both sides are available.

This change augments Compilation class to carry information about
toolchains used during different CUDA compilation passes and refactors
BuildActions to use it when it constructs CUDA jobs.

Removed DeviceTriple from CudaHostAction/CudaDeviceAction as it's no
longer needed.

Differential Revision: http://reviews.llvm.org/D13144

llvm-svn: 253385
2015-11-17 22:28:40 +00:00
Justin Bogner 0cd9248d9e Driver: Remove the Job class. NFC
We had a strange relationship here where we made a list of Jobs
inherit from a single Job, but there weren't actually any places where
this arbitrary nesting was used or needed.

Simplify all of this by removing Job entirely and updating all of the
users to either work with a JobList or a single Command.

llvm-svn: 241310
2015-07-02 22:52:08 +00:00
Justin Bogner aab9792b6c Driver: Use pointee_iterator rather than iterating over unique_ptrs
There's probably never a good reason to iterate over unique_ptrs. This
lets us use range-for and say Job.foo instead of (*it)->foo in a few
places.

llvm-svn: 218938
2014-10-03 01:04:53 +00:00
Reid Kleckner 0290c9ca5c Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!

This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.

I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.

I designed it to support different kinds of tools and
internationalisation needs:

- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
  support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )

With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.

Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.

In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.

Reviewers: asl, rafael, silvas

Reviewed By: silvas

Subscribers: silvas, rnk, thakis, cfe-commits

Differential Revision: http://reviews.llvm.org/D4897

llvm-svn: 217792
2014-09-15 17:45:39 +00:00
Craig Topper bf3e32705a Fix some cases where StringRef was being passed by const reference. Remove const from some other StringRefs since its implicitly const already.
llvm-svn: 216825
2014-08-30 16:55:52 +00:00
Rafael Espindola dae941a6c8 Update for llvm api change.
llvm-svn: 216397
2014-08-25 18:17:04 +00:00
Alp Toker 221285bde7 Remove unused sys/stat.h includes
The facility was abstracted to LLVM in r187364.

llvm-svn: 212441
2014-07-07 08:37:15 +00:00
Justin Bogner 332a5e526e Driver: Record that we're in crashdump and push flags to ConstructJob
It's more flexible and arguably better layering to set flags to modify
compiling for diagnostics in the CC1 job themselves, rather than
tweaking the driver flags and letting them propagate.

There is one visible change this causes: crash report files will now
get preprocessed names (.i and friends).

llvm-svn: 211411
2014-06-20 22:16:00 +00:00
Rafael Espindola c080917ec2 Replace llvm::error_code with std::error_code.
llvm-svn: 210780
2014-06-12 14:02:15 +00:00
Craig Topper 92fc2dfa6f [C++11] Use 'nullptr'. Driver edition.
llvm-svn: 209069
2014-05-17 16:56:41 +00:00
Rafael Espindola 4fbd373815 Update for llvm api change.
llvm-svn: 202053
2014-02-24 18:20:21 +00:00
Alp Toker 965f882588 Remove a whole lot of unused variables
There are about 30 removed in this patch, generated by a new FixIt I haven't
got round to submitting yet.

llvm-svn: 195814
2013-11-27 05:22:15 +00:00
Hans Wennborg e8677ef5ca Move the execution code from Compilation::ExecuteCommand to Command::Execute
I think it makes sense that a Command knows how to execute itself.

There's no functionality change but i rewrote the code to avoid the manual
memory management of Argv.

My motivation for this is that I plan to subclass Command to build fall-back
functionality into clang-cl.

Differential Revision: http://llvm-reviews.chandlerc.com/D1654

llvm-svn: 190621
2013-09-12 18:35:08 +00:00
Hans Wennborg b212b34f19 Move Compilation::PrintJob and PrintDiagnosticJob into Job::Print.
This moves the code to Job.cpp, which seems like a more natural fit,
and replaces the "is this a JobList? is this a Command?" logic with
a virtual function call.

It also removes the code duplication between PrintJob and
PrintDiagnosticJob and simplifies the code a little.

There's no functionality change here, except that the Executable is
now always printed within quotes, whereas it would previously not be
quoted in crash reports, which I think was a bug.

Differential Revision: http://llvm-reviews.chandlerc.com/D1653

llvm-svn: 190620
2013-09-12 18:23:34 +00:00
Rafael Espindola 8c4245455a Remove the -ccc-echo option that is now unused.
llvm-svn: 186970
2013-07-23 17:58:53 +00:00
Rafael Espindola 16125fb652 Update for llvm API change.
llvm-svn: 186448
2013-07-16 19:44:23 +00:00
Rafael Espindola 03bc68268f Convert last use of PathV1.h in Compilation.cpp
The way we decide which file to remove is fairly odd. I took a quick look at
maybe changing that, but it would be a more work than I want to put at this
right now, so I left pair of FIXMEs.

llvm-svn: 184766
2013-06-24 17:59:44 +00:00
Rafael Espindola a466b9aeb9 Convert a use of PathV1.h
llvm-svn: 184753
2013-06-24 16:46:15 +00:00
Rafael Espindola fc92e84586 Use llvm::sys::fs::can_write.
llvm-svn: 184234
2013-06-18 20:58:25 +00:00
Rafael Espindola 1600a53bc0 Include PathV1.h only where it is used.
llvm-svn: 184090
2013-06-17 17:23:47 +00:00
Reid Kleckner 898229ab4b [Driver] Refactor clang driver to use LLVM's Option library
The big changes are:
- Deleting Driver/(Arg|Opt)*
- Rewriting includes to llvm/Option/ and re-sorting
- 'using namespace llvm::opt' in clang::driver
- Fixing the autoconf build by adding option everywhere

As discussed in the review, this change includes using directives in
header files.  I'll make follow up changes to remove those in favor of
name specifiers.

Reviewers: espindola

Differential Revision: http://llvm-reviews.chandlerc.com/D975

llvm-svn: 183989
2013-06-14 17:17:23 +00:00
Rafael Espindola cb4bb19070 Use the sys::ExecuteAndWait that takes StringRefs.
Also don't depend on Program.h including PathV1.h.

llvm-svn: 183935
2013-06-13 20:08:52 +00:00
Rafael Espindola a3346d8765 Use the global functions instead of the Program methods.
llvm-svn: 183861
2013-06-12 20:44:26 +00:00
Chad Rosier d14757751f [driver] Do not generate crash diagnostics if the compilation command failed
to execute as the crash will surely reoccur while generating the diagnostics.
rdar://13362359

llvm-svn: 178089
2013-03-26 23:41:30 +00:00
Chad Rosier 6a1de5c634 [driver] The failure of any phase (e.g., preprocess, compile, assemble) for a
single translation unit should prevent later phases from executing.  Otherwise,
this generates lots of noise in build systems.  This a fallout from r173825.
Patch by Matthew Curtis <mcurtis@codeaurora.org>.
rdar://13298009

llvm-svn: 176198
2013-02-27 18:46:04 +00:00
Douglas Gregor 4bedb499ea Form the default -fmodules-cache-path= properly.
llvm-svn: 174674
2013-02-07 22:59:12 +00:00
Chad Rosier c5103c3f3e [driver] Clear the FailureResultFiles when initializing clang diagnostics. Also,
minor cleanup.

llvm-svn: 173852
2013-01-29 23:57:10 +00:00
Chad Rosier dd60e09021 [driver] Refactor the driver so that a failing commands doesn't prevent
subsequent commands from being executed.

The diagnostics generation isn't designed for this use case, so add a note to
fix this in the very near future.  For now, just generated the diagnostics for
the first failing command.
Part of rdar://12984531

llvm-svn: 173825
2013-01-29 20:15:05 +00:00
Chad Rosier 633dcdc52d [driver] Associate a JobAction with each result file. This enables the driver
to delete result files for only those commands that fail.
Part of rdar://12984531

llvm-svn: 173361
2013-01-24 19:14:47 +00:00
Daniel Dunbar 582b2ab0dd [Driver] Don't remove non-regular files that were outputs.
llvm-svn: 173215
2013-01-23 01:08:23 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Dmitri Gribenko b2aa9234b6 Use empty parens for empty function parameter list instead of '(void)'.
llvm-svn: 168041
2012-11-15 14:28:07 +00:00