LLVM API Documentation
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/ADT/hash_map"
#include "llvm/ADT/Statistic.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Debug.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/IPO.h"
Include dependency graph for SimplifyLibCalls.cpp:
Go to the source code of this file.
Defines | |
#define | DEBUG_TYPE "simplify-libcalls" |
Functions | |
ModulePass * | llvm::createSimplifyLibCallsPass () |
bool | getConstantStringLength (Value *V, uint64_t &len, ConstantArray **A=0) |
Value * | CastToCStr (Value *V, Instruction &IP) |
static bool | IsOnlyUsedInEqualsZeroComparison (Instruction *I) |
LLVMMemCpyMoveOptzn | LLVMMemCpyOptimizer32 ("llvm.memcpy.i32","Number of 'llvm.memcpy' calls simplified") |
LLVMMemCpyMoveOptzn | LLVMMemCpyOptimizer64 ("llvm.memcpy.i64","Number of 'llvm.memcpy' calls simplified") |
LLVMMemCpyMoveOptzn | LLVMMemMoveOptimizer32 ("llvm.memmove.i32","Number of 'llvm.memmove' calls simplified") |
LLVMMemCpyMoveOptzn | LLVMMemMoveOptimizer64 ("llvm.memmove.i64","Number of 'llvm.memmove' calls simplified") |
LLVMMemSetOptimization | MemSet32Optimizer ("llvm.memset.i32") |
LLVMMemSetOptimization | MemSet64Optimizer ("llvm.memset.i64") |
bool | getConstantStringLength (Value *V, uint64_t &len, ConstantArray **CA) |
Get the length of a constant string (null-terminated array). | |
Value * | CastToCStr (Value *V, Instruction &IP) |
Cast a value to a "C" string. | |
Variables | |
Statistic | SimplifiedLibCalls ("simplify-libcalls","Number of library calls simplified") |
static LibCallOptimization * | OptList = 0 |
The list of optimizations deriving from LibCallOptimization. | |
RegisterOpt< SimplifyLibCalls > | X ("simplify-libcalls","Simplify well-known library calls") |
{ ... } ::ExitInMainOptimization | ExitInMainOptimizer |
Replace calls to exit in main with a simple return. | |
{ ... } ::StrCatOptimization | StrCatOptimizer |
Simplify the strcat library function. | |
{ ... } ::StrChrOptimization | StrChrOptimizer |
Simplify the strcmp library function. | |
{ ... } ::StrCmpOptimization | StrCmpOptimizer |
Simplify the strcmp library function. | |
{ ... } ::StrNCmpOptimization | StrNCmpOptimizer |
Simplify the strncmp library function. | |
{ ... } ::StrCpyOptimization | StrCpyOptimizer |
Simplify the strcpy library function. | |
{ ... } ::StrLenOptimization | StrLenOptimizer |
Simplify the strlen library function. | |
{ ... } ::memcmpOptimization | memcmpOptimizer |
{ ... } ::PowOptimization | PowOptimizer |
Simplify the pow library function. | |
{ ... } ::PrintfOptimization | PrintfOptimizer |
Simplify the printf library function. | |
{ ... } ::FPrintFOptimization | FPrintFOptimizer |
Simplify the fprintf library function. | |
{ ... } ::SPrintFOptimization | SPrintFOptimizer |
Simplify the sprintf library function. | |
{ ... } ::PutsOptimization | PutsOptimizer |
Simplify the puts library function. | |
{ ... } ::isdigitOptimization | isdigitOptimizer |
Simplify the isdigit library function. | |
{ ... } ::isasciiOptimization | isasciiOptimizer |
{ ... } ::ToAsciiOptimization | ToAsciiOptimizer |
Simplify the toascii library function. | |
{ ... } ::FFSOptimization | FFSOptimizer |
Simplify the ffs library function. | |
{ ... } ::FFSLOptimization | FFSLOptimizer |
Simplify the ffsl library function. | |
{ ... } ::FFSLLOptimization | FFSLLOptimizer |
Simplify the ffsl library function. | |
{ ... } ::FloorOptimization | FloorOptimizer |
{ ... } ::CeilOptimization | CeilOptimizer |
{ ... } ::RoundOptimization | RoundOptimizer |
{ ... } ::RintOptimization | RintOptimizer |
{ ... } ::NearByIntOptimization | NearByIntOptimizer |
#define DEBUG_TYPE "simplify-libcalls" |
Definition at line 20 of file SimplifyLibCalls.cpp.
Value* @787::CastToCStr | ( | Value * | V, | |
Instruction & | IP | |||
) | [static] |
Cast a value to a "C" string.
CastToCStr - Return V if it is an sbyte*, otherwise cast it to sbyte*, inserting the cast before IP, and return the cast.
Definition at line 2103 of file SimplifyLibCalls.cpp.
References V.
Value* @787::CastToCStr | ( | Value * | V, | |
Instruction & | IP | |||
) | [static] |
bool @787::getConstantStringLength | ( | Value * | V, | |
uint64_t & | len, | |||
ConstantArray ** | CA | |||
) | [static] |
Get the length of a constant string (null-terminated array).
A function to compute the length of a null-terminated constant array of integers. This function can't rely on the size of the constant array because there could be a null terminator in the middle of the array. We also have to bail out if we find a non-integer constant initializer of one of the elements or if there is no null-terminator. The logic below checks each of these conditions and will return true only if all conditions are met. In that case, the len
parameter is set to the length of the null-terminated string. If false is returned, the conditions were not met and len is set to 0.
Definition at line 2014 of file SimplifyLibCalls.cpp.
References A, llvm::User::getNumOperands(), llvm::User::getOperand(), GV, and V.
bool @787::getConstantStringLength | ( | Value * | V, | |
uint64_t & | len, | |||
ConstantArray ** | A = 0 | |||
) | [static] |
static bool @787::IsOnlyUsedInEqualsZeroComparison | ( | Instruction * | I | ) | [static] |
IsOnlyUsedInEqualsComparison - Return true if it only matters that the value is equal or not-equal to zero.
Definition at line 931 of file SimplifyLibCalls.cpp.
References E, llvm::Value::use_begin(), and llvm::Value::use_end().
LLVMMemCpyMoveOptzn @787::LLVMMemCpyOptimizer32 | ( | "llvm.memcpy.i32" | , | |
"Number of 'llvm.memcpy' calls simplified" | ||||
) | [static] |
This LibCallOptimization will simplify a call to the memcpy/memmove library functions.
LLVMMemCpyMoveOptzn @787::LLVMMemCpyOptimizer64 | ( | "llvm.memcpy.i64" | , | |
"Number of 'llvm.memcpy' calls simplified" | ||||
) | [static] |
LLVMMemCpyMoveOptzn @787::LLVMMemMoveOptimizer32 | ( | "llvm.memmove.i32" | , | |
"Number of 'llvm.memmove' calls simplified" | ||||
) | [static] |
LLVMMemCpyMoveOptzn @787::LLVMMemMoveOptimizer64 | ( | "llvm.memmove.i64" | , | |
"Number of 'llvm.memmove' calls simplified" | ||||
) | [static] |
LLVMMemSetOptimization @787::MemSet32Optimizer | ( | "llvm.memset.i32" | ) | [static] |
LLVMMemSetOptimization @787::MemSet64Optimizer | ( | "llvm.memset.i64" | ) | [static] |
Definition at line 362 of file SimplifyLibCalls.cpp.
{ ... } CeilOptimization CeilOptimizer [static] |
{ ... } ExitInMainOptimization ExitInMainOptimizer [static] |
Replace calls to exit in main with a simple return.
This LibCallOptimization will find instances of a call to "exit" that occurs within the "main" function and change it to a simple "ret" instruction with the same value passed to the exit function. When this is done, it splits the basic block at the exit(3) call and deletes the call instruction.
{ ... } FFSLLOptimization FFSLLOptimizer [static] |
Simplify the ffsl library function.
This LibCallOptimization will simplify calls to the "ffsll" library calls. It simply uses FFSOptimization for which the transformation is identical.
{ ... } FFSLOptimization FFSLOptimizer [static] |
Simplify the ffsl library function.
This LibCallOptimization will simplify calls to the "ffsl" library calls. It simply uses FFSOptimization for which the transformation is identical.
{ ... } FFSOptimization FFSOptimizer [static] |
Simplify the ffs library function.
This LibCallOptimization will simplify calls to the "ffs" library calls which find the first set bit in an int, long, or long long. The optimization is to compute the result at compile time if the argument is a constant.
Definition at line 362 of file SimplifyLibCalls.cpp.
{ ... } FloorOptimization FloorOptimizer [static] |
{ ... } FPrintFOptimization FPrintFOptimizer [static] |
Simplify the fprintf library function.
This LibCallOptimization will simplify calls to the "fprintf" library function. It looks for cases where the result of fprintf is not used and the operation can be reduced to something simpler.
Definition at line 358 of file SimplifyLibCalls.cpp.
Definition at line 358 of file SimplifyLibCalls.cpp.
const char* FunctionName |
Definition at line 358 of file SimplifyLibCalls.cpp.
{ ... } isasciiOptimization isasciiOptimizer [static] |
{ ... } isdigitOptimization isdigitOptimizer [static] |
Simplify the isdigit library function.
This LibCallOptimization will simplify calls to the "isdigit" library function. It simply does range checks the parameter explicitly.
Definition at line 359 of file SimplifyLibCalls.cpp.
{ ... } memcmpOptimization memcmpOptimizer [static] |
This memcmpOptimization will simplify a call to the memcmp library function.
Definition at line 359 of file SimplifyLibCalls.cpp.
Definition at line 363 of file SimplifyLibCalls.cpp.
{ ... } NearByIntOptimization NearByIntOptimizer [static] |
LibCallOptimization * Next |
Definition at line 68 of file SimplifyLibCalls.cpp.
LibCallOptimization* OptList = 0 [static] |
The list of optimizations deriving from LibCallOptimization.
This list is populated by the constructor for LibCallOptimization class. Therefore all subclasses are registered here at static initialization time and this list is what the SimplifyLibCalls pass uses to apply the individual optimizations to the call sites.
Definition at line 50 of file SimplifyLibCalls.cpp.
{ ... } PowOptimization PowOptimizer [static] |
Simplify the pow library function.
This LibCallOptimization will simplify calls to the "pow" library function. It looks for cases where the result of pow is well known and substitutes the appropriate value.
LibCallOptimization** Prev |
Definition at line 68 of file SimplifyLibCalls.cpp.
{ ... } PrintfOptimization PrintfOptimizer [static] |
Simplify the printf library function.
This LibCallOptimization will simplify calls to the "printf" library function. It looks for cases where the result of printf is not used and the operation can be reduced to something simpler.
Definition at line 357 of file SimplifyLibCalls.cpp.
{ ... } PutsOptimization PutsOptimizer [static] |
Simplify the puts library function.
This LibCallOptimization will simplify calls to the "fputs" library function. It looks for cases where the result of fputs is not used and the operation can be reduced to something simpler.
Definition at line 363 of file SimplifyLibCalls.cpp.
{ ... } RintOptimization RintOptimizer [static] |
Definition at line 362 of file SimplifyLibCalls.cpp.
{ ... } RoundOptimization RoundOptimizer [static] |
Statistic SimplifiedLibCalls("simplify-libcalls","Number of library calls simplified") [static] |
This statistic keeps track of the total number of library calls that have been simplified regardless of which call it is.
{ ... } SPrintFOptimization SPrintFOptimizer [static] |
Simplify the sprintf library function.
This LibCallOptimization will simplify calls to the "sprintf" library function. It looks for cases where the result of sprintf is not used and the operation can be reduced to something simpler.
Definition at line 360 of file SimplifyLibCalls.cpp.
{ ... } StrCatOptimization StrCatOptimizer [static] |
Simplify the strcat library function.
This LibCallOptimization will simplify a call to the strcat library function. The simplification is possible only if the string being concatenated is a constant array or a constant expression that results in a constant string. In this case we can replace it with strlen + llvm.memcpy of the constant string. Both of these calls are further reduced, if possible on subsequent passes.
{ ... } StrChrOptimization StrChrOptimizer [static] |
Simplify the strcmp library function.
This LibCallOptimization will simplify a call to the strchr library function. It optimizes out cases where the arguments are both constant and the result can be determined statically.
{ ... } StrCmpOptimization StrCmpOptimizer [static] |
Simplify the strcmp library function.
This LibCallOptimization will simplify a call to the strcmp library function. It optimizes out cases where one or both arguments are constant and the result can be determined statically.
Definition at line 361 of file SimplifyLibCalls.cpp.
{ ... } StrCpyOptimization StrCpyOptimizer [static] |
Simplify the strcpy library function.
This LibCallOptimization will simplify a call to the strcpy library function. Two optimizations are possible: (1) If src and dest are the same and not volatile, just return dest (2) If the src is a constant then we can convert to llvm.memmove
Definition at line 361 of file SimplifyLibCalls.cpp.
{ ... } StrLenOptimization StrLenOptimizer [static] |
Simplify the strlen library function.
This LibCallOptimization will simplify a call to the strlen library function by replacing it with a constant value if the string provided to it is a constant array.
{ ... } StrNCmpOptimization StrNCmpOptimizer [static] |
Simplify the strncmp library function.
This LibCallOptimization will simplify a call to the strncmp library function. It optimizes out cases where one or both arguments are constant and the result can be determined statically.
{ ... } ToAsciiOptimization ToAsciiOptimizer [static] |
Simplify the toascii library function.
This LibCallOptimization will simplify calls to the "toascii" library function. It simply does the corresponding and operation to restrict the range of values to the ASCII character set (0-127).
RegisterOpt<SimplifyLibCalls> X("simplify-libcalls","Simplify well-known library calls") [static] |