annotate gen/passes/StripExternals.cpp @ 1547:259b031f3d22

Some minor cleanups * remove an #ifdef USE_METADATA I accidently left in * remove now unneeded llvm-version includes * fix indentation in metadata.h * prevent the "Found native target" message from interrupting ccmake
author Benjamin Kramer <benny.kra@gmail.com>
date Mon, 20 Jul 2009 18:16:11 +0200
parents c88b16d4a13c
children ed0feda76820
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"
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
27 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
28
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
29 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
30 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
31
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
32 namespace {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
33 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
34 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
35 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
36
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
37 // 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
38 //
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
39 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
40 };
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 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
44 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
45 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
46
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
47 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
48
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
49 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
50 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
51
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
52 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
53 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
54 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
55 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
56 ++NumFunctions;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
57 if (I->use_empty()) {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
58 DOUT << "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
59 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
60 ++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 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
62 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
63 } else {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
64 I->deleteBody();
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
65 DOUT << "Deleted function body: " << *I;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
66 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
67 }
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
68 ++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
69 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
70
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
71 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
72 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
73 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
74 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
75 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
76 ++NumVariables;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
77 if (I->use_empty()) {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
78 DOUT << "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
79 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
80 ++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 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
82 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
83 } else {
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
84 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
85 I->setLinkage(GlobalValue::ExternalLinkage);
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
86 DOUT << "Deleted initializer: " << *I;
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
87 }
defafbabbe32 Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
88 }
1493
7cca8cf730de Increment the iterator before deleting redundant functions or globals in the StripExternals pass.
Christian Kamm <kamm incasoftware de>
parents: 1483
diff changeset
89 ++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
90 }
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 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
93 }