| Index: lib/IR/NaClAsm.cpp
|
| diff --git a/lib/IR/NaClAsm.cpp b/lib/IR/NaClAsm.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2d8d6ad4e72231b3a9c21eef8dad938b35023528
|
| --- /dev/null
|
| +++ b/lib/IR/NaClAsm.cpp
|
| @@ -0,0 +1,46 @@
|
| +//===-- llvm/IR/NaClAsm.h - NaCl Assembly Handling --------------*- C++ -*-===//
|
| +//
|
| +// The LLVM Compiler Infrastructure
|
| +//
|
| +// This file is distributed under the University of Illinois Open Source
|
| +// License. See LICENSE.TXT for details.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +
|
| +#include "llvm/IR/InlineAsm.h"
|
| +#include "llvm/IR/Instruction.h"
|
| +#include "llvm/IR/Instructions.h"
|
| +#include "llvm/IR/NaClAsm.h"
|
| +#include <string>
|
| +
|
| +namespace llvm {
|
| +
|
| +namespace NaCl {
|
| +
|
| +bool isAsmMemory(const Instruction *I) {
|
| + if (!I)
|
| + return false;
|
| + const CallInst *CI = dyn_cast<CallInst>(I);
|
| + if (!CI || !CI->isInlineAsm())
|
| + return false;
|
| +
|
| + const InlineAsm *A = cast<InlineAsm>(CI->getCalledValue());
|
| + std::string AsmString(A->getAsmString());
|
| + std::string Constraints(A->getConstraintString());
|
| + Type *T = CI->getType();
|
| +
|
| + bool isEmptyAsm = AsmString.empty();
|
| + // Different triples will encode "touch everything" differently, e.g.:
|
| + // - le32-unknown-nacl has "~{memory}".
|
| + // - x86 "~{memory},~{dirflag},~{fpsr},~{flags}".
|
| + // The following code therefore only searches for memory: this pass
|
| + // deals with portable assembly, touching anything else than memory in
|
| + // an empty assembly statement is meaningless.
|
| + bool touchesMemory = Constraints.find("~{memory}") != std::string::npos;
|
| +
|
| + return T->isVoidTy() && A->hasSideEffects() && isEmptyAsm && touchesMemory;
|
| +}
|
| +
|
| +} // End NaCl namespace
|
| +
|
| +} // End llvm namespace
|
|
|