IPO.cpp revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
1126048c18c4a735ebb2c7c544b9bd48f395b53d9Craig Topper//===-- IPO.cpp -----------------------------------------------------------===// 257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// 357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// The LLVM Compiler Infrastructure 457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// 557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// This file is distributed under the University of Illinois Open Source 657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// License. See LICENSE.TXT for details. 757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// 857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner//===----------------------------------------------------------------------===// 957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// 102c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson// This file implements the common infrastructure (including C bindings) for 112c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson// libLLVMIPO.a, which implements several transformations over the LLVM 122c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson// intermediate representation. 1357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner// 1457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner//===----------------------------------------------------------------------===// 1557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 16613d13beb03bb56a17e6b3262c5e8e539a7e9db8Benjamin Kramer#include "llvm-c/Initialization.h" 1757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner#include "llvm-c/Transforms/IPO.h" 182c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson#include "llvm/InitializePasses.h" 1957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner#include "llvm/PassManager.h" 2057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner#include "llvm/Transforms/IPO.h" 2157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 2257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnerusing namespace llvm; 2357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 242c81296bc237cb26c2bb789514e331b3b5b31f79Owen Andersonvoid llvm::initializeIPO(PassRegistry &Registry) { 252c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeArgPromotionPass(Registry); 262c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeConstantMergePass(Registry); 272c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeDAEPass(Registry); 282c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeDAHPass(Registry); 292c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeFunctionAttrsPass(Registry); 302c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeGlobalDCEPass(Registry); 312c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeGlobalOptPass(Registry); 322c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeIPCPPass(Registry); 332c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeAlwaysInlinerPass(Registry); 342c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeSimpleInlinerPass(Registry); 352c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeInternalizePassPass(Registry); 362c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeLoopExtractorPass(Registry); 372c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeBlockExtractorPassPass(Registry); 382c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeSingleLoopExtractorPass(Registry); 392c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeMergeFunctionsPass(Registry); 402c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializePartialInlinerPass(Registry); 412c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializePruneEHPass(Registry); 422c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDeadPrototypesPassPass(Registry); 432c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripSymbolsPass(Registry); 442c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDebugDeclarePass(Registry); 452c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDeadDebugInfoPass(Registry); 462c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripNonDebugSymbolsPass(Registry); 4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines initializeBarrierNoopPass(Registry); 482c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson} 492c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson 502c81296bc237cb26c2bb789514e331b3b5b31f79Owen Andersonvoid LLVMInitializeIPO(LLVMPassRegistryRef R) { 512c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeIPO(*unwrap(R)); 522c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson} 532c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson 5457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { 5557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createArgumentPromotionPass()); 5657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 5757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 5857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddConstantMergePass(LLVMPassManagerRef PM) { 5957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createConstantMergePass()); 6057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 6157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 6257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { 6357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createDeadArgEliminationPass()); 6457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 6557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 6657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { 6757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createFunctionAttrsPass()); 6857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 6957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 7057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { 7157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createFunctionInliningPass()); 7257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 7357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 743d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindolavoid LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { 753d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola unwrap(PM)->add(llvm::createAlwaysInlinerPass()); 763d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola} 773d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola 7857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { 7957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createGlobalDCEPass()); 8057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 8157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 8257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { 8357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createGlobalOptimizerPass()); 8457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 8557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 8657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { 8757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createIPConstantPropagationPass()); 8857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 8957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 9057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddPruneEHPass(LLVMPassManagerRef PM) { 9157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createPruneEHPass()); 9257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 9357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 9416ddd885d84beb57ac68e1503faa94cda279be4bWesley Peckvoid LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { 9516ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck unwrap(PM)->add(createIPSCCPPass()); 9616ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck} 9716ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck 9816ddd885d84beb57ac68e1503faa94cda279be4bWesley Peckvoid LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { 99e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola std::vector<const char *> Export; 100e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola if (AllButMain) 101e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola Export.push_back("main"); 102e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola unwrap(PM)->add(createInternalizePass(Export)); 10316ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck} 10416ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck 10557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { 10657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createStripDeadPrototypesPass()); 10757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 10857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 10957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { 11057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createStripSymbolsPass()); 11157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 112