llvm.org GIT mirror llvm / dbb1735
Initial checkin of new "Internalize" pass for GCCLD git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2362 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
2 changed file(s) with 53 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- Transforms/IPO/Internalize.h - Mark functions internal ---*- C++ -*--=//
1 //
2 // This pass loops over all of the functions in the input module, looking for a
3 // main function. If a main function is found, all other functions are marked
4 // as internal.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_TRANSFORM_IPO_INTERNALIZE_H
9 #define LLVM_TRANSFORM_IPO_INTERNALIZE_H
10
11 class Pass;
12 Pass *createInternalizePass();
13
14 #endif
0 //===-- Internalize.cpp - Mark functions internal -------------------------===//
1 //
2 // This pass loops over all of the functions in the input module, looking for a
3 // main function. If a main function is found, all other functions are marked
4 // as internal.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Transforms/IPO/Internalize.h"
9 #include "llvm/Pass.h"
10 #include "llvm/Module.h"
11 #include "llvm/Function.h"
12
13 class InternalizePass : public Pass {
14 virtual bool run(Module *M) {
15 bool FoundMain = false; // Look for a function named main...
16 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
17 if ((*I)->getName() == "main") {
18 FoundMain = true;
19 break;
20 }
21
22 if (!FoundMain) return false; // No main found, must be a library...
23
24 bool Changed = false;
25
26 // Found a main function, mark all functions not named main as internal.
27 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
28 if ((*I)->getName() != "main") // Leave the main function external
29 (*I)->setInternalLinkage(Changed = true);
30
31 return Changed;
32 }
33 };
34
35 Pass *createInternalizePass() {
36 return new InternalizePass();
37 }