diff options
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/CodeGen/JITCodeEmitter.h | 66 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineCodeEmitter.h | 70 | ||||
-rw-r--r-- | include/llvm/ExecutionEngine/JITMemoryManager.h | 26 | ||||
-rw-r--r-- | include/llvm/Support/StandardPasses.h | 250 |
4 files changed, 332 insertions, 80 deletions
diff --git a/include/llvm/CodeGen/JITCodeEmitter.h b/include/llvm/CodeGen/JITCodeEmitter.h index bf6b76ee9001..81a7c60bdb60 100644 --- a/include/llvm/CodeGen/JITCodeEmitter.h +++ b/include/llvm/CodeGen/JITCodeEmitter.h @@ -89,7 +89,7 @@ public: /// emitByte - This callback is invoked when a byte needs to be written to the /// output stream. /// - void emitByte(uint8_t B) { + void emitByte(unsigned char B) { if (CurBufferPtr != BufferEnd) *CurBufferPtr++ = B; } @@ -99,10 +99,10 @@ public: /// void emitWordLE(unsigned W) { if (4 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 0); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 24); } else { CurBufferPtr = BufferEnd; } @@ -113,10 +113,10 @@ public: /// void emitWordBE(unsigned W) { if (4 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 0); } else { CurBufferPtr = BufferEnd; } @@ -127,14 +127,14 @@ public: /// void emitDWordLE(uint64_t W) { if (8 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 0); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 32); - *CurBufferPtr++ = (uint8_t)(W >> 40); - *CurBufferPtr++ = (uint8_t)(W >> 48); - *CurBufferPtr++ = (uint8_t)(W >> 56); + *CurBufferPtr++ = (unsigned char)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 32); + *CurBufferPtr++ = (unsigned char)(W >> 40); + *CurBufferPtr++ = (unsigned char)(W >> 48); + *CurBufferPtr++ = (unsigned char)(W >> 56); } else { CurBufferPtr = BufferEnd; } @@ -145,14 +145,14 @@ public: /// void emitDWordBE(uint64_t W) { if (8 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 56); - *CurBufferPtr++ = (uint8_t)(W >> 48); - *CurBufferPtr++ = (uint8_t)(W >> 40); - *CurBufferPtr++ = (uint8_t)(W >> 32); - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 56); + *CurBufferPtr++ = (unsigned char)(W >> 48); + *CurBufferPtr++ = (unsigned char)(W >> 40); + *CurBufferPtr++ = (unsigned char)(W >> 32); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 0); } else { CurBufferPtr = BufferEnd; } @@ -166,8 +166,8 @@ public: if(Alignment <= (uintptr_t)(BufferEnd-CurBufferPtr)) { // Move the current buffer ptr up to the specified alignment. CurBufferPtr = - (uint8_t*)(((uintptr_t)CurBufferPtr+Alignment-1) & - ~(uintptr_t)(Alignment-1)); + (unsigned char*)(((uintptr_t)CurBufferPtr+Alignment-1) & + ~(uintptr_t)(Alignment-1)); } else { CurBufferPtr = BufferEnd; } @@ -178,7 +178,7 @@ public: /// written to the output stream. void emitULEB128Bytes(unsigned Value) { do { - uint8_t Byte = Value & 0x7f; + unsigned char Byte = Value & 0x7f; Value >>= 7; if (Value) Byte |= 0x80; emitByte(Byte); @@ -187,12 +187,12 @@ public: /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be /// written to the output stream. - void emitSLEB128Bytes(int32_t Value) { - int32_t Sign = Value >> (8 * sizeof(Value) - 1); + void emitSLEB128Bytes(int Value) { + int Sign = Value >> (8 * sizeof(Value) - 1); bool IsMore; do { - uint8_t Byte = Value & 0x7f; + unsigned char Byte = Value & 0x7f; Value >>= 7; IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; if (IsMore) Byte |= 0x80; @@ -205,14 +205,14 @@ public: void emitString(const std::string &String) { for (unsigned i = 0, N = static_cast<unsigned>(String.size()); i < N; ++i) { - uint8_t C = String[i]; + unsigned char C = String[i]; emitByte(C); } emitByte(0); } /// emitInt32 - Emit a int32 directive. - void emitInt32(int32_t Value) { + void emitInt32(int Value) { if (4 <= BufferEnd-CurBufferPtr) { *((uint32_t*)CurBufferPtr) = Value; CurBufferPtr += 4; diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h index aaa41a48cb27..226c4c2ad8fb 100644 --- a/include/llvm/CodeGen/MachineCodeEmitter.h +++ b/include/llvm/CodeGen/MachineCodeEmitter.h @@ -50,14 +50,14 @@ class MachineCodeEmitter { protected: /// BufferBegin/BufferEnd - Pointers to the start and end of the memory /// allocated for this code buffer. - uint8_t *BufferBegin, *BufferEnd; + unsigned char *BufferBegin, *BufferEnd; /// CurBufferPtr - Pointer to the next byte of memory to fill when emitting /// code. This is guranteed to be in the range [BufferBegin,BufferEnd]. If /// this pointer is at BufferEnd, it will never move due to code emission, and /// all code emission requests will be ignored (this is the buffer overflow /// condition). - uint8_t *CurBufferPtr; + unsigned char *CurBufferPtr; public: virtual ~MachineCodeEmitter() {} @@ -96,7 +96,7 @@ public: /// emitByte - This callback is invoked when a byte needs to be written to the /// output stream. /// - void emitByte(uint8_t B) { + void emitByte(unsigned char B) { if (CurBufferPtr != BufferEnd) *CurBufferPtr++ = B; } @@ -106,10 +106,10 @@ public: /// void emitWordLE(unsigned W) { if (4 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 0); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 24); } else { CurBufferPtr = BufferEnd; } @@ -120,10 +120,10 @@ public: /// void emitWordBE(unsigned W) { if (4 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 0); } else { CurBufferPtr = BufferEnd; } @@ -134,14 +134,14 @@ public: /// void emitDWordLE(uint64_t W) { if (8 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 0); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 32); - *CurBufferPtr++ = (uint8_t)(W >> 40); - *CurBufferPtr++ = (uint8_t)(W >> 48); - *CurBufferPtr++ = (uint8_t)(W >> 56); + *CurBufferPtr++ = (unsigned char)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 32); + *CurBufferPtr++ = (unsigned char)(W >> 40); + *CurBufferPtr++ = (unsigned char)(W >> 48); + *CurBufferPtr++ = (unsigned char)(W >> 56); } else { CurBufferPtr = BufferEnd; } @@ -152,14 +152,14 @@ public: /// void emitDWordBE(uint64_t W) { if (8 <= BufferEnd-CurBufferPtr) { - *CurBufferPtr++ = (uint8_t)(W >> 56); - *CurBufferPtr++ = (uint8_t)(W >> 48); - *CurBufferPtr++ = (uint8_t)(W >> 40); - *CurBufferPtr++ = (uint8_t)(W >> 32); - *CurBufferPtr++ = (uint8_t)(W >> 24); - *CurBufferPtr++ = (uint8_t)(W >> 16); - *CurBufferPtr++ = (uint8_t)(W >> 8); - *CurBufferPtr++ = (uint8_t)(W >> 0); + *CurBufferPtr++ = (unsigned char)(W >> 56); + *CurBufferPtr++ = (unsigned char)(W >> 48); + *CurBufferPtr++ = (unsigned char)(W >> 40); + *CurBufferPtr++ = (unsigned char)(W >> 32); + *CurBufferPtr++ = (unsigned char)(W >> 24); + *CurBufferPtr++ = (unsigned char)(W >> 16); + *CurBufferPtr++ = (unsigned char)(W >> 8); + *CurBufferPtr++ = (unsigned char)(W >> 0); } else { CurBufferPtr = BufferEnd; } @@ -173,8 +173,8 @@ public: if(Alignment <= (uintptr_t)(BufferEnd-CurBufferPtr)) { // Move the current buffer ptr up to the specified alignment. CurBufferPtr = - (uint8_t*)(((uintptr_t)CurBufferPtr+Alignment-1) & - ~(uintptr_t)(Alignment-1)); + (unsigned char*)(((uintptr_t)CurBufferPtr+Alignment-1) & + ~(uintptr_t)(Alignment-1)); } else { CurBufferPtr = BufferEnd; } @@ -185,7 +185,7 @@ public: /// written to the output stream. void emitULEB128Bytes(unsigned Value) { do { - uint8_t Byte = Value & 0x7f; + unsigned char Byte = Value & 0x7f; Value >>= 7; if (Value) Byte |= 0x80; emitByte(Byte); @@ -194,12 +194,12 @@ public: /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be /// written to the output stream. - void emitSLEB128Bytes(int32_t Value) { - int32_t Sign = Value >> (8 * sizeof(Value) - 1); + void emitSLEB128Bytes(int Value) { + int Sign = Value >> (8 * sizeof(Value) - 1); bool IsMore; do { - uint8_t Byte = Value & 0x7f; + unsigned char Byte = Value & 0x7f; Value >>= 7; IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; if (IsMore) Byte |= 0x80; @@ -212,14 +212,14 @@ public: void emitString(const std::string &String) { for (unsigned i = 0, N = static_cast<unsigned>(String.size()); i < N; ++i) { - uint8_t C = String[i]; + unsigned char C = String[i]; emitByte(C); } emitByte(0); } /// emitInt32 - Emit a int32 directive. - void emitInt32(int32_t Value) { + void emitInt32(int Value) { if (4 <= BufferEnd-CurBufferPtr) { *((uint32_t*)CurBufferPtr) = Value; CurBufferPtr += 4; diff --git a/include/llvm/ExecutionEngine/JITMemoryManager.h b/include/llvm/ExecutionEngine/JITMemoryManager.h index 688a1626d2c3..581300e6e370 100644 --- a/include/llvm/ExecutionEngine/JITMemoryManager.h +++ b/include/llvm/ExecutionEngine/JITMemoryManager.h @@ -60,7 +60,7 @@ public: /// getGOTBase - If this is managing a Global Offset Table, this method should /// return a pointer to its base. - virtual uint8_t *getGOTBase() const = 0; + virtual unsigned char *getGOTBase() const = 0; /// SetDlsymTable - If the JIT must be able to relocate stubs after they have /// been emitted, potentially because they are being copied to a process @@ -89,8 +89,8 @@ public: /// emit the function, so it doesn't pass in the size. Instead, this method /// is required to pass back a "valid size". The JIT will be careful to not /// write more than the returned ActualSize bytes of memory. - virtual uint8_t *startFunctionBody(const Function *F, - uintptr_t &ActualSize) = 0; + virtual unsigned char *startFunctionBody(const Function *F, + uintptr_t &ActualSize) = 0; /// allocateStub - This method is called by the JIT to allocate space for a /// function stub (used to handle limited branch displacements) while it is @@ -100,8 +100,9 @@ public: /// thunk for it. The stub should be "close" to the current function body, /// but should not be included in the 'actualsize' returned by /// startFunctionBody. - virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, - unsigned Alignment) = 0; + virtual unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize, + unsigned Alignment) =0; + /// endFunctionBody - This method is called when the JIT is done codegen'ing /// the specified function. At this point we know the size of the JIT @@ -109,11 +110,11 @@ public: /// the startFunctionBody method) and FunctionEnd which is a pointer to the /// actual end of the function. This method should mark the space allocated /// and remember where it is in case the client wants to deallocate it. - virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart, - uint8_t *FunctionEnd) = 0; + virtual void endFunctionBody(const Function *F, unsigned char *FunctionStart, + unsigned char *FunctionEnd) = 0; /// allocateSpace - Allocate a memory block of the given size. - virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) = 0; + virtual unsigned char *allocateSpace(intptr_t Size, unsigned Alignment) = 0; /// deallocateMemForFunction - Free JIT memory for the specified function. /// This is never called when the JIT is currently emitting a function. @@ -121,13 +122,14 @@ public: /// startExceptionTable - When we finished JITing the function, if exception /// handling is set, we emit the exception table. - virtual uint8_t* startExceptionTable(const Function* F, - uintptr_t &ActualSize) = 0; + virtual unsigned char* startExceptionTable(const Function* F, + uintptr_t &ActualSize) = 0; /// endExceptionTable - This method is called when the JIT is done emitting /// the exception table. - virtual void endExceptionTable(const Function *F, uint8_t *TableStart, - uint8_t *TableEnd, uint8_t* FrameRegister) = 0; + virtual void endExceptionTable(const Function *F, unsigned char *TableStart, + unsigned char *TableEnd, + unsigned char* FrameRegister) = 0; }; } // end namespace llvm. diff --git a/include/llvm/Support/StandardPasses.h b/include/llvm/Support/StandardPasses.h new file mode 100644 index 000000000000..024c0194d4e0 --- /dev/null +++ b/include/llvm/Support/StandardPasses.h @@ -0,0 +1,250 @@ +//===-- llvm/Support/StandardPasses.h - Standard pass lists -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines utility functions for creating a "standard" set of +// optimization passes, so that compilers and tools which use optimization +// passes use the same set of standard passes. +// +// These are implemented as inline functions so that we do not have to worry +// about link issues. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_STANDARDPASSES_H +#define LLVM_SUPPORT_STANDARDPASSES_H + +#include "llvm/PassManager.h" +#include "llvm/Analysis/Passes.h" +#include "llvm/Analysis/Verifier.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/IPO.h" + +namespace llvm { + /// createStandardFunctionPasses - Add the standard list of function passes to + /// the provided pass manager. + /// + /// \arg OptimizationLevel - The optimization level, corresponding to -O0, + /// -O1, etc. + static inline void createStandardFunctionPasses(FunctionPassManager *PM, + unsigned OptimizationLevel); + + /// createStandardModulePasses - Add the standard list of module passes to the + /// provided pass manager. + /// + /// \arg OptimizationLevel - The optimization level, corresponding to -O0, + /// -O1, etc. + /// \arg OptimizeSize - Whether the transformations should optimize for size. + /// \arg UnitAtATime - Allow passes which may make global module changes. + /// \arg UnrollLoops - Allow loop unrolling. + /// \arg SimplifyLibCalls - Allow library calls to be simplified. + /// \arg HaveExceptions - Whether the module may have code using exceptions. + /// \arg InliningPass - The inlining pass to use, if any, or null. This will + /// always be added, even at -O0.a + static inline void createStandardModulePasses(PassManager *PM, + unsigned OptimizationLevel, + bool OptimizeSize, + bool UnitAtATime, + bool UnrollLoops, + bool SimplifyLibCalls, + bool HaveExceptions, + Pass *InliningPass); + + /// createStandardLTOPasses - Add the standard list of module passes suitable + /// for link time optimization. + /// + /// Internalize - Run the internalize pass. + /// RunInliner - Use a function inlining pass. + /// RunSecondGlobalOpt - Run the global optimizer pass twice. + /// VerifyEach - Run the verifier after each pass. + // + // FIXME: RunSecondGlobalOpt should go away once we resolve which of LTO or + // llvm-ld is better. + static inline void createStandardLTOPasses(PassManager *PM, + bool Internalize, + bool RunInliner, + bool RunSecondGlobalOpt, + bool VerifyEach); + + // Implementations + + static inline void createStandardFunctionPasses(FunctionPassManager *PM, + unsigned OptimizationLevel) { + if (OptimizationLevel > 0) { + PM->add(createCFGSimplificationPass()); + if (OptimizationLevel == 1) + PM->add(createPromoteMemoryToRegisterPass()); + else + PM->add(createScalarReplAggregatesPass()); + PM->add(createInstructionCombiningPass()); + } + } + + static inline void createStandardModulePasses(PassManager *PM, + unsigned OptimizationLevel, + bool OptimizeSize, + bool UnitAtATime, + bool UnrollLoops, + bool SimplifyLibCalls, + bool HaveExceptions, + Pass *InliningPass) { + if (OptimizationLevel == 0) { + if (InliningPass) + PM->add(InliningPass); + } else { + if (UnitAtATime) + PM->add(createRaiseAllocationsPass()); // call %malloc -> malloc inst + PM->add(createCFGSimplificationPass()); // Clean up disgusting code + // Kill useless allocas + PM->add(createPromoteMemoryToRegisterPass()); + if (UnitAtATime) { + PM->add(createGlobalOptimizerPass()); // Optimize out global vars + PM->add(createGlobalDCEPass()); // Remove unused fns and globs + // IP Constant Propagation + PM->add(createIPConstantPropagationPass()); + PM->add(createDeadArgEliminationPass()); // Dead argument elimination + } + PM->add(createInstructionCombiningPass()); // Clean up after IPCP & DAE + PM->add(createCFGSimplificationPass()); // Clean up after IPCP & DAE + if (UnitAtATime) { + if (HaveExceptions) + PM->add(createPruneEHPass()); // Remove dead EH info + PM->add(createFunctionAttrsPass()); // Set readonly/readnone attrs + } + if (InliningPass) + PM->add(InliningPass); + if (OptimizationLevel > 2) + PM->add(createArgumentPromotionPass()); // Scalarize uninlined fn args + if (SimplifyLibCalls) + PM->add(createSimplifyLibCallsPass()); // Library Call Optimizations + PM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl. + PM->add(createJumpThreadingPass()); // Thread jumps. + PM->add(createCFGSimplificationPass()); // Merge & remove BBs + PM->add(createScalarReplAggregatesPass()); // Break up aggregate allocas + PM->add(createInstructionCombiningPass()); // Combine silly seq's + PM->add(createCondPropagationPass()); // Propagate conditionals + PM->add(createTailCallEliminationPass()); // Eliminate tail calls + PM->add(createCFGSimplificationPass()); // Merge & remove BBs + PM->add(createReassociatePass()); // Reassociate expressions + PM->add(createLoopRotatePass()); // Rotate Loop + PM->add(createLICMPass()); // Hoist loop invariants + PM->add(createLoopUnswitchPass(OptimizeSize)); + PM->add(createLoopIndexSplitPass()); // Split loop index + PM->add(createInstructionCombiningPass()); + PM->add(createIndVarSimplifyPass()); // Canonicalize indvars + PM->add(createLoopDeletionPass()); // Delete dead loops + if (UnrollLoops) + PM->add(createLoopUnrollPass()); // Unroll small loops + PM->add(createInstructionCombiningPass()); // Clean up after the unroller + PM->add(createGVNPass()); // Remove redundancies + PM->add(createMemCpyOptPass()); // Remove memcpy / form memset + PM->add(createSCCPPass()); // Constant prop with SCCP + + // Run instcombine after redundancy elimination to exploit opportunities + // opened up by them. + PM->add(createInstructionCombiningPass()); + PM->add(createCondPropagationPass()); // Propagate conditionals + PM->add(createDeadStoreEliminationPass()); // Delete dead stores + PM->add(createAggressiveDCEPass()); // Delete dead instructions + PM->add(createCFGSimplificationPass()); // Merge & remove BBs + + if (UnitAtATime) { + PM->add(createStripDeadPrototypesPass()); // Get rid of dead prototypes + PM->add(createDeadTypeEliminationPass()); // Eliminate dead types + } + + if (OptimizationLevel > 1 && UnitAtATime) + PM->add(createConstantMergePass()); // Merge dup global constants + } + } + + static inline void addOnePass(PassManager *PM, Pass *P, bool AndVerify) { + PM->add(P); + + if (AndVerify) + PM->add(createVerifierPass()); + } + + static inline void createStandardLTOPasses(PassManager *PM, + bool Internalize, + bool RunInliner, + bool RunSecondGlobalOpt, + bool VerifyEach) { + // Now that composite has been compiled, scan through the module, looking + // for a main function. If main is defined, mark all other functions + // internal. + if (Internalize) + addOnePass(PM, createInternalizePass(true), VerifyEach); + + // Propagate constants at call sites into the functions they call. This + // opens opportunities for globalopt (and inlining) by substituting function + // pointers passed as arguments to direct uses of functions. + addOnePass(PM, createIPSCCPPass(), VerifyEach); + + // Now that we internalized some globals, see if we can hack on them! + addOnePass(PM, createGlobalOptimizerPass(), VerifyEach); + + // Linking modules together can lead to duplicated global constants, only + // keep one copy of each constant... + addOnePass(PM, createConstantMergePass(), VerifyEach); + + // Remove unused arguments from functions... + addOnePass(PM, createDeadArgEliminationPass(), VerifyEach); + + // Reduce the code after globalopt and ipsccp. Both can open up significant + // simplification opportunities, and both can propagate functions through + // function pointers. When this happens, we often have to resolve varargs + // calls, etc, so let instcombine do this. + addOnePass(PM, createInstructionCombiningPass(), VerifyEach); + + // Inline small functions + if (RunInliner) + addOnePass(PM, createFunctionInliningPass(), VerifyEach); + + addOnePass(PM, createPruneEHPass(), VerifyEach); // Remove dead EH info. + // Optimize globals again. + if (RunSecondGlobalOpt) + addOnePass(PM, createGlobalOptimizerPass(), VerifyEach); + addOnePass(PM, createGlobalDCEPass(), VerifyEach); // Remove dead functions. + + // If we didn't decide to inline a function, check to see if we can + // transform it to pass arguments by value instead of by reference. + addOnePass(PM, createArgumentPromotionPass(), VerifyEach); + + // The IPO passes may leave cruft around. Clean up after them. + addOnePass(PM, createInstructionCombiningPass(), VerifyEach); + addOnePass(PM, createJumpThreadingPass(), VerifyEach); + // Break up allocas + addOnePass(PM, createScalarReplAggregatesPass(), VerifyEach); + + // Run a few AA driven optimizations here and now, to cleanup the code. + addOnePass(PM, createFunctionAttrsPass(), VerifyEach); // Add nocapture. + addOnePass(PM, createGlobalsModRefPass(), VerifyEach); // IP alias analysis. + + addOnePass(PM, createLICMPass(), VerifyEach); // Hoist loop invariants. + addOnePass(PM, createGVNPass(), VerifyEach); // Remove redundancies. + addOnePass(PM, createMemCpyOptPass(), VerifyEach); // Remove dead memcpys. + // Nuke dead stores. + addOnePass(PM, createDeadStoreEliminationPass(), VerifyEach); + + // Cleanup and simplify the code after the scalar optimizations. + addOnePass(PM, createInstructionCombiningPass(), VerifyEach); + + addOnePass(PM, createJumpThreadingPass(), VerifyEach); + // Cleanup jump threading. + addOnePass(PM, createPromoteMemoryToRegisterPass(), VerifyEach); + + // Delete basic blocks, which optimization passes may have killed... + addOnePass(PM, createCFGSimplificationPass(), VerifyEach); + + // Now that we have optimized the program, discard unreachable functions. + addOnePass(PM, createGlobalDCEPass(), VerifyEach); + } +} + +#endif |