Commit Graph

31 Commits

Author SHA1 Message Date
Axel Naumann
ab8fcc633a Remove default-by-tokens default ctor (NFC). 2019-06-28 23:59:17 +02:00
Vassil Vassilev
272905eced Implement clang plugin support.
Clang allows third party shared libraries to provide user-defined
extensions. For example, a custom libTemplateInstantiation.so can
visualize all template instantiation chains in clang. To enable it
one needs to pass a set of options such as -fplugin.

Cling should be able to inherently work with clang plugins. However,
cling still does not make full use of the clang driver where the plugin
setup is handled.

This patch enables plugins in cling and extends them in some aspects.
In particular, cling allows loading of plugins from shared libraries
but also if they are linked to the same library where cling is. This is
very useful in cases where cling runs itself in a shared library (eg
libCling). Users of libCling (such as ROOT) prefer to keep all llvm and
clang related symbols local to avoid symbol clashes if there is another
version of clang and llvm linked against a package. This can be done by
dlopen-ing libCling with RTLD_LOCAL visibility mode. Then the only way
for clang plugins to work in this scenario is to be linked to libCling.

Patch by Aleksandr Efremov and me.
2018-07-28 13:17:44 +02:00
Yuka Takahashi
35a8988d50 Autoload less libraries
In previous allmodules&autoloading patch, we used callback from
DeserializationListener to get Decl and loaded corresponding libraries.
It worked, but the performance was bad because ROOT was loading
excessive libraries.

In this patch, we use TCling::LazyFunctionCreatorAutoloadForModule. This
function gets callback when "mangled_name" was not found in loaded
libraries thus we have to the load corresponding library and lookup
again.

I used unordered_map to store mangled identifier and library pair. I'm
doing an optimization by hashing mangled name and storing library not by
name but by uint8 and hold uint8-name information in another vector.
Also tried std::map but unorderd_map was more performant. There are
better hash table like:
https://probablydance.com/2018/05/28/a-new-fast-hash-table-in-response-to-googles-new-fast-hash-table/
we can try to use them if this part gets crucial.

With this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.04 seconds Cpu Time =   0.03 seconds
(TFile *) 0x562b37a14fe0
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 0.362307 seconds
sys  time = 0.039741 seconds
res  memory = 278.215 Mbytes
vir  memory = 448.973 Mbytes
```

W/o this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.08 seconds Cpu Time =   0.07 seconds
(TFile *) 0x5563018a1d30
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 1.524314 seconds
sys  time = 0.157075 seconds
res  memory = 546.867 Mbytes
vir  memory = 895.184 Mbytes
```

So it improves time by 4x times and memory by 2x.
2018-06-02 10:44:38 +02:00
Yuka Takahashi
98719ad352 Preloading modules and autoloading libraries by deserialized decls
Preloading all the modules has several advantages. 1. We do not have to
rely on rootmap files which don't support some features (namespaces and
templates) 2. Lookup would be faster because we don't have to do
trampoline via rootmap files.

Autoloading libraries when decls are deserialized gives us correctness.
However we still need to optimize the performance by reducing the amount
of loaded libraries and improving Clang performance.
2018-05-18 10:14:30 +02:00
Frederich Munch
760df2116a Hide DeclCollectorPPAdapter and use DeclCollector for setup. No need for these details to be public. 2017-07-15 10:14:38 +02:00
Frederich Munch
eba5ccd09a Update DeclCollectorPPAdapter to allow unloading of #undef command. 2017-07-15 10:14:38 +02:00
Frederich Munch
68d2bac1b1 Use final instead of virtual keyword for DeclCollector. 2017-07-15 10:14:38 +02:00
Axel Naumann
4cec420bf1 Unloaded declarations are now put back into CodeGen; no need to mark them used. 2016-11-07 13:02:51 +01:00
Axel Naumann
e0ba0a3f1e Remove unused function. 2016-09-13 09:59:43 +02:00
Axel Naumann
1f4d6c063a Fix Coverity CID60779,60780 - clash with parameter name. 2016-09-12 22:31:57 +02:00
Axel Naumann
22fe0f2c20 Do not transform recursively; each Decl should only be transformed once.
(cherry picked from commit a1a1288176480f717f6031aa6a7e664f2135e537)
2016-08-30 11:14:19 +02:00
Philippe Canal
569ef839cb Implement DeclCollector::HandleInvalidTagDeclDefinition.
This allow the transaction from noticing and removing invalid decl (appear during template instantiation)
2015-09-23 09:43:03 +02:00
Axel Naumann
690d4b0578 Rename ASTTransformer.h -> TransactionTransformer.h. 2015-03-16 15:24:52 +01:00
Axel Naumann
166032069e Emit Decls as DeclCollector sees them.
Now that we can easily revert Transactions' IR (by unloading their
module) we do not need to queue the Decls before emitting them.
This enables EndOfTU actions to be emitted seeminglessly, without
extra transactions, or explicit post-EndOfTU-emission: each
Transaction will have its TU finalized exactly once.

This in turn allows us to turn on Debug emission - which relies on
being invoked exactly once per Module.

Transformers must be invoked before emitting Decls. They are now
invoked for each Decl; WrapperTransformers are invoked when seeing
a wrapper decl. They do not see the "full transaction AST" anymore
- luckily none of our transformers requires this and actually become
simpler because of this change.

This also fixes a bug where the relative sequencing of parsed and
deserialized Decls was lost (parsed was emitted before deserialized).

Remove unused IRTransactions; they should really be llvm::Pass-es.
We don't have them anyway.

Disable a few transformations if the Decl isFromASTFile.

When reverting a Transaction, also revert its nested ones.

In the ValueExtractionSynthesizer, pass the ValuePrinter option as
int, instead of the transaction pointer - that might have changed
(at least its options) by the time we invoke the wrapper.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i or -o; assuming --only paths...
# rebase in progress; onto b3d9f92
# You are currently splitting a commit while rebasing branch 'declcollector-emits-v2' on 'b3d9f92'.
#
# Changes to be committed:
#	modified:   interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h
#	modified:   interpreter/cling/lib/Interpreter/AutoSynthesizer.cpp
#	modified:   interpreter/cling/lib/Interpreter/AutoSynthesizer.h
#	modified:   interpreter/cling/lib/Interpreter/CheckEmptyTransactionTransformer.cpp
#	modified:   interpreter/cling/lib/Interpreter/CheckEmptyTransactionTransformer.h
#	modified:   interpreter/cling/lib/Interpreter/DeclCollector.cpp
#	modified:   interpreter/cling/lib/Interpreter/DeclCollector.h
#	modified:   interpreter/cling/lib/Interpreter/DeclExtractor.cpp
#	modified:   interpreter/cling/lib/Interpreter/DeclExtractor.h
#	modified:   interpreter/cling/lib/Interpreter/DynamicLookup.cpp
#	modified:   interpreter/cling/lib/Interpreter/DynamicLookup.h
#	modified:   interpreter/cling/lib/Interpreter/IncrementalParser.cpp
#	modified:   interpreter/cling/lib/Interpreter/IncrementalParser.h
#	modified:   interpreter/cling/lib/Interpreter/NullDerefProtectionTransformer.cpp
#	modified:   interpreter/cling/lib/Interpreter/NullDerefProtectionTransformer.h
#	modified:   interpreter/cling/lib/Interpreter/TransactionTransformer.cpp
#	modified:   interpreter/cling/lib/Interpreter/TransactionTransformer.h
#	modified:   interpreter/cling/lib/Interpreter/TransactionUnloader.cpp
#	modified:   interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp
#	modified:   interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.h
#	modified:   interpreter/cling/lib/Interpreter/ValuePrinterSynthesizer.cpp
#	modified:   interpreter/cling/lib/Interpreter/ValuePrinterSynthesizer.h
#
# Untracked files:
#	.idea/
#	0001-Fix-llvm-merge-issue.patch
#	0002-Fix-warnings.patch
#	0003-Keep-weak-symbols-around-subsequent-transactions-mig.patch
#	T.cxx
#	T.cxx~
#	TMVA.root
#	a.out
#	boost.root
#	config/Makefile.depend~
#	core/textinput/src/textinput/TerminalDisplayWin.cpp.orig
#	ct.root
#	data.root
#	interpreter/cling/76fc2055249da7b03148a7d4197a279e9943f012.patch
#	interpreter/cling/lib/Interpreter/CIFactory.cpp~
#	interpreter/cling/lib/Interpreter/DeclCollector.h~
#	interpreter/cling/lib/Interpreter/DynamicLibraryManager.cpp~
#	modulemap-one-header-per-file.txt
#	osrm-routed
#	tiles.tar.bz2
#	tmva_class_example.root
#	tutorials/v3.root
#	weights/
#
2015-03-16 14:58:58 +01:00
Axel Naumann
c44e538008 Follow interface change. 2015-02-11 10:57:46 +01:00
Axel Naumann
6b3843b2ba Implement new DeclCollectorPPAdapter.
As emitter objects now own their callback objects, DeclCollector has two owners.
Fix that by using an explicit bridge callback for the Preprocessor that it can own.
2015-02-11 10:57:41 +01:00
Vassil Vassilev
08a9274c02 Mark implicit members coming from a PCH as used.
Implicitly generated members from a CXXRecordDecls coming from a PCH should not be
unloaded. CodeGen 'records' that it once emitted the implicit members and if they
get unloaded it would be out of sync. The key difference is the information about
all the implicitly generated members (trivial ctors/dtors, etc) comes from an
ASTMutationListener and they are not part of the transaction. We still do not
record it as a part of the transaction, we just mark them as used so that they
don't get unloaded from the llvm::Module.

Once the list of llvm.used decls is emitted we need to clear it, otherwise we
end up emitting one and the same thing over and over.

Fixes ROOT-6722
Tests should be coming shortly.
2014-09-29 15:51:10 +02:00
Philippe Canal
576ca3ca96 Remove trailing spaces 2014-08-13 16:08:36 +02:00
Axel Naumann
44481ace1e Fix license; remove $Id$ version. 2014-01-07 11:14:04 +01:00
CristinaCristescu
1d06b2725b Workaround multiple DeclCollector instances. 2013-11-25 13:56:02 +01:00
CristinaCristescu
d6e2f85d1c Fix and improve macro error recovery. 2013-11-25 13:56:02 +01:00
CristinaCristescu
85b4232729 Revert macro def for error recovery. 2013-11-25 13:56:01 +01:00
CristinaCristescu
0490caaa99 Macro recovery 2013-11-25 13:56:00 +01:00
Vassil Vassilev
59ced3f193 Move codegenning of deserialized declarations in the IncrementalParser.
We had two different codepath for codegeneration. The first one was for
declarations that came from text and the second one for declarations that came
from 'ExternalSource' such as PCH. In the latter case we had to do some
extra equilibristics to emulate a PCM and ignore generating code for decls with
static storage, because it will clash with the loading of the library that already
contains them.

The advantage of the new implementation is that instead of communicating the
deserialized decls to ROOT via some fishy deserialization listeners we can use
the cling::Transaction as we use it for decls that came from code.
2013-08-28 16:44:01 +02:00
Axel Naumann
48b4a4e934 For Decls coming from a parsed file that describes the content of a library:
the callbacks must be triggered for those, too.
As they are not part of a transaction (think "module") they are now sent to the deserialization listener.
This can be removed once the modules work.

Set the state of the transaction to Committing before the static init - which might trigger more decls even though CodeGen has been run over the decls.

Forward DeclCollector::HandleInterestingDecl() to DeclCollector::HandleTopLevelDecl() for decls from the AST reader / from headers describing libraries.

Empty transactions must be passed to TCling; they trigger the sending of deserialized decls to ROOT/Meta.

Don't start TCling's artificial TU Transaction if the transaction coming in is empty - we need a decl to get the ASTContext.

Swap the deserialized decls before handling them in TCling, such that nested calls don't see the same decls again.


git-svn-id: http://root.cern.ch/svn/root/trunk@49197 27541ba8-7e3a-0410-8455-c3a389f83636
2013-04-10 15:15:49 +00:00
Axel Naumann
e70dfc300b Recurse over Namespaces; add comments / doc.
git-svn-id: http://root.cern.ch/svn/root/trunk@49169 27541ba8-7e3a-0410-8455-c3a389f83636
2013-04-10 06:57:36 +00:00
Axel Naumann
95db59648c Logic improvement: if a decl comes from an ASTReader is should not be collected, even if no codegen object exists.
Don't codegen statics and non-inline functions if from AST file or "forModules" is set:
Filter decls to be sent to codegen also based on the "forModules" flag, not only on whether it's from an AST file - in the end they are the same (forModules will vanish once we have modules).
Iterate over NamespaceDecls before emitting, to be able to filter their elements.


git-svn-id: http://root.cern.ch/svn/root/trunk@49152 27541ba8-7e3a-0410-8455-c3a389f83636
2013-04-09 15:38:50 +00:00
Vassil Vassilev
e9c68e3d38 One more (final) of "Resurrect the trunk" series:
Implement a shortcut for the deserialized decls to codegen. We do not need to put
the deserialized declaration in a transaction, because they are not interesting.
They are valid so we don't need to do sanity checks and if we'd want to unload
we would unload the entire PCH/PCM, which contains a list of all the deserialized
declarations.

NOTE that the implementation is rough and needs further polishing, which will 
happen some time soon...


git-svn-id: http://root.cern.ch/svn/root/trunk@49076 27541ba8-7e3a-0410-8455-c3a389f83636
2013-04-04 15:40:05 +00:00
Axel Naumann
c759ab29ed Add two missing ASTConsumer interfaces to the DeclCollector.
git-svn-id: http://root.cern.ch/svn/root/trunk@47986 27541ba8-7e3a-0410-8455-c3a389f83636
2012-12-12 08:08:56 +00:00
Vassil Vassilev
a26dec6bb1 Adapt to the newest changes in clang (in dyn_cast/isa support).
git-svn-id: http://root.cern.ch/svn/root/trunk@46525 27541ba8-7e3a-0410-8455-c3a389f83636
2012-10-13 15:04:49 +00:00
Axel Naumann
05ba8a3a07 Move cling from cint/ to interpreter/ (Will add a "we have moved" readme to cint/cling.)
git-svn-id: http://root.cern.ch/svn/root/trunk@45844 27541ba8-7e3a-0410-8455-c3a389f83636
2012-09-05 09:37:39 +00:00