annotate gen/passes/StripExternals.cpp @ 1650:40bd4a0d4870

Update to work with LLVM 2.7. Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents ed0feda76820
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
1 //===-- StripExternals.cpp - Strip available_externally symbols -----------===//
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
2 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
3 // The LLVM D Compiler
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
4 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
7 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
9 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
10 // This transform stips the bodies of available_externally functions and
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
11 // initializers of available_externally globals, turning them into external
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
12 // declarations.
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
13 // This is useful to allow Global DCE (-globaldce) to clean up references to
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
14 // globals only used by available_externally functions and initializers.
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
15 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
16 //===----------------------------------------------------------------------===//
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
17
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
18 #define DEBUG_TYPE "strip-externals"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
19
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
20 #include "Passes.h"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
21
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
22 #include "llvm/Module.h"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
23 #include "llvm/Pass.h"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
24 #include "llvm/ADT/Statistic.h"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
25 #include "llvm/Support/Compiler.h"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
26 #include "llvm/Support/Debug.h"
1551
ed0feda76820 DOUT is deprecated, use DEBUG(errs()) instead
Benjamin Kramer <benny.kra@gmail.com>
parents: 1547
diff changeset
27 #include "llvm/Support/raw_ostream.h"
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
28 using namespace llvm;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
29
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
30 STATISTIC(NumFunctions, "Number of function bodies removed");
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
31 STATISTIC(NumVariables, "Number of global initializers removed");
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
32
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
33 namespace {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
34 struct VISIBILITY_HIDDEN StripExternals : public ModulePass {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
35 static char ID; // Pass identification, replacement for typeid
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
36 StripExternals() : ModulePass(&ID) {}
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
37
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
38 // run - Do the StripExternals pass on the specified module.
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
39 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
40 bool runOnModule(Module &M);
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
41 };
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
42 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
43
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
44 char StripExternals::ID = 0;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
45 static RegisterPass<StripExternals>
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
46 X("strip-externals", "Strip available_externally bodies and initializers");
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
47
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
48 ModulePass *createStripExternalsPass() { return new StripExternals(); }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
49
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
50 bool StripExternals::runOnModule(Module &M) {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
51 bool Changed = false;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
52
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
53 for (Module::iterator I = M.begin(); I != M.end(); ) {
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
54 if (I->hasAvailableExternallyLinkage()) {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
55 assert(!I->isDeclaration()&&"Declarations can't be available_externally");
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
56 Changed = true;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
57 ++NumFunctions;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
58 if (I->use_empty()) {
1551
ed0feda76820 DOUT is deprecated, use DEBUG(errs()) instead
Benjamin Kramer <benny.kra@gmail.com>
parents: 1547
diff changeset
59 DEBUG(errs() << "Deleting function: " << *I);
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
60 Module::iterator todelete = I;
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
61 ++I;
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
62 todelete->eraseFromParent();
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
63 continue;
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
64 } else {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
65 I->deleteBody();
1551
ed0feda76820 DOUT is deprecated, use DEBUG(errs()) instead
Benjamin Kramer <benny.kra@gmail.com>
parents: 1547
diff changeset
66 DEBUG(errs() << "Deleted function body: " << *I);
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
67 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
68 }
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
69 ++I;
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
70 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
71
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
72 for (Module::global_iterator I = M.global_begin();
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
73 I != M.global_end(); ) {
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
74 if (I->hasAvailableExternallyLinkage()) {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
75 assert(!I->isDeclaration()&&"Declarations can't be available_externally");
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
76 Changed = true;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
77 ++NumVariables;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
78 if (I->use_empty()) {
1551
ed0feda76820 DOUT is deprecated, use DEBUG(errs()) instead
Benjamin Kramer <benny.kra@gmail.com>
parents: 1547
diff changeset
79 DEBUG(errs() << "Deleting global: " << *I);
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
80 Module::global_iterator todelete = I;
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
81 ++I;
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
82 todelete->eraseFromParent();
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
83 continue;
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
84 } else {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
85 I->setInitializer(0);
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
86 I->setLinkage(GlobalValue::ExternalLinkage);
1551
ed0feda76820 DOUT is deprecated, use DEBUG(errs()) instead
Benjamin Kramer <benny.kra@gmail.com>
parents: 1547
diff changeset
87 DEBUG(errs() << "Deleted initializer: " << *I);
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
88 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
89 }
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
90 ++I;
1483
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
91 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
92
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
93 return Changed;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
94 }