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

Side by Side Diff: lib/Transforms/NaCl/RemoveAsmMemory.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 unified diff | Download patch
OLDNEW
(Empty)
1 //===- RemoveAsmMemory.cpp - Remove ``asm("":::"memory")`` ----------------===//
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 // This pass removes all instances of ``asm("":::"memory")``.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/IR/Function.h"
16 #include "llvm/IR/InlineAsm.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/NaClAsm.h"
20 #include "llvm/InstVisitor.h"
21 #include "llvm/Pass.h"
22 #include <string>
23
24 using namespace llvm;
25
26 namespace {
27 class RemoveAsmMemory : public FunctionPass {
28 public:
29 static char ID; // Pass identification, replacement for typeid
30 RemoveAsmMemory() : FunctionPass(ID) {
31 initializeRemoveAsmMemoryPass(*PassRegistry::getPassRegistry());
32 }
33
34 virtual bool runOnFunction(Function &F);
35 };
36
37 class AsmDirectivesVisitor : public InstVisitor<AsmDirectivesVisitor> {
38 public:
39 AsmDirectivesVisitor(Function &F)
40 : F(F), C(F.getParent()->getContext()), ModifiedFunction(false) {}
41 ~AsmDirectivesVisitor() {}
42 bool modifiedFunction() const { return ModifiedFunction; }
43
44 /// Only Call Instructions are ever inline assembly directives.
45 void visitCallInst(CallInst &CI);
46
47 private:
48 Function &F;
49 LLVMContext &C;
50 bool ModifiedFunction;
51
52 AsmDirectivesVisitor() LLVM_DELETED_FUNCTION;
53 AsmDirectivesVisitor(const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
54 AsmDirectivesVisitor &operator=(
55 const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
56 };
57 }
58
59 char RemoveAsmMemory::ID = 0;
60 INITIALIZE_PASS(RemoveAsmMemory, "remove-asm-memory",
61 "remove all instances of ``asm(\"\":::\"memory\")``", false,
62 false)
63
64 bool RemoveAsmMemory::runOnFunction(Function &F) {
65 AsmDirectivesVisitor AV(F);
66 AV.visit(F);
67 return AV.modifiedFunction();
68 }
69
70 void AsmDirectivesVisitor::visitCallInst(CallInst &CI) {
71 if (!NaCl::isAsmMemory(&CI))
72 return;
73
74 // In NaCl ``asm("":::"memory")`` always comes in pairs, straddling a
75 // sequentially consistent fence. Other passes rewrite this fence to
76 // an equivalent stable NaCl intrinsic, meaning that this assembly can
77 // be removed.
78 CI.eraseFromParent();
79 ModifiedFunction = true;
80 }
81
82 namespace llvm {
83 FunctionPass *createRemoveAsmMemoryPass() { return new RemoveAsmMemory(); }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698