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

Side by Side Diff: lib/Transforms/NaCl/ExpandUtils.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 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/ExpandTlsConstantExpr.cpp ('k') | lib/Transforms/NaCl/ExpandVarArgs.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 //===-- ExpandUtils.cpp - Helper functions for expansion passes -----------===//
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 #include "llvm/IR/BasicBlock.h"
11 #include "llvm/IR/Constants.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/Instructions.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Transforms/NaCl.h"
17
18 using namespace llvm;
19
20 Instruction *llvm::PhiSafeInsertPt(Use *U) {
21 Instruction *InsertPt = cast<Instruction>(U->getUser());
22 if (PHINode *PN = dyn_cast<PHINode>(InsertPt)) {
23 // We cannot insert instructions before a PHI node, so insert
24 // before the incoming block's terminator. This could be
25 // suboptimal if the terminator is a conditional.
26 InsertPt = PN->getIncomingBlock(*U)->getTerminator();
27 }
28 return InsertPt;
29 }
30
31 void llvm::PhiSafeReplaceUses(Use *U, Value *NewVal) {
32 User *UR = U->getUser();
33 if (PHINode *PN = dyn_cast<PHINode>(UR)) {
34 // A PHI node can have multiple incoming edges from the same
35 // block, in which case all these edges must have the same
36 // incoming value.
37 BasicBlock *BB = PN->getIncomingBlock(*U);
38 for (unsigned I = 0; I < PN->getNumIncomingValues(); ++I) {
39 if (PN->getIncomingBlock(I) == BB)
40 PN->setIncomingValue(I, NewVal);
41 }
42 } else {
43 UR->replaceUsesOfWith(U->get(), NewVal);
44 }
45 }
46
47 Function *llvm::RecreateFunction(Function *Func, FunctionType *NewType) {
48 Function *NewFunc = Function::Create(NewType, Func->getLinkage());
49 NewFunc->copyAttributesFrom(Func);
50 Func->getParent()->getFunctionList().insert(Func, NewFunc);
51 NewFunc->takeName(Func);
52 NewFunc->getBasicBlockList().splice(NewFunc->begin(),
53 Func->getBasicBlockList());
54 Func->replaceAllUsesWith(
55 ConstantExpr::getBitCast(NewFunc,
56 Func->getFunctionType()->getPointerTo()));
57 return NewFunc;
58 }
OLDNEW
« 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