diff --git a/opts/ObjectiveCOpts.cpp b/opts/ObjectiveCOpts.cpp index 99d8e5b..9cc6404 100644 --- a/opts/ObjectiveCOpts.cpp +++ b/opts/ObjectiveCOpts.cpp @@ -1,9 +1,14 @@ #include "llvm/Pass.h" #include "llvm/Module.h" +#if LLVM_MAJOR >= 3 +#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#include "llvm/PassManager.h" +#endif #include "ObjectiveCOpts.h" using namespace llvm; + namespace { class ObjectiveCOpts : public ModulePass { @@ -52,4 +57,36 @@ namespace RegisterPass X("gnu-objc", "Run all of the GNUstep Objective-C runtimm optimisations"); + +#if LLVM_MAJOR >= 3 + + void addObjCPasses(const PassManagerBuilder &Builder, PassManagerBase &PM) { + // Always add the ivar simplification pass + PM.add(createGNUNonfragileIvarPass()); + // Only cache IMPs in loops if we're not optimising for size. + if (Builder.SizeLevel == 0) { + PM.add(createGNULoopIMPCachePass()); + } + // Do the rest of the caching if we're not aggressively optimising for size + if (Builder.SizeLevel < 2) { + PM.add(createClassIMPCachePass()); + PM.add(createClassLookupCachePass()); + } + // Definitely don't do extra inlining if we're optimising for size! + if (Builder.SizeLevel == 0) { + PM.add(createClassMethodInliner()); + } + } + /* + static struct PluginRegister { + PluginRegister() { + PassManagerBuilder::addGlobalExtension(PassManagerBuilder::EP_LoopOptimizerEnd, + addObjCPasses); + } + } Register; + */ + RegisterStandardPasses S(PassManagerBuilder::EP_LoopOptimizerEnd, + addObjCPasses); +#endif + }