OLD | NEW |
(Empty) | |
| 1 //===-- llvm/IR/NaClAsm.h - NaCl Assembly Handling --------------*- C++ -*-===// |
| 2 // |
| 3 // The LLVM Compiler Infrastructure |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 |
| 10 #include "llvm/IR/InlineAsm.h" |
| 11 #include "llvm/IR/Instruction.h" |
| 12 #include "llvm/IR/Instructions.h" |
| 13 #include "llvm/IR/NaClAsm.h" |
| 14 #include <string> |
| 15 |
| 16 namespace llvm { |
| 17 |
| 18 namespace NaCl { |
| 19 |
| 20 bool isAsmMemory(const Instruction *I) { |
| 21 if (!I) |
| 22 return false; |
| 23 const CallInst *CI = dyn_cast<CallInst>(I); |
| 24 if (!CI || !CI->isInlineAsm()) |
| 25 return false; |
| 26 |
| 27 const InlineAsm *A = cast<InlineAsm>(CI->getCalledValue()); |
| 28 std::string AsmString(A->getAsmString()); |
| 29 std::string Constraints(A->getConstraintString()); |
| 30 Type *T = CI->getType(); |
| 31 |
| 32 bool isEmptyAsm = AsmString.empty(); |
| 33 // Different triples will encode "touch everything" differently, e.g.: |
| 34 // - le32-unknown-nacl has "~{memory}". |
| 35 // - x86 "~{memory},~{dirflag},~{fpsr},~{flags}". |
| 36 // The following code therefore only searches for memory: this pass |
| 37 // deals with portable assembly, touching anything else than memory in |
| 38 // an empty assembly statement is meaningless. |
| 39 bool touchesMemory = Constraints.find("~{memory}") != std::string::npos; |
| 40 |
| 41 return T->isVoidTy() && A->hasSideEffects() && isEmptyAsm && touchesMemory; |
| 42 } |
| 43 |
| 44 } // End NaCl namespace |
| 45 |
| 46 } // End llvm namespace |
OLD | NEW |