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

Unified Diff: lib/Transforms/NaCl/ExpandUtils.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/ExpandTlsConstantExpr.cpp ('k') | lib/Transforms/NaCl/ExpandVarArgs.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Transforms/NaCl/ExpandUtils.cpp
diff --git a/lib/Transforms/NaCl/ExpandUtils.cpp b/lib/Transforms/NaCl/ExpandUtils.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f825f3fce3bd06819ddacca8150d6d42df3676b0
--- /dev/null
+++ b/lib/Transforms/NaCl/ExpandUtils.cpp
@@ -0,0 +1,58 @@
+//===-- ExpandUtils.cpp - Helper functions for expansion passes -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/NaCl.h"
+
+using namespace llvm;
+
+Instruction *llvm::PhiSafeInsertPt(Use *U) {
+ Instruction *InsertPt = cast<Instruction>(U->getUser());
+ if (PHINode *PN = dyn_cast<PHINode>(InsertPt)) {
+ // We cannot insert instructions before a PHI node, so insert
+ // before the incoming block's terminator. This could be
+ // suboptimal if the terminator is a conditional.
+ InsertPt = PN->getIncomingBlock(*U)->getTerminator();
+ }
+ return InsertPt;
+}
+
+void llvm::PhiSafeReplaceUses(Use *U, Value *NewVal) {
+ User *UR = U->getUser();
+ if (PHINode *PN = dyn_cast<PHINode>(UR)) {
+ // A PHI node can have multiple incoming edges from the same
+ // block, in which case all these edges must have the same
+ // incoming value.
+ BasicBlock *BB = PN->getIncomingBlock(*U);
+ for (unsigned I = 0; I < PN->getNumIncomingValues(); ++I) {
+ if (PN->getIncomingBlock(I) == BB)
+ PN->setIncomingValue(I, NewVal);
+ }
+ } else {
+ UR->replaceUsesOfWith(U->get(), NewVal);
+ }
+}
+
+Function *llvm::RecreateFunction(Function *Func, FunctionType *NewType) {
+ Function *NewFunc = Function::Create(NewType, Func->getLinkage());
+ NewFunc->copyAttributesFrom(Func);
+ Func->getParent()->getFunctionList().insert(Func, NewFunc);
+ NewFunc->takeName(Func);
+ NewFunc->getBasicBlockList().splice(NewFunc->begin(),
+ Func->getBasicBlockList());
+ Func->replaceAllUsesWith(
+ ConstantExpr::getBitCast(NewFunc,
+ Func->getFunctionType()->getPointerTo()));
+ return NewFunc;
+}
« no previous file with comments | « lib/Transforms/NaCl/ExpandTlsConstantExpr.cpp ('k') | lib/Transforms/NaCl/ExpandVarArgs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698