Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1 | //===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===// |
| 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 implements some functions that will create standard C libcalls. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Transforms/Utils/BuildLibCalls.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Statistic.h" |
Weiming Zhao | 45d4cb9 | 2015-11-24 18:57:06 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Constants.h" |
| 19 | #include "llvm/IR/DataLayout.h" |
| 20 | #include "llvm/IR/Function.h" |
| 21 | #include "llvm/IR/IRBuilder.h" |
| 22 | #include "llvm/IR/Intrinsics.h" |
| 23 | #include "llvm/IR/LLVMContext.h" |
| 24 | #include "llvm/IR/Module.h" |
| 25 | #include "llvm/IR/Type.h" |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace llvm; |
| 28 | |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 29 | #define DEBUG_TYPE "build-libcalls" |
| 30 | |
| 31 | //- Infer Attributes ---------------------------------------------------------// |
| 32 | |
| 33 | STATISTIC(NumReadNone, "Number of functions inferred as readnone"); |
| 34 | STATISTIC(NumReadOnly, "Number of functions inferred as readonly"); |
| 35 | STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly"); |
| 36 | STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind"); |
| 37 | STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture"); |
| 38 | STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly"); |
| 39 | STATISTIC(NumNoAlias, "Number of function returns inferred as noalias"); |
| 40 | STATISTIC(NumNonNull, "Number of function returns inferred as nonnull returns"); |
| 41 | |
| 42 | static bool setDoesNotAccessMemory(Function &F) { |
| 43 | if (F.doesNotAccessMemory()) |
| 44 | return false; |
| 45 | F.setDoesNotAccessMemory(); |
| 46 | ++NumReadNone; |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | static bool setOnlyReadsMemory(Function &F) { |
| 51 | if (F.onlyReadsMemory()) |
| 52 | return false; |
| 53 | F.setOnlyReadsMemory(); |
| 54 | ++NumReadOnly; |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | static bool setOnlyAccessesArgMemory(Function &F) { |
| 59 | if (F.onlyAccessesArgMemory()) |
| 60 | return false; |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 61 | F.setOnlyAccessesArgMemory(); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 62 | ++NumArgMemOnly; |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | static bool setDoesNotThrow(Function &F) { |
| 67 | if (F.doesNotThrow()) |
| 68 | return false; |
| 69 | F.setDoesNotThrow(); |
| 70 | ++NumNoUnwind; |
| 71 | return true; |
| 72 | } |
| 73 | |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 74 | static bool setRetDoesNotAlias(Function &F) { |
| 75 | if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias)) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 76 | return false; |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 77 | F.addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 78 | ++NumNoAlias; |
| 79 | return true; |
| 80 | } |
| 81 | |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 82 | static bool setDoesNotCapture(Function &F, unsigned ArgNo) { |
| 83 | if (F.hasParamAttribute(ArgNo, Attribute::NoCapture)) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 84 | return false; |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 85 | F.addParamAttr(ArgNo, Attribute::NoCapture); |
| 86 | ++NumNoCapture; |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) { |
| 91 | if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly)) |
| 92 | return false; |
| 93 | F.addParamAttr(ArgNo, Attribute::ReadOnly); |
| 94 | ++NumReadOnlyArg; |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | static bool setRetNonNull(Function &F) { |
| 99 | assert(F.getReturnType()->isPointerTy() && |
| 100 | "nonnull applies only to pointers"); |
| 101 | if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NonNull)) |
| 102 | return false; |
| 103 | F.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 104 | ++NumNonNull; |
| 105 | return true; |
| 106 | } |
| 107 | |
Sriraman Tallam | 182f2df | 2018-04-10 23:32:36 +0000 | [diff] [blame] | 108 | static bool setNonLazyBind(Function &F) { |
| 109 | if (F.hasFnAttribute(Attribute::NonLazyBind)) |
| 110 | return false; |
| 111 | F.addFnAttr(Attribute::NonLazyBind); |
| 112 | return true; |
| 113 | } |
| 114 | |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 115 | bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 116 | LibFunc TheLibFunc; |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 117 | if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc))) |
| 118 | return false; |
| 119 | |
| 120 | bool Changed = false; |
Sriraman Tallam | 182f2df | 2018-04-10 23:32:36 +0000 | [diff] [blame] | 121 | |
| 122 | if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT()) |
| 123 | Changed |= setNonLazyBind(F); |
| 124 | |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 125 | switch (TheLibFunc) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 126 | case LibFunc_strlen: |
Matthias Braun | 60b40b8 | 2017-05-05 20:25:50 +0000 | [diff] [blame] | 127 | case LibFunc_wcslen: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 128 | Changed |= setOnlyReadsMemory(F); |
| 129 | Changed |= setDoesNotThrow(F); |
Xin Tong | 9d2a5b1 | 2017-06-18 03:10:26 +0000 | [diff] [blame] | 130 | Changed |= setOnlyAccessesArgMemory(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 131 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 132 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 133 | case LibFunc_strchr: |
| 134 | case LibFunc_strrchr: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 135 | Changed |= setOnlyReadsMemory(F); |
| 136 | Changed |= setDoesNotThrow(F); |
| 137 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 138 | case LibFunc_strtol: |
| 139 | case LibFunc_strtod: |
| 140 | case LibFunc_strtof: |
| 141 | case LibFunc_strtoul: |
| 142 | case LibFunc_strtoll: |
| 143 | case LibFunc_strtold: |
| 144 | case LibFunc_strtoull: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 145 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 146 | Changed |= setDoesNotCapture(F, 1); |
| 147 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 148 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 149 | case LibFunc_strcpy: |
| 150 | case LibFunc_stpcpy: |
| 151 | case LibFunc_strcat: |
| 152 | case LibFunc_strncat: |
| 153 | case LibFunc_strncpy: |
| 154 | case LibFunc_stpncpy: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 155 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 156 | Changed |= setDoesNotCapture(F, 1); |
| 157 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 158 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 159 | case LibFunc_strxfrm: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 160 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 161 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 162 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 163 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 164 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 165 | case LibFunc_strcmp: // 0,1 |
| 166 | case LibFunc_strspn: // 0,1 |
| 167 | case LibFunc_strncmp: // 0,1 |
| 168 | case LibFunc_strcspn: // 0,1 |
| 169 | case LibFunc_strcoll: // 0,1 |
| 170 | case LibFunc_strcasecmp: // 0,1 |
| 171 | case LibFunc_strncasecmp: // |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 172 | Changed |= setOnlyReadsMemory(F); |
| 173 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 174 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 175 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 176 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 177 | case LibFunc_strstr: |
| 178 | case LibFunc_strpbrk: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 179 | Changed |= setOnlyReadsMemory(F); |
| 180 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 181 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 182 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 183 | case LibFunc_strtok: |
| 184 | case LibFunc_strtok_r: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 185 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 186 | Changed |= setDoesNotCapture(F, 1); |
| 187 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 188 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 189 | case LibFunc_scanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 190 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 191 | Changed |= setDoesNotCapture(F, 0); |
| 192 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 193 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 194 | case LibFunc_setbuf: |
| 195 | case LibFunc_setvbuf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 196 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 197 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 198 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 199 | case LibFunc_strdup: |
| 200 | case LibFunc_strndup: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 201 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 202 | Changed |= setRetDoesNotAlias(F); |
| 203 | Changed |= setDoesNotCapture(F, 0); |
| 204 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 205 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 206 | case LibFunc_stat: |
| 207 | case LibFunc_statvfs: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 208 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 209 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 210 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 211 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 212 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 213 | case LibFunc_sscanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 214 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 215 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 216 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 217 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 218 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 219 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 220 | case LibFunc_sprintf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 221 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 222 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 223 | Changed |= setDoesNotCapture(F, 1); |
| 224 | Changed |= setOnlyReadsMemory(F, 1); |
| 225 | return Changed; |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 226 | case LibFunc_snprintf: |
| 227 | Changed |= setDoesNotThrow(F); |
| 228 | Changed |= setDoesNotCapture(F, 0); |
| 229 | Changed |= setDoesNotCapture(F, 2); |
| 230 | Changed |= setOnlyReadsMemory(F, 2); |
| 231 | return Changed; |
| 232 | case LibFunc_setitimer: |
| 233 | Changed |= setDoesNotThrow(F); |
| 234 | Changed |= setDoesNotCapture(F, 1); |
| 235 | Changed |= setDoesNotCapture(F, 2); |
| 236 | Changed |= setOnlyReadsMemory(F, 1); |
| 237 | return Changed; |
| 238 | case LibFunc_system: |
| 239 | // May throw; "system" is a valid pthread cancellation point. |
| 240 | Changed |= setDoesNotCapture(F, 0); |
| 241 | Changed |= setOnlyReadsMemory(F, 0); |
| 242 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 243 | case LibFunc_malloc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 244 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 245 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 246 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 247 | case LibFunc_memcmp: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 248 | Changed |= setOnlyReadsMemory(F); |
| 249 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 250 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 251 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 252 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 253 | case LibFunc_memchr: |
| 254 | case LibFunc_memrchr: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 255 | Changed |= setOnlyReadsMemory(F); |
| 256 | Changed |= setDoesNotThrow(F); |
| 257 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 258 | case LibFunc_modf: |
| 259 | case LibFunc_modff: |
| 260 | case LibFunc_modfl: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 261 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 262 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 263 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 264 | case LibFunc_memcpy: |
| 265 | case LibFunc_mempcpy: |
| 266 | case LibFunc_memccpy: |
| 267 | case LibFunc_memmove: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 268 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 269 | Changed |= setDoesNotCapture(F, 1); |
| 270 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 271 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 272 | case LibFunc_memcpy_chk: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 273 | Changed |= setDoesNotThrow(F); |
| 274 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 275 | case LibFunc_memalign: |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 276 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 277 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 278 | case LibFunc_mkdir: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 279 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 280 | Changed |= setDoesNotCapture(F, 0); |
| 281 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 282 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 283 | case LibFunc_mktime: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 284 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 285 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 286 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 287 | case LibFunc_realloc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 288 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 289 | Changed |= setRetDoesNotAlias(F); |
| 290 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 291 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 292 | case LibFunc_read: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 293 | // May throw; "read" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 294 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 295 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 296 | case LibFunc_rewind: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 297 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 298 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 299 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 300 | case LibFunc_rmdir: |
| 301 | case LibFunc_remove: |
| 302 | case LibFunc_realpath: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 303 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 304 | Changed |= setDoesNotCapture(F, 0); |
| 305 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 306 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 307 | case LibFunc_rename: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 308 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 309 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 310 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 311 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 312 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 313 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 314 | case LibFunc_readlink: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 315 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 316 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 317 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 318 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 319 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 320 | case LibFunc_write: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 321 | // May throw; "write" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 322 | Changed |= setDoesNotCapture(F, 1); |
| 323 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 324 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 325 | case LibFunc_bcopy: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 326 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 327 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 328 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 329 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 330 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 331 | case LibFunc_bcmp: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 332 | Changed |= setDoesNotThrow(F); |
| 333 | Changed |= setOnlyReadsMemory(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 334 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 335 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 336 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 337 | case LibFunc_bzero: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 338 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 339 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 340 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 341 | case LibFunc_calloc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 342 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 343 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 344 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 345 | case LibFunc_chmod: |
| 346 | case LibFunc_chown: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 347 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 348 | Changed |= setDoesNotCapture(F, 0); |
| 349 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 350 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 351 | case LibFunc_ctermid: |
| 352 | case LibFunc_clearerr: |
| 353 | case LibFunc_closedir: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 354 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 355 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 356 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 357 | case LibFunc_atoi: |
| 358 | case LibFunc_atol: |
| 359 | case LibFunc_atof: |
| 360 | case LibFunc_atoll: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 361 | Changed |= setDoesNotThrow(F); |
| 362 | Changed |= setOnlyReadsMemory(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 363 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 364 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 365 | case LibFunc_access: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 366 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 367 | Changed |= setDoesNotCapture(F, 0); |
| 368 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 369 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 370 | case LibFunc_fopen: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 371 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 372 | Changed |= setRetDoesNotAlias(F); |
| 373 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 374 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 375 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 376 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 377 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 378 | case LibFunc_fdopen: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 379 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 380 | Changed |= setRetDoesNotAlias(F); |
| 381 | Changed |= setDoesNotCapture(F, 1); |
| 382 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 383 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 384 | case LibFunc_feof: |
| 385 | case LibFunc_free: |
| 386 | case LibFunc_fseek: |
| 387 | case LibFunc_ftell: |
| 388 | case LibFunc_fgetc: |
| 389 | case LibFunc_fseeko: |
| 390 | case LibFunc_ftello: |
| 391 | case LibFunc_fileno: |
| 392 | case LibFunc_fflush: |
| 393 | case LibFunc_fclose: |
| 394 | case LibFunc_fsetpos: |
| 395 | case LibFunc_flockfile: |
| 396 | case LibFunc_funlockfile: |
| 397 | case LibFunc_ftrylockfile: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 398 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 399 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 400 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 401 | case LibFunc_ferror: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 402 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 403 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 404 | Changed |= setOnlyReadsMemory(F); |
| 405 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 406 | case LibFunc_fputc: |
| 407 | case LibFunc_fstat: |
| 408 | case LibFunc_frexp: |
| 409 | case LibFunc_frexpf: |
| 410 | case LibFunc_frexpl: |
| 411 | case LibFunc_fstatvfs: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 412 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 413 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 414 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 415 | case LibFunc_fgets: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 416 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 417 | Changed |= setDoesNotCapture(F, 2); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 418 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 419 | case LibFunc_fread: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 420 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 421 | Changed |= setDoesNotCapture(F, 0); |
| 422 | Changed |= setDoesNotCapture(F, 3); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 423 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 424 | case LibFunc_fwrite: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 425 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 426 | Changed |= setDoesNotCapture(F, 0); |
| 427 | Changed |= setDoesNotCapture(F, 3); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 428 | // FIXME: readonly #1? |
| 429 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 430 | case LibFunc_fputs: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 431 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 432 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 433 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 434 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 435 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 436 | case LibFunc_fscanf: |
| 437 | case LibFunc_fprintf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 438 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 439 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 440 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 441 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 442 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 443 | case LibFunc_fgetpos: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 444 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 445 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 446 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 447 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 448 | case LibFunc_getc: |
| 449 | case LibFunc_getlogin_r: |
| 450 | case LibFunc_getc_unlocked: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 451 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 452 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 453 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 454 | case LibFunc_getenv: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 455 | Changed |= setDoesNotThrow(F); |
| 456 | Changed |= setOnlyReadsMemory(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 457 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 458 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 459 | case LibFunc_gets: |
| 460 | case LibFunc_getchar: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 461 | Changed |= setDoesNotThrow(F); |
| 462 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 463 | case LibFunc_getitimer: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 464 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 465 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 466 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 467 | case LibFunc_getpwnam: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 468 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 469 | Changed |= setDoesNotCapture(F, 0); |
| 470 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 471 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 472 | case LibFunc_ungetc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 473 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 474 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 475 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 476 | case LibFunc_uname: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 477 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 478 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 479 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 480 | case LibFunc_unlink: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 481 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 482 | Changed |= setDoesNotCapture(F, 0); |
| 483 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 484 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 485 | case LibFunc_unsetenv: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 486 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 487 | Changed |= setDoesNotCapture(F, 0); |
| 488 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 489 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 490 | case LibFunc_utime: |
| 491 | case LibFunc_utimes: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 492 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 493 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 494 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 495 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 496 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 497 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 498 | case LibFunc_putc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 499 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 500 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 501 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 502 | case LibFunc_puts: |
| 503 | case LibFunc_printf: |
| 504 | case LibFunc_perror: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 505 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 506 | Changed |= setDoesNotCapture(F, 0); |
| 507 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 508 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 509 | case LibFunc_pread: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 510 | // May throw; "pread" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 511 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 512 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 513 | case LibFunc_pwrite: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 514 | // May throw; "pwrite" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 515 | Changed |= setDoesNotCapture(F, 1); |
| 516 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 517 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 518 | case LibFunc_putchar: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 519 | Changed |= setDoesNotThrow(F); |
| 520 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 521 | case LibFunc_popen: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 522 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 523 | Changed |= setRetDoesNotAlias(F); |
| 524 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 525 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 526 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 527 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 528 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 529 | case LibFunc_pclose: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 530 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 531 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 532 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 533 | case LibFunc_vscanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 534 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 535 | Changed |= setDoesNotCapture(F, 0); |
| 536 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 537 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 538 | case LibFunc_vsscanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 539 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 540 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 541 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 542 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 543 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 544 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 545 | case LibFunc_vfscanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 546 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 547 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 548 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 549 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 550 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 551 | case LibFunc_valloc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 552 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 553 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 554 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 555 | case LibFunc_vprintf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 556 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 557 | Changed |= setDoesNotCapture(F, 0); |
| 558 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 559 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 560 | case LibFunc_vfprintf: |
| 561 | case LibFunc_vsprintf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 562 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 563 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 564 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 565 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 566 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 567 | case LibFunc_vsnprintf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 568 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 569 | Changed |= setDoesNotCapture(F, 0); |
| 570 | Changed |= setDoesNotCapture(F, 2); |
| 571 | Changed |= setOnlyReadsMemory(F, 2); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 572 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 573 | case LibFunc_open: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 574 | // May throw; "open" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 575 | Changed |= setDoesNotCapture(F, 0); |
| 576 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 577 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 578 | case LibFunc_opendir: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 579 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 580 | Changed |= setRetDoesNotAlias(F); |
| 581 | Changed |= setDoesNotCapture(F, 0); |
| 582 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 583 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 584 | case LibFunc_tmpfile: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 585 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 586 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 587 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 588 | case LibFunc_times: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 589 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 590 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 591 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 592 | case LibFunc_htonl: |
| 593 | case LibFunc_htons: |
| 594 | case LibFunc_ntohl: |
| 595 | case LibFunc_ntohs: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 596 | Changed |= setDoesNotThrow(F); |
| 597 | Changed |= setDoesNotAccessMemory(F); |
| 598 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 599 | case LibFunc_lstat: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 600 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 601 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 602 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 603 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 604 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 605 | case LibFunc_lchown: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 606 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 607 | Changed |= setDoesNotCapture(F, 0); |
| 608 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 609 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 610 | case LibFunc_qsort: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 611 | // May throw; places call through function pointer. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 612 | Changed |= setDoesNotCapture(F, 3); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 613 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 614 | case LibFunc_dunder_strdup: |
| 615 | case LibFunc_dunder_strndup: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 616 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 617 | Changed |= setRetDoesNotAlias(F); |
| 618 | Changed |= setDoesNotCapture(F, 0); |
| 619 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 620 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 621 | case LibFunc_dunder_strtok_r: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 622 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 623 | Changed |= setDoesNotCapture(F, 1); |
| 624 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 625 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 626 | case LibFunc_under_IO_getc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 627 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 628 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 629 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 630 | case LibFunc_under_IO_putc: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 631 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 632 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 633 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 634 | case LibFunc_dunder_isoc99_scanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 635 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 636 | Changed |= setDoesNotCapture(F, 0); |
| 637 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 638 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 639 | case LibFunc_stat64: |
| 640 | case LibFunc_lstat64: |
| 641 | case LibFunc_statvfs64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 642 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 643 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 644 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 645 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 646 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 647 | case LibFunc_dunder_isoc99_sscanf: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 648 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 649 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 650 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 651 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 652 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 653 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 654 | case LibFunc_fopen64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 655 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 656 | Changed |= setRetDoesNotAlias(F); |
| 657 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 658 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 659 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 660 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 661 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 662 | case LibFunc_fseeko64: |
| 663 | case LibFunc_ftello64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 664 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 665 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 666 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 667 | case LibFunc_tmpfile64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 668 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 669 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 670 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 671 | case LibFunc_fstat64: |
| 672 | case LibFunc_fstatvfs64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 673 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 674 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 675 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 676 | case LibFunc_open64: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 677 | // May throw; "open" is a valid pthread cancellation point. |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 678 | Changed |= setDoesNotCapture(F, 0); |
| 679 | Changed |= setOnlyReadsMemory(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 680 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 681 | case LibFunc_gettimeofday: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 682 | // Currently some platforms have the restrict keyword on the arguments to |
| 683 | // gettimeofday. To be conservative, do not add noalias to gettimeofday's |
| 684 | // arguments. |
| 685 | Changed |= setDoesNotThrow(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 686 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 687 | Changed |= setDoesNotCapture(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 688 | return Changed; |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 689 | case LibFunc_Znwj: // new(unsigned int) |
| 690 | case LibFunc_Znwm: // new(unsigned long) |
| 691 | case LibFunc_Znaj: // new[](unsigned int) |
| 692 | case LibFunc_Znam: // new[](unsigned long) |
| 693 | case LibFunc_msvc_new_int: // new(unsigned int) |
| 694 | case LibFunc_msvc_new_longlong: // new(unsigned long long) |
| 695 | case LibFunc_msvc_new_array_int: // new[](unsigned int) |
| 696 | case LibFunc_msvc_new_array_longlong: // new[](unsigned long long) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 697 | // Operator new always returns a nonnull noalias pointer |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 698 | Changed |= setRetNonNull(F); |
| 699 | Changed |= setRetDoesNotAlias(F); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 700 | return Changed; |
| 701 | //TODO: add LibFunc entries for: |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 702 | //case LibFunc_memset_pattern4: |
| 703 | //case LibFunc_memset_pattern8: |
| 704 | case LibFunc_memset_pattern16: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 705 | Changed |= setOnlyAccessesArgMemory(F); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 706 | Changed |= setDoesNotCapture(F, 0); |
Ahmed Bougacha | 44c1987 | 2016-04-27 19:04:43 +0000 | [diff] [blame] | 707 | Changed |= setDoesNotCapture(F, 1); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 708 | Changed |= setOnlyReadsMemory(F, 1); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 709 | return Changed; |
| 710 | // int __nvvm_reflect(const char *) |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 711 | case LibFunc_nvvm_reflect: |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 712 | Changed |= setDoesNotAccessMemory(F); |
| 713 | Changed |= setDoesNotThrow(F); |
| 714 | return Changed; |
| 715 | |
| 716 | default: |
| 717 | // FIXME: It'd be really nice to cover all the library functions we're |
| 718 | // aware of here. |
| 719 | return false; |
| 720 | } |
| 721 | } |
| 722 | |
Dmitry Venikov | e5fbf59 | 2018-01-11 06:33:00 +0000 | [diff] [blame] | 723 | bool llvm::hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, |
| 724 | LibFunc DoubleFn, LibFunc FloatFn, |
| 725 | LibFunc LongDoubleFn) { |
| 726 | switch (Ty->getTypeID()) { |
| 727 | case Type::FloatTyID: |
| 728 | return TLI->has(FloatFn); |
| 729 | case Type::DoubleTyID: |
| 730 | return TLI->has(DoubleFn); |
| 731 | default: |
| 732 | return TLI->has(LongDoubleFn); |
| 733 | } |
| 734 | } |
| 735 | |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 736 | //- Emit LibCalls ------------------------------------------------------------// |
| 737 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 738 | Value *llvm::castToCStr(Value *V, IRBuilder<> &B) { |
Matt Arsenault | be55888 | 2014-04-23 20:58:57 +0000 | [diff] [blame] | 739 | unsigned AS = V->getType()->getPointerAddressSpace(); |
| 740 | return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr"); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 743 | Value *llvm::emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 744 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 745 | if (!TLI->has(LibFunc_strlen)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 746 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 747 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 748 | Module *M = B.GetInsertBlock()->getModule(); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 749 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 750 | Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 751 | B.getInt8PtrTy()); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 752 | inferLibFuncAttributes(*M->getFunction("strlen"), *TLI); |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 753 | CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 754 | if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts())) |
| 755 | CI->setCallingConv(F->getCallingConv()); |
| 756 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 757 | return CI; |
| 758 | } |
| 759 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 760 | Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 761 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 762 | if (!TLI->has(LibFunc_strchr)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 763 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 764 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 765 | Module *M = B.GetInsertBlock()->getModule(); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 766 | Type *I8Ptr = B.getInt8PtrTy(); |
| 767 | Type *I32Ty = B.getInt32Ty(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 768 | Constant *StrChr = |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 769 | M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 770 | inferLibFuncAttributes(*M->getFunction("strchr"), *TLI); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 771 | CallInst *CI = B.CreateCall( |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 772 | StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 773 | if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts())) |
| 774 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 775 | return CI; |
| 776 | } |
| 777 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 778 | Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 779 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 780 | if (!TLI->has(LibFunc_strncmp)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 781 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 782 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 783 | Module *M = B.GetInsertBlock()->getModule(); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 784 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 785 | Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(), |
| 786 | B.getInt8PtrTy(), B.getInt8PtrTy(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 787 | DL.getIntPtrType(Context)); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 788 | inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 789 | CallInst *CI = B.CreateCall( |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 790 | StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 791 | |
| 792 | if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts())) |
| 793 | CI->setCallingConv(F->getCallingConv()); |
| 794 | |
Benjamin Kramer | 1118860 | 2010-06-15 21:34:25 +0000 | [diff] [blame] | 795 | return CI; |
| 796 | } |
| 797 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 798 | Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 799 | const TargetLibraryInfo *TLI, StringRef Name) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 800 | if (!TLI->has(LibFunc_strcpy)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 801 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 802 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 803 | Module *M = B.GetInsertBlock()->getModule(); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 804 | Type *I8Ptr = B.getInt8PtrTy(); |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 805 | Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 806 | inferLibFuncAttributes(*M->getFunction(Name), *TLI); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 807 | CallInst *CI = |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 808 | B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 809 | if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts())) |
| 810 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 811 | return CI; |
| 812 | } |
| 813 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 814 | Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 815 | const TargetLibraryInfo *TLI, StringRef Name) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 816 | if (!TLI->has(LibFunc_strncpy)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 817 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 818 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 819 | Module *M = B.GetInsertBlock()->getModule(); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 820 | Type *I8Ptr = B.getInt8PtrTy(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 821 | Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 822 | Len->getType()); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 823 | inferLibFuncAttributes(*M->getFunction(Name), *TLI); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 824 | CallInst *CI = B.CreateCall( |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 825 | StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 826 | if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts())) |
| 827 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 43dc11c | 2010-03-11 01:25:07 +0000 | [diff] [blame] | 828 | return CI; |
| 829 | } |
| 830 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 831 | Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 832 | IRBuilder<> &B, const DataLayout &DL, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 833 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 834 | if (!TLI->has(LibFunc_memcpy_chk)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 835 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 836 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 837 | Module *M = B.GetInsertBlock()->getModule(); |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 838 | AttributeList AS; |
| 839 | AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex, |
| 840 | Attribute::NoUnwind); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 841 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 842 | Value *MemCpy = M->getOrInsertFunction( |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 843 | "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(), |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 844 | B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 845 | DL.getIntPtrType(Context)); |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 846 | Dst = castToCStr(Dst, B); |
| 847 | Src = castToCStr(Src, B); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 848 | CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 849 | if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts())) |
| 850 | CI->setCallingConv(F->getCallingConv()); |
Evan Cheng | d9e8223 | 2010-03-23 15:48:04 +0000 | [diff] [blame] | 851 | return CI; |
| 852 | } |
| 853 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 854 | Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 855 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 856 | if (!TLI->has(LibFunc_memchr)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 857 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 858 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 859 | Module *M = B.GetInsertBlock()->getModule(); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 860 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 861 | Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(), |
| 862 | B.getInt8PtrTy(), B.getInt32Ty(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 863 | DL.getIntPtrType(Context)); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 864 | inferLibFuncAttributes(*M->getFunction("memchr"), *TLI); |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 865 | CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 866 | |
| 867 | if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts())) |
| 868 | CI->setCallingConv(F->getCallingConv()); |
| 869 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 870 | return CI; |
| 871 | } |
| 872 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 873 | Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 874 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 875 | if (!TLI->has(LibFunc_memcmp)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 876 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 877 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 878 | Module *M = B.GetInsertBlock()->getModule(); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 879 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 880 | Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(), |
| 881 | B.getInt8PtrTy(), B.getInt8PtrTy(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 882 | DL.getIntPtrType(Context)); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 883 | inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 884 | CallInst *CI = B.CreateCall( |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 885 | MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 886 | |
| 887 | if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts())) |
| 888 | CI->setCallingConv(F->getCallingConv()); |
| 889 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 890 | return CI; |
| 891 | } |
| 892 | |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 893 | /// Append a suffix to the function name according to the type of 'Op'. |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 894 | static void appendTypeSuffix(Value *Op, StringRef &Name, |
Sanjay Patel | b50325e | 2016-01-19 19:17:47 +0000 | [diff] [blame] | 895 | SmallString<20> &NameBuffer) { |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 896 | if (!Op->getType()->isDoubleTy()) { |
| 897 | NameBuffer += Name; |
| 898 | |
| 899 | if (Op->getType()->isFloatTy()) |
| 900 | NameBuffer += 'f'; |
| 901 | else |
| 902 | NameBuffer += 'l'; |
| 903 | |
| 904 | Name = NameBuffer; |
| 905 | } |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 908 | Value *llvm::emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 909 | const AttributeList &Attrs) { |
Benjamin Kramer | b106bcc | 2011-11-15 19:12:09 +0000 | [diff] [blame] | 910 | SmallString<20> NameBuffer; |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 911 | appendTypeSuffix(Op, Name, NameBuffer); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 912 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 913 | Module *M = B.GetInsertBlock()->getModule(); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 914 | Value *Callee = M->getOrInsertFunction(Name, Op->getType(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 915 | Op->getType()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 916 | CallInst *CI = B.CreateCall(Callee, Op, Name); |
Matt Arsenault | 6a288c1 | 2017-05-03 02:26:10 +0000 | [diff] [blame] | 917 | |
| 918 | // The incoming attribute set may have come from a speculatable intrinsic, but |
| 919 | // is being replaced with a library call which is not allowed to be |
| 920 | // speculatable. |
| 921 | CI->setAttributes(Attrs.removeAttribute(B.getContext(), |
| 922 | AttributeList::FunctionIndex, |
| 923 | Attribute::Speculatable)); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 924 | if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) |
| 925 | CI->setCallingConv(F->getCallingConv()); |
| 926 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 927 | return CI; |
| 928 | } |
| 929 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 930 | Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 931 | IRBuilder<> &B, const AttributeList &Attrs) { |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 932 | SmallString<20> NameBuffer; |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 933 | appendTypeSuffix(Op1, Name, NameBuffer); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 934 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 935 | Module *M = B.GetInsertBlock()->getModule(); |
Sanjay Patel | b50325e | 2016-01-19 19:17:47 +0000 | [diff] [blame] | 936 | Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 937 | Op2->getType()); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 938 | CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 939 | CI->setAttributes(Attrs); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 940 | if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) |
| 941 | CI->setCallingConv(F->getCallingConv()); |
| 942 | |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 943 | return CI; |
| 944 | } |
| 945 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 946 | Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 947 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 948 | if (!TLI->has(LibFunc_putchar)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 949 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 950 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 951 | Module *M = B.GetInsertBlock()->getModule(); |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 952 | Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), B.getInt32Ty()); |
Craig Topper | 0f5063c | 2017-03-17 23:48:02 +0000 | [diff] [blame] | 953 | inferLibFuncAttributes(*M->getFunction("putchar"), *TLI); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 954 | CallInst *CI = B.CreateCall(PutChar, |
| 955 | B.CreateIntCast(Char, |
| 956 | B.getInt32Ty(), |
| 957 | /*isSigned*/true, |
| 958 | "chari"), |
| 959 | "putchar"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 960 | |
| 961 | if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts())) |
| 962 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 963 | return CI; |
| 964 | } |
| 965 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 966 | Value *llvm::emitPutS(Value *Str, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 967 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 968 | if (!TLI->has(LibFunc_puts)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 969 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 970 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 971 | Module *M = B.GetInsertBlock()->getModule(); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 972 | Value *PutS = |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 973 | M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy()); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 974 | inferLibFuncAttributes(*M->getFunction("puts"), *TLI); |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 975 | CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 976 | if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts())) |
| 977 | CI->setCallingConv(F->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 978 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 981 | Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 982 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 983 | if (!TLI->has(LibFunc_fputc)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 984 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 985 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 986 | Module *M = B.GetInsertBlock()->getModule(); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 987 | Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 988 | File->getType()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 989 | if (File->getType()->isPointerTy()) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 990 | inferLibFuncAttributes(*M->getFunction("fputc"), *TLI); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 991 | Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true, |
| 992 | "chari"); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 993 | CallInst *CI = B.CreateCall(F, {Char, File}, "fputc"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 994 | |
| 995 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 996 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 997 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 1000 | Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1001 | const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1002 | if (!TLI->has(LibFunc_fputs)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 1003 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 1004 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 1005 | Module *M = B.GetInsertBlock()->getModule(); |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1006 | StringRef FPutsName = TLI->getName(LibFunc_fputs); |
Mehdi Amini | db11fdf | 2017-04-06 20:23:57 +0000 | [diff] [blame] | 1007 | Constant *F = M->getOrInsertFunction( |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 1008 | FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1009 | if (File->getType()->isPointerTy()) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 1010 | inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI); |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 1011 | CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 1012 | |
| 1013 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 1014 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 1015 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 1018 | Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1019 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1020 | if (!TLI->has(LibFunc_fwrite)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 1021 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 1022 | |
Sanjay Patel | d4af297 | 2016-01-19 19:58:49 +0000 | [diff] [blame] | 1023 | Module *M = B.GetInsertBlock()->getModule(); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 1024 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
David L. Jones | d21529f | 2017-01-23 23:16:46 +0000 | [diff] [blame] | 1025 | StringRef FWriteName = TLI->getName(LibFunc_fwrite); |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 1026 | Constant *F = M->getOrInsertFunction( |
| 1027 | FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(), |
Serge Guelton | 59a2d7b | 2017-04-11 15:01:18 +0000 | [diff] [blame] | 1028 | DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); |
| 1029 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1030 | if (File->getType()->isPointerTy()) |
Ahmed Bougacha | b0624a2 | 2016-04-27 19:04:40 +0000 | [diff] [blame] | 1031 | inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 1032 | CallInst *CI = |
Sanjay Patel | d3112a5 | 2016-01-19 19:46:10 +0000 | [diff] [blame] | 1033 | B.CreateCall(F, {castToCStr(Ptr, B), Size, |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 1034 | ConstantInt::get(DL.getIntPtrType(Context), 1), File}); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 1035 | |
| 1036 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 1037 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 1038 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1039 | } |
Sanjay Patel | b2ab3f2 | 2018-04-18 14:21:31 +0000 | [diff] [blame] | 1040 | |
| 1041 | Value *llvm::emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, |
| 1042 | const TargetLibraryInfo *TLI) { |
| 1043 | if (!TLI->has(LibFunc_malloc)) |
| 1044 | return nullptr; |
| 1045 | |
| 1046 | Module *M = B.GetInsertBlock()->getModule(); |
| 1047 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
| 1048 | Value *Malloc = M->getOrInsertFunction("malloc", B.getInt8PtrTy(), |
| 1049 | DL.getIntPtrType(Context)); |
| 1050 | inferLibFuncAttributes(*M->getFunction("malloc"), *TLI); |
| 1051 | CallInst *CI = B.CreateCall(Malloc, Num, "malloc"); |
| 1052 | |
| 1053 | if (const Function *F = dyn_cast<Function>(Malloc->stripPointerCasts())) |
| 1054 | CI->setCallingConv(F->getCallingConv()); |
| 1055 | |
| 1056 | return CI; |
| 1057 | } |
| 1058 | |
| 1059 | Value *llvm::emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, |
| 1060 | IRBuilder<> &B, const TargetLibraryInfo &TLI) { |
| 1061 | if (!TLI.has(LibFunc_calloc)) |
| 1062 | return nullptr; |
| 1063 | |
| 1064 | Module *M = B.GetInsertBlock()->getModule(); |
| 1065 | const DataLayout &DL = M->getDataLayout(); |
| 1066 | IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext())); |
| 1067 | Value *Calloc = M->getOrInsertFunction("calloc", Attrs, B.getInt8PtrTy(), |
| 1068 | PtrType, PtrType); |
| 1069 | inferLibFuncAttributes(*M->getFunction("calloc"), TLI); |
| 1070 | CallInst *CI = B.CreateCall(Calloc, {Num, Size}, "calloc"); |
| 1071 | |
| 1072 | if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts())) |
| 1073 | CI->setCallingConv(F->getCallingConv()); |
| 1074 | |
| 1075 | return CI; |
| 1076 | } |