Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: lib/IR/NaClAsm.cpp

Issue 22474008: Add the new @llvm.nacl.atomic.fence.all intrinsic (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698