| 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 |
| 11 // normally run in the PNaCl translator. | 11 // normally run in the PNaCl translator. |
| 12 // | 12 // |
| 13 // Running AddPNaClExternalDeclsPass is a precondition for running this | 13 // Running AddPNaClExternalDeclsPass is a precondition for running this |
| 14 // pass. They are separate because one is a ModulePass and the other is | 14 // pass. They are separate because one is a ModulePass and the other is |
| 15 // a FunctionPass. | 15 // a FunctionPass. |
| 16 // | 16 // |
| 17 //===----------------------------------------------------------------------===// | 17 //===----------------------------------------------------------------------===// |
| 18 | 18 |
| 19 #include "llvm/ADT/SmallVector.h" | 19 #include "llvm/ADT/SmallVector.h" |
| 20 #include "llvm/IR/Constant.h" | 20 #include "llvm/IR/Constant.h" |
| 21 #include "llvm/IR/DerivedTypes.h" |
| 22 #include "llvm/IR/InlineAsm.h" |
| 21 #include "llvm/IR/Instructions.h" | 23 #include "llvm/IR/Instructions.h" |
| 22 #include "llvm/IR/IntrinsicInst.h" | 24 #include "llvm/IR/IntrinsicInst.h" |
| 23 #include "llvm/IR/Intrinsics.h" | 25 #include "llvm/IR/Intrinsics.h" |
| 24 #include "llvm/IR/Module.h" | 26 #include "llvm/IR/Module.h" |
| 25 #include "llvm/IR/NaClAtomicIntrinsics.h" | 27 #include "llvm/IR/NaClAtomicIntrinsics.h" |
| 26 #include "llvm/IR/Value.h" | 28 #include "llvm/IR/Value.h" |
| 27 #include "llvm/Pass.h" | 29 #include "llvm/Pass.h" |
| 28 #include "llvm/Support/Compiler.h" | 30 #include "llvm/Support/Compiler.h" |
| 29 #include "llvm/Transforms/NaCl.h" | 31 #include "llvm/Transforms/NaCl.h" |
| 30 #if defined(__pnacl__) | 32 #if defined(__pnacl__) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // failure one. | 237 // failure one. |
| 236 I = new AtomicCmpXchgInst(Call->getArgOperand(0), Call->getArgOperand(1), | 238 I = new AtomicCmpXchgInst(Call->getArgOperand(0), Call->getArgOperand(1), |
| 237 Call->getArgOperand(2), | 239 Call->getArgOperand(2), |
| 238 thawMemoryOrder(Call->getArgOperand(3)), SS, | 240 thawMemoryOrder(Call->getArgOperand(3)), SS, |
| 239 Call); | 241 Call); |
| 240 break; | 242 break; |
| 241 case Intrinsic::nacl_atomic_fence: | 243 case Intrinsic::nacl_atomic_fence: |
| 242 I = new FenceInst(M->getContext(), | 244 I = new FenceInst(M->getContext(), |
| 243 thawMemoryOrder(Call->getArgOperand(0)), SS, Call); | 245 thawMemoryOrder(Call->getArgOperand(0)), SS, Call); |
| 244 break; | 246 break; |
| 247 case Intrinsic::nacl_atomic_fence_all: { |
| 248 FunctionType *FTy = |
| 249 FunctionType::get(Type::getVoidTy(M->getContext()), false); |
| 250 std::string AsmString; // Empty. |
| 251 std::string Constraints("~{memory}"); |
| 252 bool HasSideEffect = true; |
| 253 CallInst *Asm = CallInst::Create( |
| 254 InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect), "", Call); |
| 255 Asm->setDebugLoc(Call->getDebugLoc()); |
| 256 I = new FenceInst(M->getContext(), SequentiallyConsistent, SS, Asm); |
| 257 Asm = CallInst::Create( |
| 258 InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect), "", I); |
| 259 Asm->setDebugLoc(Call->getDebugLoc()); |
| 260 } break; |
| 245 } | 261 } |
| 246 I->setName(Call->getName()); | 262 I->setName(Call->getName()); |
| 247 I->setDebugLoc(Call->getDebugLoc()); | 263 I->setDebugLoc(Call->getDebugLoc()); |
| 248 Call->replaceAllUsesWith(I); | 264 Call->replaceAllUsesWith(I); |
| 249 Call->eraseFromParent(); | 265 Call->eraseFromParent(); |
| 250 | 266 |
| 251 return true; | 267 return true; |
| 252 } | 268 } |
| 253 | 269 |
| 254 unsigned alignmentFromPointer(const Value *Ptr) const { | 270 unsigned alignmentFromPointer(const Value *Ptr) const { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return Changed; | 358 return Changed; |
| 343 } | 359 } |
| 344 | 360 |
| 345 char ResolvePNaClIntrinsics::ID = 0; | 361 char ResolvePNaClIntrinsics::ID = 0; |
| 346 INITIALIZE_PASS(ResolvePNaClIntrinsics, "resolve-pnacl-intrinsics", | 362 INITIALIZE_PASS(ResolvePNaClIntrinsics, "resolve-pnacl-intrinsics", |
| 347 "Resolve PNaCl intrinsic calls", false, false) | 363 "Resolve PNaCl intrinsic calls", false, false) |
| 348 | 364 |
| 349 FunctionPass *llvm::createResolvePNaClIntrinsicsPass() { | 365 FunctionPass *llvm::createResolvePNaClIntrinsicsPass() { |
| 350 return new ResolvePNaClIntrinsics(); | 366 return new ResolvePNaClIntrinsics(); |
| 351 } | 367 } |
| OLD | NEW |