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

Side by Side Diff: lib/Transforms/NaCl/FixVectorLoadStoreAlignment.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 //===- FixVectorLoadStoreAlignment.cpp - Vector load/store alignment ------===// 1 //===- FixVectorLoadStoreAlignment.cpp - Vector load/store alignment ------===//
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 // Fix vector load/store alignment by: 10 // Fix vector load/store alignment by:
(...skipping 12 matching lines...) Expand all
23 //===----------------------------------------------------------------------===// 23 //===----------------------------------------------------------------------===//
24 24
25 #include "llvm/IR/DataLayout.h" 25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/IRBuilder.h" 26 #include "llvm/IR/IRBuilder.h"
27 #include "llvm/IR/Instruction.h" 27 #include "llvm/IR/Instruction.h"
28 #include "llvm/IR/Instructions.h" 28 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/Module.h" 29 #include "llvm/IR/Module.h"
30 #include "llvm/Pass.h" 30 #include "llvm/Pass.h"
31 #include "llvm/Support/Debug.h" 31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/MathExtras.h" 32 #include "llvm/Support/MathExtras.h"
33 #include "llvm/Support/raw_ostream.h"
33 #include "llvm/Transforms/NaCl.h" 34 #include "llvm/Transforms/NaCl.h"
34 35
35 using namespace llvm; 36 using namespace llvm;
36 37
37 namespace { 38 namespace {
38 class FixVectorLoadStoreAlignment : public BasicBlockPass { 39 class FixVectorLoadStoreAlignment : public BasicBlockPass {
39 public: 40 public:
40 static char ID; // Pass identification, replacement for typeid 41 static char ID; // Pass identification, replacement for typeid
41 FixVectorLoadStoreAlignment() : BasicBlockPass(ID), M(0), DL(0) { 42 FixVectorLoadStoreAlignment() : BasicBlockPass(ID), M(0), DL(0) {
42 initializeFixVectorLoadStoreAlignmentPass(*PassRegistry::getPassRegistry()); 43 initializeFixVectorLoadStoreAlignmentPass(*PassRegistry::getPassRegistry());
43 } 44 }
44 void getAnalysisUsage(AnalysisUsage &AU) const override {
45 AU.addRequired<DataLayoutPass>();
46 BasicBlockPass::getAnalysisUsage(AU);
47 }
48 using BasicBlockPass::doInitialization; 45 using BasicBlockPass::doInitialization;
49 bool doInitialization(Module &Mod) override { 46 bool doInitialization(Module &Mod) override {
50 M = &Mod; 47 M = &Mod;
51 return false; // Unchanged. 48 return false; // Unchanged.
52 } 49 }
53 bool runOnBasicBlock(BasicBlock &BB) override; 50 bool runOnBasicBlock(BasicBlock &BB) override;
54 51
55 private: 52 private:
56 typedef SmallVector<Instruction *, 8> Instructions; 53 typedef SmallVector<Instruction *, 8> Instructions;
57 const Module *M; 54 const Module *M;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 193
197 // Fill in the vector element by element. 194 // Fill in the vector element by element.
198 IRBuilder<> IRB(VecLoad); 195 IRBuilder<> IRB(VecLoad);
199 Value *Loaded = UndefValue::get(LoadedVecTy); 196 Value *Loaded = UndefValue::get(LoadedVecTy);
200 Value *Base = 197 Value *Base =
201 IRB.CreateBitCast(VecLoad->getPointerOperand(), ElemTy->getPointerTo()); 198 IRB.CreateBitCast(VecLoad->getPointerOperand(), ElemTy->getPointerTo());
202 199
203 for (unsigned Elem = 0, NumElems = LoadedVecTy->getNumElements(); 200 for (unsigned Elem = 0, NumElems = LoadedVecTy->getNumElements();
204 Elem != NumElems; ++Elem) { 201 Elem != NumElems; ++Elem) {
205 unsigned Align = MinAlign(BaseAlign, ElemAllocSize * Elem); 202 unsigned Align = MinAlign(BaseAlign, ElemAllocSize * Elem);
206 Value *GEP = IRB.CreateConstInBoundsGEP1_32(Base, Elem); 203 Value *GEP = IRB.CreateConstInBoundsGEP1_32(ElemTy, Base, Elem);
207 LoadInst *LoadedElem = 204 LoadInst *LoadedElem =
208 IRB.CreateAlignedLoad(GEP, Align, VecLoad->isVolatile()); 205 IRB.CreateAlignedLoad(GEP, Align, VecLoad->isVolatile());
209 LoadedElem->setSynchScope(VecLoad->getSynchScope()); 206 LoadedElem->setSynchScope(VecLoad->getSynchScope());
210 Loaded = IRB.CreateInsertElement( 207 Loaded = IRB.CreateInsertElement(
211 Loaded, LoadedElem, 208 Loaded, LoadedElem,
212 ConstantInt::get(Type::getInt32Ty(M->getContext()), Elem)); 209 ConstantInt::get(Type::getInt32Ty(M->getContext()), Elem));
213 } 210 }
214 211
215 VecLoad->replaceAllUsesWith(Loaded); 212 VecLoad->replaceAllUsesWith(Loaded);
216 VecLoad->eraseFromParent(); 213 VecLoad->eraseFromParent();
(...skipping 12 matching lines...) Expand all
229 unsigned ElemAllocSize = DL->getTypeAllocSize(ElemTy); 226 unsigned ElemAllocSize = DL->getTypeAllocSize(ElemTy);
230 227
231 // Fill in the vector element by element. 228 // Fill in the vector element by element.
232 IRBuilder<> IRB(VecStore); 229 IRBuilder<> IRB(VecStore);
233 Value *Base = IRB.CreateBitCast(VecStore->getPointerOperand(), 230 Value *Base = IRB.CreateBitCast(VecStore->getPointerOperand(),
234 ElemTy->getPointerTo()); 231 ElemTy->getPointerTo());
235 232
236 for (unsigned Elem = 0, NumElems = StoredVecTy->getNumElements(); 233 for (unsigned Elem = 0, NumElems = StoredVecTy->getNumElements();
237 Elem != NumElems; ++Elem) { 234 Elem != NumElems; ++Elem) {
238 unsigned Align = MinAlign(BaseAlign, ElemAllocSize * Elem); 235 unsigned Align = MinAlign(BaseAlign, ElemAllocSize * Elem);
239 Value *GEP = IRB.CreateConstInBoundsGEP1_32(Base, Elem); 236 Value *GEP = IRB.CreateConstInBoundsGEP1_32(ElemTy, Base, Elem);
240 Value *ElemToStore = IRB.CreateExtractElement( 237 Value *ElemToStore = IRB.CreateExtractElement(
241 StoredVec, ConstantInt::get(Type::getInt32Ty(M->getContext()), Elem)); 238 StoredVec, ConstantInt::get(Type::getInt32Ty(M->getContext()), Elem));
242 StoreInst *StoredElem = IRB.CreateAlignedStore(ElemToStore, GEP, Align, 239 StoreInst *StoredElem = IRB.CreateAlignedStore(ElemToStore, GEP, Align,
243 VecStore->isVolatile()); 240 VecStore->isVolatile());
244 StoredElem->setSynchScope(VecStore->getSynchScope()); 241 StoredElem->setSynchScope(VecStore->getSynchScope());
245 } 242 }
246 243
247 VecStore->eraseFromParent(); 244 VecStore->eraseFromParent();
248 } 245 }
249 } 246 }
250 247
251 bool FixVectorLoadStoreAlignment::runOnBasicBlock(BasicBlock &BB) { 248 bool FixVectorLoadStoreAlignment::runOnBasicBlock(BasicBlock &BB) {
252 bool Changed = false; 249 bool Changed = false;
253 if (!DL) 250 if (!DL)
254 DL = &getAnalysis<DataLayoutPass>().getDataLayout(); 251 DL = &BB.getParent()->getParent()->getDataLayout();
jvoung (off chromium) 2015/05/26 20:39:45 could be getModule()
Derek Schuff 2015/05/26 22:01:32 Done.
255 Instructions Loads; 252 Instructions Loads;
256 Instructions Stores; 253 Instructions Stores;
257 visitVectorLoadStore(BB, Loads, Stores); 254 visitVectorLoadStore(BB, Loads, Stores);
258 if (!(Loads.empty() && Stores.empty())) { 255 if (!(Loads.empty() && Stores.empty())) {
259 Changed = true; 256 Changed = true;
260 scalarizeVectorLoadStore(BB, Loads, Stores); 257 scalarizeVectorLoadStore(BB, Loads, Stores);
261 } 258 }
262 return Changed; 259 return Changed;
263 } 260 }
264 261
265 BasicBlockPass *llvm::createFixVectorLoadStoreAlignmentPass() { 262 BasicBlockPass *llvm::createFixVectorLoadStoreAlignmentPass() {
266 return new FixVectorLoadStoreAlignment(); 263 return new FixVectorLoadStoreAlignment();
267 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698