BuildLibCalls.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //===- BuildLibCalls.h - Utility builder for libcalls -----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file exposes an interface to build some C language libcalls for
  11. // optimization passes that need to call the various functions.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
  15. #define LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
  16. #include "llvm/IR/IRBuilder.h"
  17. namespace llvm {
  18. class Value;
  19. class DataLayout;
  20. class TargetLibraryInfo;
  21. /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
  22. Value *CastToCStr(Value *V, IRBuilder<> &B);
  23. /// EmitStrLen - Emit a call to the strlen function to the builder, for the
  24. /// specified pointer. Ptr is required to be some pointer type, and the
  25. /// return value has 'intptr_t' type.
  26. Value *EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
  27. const TargetLibraryInfo *TLI);
  28. /// EmitStrNLen - Emit a call to the strnlen function to the builder, for the
  29. /// specified pointer. Ptr is required to be some pointer type, MaxLen must
  30. /// be of size_t type, and the return value has 'intptr_t' type.
  31. Value *EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
  32. const DataLayout &DL, const TargetLibraryInfo *TLI);
  33. /// EmitStrChr - Emit a call to the strchr function to the builder, for the
  34. /// specified pointer and character. Ptr is required to be some pointer type,
  35. /// and the return value has 'i8*' type.
  36. Value *EmitStrChr(Value *Ptr, char C, IRBuilder<> &B,
  37. const TargetLibraryInfo *TLI);
  38. /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
  39. Value *EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
  40. const DataLayout &DL, const TargetLibraryInfo *TLI);
  41. /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
  42. /// specified pointer arguments.
  43. Value *EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
  44. const TargetLibraryInfo *TLI, StringRef Name = "strcpy");
  45. /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
  46. /// specified pointer arguments and length.
  47. Value *EmitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
  48. const TargetLibraryInfo *TLI, StringRef Name = "strncpy");
  49. /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
  50. /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
  51. /// are pointers.
  52. Value *EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
  53. IRBuilder<> &B, const DataLayout &DL,
  54. const TargetLibraryInfo *TLI);
  55. /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
  56. /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
  57. Value *EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
  58. const DataLayout &DL, const TargetLibraryInfo *TLI);
  59. /// EmitMemCmp - Emit a call to the memcmp function.
  60. Value *EmitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
  61. const DataLayout &DL, const TargetLibraryInfo *TLI);
  62. /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name'
  63. /// (e.g. 'floor'). This function is known to take a single of type matching
  64. /// 'Op' and returns one value with the same type. If 'Op' is a long double,
  65. /// 'l' is added as the suffix of name, if 'Op' is a float, we add a 'f'
  66. /// suffix.
  67. Value *EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
  68. const AttributeSet &Attrs);
  69. /// EmitUnaryFloatFnCall - Emit a call to the binary function named 'Name'
  70. /// (e.g. 'fmin'). This function is known to take type matching 'Op1' and
  71. /// 'Op2' and return one value with the same type. If 'Op1/Op2' are long
  72. /// double, 'l' is added as the suffix of name, if 'Op1/Op2' are float, we
  73. /// add a 'f' suffix.
  74. Value *EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
  75. IRBuilder<> &B, const AttributeSet &Attrs);
  76. /// EmitPutChar - Emit a call to the putchar function. This assumes that Char
  77. /// is an integer.
  78. Value *EmitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI);
  79. /// EmitPutS - Emit a call to the puts function. This assumes that Str is
  80. /// some pointer.
  81. Value *EmitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI);
  82. /// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
  83. /// an i32, and File is a pointer to FILE.
  84. Value *EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
  85. const TargetLibraryInfo *TLI);
  86. /// EmitFPutS - Emit a call to the puts function. Str is required to be a
  87. /// pointer and File is a pointer to FILE.
  88. Value *EmitFPutS(Value *Str, Value *File, IRBuilder<> &B,
  89. const TargetLibraryInfo *TLI);
  90. /// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
  91. /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
  92. Value *EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
  93. const DataLayout &DL, const TargetLibraryInfo *TLI);
  94. }
  95. #endif