| OLD | NEW |
| 1 //===- ResolvePNaClIntrinsics.cpp - Resolve calls to PNaCl intrinsics ----====// | 1 //===- ResolvePNaClIntrinsics.cpp - Resolve calls to PNaCl intrinsics ----====// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This pass resolves calls to PNaCl stable bitcode intrinsics. It is | 10 // This pass resolves calls to PNaCl stable bitcode intrinsics. It is |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Constant *C = Functor(Call); | 159 Constant *C = Functor(Call); |
| 160 Call->replaceAllUsesWith(C); | 160 Call->replaceAllUsesWith(C); |
| 161 Call->eraseFromParent(); | 161 Call->eraseFromParent(); |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 ConstantCallResolver(const ConstantCallResolver &) = delete; | 165 ConstantCallResolver(const ConstantCallResolver &) = delete; |
| 166 ConstantCallResolver &operator=(const ConstantCallResolver &) = delete; | 166 ConstantCallResolver &operator=(const ConstantCallResolver &) = delete; |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 /// Resolve __nacl_atomic_is_lock_free to true/false at translation | 169 /// Resolve __nacl_atomic_is_lock_free to true/false at translation / time. |
| 170 /// time. PNaCl's currently supported platforms all support lock-free atomics at | 170 //PNaCl's currently supported platforms all support lock-free atomics at / byte |
| 171 /// byte sizes {1,2,4,8} except for MIPS and asmjs architectures that supports | 171 //sizes {1,2,4,8} except for MIPS architecture that supports / lock-free atomics |
| 172 /// lock-free atomics at byte sizes {1,2,4}, and the alignment of the pointer is | 172 //at byte sizes {1,2,4}, and the alignment of the pointer is / always expected |
| 173 /// always expected to be natural (as guaranteed by C11 and C++11). PNaCl's | 173 //to be natural (as guaranteed by C11 and C++11). PNaCl's / Module-level ABI |
| 174 /// Module-level ABI verification checks that the byte size is constant and in | 174 //verification checks that the byte size is constant and in / {1,2,4,8}. |
| 175 /// {1,2,4,8}. | |
| 176 struct IsLockFreeToConstant { | 175 struct IsLockFreeToConstant { |
| 177 Constant *operator()(CallInst *Call) { | 176 Constant *operator()(CallInst *Call) { |
| 178 uint64_t MaxLockFreeByteSize = 8; | 177 uint64_t MaxLockFreeByteSize = 8; |
| 179 const APInt &ByteSize = | 178 const APInt &ByteSize = |
| 180 cast<Constant>(Call->getOperand(0))->getUniqueInteger(); | 179 cast<Constant>(Call->getOperand(0))->getUniqueInteger(); |
| 181 | 180 |
| 182 # if defined(PNACL_BROWSER_TRANSLATOR) | 181 # if defined(PNACL_BROWSER_TRANSLATOR) |
| 183 switch (__builtin_nacl_target_arch()) { | 182 switch (__builtin_nacl_target_arch()) { |
| 184 case PnaclTargetArchitectureX86_32: | 183 case PnaclTargetArchitectureX86_32: |
| 185 case PnaclTargetArchitectureX86_64: | 184 case PnaclTargetArchitectureX86_64: |
| 186 case PnaclTargetArchitectureARM_32: | 185 case PnaclTargetArchitectureARM_32: |
| 187 break; | 186 break; |
| 188 case PnaclTargetArchitectureMips_32: | 187 case PnaclTargetArchitectureMips_32: |
| 189 MaxLockFreeByteSize = 4; | 188 MaxLockFreeByteSize = 4; |
| 190 break; | 189 break; |
| 191 default: | 190 default: |
| 192 errs() << "Architecture: " << Triple::getArchTypeName(Arch) << "\n"; | 191 errs() << "Architecture: " << Triple::getArchTypeName(Arch) << "\n"; |
| 193 report_fatal_error("is_lock_free: unhandled architecture"); | 192 report_fatal_error("is_lock_free: unhandled architecture"); |
| 194 } | 193 } |
| 195 # else | 194 # else |
| 196 switch (Arch) { | 195 switch (Arch) { |
| 197 case Triple::x86: | 196 case Triple::x86: |
| 198 case Triple::x86_64: | 197 case Triple::x86_64: |
| 199 case Triple::arm: | 198 case Triple::arm: |
| 200 break; | 199 break; |
| 201 case Triple::mipsel: | 200 case Triple::mipsel: |
| 202 case Triple::asmjs: | |
| 203 MaxLockFreeByteSize = 4; | 201 MaxLockFreeByteSize = 4; |
| 204 break; | 202 break; |
| 205 default: | 203 default: |
| 206 errs() << "Architecture: " << Triple::getArchTypeName(Arch) << "\n"; | 204 errs() << "Architecture: " << Triple::getArchTypeName(Arch) << "\n"; |
| 207 report_fatal_error("is_lock_free: unhandled architecture"); | 205 report_fatal_error("is_lock_free: unhandled architecture"); |
| 208 } | 206 } |
| 209 # endif | 207 # endif |
| 210 | 208 |
| 211 bool IsLockFree = ByteSize.ule(MaxLockFreeByteSize); | 209 bool IsLockFree = ByteSize.ule(MaxLockFreeByteSize); |
| 212 auto *C = ConstantInt::get(Call->getType(), IsLockFree); | 210 auto *C = ConstantInt::get(Call->getType(), IsLockFree); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 return Changed; | 478 return Changed; |
| 481 } | 479 } |
| 482 | 480 |
| 483 char ResolvePNaClIntrinsics::ID = 0; | 481 char ResolvePNaClIntrinsics::ID = 0; |
| 484 INITIALIZE_PASS(ResolvePNaClIntrinsics, "resolve-pnacl-intrinsics", | 482 INITIALIZE_PASS(ResolvePNaClIntrinsics, "resolve-pnacl-intrinsics", |
| 485 "Resolve PNaCl intrinsic calls", false, false) | 483 "Resolve PNaCl intrinsic calls", false, false) |
| 486 | 484 |
| 487 FunctionPass *llvm::createResolvePNaClIntrinsicsPass() { | 485 FunctionPass *llvm::createResolvePNaClIntrinsicsPass() { |
| 488 return new ResolvePNaClIntrinsics(); | 486 return new ResolvePNaClIntrinsics(); |
| 489 } | 487 } |
| OLD | NEW |