Commit Graph

353 Commits

Author SHA1 Message Date
James Molloy f6f121e277 Extend RemapInstruction and friends to take an optional new parameter, a ValueMaterializer.
Extend LinkModules to pass a ValueMaterializer to RemapInstruction and friends to lazily create Functions for lazily linked globals. This is a big win when linking small modules with large (mostly unused) library modules.

llvm-svn: 182776
2013-05-28 15:17:05 +00:00
Rafael Espindola aa9918aac7 Fix a performance bug in the Linker.
Now that we hava a convinient place to keep it, remeber the set of
identified structs as we merge modules.

This speeds up the linking of all the bitcode files in clang with the
gold plugin and -plugin-opt=emit-llvm (i.e., link only, no codegen) from
5:25 minutes to 13.6 seconds!

Patch by Xiaofei Wan!

llvm-svn: 181104
2013-05-04 05:05:18 +00:00
Rafael Espindola 287f18b4b8 Implement Linker::LinkModules with Linker::linkInModule.
Flipping which one is the implementation will let us optimize linkInModule.

llvm-svn: 181102
2013-05-04 04:08:02 +00:00
Rafael Espindola 3df61b7bef Now that Linker.cpp is almost empty, merge it into LinkModules.cpp.
Also remove unused includes.

llvm-svn: 181100
2013-05-04 03:48:37 +00:00
Rafael Espindola a8023c1c9f Last batch of cleanups to Linker.h.
Update comments, fix * placement, fix method names that are not
used in clang, add a linkInModule that takes a Mode and put it
in Linker.cpp.

llvm-svn: 181099
2013-05-04 03:06:50 +00:00
Rafael Espindola 0229acaa0f Don't construct or delete a module on the Linker.
The linker is now responsible only for actually linking the modules, it
is up to the clients to create and destroy them.

llvm-svn: 181098
2013-05-04 02:43:00 +00:00
Rafael Espindola 02a071aca8 Don't store the context in the Linker.
llvm-svn: 181097
2013-05-04 02:34:41 +00:00
Rafael Espindola 40bbfa1080 Remove unused members and constructor arguments.
llvm-svn: 181096
2013-05-04 02:28:57 +00:00
Rafael Espindola f1d3a37427 Delete dead code from the linker.
llvm-svn: 181094
2013-05-04 02:13:18 +00:00
Filip Pizlo dec20e43c0 This patch breaks up Wrap.h so that it does not have to include all of
the things, and renames it to CBindingWrapping.h.  I also moved 
CBindingWrapping.h into Support/.

This new file just contains the macros for defining different wrap/unwrap 
methods.

The calls to those macros, as well as any custom wrap/unwrap definitions 
(like for array of Values for example), are put into corresponding C++ 
headers.

Doing this required some #include surgery, since some .cpp files relied 
on the fact that including Wrap.h implicitly caused the inclusion of a 
bunch of other things.

This also now means that the C++ headers will include their corresponding 
C API headers; for example Value.h must include llvm-c/Core.h.  I think 
this is harmless, since the C API headers contain just external function 
declarations and some C types, so I don't believe there should be any 
nasty dependency issues here.

llvm-svn: 180881
2013-05-01 20:59:00 +00:00
Eric Christopher 04d4e9312c Move C++ code out of the C headers and into either C++ headers
or the C++ files themselves. This enables people to use
just a C compiler to interoperate with LLVM.

llvm-svn: 180063
2013-04-22 22:47:22 +00:00
Bill Wendling fa2287825d Specutively revert r178130.
This may be causing a failure on some buildbots:

Referencing function in another module!
  tail call fastcc void @_ZL11EvaluateOpstPtRj(i16 zeroext %17, i16* %Vals, i32* %NumVals), !dbg !219
Referencing function in another module!
  tail call fastcc void @_ZL11EvaluateOpstPtRj(i16 zeroext %19, i16* %Vals, i32* %NumVals), !dbg !221
Broken module found, compilation aborted!
Stack dump:
0.    Running pass 'Function Pass Manager' on module 'ld-temp.o'.
1.    Running pass 'Module Verifier' on function '@_ZL11EvaluateOpstPtRj'
clang: error: unable to execute command: Illegal instruction: 4
clang: error: linker command failed due to signal (use -v to see invocation)

<rdar://problem/13516485>

llvm-svn: 178156
2013-03-27 17:54:41 +00:00
James Molloy ec25de421c Improve performance of LinkModules when linking with modules with large numbers of functions which link lazily. Instead of creating and destroying function prototypes irrespective of if they are used, only create them if they are used.
llvm-svn: 178130
2013-03-27 10:23:32 +00:00
Eli Bendersky 0f7fd36f86 The Linker interface has some dead code after the cleanup in r172749
(and possibly others). The attached patch removes it, and tries to
update comments accordingly.

llvm-svn: 177406
2013-03-19 15:26:24 +00:00
Eli Bendersky 970cc63448 Clean up out-of-date comments and some stray whitespace
llvm-svn: 176729
2013-03-08 22:29:44 +00:00
Guy Benyei 83c74e9fad Add static cast to unsigned char whenever a character classification function is called with a signed char argument, in order to avoid assertions in Windows Debug configuration.
llvm-svn: 175006
2013-02-12 21:21:59 +00:00
Daniel Dunbar a32a546dcb [Linker] Kill Linker::LoadObject which is dead, and drop the BitReader dependency again.
llvm-svn: 172838
2013-01-18 19:37:11 +00:00
Benjamin Kramer d4c212eb60 The IR linker still depends on the bitcode reader.
llvm-svn: 172824
2013-01-18 15:03:03 +00:00
Daniel Dunbar 50dc8a6a38 [Linker] Drop some now-dead component dependencies.
llvm-svn: 172759
2013-01-17 22:05:18 +00:00
Daniel Dunbar 8a81c24312 [Linker] Drop support for IR-level extended linking support (archives, etc.).
- This code is dead, and the "right" way to get this support is to use the
   platform-specific linker-integrated LTO mechanisms, or the forthcoming LLVM
   linker.

llvm-svn: 172749
2013-01-17 19:52:25 +00:00
Daniel Dunbar d77d9fb04d [IR] Add 'Append' and 'AppendUnique' module flag behaviors.
llvm-svn: 172659
2013-01-16 21:38:56 +00:00
Daniel Dunbar 0ec72bbc4d [Linker] Change module flag linking to be more extensible.
- Instead of computing a bunch of buckets of different flag types, just do an
   incremental link resolving conflicts as they arise.

 - This also has the advantage of making the link result deterministic and not
   dependent on map iteration order.

llvm-svn: 172634
2013-01-16 18:39:23 +00:00
Daniel Dunbar 6afb94f9e0 [Linker] Drop asserts that are embedded in cast<> and now checked by the verifier.
llvm-svn: 172550
2013-01-15 20:52:09 +00:00
Joey Gouly 5fad3e9ad6 Fix a copy/paste error in the IR Linker, casting an ArrayType instead of a VectorType.
llvm-svn: 172054
2013-01-10 10:49:36 +00:00
Chandler Carruth dcb603feef Move TypeFinder.h into the IR tree, it clearly belongs with the IR library.
llvm-svn: 171749
2013-01-07 15:43:51 +00:00
Chandler Carruth 9fb823bbd4 Move all of the header files which are involved in modelling the LLVM IR
into their new header subdirectory: include/llvm/IR. This matches the
directory structure of lib, and begins to correct a long standing point
of file layout clutter in LLVM.

There are still more header files to move here, but I wanted to handle
them in separate commits to make tracking what files make sense at each
layer easier.

The only really questionable files here are the target intrinsic
tablegen files. But that's a battle I'd rather not fight today.

I've updated both CMake and Makefile build systems (I think, and my
tests think, but I may have missed something).

I've also re-sorted the includes throughout the project. I'll be
committing updates to Clang, DragonEgg, and Polly momentarily.

llvm-svn: 171366
2013-01-02 11:36:10 +00:00
Chandler Carruth ed0881b2a6 Use the new script to sort the includes of every file under lib.
Sooooo many of these had incorrect or strange main module includes.
I have manually inspected all of these, and fixed the main module
include to be the nearest plausible thing I could find. If you own or
care about any of these source files, I encourage you to take some time
and check that these edits were sensible. I can't have broken anything
(I strictly added headers, and reordered them, never removed), but they
may not be the headers you'd really like to identify as containing the
API being implemented.

Many forward declarations and missing includes were added to a header
files to allow them to parse cleanly when included first. The main
module rule does in fact have its merits. =]

llvm-svn: 169131
2012-12-03 16:50:05 +00:00
Bill Wendling ee5984df39 Remove the dependent libraries feature.
The dependent libraries feature was never used and has bit-rotted. Remove it.

llvm-svn: 168694
2012-11-27 09:55:56 +00:00
Bill Wendling 8555a37c04 Move the "findUsedStructTypes" functionality outside of the Module class.
The "findUsedStructTypes" method is very expensive to run. It needs to be
optimized so that LTO can run faster. Splitting this method out of the Module
class will help this occur. For instance, it can keep a list of seen objects so
that it doesn't process them over and over again.

llvm-svn: 161228
2012-08-03 00:30:35 +00:00
Hans Wennborg cbe34b4cc9 Extend the IL for selecting TLS models (PR9788)
This allows the user/front-end to specify a model that is better
than what LLVM would choose by default. For example, a variable
might be declared as

  @x = thread_local(initialexec) global i32 42

if it will not be used in a shared library that is dlopen'ed.

If the specified model isn't supported by the target, or if LLVM can
make a better choice, a different model may be used.

llvm-svn: 159077
2012-06-23 11:37:03 +00:00
Bill Wendling a3aeb980d2 Supply a C interface to the "LinkModules" method.
Patch by Andrew Wilkins!

llvm-svn: 156469
2012-05-09 08:55:40 +00:00
Bill Wendling 32854e2727 Add a flag to the struct type finder to collect only those types which have
names. This saves collecting types we normally don't care about.

llvm-svn: 155300
2012-04-21 23:59:16 +00:00
Bill Wendling 8737480dfa It's possible for two types, which are isomorphic, to be added to the
destination module, but one of them isn't used in the destination module. If
another module comes along and the uses the unused type, there could be type
conflicts when the modules are finally linked together. (This happened when
building LLVM.)

The test that was reduced is:

Module A:

%Z = type { %A }
%A = type { %B.1, [7 x x86_fp80] }
%B.1 = type { %C }
%C = type { i8* }

declare void @func_x(%C*, i64, i64)
declare void @func_z(%Z* nocapture)

Module B:

%B = type { %C.1 }
%C.1 = type { i8* }
%A.2 = type { %B.3, [5 x x86_fp80] }
%B.3 = type { %C.1 }

define void @func_z() {
  %x = alloca %A.2, align 16
  %y = getelementptr inbounds %A.2* %x, i64 0, i32 0, i32 0
  call void @func_x(%C.1* %y, i64 37, i64 927) nounwind
  ret void
}

declare void @func_x(%C.1*, i64, i64)
declare void @func_y(%B* nocapture)

(Unfortunately, this test doesn't fail under llvm-link, only during an LTO
linking.) The '%C' and '%C.1' clash. The destination module gets the '%C'
declaration. When merging Module B, it looks at the '%C.1' subtype of the '%B'
structure. It adds that in, because that's cool. And when '%B.3' is processed,
it uses the '%C.1'. But the '%B' has used '%C' and we prefer to use '%C'. So the
'@func_x' type is changed to 'void (%C*, i64, i64)', but the type of '%x' in
'@func_z' remains '%A.2'. The GEP resolves to a '%C.1', which conflicts with the
'@func_x' signature.

We can resolve this situation by making sure that the type is used in the
destination before saying that it should be used in the module being merged in.

With this fix, LLVM and Clang both compile under LTO.
<rdar://problem/10913281>

llvm-svn: 153351
2012-03-23 23:17:38 +00:00
Bill Wendling 00623787c0 Ignore the last message.
llvm-svn: 153315
2012-03-23 07:22:49 +00:00
Bill Wendling 947f92869a Revert patch. It broke the build.
llvm-svn: 153314
2012-03-23 07:21:18 +00:00
Bill Wendling 7389acda89 Dematerialize the source functions after we're done with them. This saves a bit
of memory during LTO.

llvm-svn: 153313
2012-03-23 07:18:22 +00:00
Bill Wendling 44022b2ae8 Some whitespace and comment cleanup.
llvm-svn: 153278
2012-03-22 20:47:54 +00:00
Bill Wendling 8c2cc41691 Remove unneeded #ifdefs.
llvm-svn: 153277
2012-03-22 20:30:41 +00:00
Bill Wendling b6af2f36cd Add a 'dump' method to the type map. Doxygenify some of the comments and add a
few comments where none existed before. Also change a function's name to match
the current coding standard.
No functionality change.

llvm-svn: 153276
2012-03-22 20:28:27 +00:00
Duncan Sands df39b7077d Include cctype for isdigit. Patch by Stephen Hines.
llvm-svn: 151973
2012-03-03 09:36:58 +00:00
Bill Wendling d48b7783e8 Oops...Don't commit the other stuff..
llvm-svn: 151618
2012-02-28 04:01:21 +00:00
Bill Wendling 73799f68d8 Modify comment to reflect the importance of this code.
llvm-svn: 151617
2012-02-28 03:47:09 +00:00
Bill Wendling 2b3f61af18 Add back removed code. It still causes LLVM to miscompile. But not having it breaks other things.
llvm-svn: 151594
2012-02-27 23:48:30 +00:00
Bill Wendling 688793da4a Don't use #if 0. Just remove until I can address this.
llvm-svn: 151580
2012-02-27 22:55:40 +00:00
Bill Wendling 7b4646184b The code that cleans up multiple, isomorphic types has a subtle error that
manifests itself when building LLVM with LTO.
<rdar://problem/10913281>

llvm-svn: 151576
2012-02-27 22:34:19 +00:00
Bill Wendling 9273b53965 Capitalize messages so that they appear nicely with the linker's error messages.
llvm-svn: 150466
2012-02-14 09:13:54 +00:00
Bill Wendling 66f02413ef [WIP] Initial code for module flags.
Module flags are key-value pairs associated with the module. They include a
'behavior' value, indicating how module flags react when mergine two
files. Normally, it's just the union of the two module flags. But if two module
flags have the same key, then the resulting flags are dictated by the behaviors.

Allowable behaviors are:

     Error
       Emits an error if two values disagree.

     Warning
       Emits a warning if two values disagree.

     Require
       Emits an error when the specified value is not present
       or doesn't have the specified value. It is an error for
       two (or more) llvm.module.flags with the same ID to have
       the Require behavior but different values. There may be
       multiple Require flags per ID.

     Override
       Uses the specified value if the two values disagree. It
       is an error for two (or more) llvm.module.flags with the
       same ID to have the Override behavior but different
       values.

llvm-svn: 150300
2012-02-11 11:38:06 +00:00
Craig Topper a2886c21d9 Convert assert(0) to llvm_unreachable
llvm-svn: 149967
2012-02-07 05:05:23 +00:00
Chris Lattner 6705883ad8 use Constant::getAggregateElement to simplify a bunch of code.
llvm-svn: 148934
2012-01-25 06:48:06 +00:00
Chris Lattner 00245f420a add more support for ConstantDataSequential
llvm-svn: 148802
2012-01-24 13:41:11 +00:00