1243789Sdim//===- SimplifyLibCalls.h - Library call simplifier -------------*- C++ -*-===//
2243789Sdim//
3243789Sdim//                     The LLVM Compiler Infrastructure
4243789Sdim//
5243789Sdim// This file is distributed under the University of Illinois Open Source
6243789Sdim// License. See LICENSE.TXT for details.
7243789Sdim//
8243789Sdim//===----------------------------------------------------------------------===//
9243789Sdim//
10243789Sdim// This file exposes an interface to build some C language libcalls for
11243789Sdim// optimization passes that need to call the various functions.
12243789Sdim//
13243789Sdim//===----------------------------------------------------------------------===//
14243789Sdim
15243789Sdim#ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYLIBCALLS_H
16243789Sdim#define LLVM_TRANSFORMS_UTILS_SIMPLIFYLIBCALLS_H
17243789Sdim
18243789Sdimnamespace llvm {
19243789Sdim  class Value;
20243789Sdim  class CallInst;
21243789Sdim  class DataLayout;
22243789Sdim  class Instruction;
23243789Sdim  class TargetLibraryInfo;
24243789Sdim  class LibCallSimplifierImpl;
25243789Sdim
26243789Sdim  /// LibCallSimplifier - This class implements a collection of optimizations
27243789Sdim  /// that replace well formed calls to library functions with a more optimal
28243789Sdim  /// form.  For example, replacing 'printf("Hello!")' with 'puts("Hello!")'.
29243789Sdim  class LibCallSimplifier {
30243789Sdim    /// Impl - A pointer to the actual implementation of the library call
31243789Sdim    /// simplifier.
32243789Sdim    LibCallSimplifierImpl *Impl;
33243789Sdim  public:
34249423Sdim    LibCallSimplifier(const DataLayout *TD, const TargetLibraryInfo *TLI,
35249423Sdim                      bool UnsafeFPShrink);
36243789Sdim    virtual ~LibCallSimplifier();
37243789Sdim
38243789Sdim    /// optimizeCall - Take the given call instruction and return a more
39243789Sdim    /// optimal value to replace the instruction with or 0 if a more
40243789Sdim    /// optimal form can't be found.  Note that the returned value may
41243789Sdim    /// be equal to the instruction being optimized.  In this case all
42243789Sdim    /// other instructions that use the given instruction were modified
43243789Sdim    /// and the given instruction is dead.
44243789Sdim    Value *optimizeCall(CallInst *CI);
45243789Sdim
46243789Sdim    /// replaceAllUsesWith - This method is used when the library call
47243789Sdim    /// simplifier needs to replace instructions other than the library
48243789Sdim    /// call being modified.
49243789Sdim    virtual void replaceAllUsesWith(Instruction *I, Value *With) const;
50243789Sdim  };
51243789Sdim} // End llvm namespace
52243789Sdim
53243789Sdim#endif
54