//===- SimplifyLibCalls.cpp - Optimize specific well-known library calls --===////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// This file implements a simple pass that applies a variety of small// optimizations for calls to specific well-known function calls (e.g. runtime// library functions). For example, a call to the function "exit(3)" that// occurs within the main() function can be transformed into a simple "return 3"// instruction. Any optimization that takes this form (replace call to library// function with simpler code that provides the same result) belongs in this// file.////===----------------------------------------------------------------------===//#define DEBUG_TYPE "simplify-libcalls"#include"llvm/Transforms/Scalar.h"#include"llvm/Intrinsics.h"#include"llvm/Module.h"#include"llvm/Pass.h"#include"llvm/Support/IRBuilder.h"#include"llvm/Target/TargetData.h"#include"llvm/ADT/SmallPtrSet.h"#include"llvm/ADT/StringMap.h"#include"llvm/ADT/Statistic.h"#include"llvm/Support/Compiler.h"#include"llvm/Config/config.h"usingnamespacellvm;STATISTIC(NumSimplified,"Number of library calls simplified");//===----------------------------------------------------------------------===//// Optimizer Base Class//===----------------------------------------------------------------------===///// This class is the abstract base class for the set of optimizations that/// corresponds to one library call.namespace{classVISIBILITY_HIDDENLibCallOptimization{protected:Function*Caller;constTargetData*TD;public:LibCallOptimization(){}virtual~LibCallOptimization(){}/// CallOptimizer - This pure virtual method is implemented by base classes to/// do various optimizations. If this returns null then no transformation was/// performed. If it returns CI, then it transformed the call and CI is to be/// deleted. If it returns something else, replace CI with the new value and/// delete CI.virtualValue*