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" 19ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/IR/LegacyPassManager.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); 39ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines initializeLowerBitSetsPass(Registry); 402c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeMergeFunctionsPass(Registry); 412c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializePartialInlinerPass(Registry); 422c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializePruneEHPass(Registry); 432c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDeadPrototypesPassPass(Registry); 442c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripSymbolsPass(Registry); 452c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDebugDeclarePass(Registry); 462c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripDeadDebugInfoPass(Registry); 472c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeStripNonDebugSymbolsPass(Registry); 4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines initializeBarrierNoopPass(Registry); 492c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson} 502c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson 512c81296bc237cb26c2bb789514e331b3b5b31f79Owen Andersonvoid LLVMInitializeIPO(LLVMPassRegistryRef R) { 522c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson initializeIPO(*unwrap(R)); 532c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson} 542c81296bc237cb26c2bb789514e331b3b5b31f79Owen Anderson 5557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM) { 5657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createArgumentPromotionPass()); 5757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 5857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 5957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddConstantMergePass(LLVMPassManagerRef PM) { 6057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createConstantMergePass()); 6157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 6257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 6357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) { 6457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createDeadArgEliminationPass()); 6557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 6657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 6757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) { 6857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createFunctionAttrsPass()); 6957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 7057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 7157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) { 7257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createFunctionInliningPass()); 7357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 7457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 753d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindolavoid LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) { 763d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola unwrap(PM)->add(llvm::createAlwaysInlinerPass()); 773d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola} 783d72290ecb30002d4372b6afbeda73812221ac3eRafael Espindola 7957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) { 8057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createGlobalDCEPass()); 8157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 8257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 8357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) { 8457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createGlobalOptimizerPass()); 8557c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 8657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 8757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM) { 8857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createIPConstantPropagationPass()); 8957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 9057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 9157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddPruneEHPass(LLVMPassManagerRef PM) { 9257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createPruneEHPass()); 9357c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 9457c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 9516ddd885d84beb57ac68e1503faa94cda279be4bWesley Peckvoid LLVMAddIPSCCPPass(LLVMPassManagerRef PM) { 9616ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck unwrap(PM)->add(createIPSCCPPass()); 9716ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck} 9816ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck 9916ddd885d84beb57ac68e1503faa94cda279be4bWesley Peckvoid LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) { 100e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola std::vector<const char *> Export; 101e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola if (AllButMain) 102e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola Export.push_back("main"); 103e5551ed9cec1ae777c4e4b8852a1d7842c2e1c3dRafael Espindola unwrap(PM)->add(createInternalizePass(Export)); 10416ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck} 10516ddd885d84beb57ac68e1503faa94cda279be4bWesley Peck 10657c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) { 10757c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createStripDeadPrototypesPass()); 10857c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 10957c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner 11057c03831ccaabd619d1d7eb164375e7e3027031dChris Lattnervoid LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) { 11157c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner unwrap(PM)->add(createStripSymbolsPass()); 11257c03831ccaabd619d1d7eb164375e7e3027031dChris Lattner} 113