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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/Transforms/NaCl/PromoteIntegers.cpp ('k') | lib/Transforms/NaCl/ReplacePtrsWithInts.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/InstVisitor.h"
20 #include "llvm/Pass.h"
21 #include <string>
22
23 using namespace llvm;
24
25 namespace {
26 class RemoveAsmMemory : public FunctionPass {
27 public:
28 static char ID; // Pass identification, replacement for typeid
29 RemoveAsmMemory() : FunctionPass(ID) {
30 initializeRemoveAsmMemoryPass(*PassRegistry::getPassRegistry());
31 }
32
33 bool runOnFunction(Function &F) override;
34 };
35
36 class AsmDirectivesVisitor : public InstVisitor<AsmDirectivesVisitor> {
37 public:
38 AsmDirectivesVisitor() : ModifiedFunction(false) {}
39 ~AsmDirectivesVisitor() {}
40 bool modifiedFunction() const { return ModifiedFunction; }
41
42 /// Only Call Instructions are ever inline assembly directives.
43 void visitCallInst(CallInst &CI);
44
45 private:
46 bool ModifiedFunction;
47
48 AsmDirectivesVisitor(const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
49 AsmDirectivesVisitor &operator=(
50 const AsmDirectivesVisitor &) LLVM_DELETED_FUNCTION;
51 };
52 }
53
54 char RemoveAsmMemory::ID = 0;
55 INITIALIZE_PASS(RemoveAsmMemory, "remove-asm-memory",
56 "remove all instances of ``asm(\"\":::\"memory\")``", false,
57 false)
58
59 bool RemoveAsmMemory::runOnFunction(Function &F) {
60 AsmDirectivesVisitor AV;
61 AV.visit(F);
62 return AV.modifiedFunction();
63 }
64
65 void AsmDirectivesVisitor::visitCallInst(CallInst &CI) {
66 if (!CI.isInlineAsm() ||
67 !cast<InlineAsm>(CI.getCalledValue())->isAsmMemory())
68 return;
69
70 // In NaCl ``asm("":::"memory")`` always comes in pairs, straddling a
71 // sequentially consistent fence. Other passes rewrite this fence to
72 // an equivalent stable NaCl intrinsic, meaning that this assembly can
73 // be removed.
74 CI.eraseFromParent();
75 ModifiedFunction = true;
76 }
77
78 namespace llvm {
79 FunctionPass *createRemoveAsmMemoryPass() { return new RemoveAsmMemory(); }
80 }
OLDNEW
« 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