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

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

Issue 1151093004: Changes from 3.7 merge to files not in upstream (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Created 5 years, 7 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
1 //==- ExpandInsertExtractElement.cpp - Expand vector insert and extract -=// 1 //==- ExpandInsertExtractElement.cpp - Expand vector insert and extract -=//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===------------------------------------------------------------------===// 8 //===------------------------------------------------------------------===//
9 // 9 //
10 // This pass expands insertelement and extractelement instructions with 10 // This pass expands insertelement and extractelement instructions with
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Instruction *Entry = F.getEntryBlock().begin(); 61 Instruction *Entry = F.getEntryBlock().begin();
62 Type *Int32 = Type::getInt32Ty(F.getContext()); 62 Type *Int32 = Type::getInt32Ty(F.getContext());
63 Constant *Zero = ConstantInt::get(Int32, 0); 63 Constant *Zero = ConstantInt::get(Int32, 0);
64 for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ) { 64 for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ) {
65 Instruction *Inst = &*I++; 65 Instruction *Inst = &*I++;
66 66
67 if (InsertElementInst *III = dyn_cast<InsertElementInst>(Inst)) { 67 if (InsertElementInst *III = dyn_cast<InsertElementInst>(Inst)) {
68 if (isa<ConstantInt>(III->getOperand(2))) 68 if (isa<ConstantInt>(III->getOperand(2)))
69 continue; 69 continue;
70 70
71 Instruction *A = new AllocaInst(III->getType(), 0, "", Entry); 71 Type *AllocaTy = III->getType();
72 Instruction *A = new AllocaInst(AllocaTy, 0, "", Entry);
72 CopyDebug(new StoreInst(III->getOperand(0), A, III), III); 73 CopyDebug(new StoreInst(III->getOperand(0), A, III), III);
73 74
74 Value *Idxs[] = { Zero, III->getOperand(2) }; 75 Value *Idxs[] = { Zero, III->getOperand(2) };
75 Instruction *B = CopyDebug(GetElementPtrInst::Create(A, Idxs, "", III), II I); 76 Instruction *B = CopyDebug(
77 GetElementPtrInst::Create(AllocaTy, A, Idxs, "", III), III);
76 CopyDebug(new StoreInst(III->getOperand(1), B, III), III); 78 CopyDebug(new StoreInst(III->getOperand(1), B, III), III);
77 79
78 Instruction *L = CopyDebug(new LoadInst(A, "", III), III); 80 Instruction *L = CopyDebug(new LoadInst(A, "", III), III);
79 III->replaceAllUsesWith(L); 81 III->replaceAllUsesWith(L);
80 III->eraseFromParent(); 82 III->eraseFromParent();
81 } else if (ExtractElementInst *EII = dyn_cast<ExtractElementInst>(Inst)) { 83 } else if (ExtractElementInst *EII = dyn_cast<ExtractElementInst>(Inst)) {
82 if (isa<ConstantInt>(EII->getOperand(1))) 84 if (isa<ConstantInt>(EII->getOperand(1)))
83 continue; 85 continue;
84 86
85 Instruction *A = new AllocaInst(EII->getOperand(0)->getType(), 0, "", Entr y); 87 Type *AllocaTy = EII->getOperand(0)->getType();
88 Instruction *A = new AllocaInst(AllocaTy, 0, "", Entry);
86 CopyDebug(new StoreInst(EII->getOperand(0), A, EII), EII); 89 CopyDebug(new StoreInst(EII->getOperand(0), A, EII), EII);
87 90
88 Value *Idxs[] = { Zero, EII->getOperand(1) }; 91 Value *Idxs[] = { Zero, EII->getOperand(1) };
89 Instruction *B = CopyDebug(GetElementPtrInst::Create(A, Idxs, "", EII), EI I); 92 Instruction *B = CopyDebug(
93 GetElementPtrInst::Create(AllocaTy, A, Idxs, "", EII), EII);
90 Instruction *L = CopyDebug(new LoadInst(B, "", EII), EII); 94 Instruction *L = CopyDebug(new LoadInst(B, "", EII), EII);
91 EII->replaceAllUsesWith(L); 95 EII->replaceAllUsesWith(L);
92 EII->eraseFromParent(); 96 EII->eraseFromParent();
93 } 97 }
94 } 98 }
95 99
96 return Changed; 100 return Changed;
97 } 101 }
98 102
99 FunctionPass *llvm::createExpandInsertExtractElementPass() { 103 FunctionPass *llvm::createExpandInsertExtractElementPass() {
100 return new ExpandInsertExtractElement(); 104 return new ExpandInsertExtractElement();
101 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698