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

Unified Diff: lib/Transforms/NaCl/RemoveAsmMemory.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 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
« no previous file with comments | « lib/Transforms/NaCl/PromoteIntegers.cpp ('k') | lib/Transforms/NaCl/ReplacePtrsWithInts.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Transforms/NaCl/RemoveAsmMemory.cpp
diff --git a/lib/Transforms/NaCl/RemoveAsmMemory.cpp b/lib/Transforms/NaCl/RemoveAsmMemory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5224fcabb2ce770eb1ba49cb94a24154f63409c3
--- /dev/null
+++ b/lib/Transforms/NaCl/RemoveAsmMemory.cpp
@@ -0,0 +1,80 @@
+//===- RemoveAsmMemory.cpp - Remove ``asm("":::"memory")`` ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass removes all instances of ``asm("":::"memory")``.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/InstVisitor.h"
+#include "llvm/Pass.h"
+#include <string>
+
+using namespace llvm;
+
+namespace {
+class RemoveAsmMemory : public FunctionPass {
+public:
+ static char ID; // Pass identification, replacement for typeid
+ RemoveAsmMemory() : FunctionPass(ID) {
+ initializeRemoveAsmMemoryPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnFunction(Function &F) override;
+};
+
+class AsmDirectivesVisitor : public InstVisitor<AsmDirectivesVisitor> {
+public:
+ AsmDirectivesVisitor() : ModifiedFunction(false) {}
+ ~AsmDirectivesVisitor() {}
+ bool modifiedFunction() const { return ModifiedFunction; }
+
+ /// Only Call Instructions are ever inline assembly directives.
+ void visitCallInst(CallInst &CI);
+
+private:
+ bool ModifiedFunction;
+
+ AsmDirectivesVisitor(const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
+ AsmDirectivesVisitor &operator=(
+ const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
+};
+}
+
+char RemoveAsmMemory::ID = 0;
+INITIALIZE_PASS(RemoveAsmMemory, "remove-asm-memory",
+ "remove all instances of ``asm(\"\":::\"memory\")``", false,
+ false)
+
+bool RemoveAsmMemory::runOnFunction(Function &F) {
+ AsmDirectivesVisitor AV;
+ AV.visit(F);
+ return AV.modifiedFunction();
+}
+
+void AsmDirectivesVisitor::visitCallInst(CallInst &CI) {
+ if (!CI.isInlineAsm() ||
+ !cast<InlineAsm>(CI.getCalledValue())->isAsmMemory())
+ return;
+
+ // In NaCl ``asm("":::"memory")`` always comes in pairs, straddling a
+ // sequentially consistent fence. Other passes rewrite this fence to
+ // an equivalent stable NaCl intrinsic, meaning that this assembly can
+ // be removed.
+ CI.eraseFromParent();
+ ModifiedFunction = true;
+}
+
+namespace llvm {
+FunctionPass *createRemoveAsmMemoryPass() { return new RemoveAsmMemory(); }
+}
« no previous file with comments | « lib/Transforms/NaCl/PromoteIntegers.cpp ('k') | lib/Transforms/NaCl/ReplacePtrsWithInts.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698