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

Side by Side Diff: lib/Transforms/NaCl/GlobalizeConstantVectors.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 //===- GlobalizeConstantVectors.cpp - Globalize constant vector -----------===// 1 //===- GlobalizeConstantVectors.cpp - Globalize constant vector -----------===//
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 replaces all constant vector operands by loads of the same 10 // This pass replaces all constant vector operands by loads of the same
(...skipping 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 // Must be a ModulePass since it adds globals. 34 // Must be a ModulePass since it adds globals.
35 class GlobalizeConstantVectors : public ModulePass { 35 class GlobalizeConstantVectors : public ModulePass {
36 public: 36 public:
37 static char ID; // Pass identification, replacement for typeid 37 static char ID; // Pass identification, replacement for typeid
38 GlobalizeConstantVectors() : ModulePass(ID), DL(0) { 38 GlobalizeConstantVectors() : ModulePass(ID), DL(0) {
39 initializeGlobalizeConstantVectorsPass(*PassRegistry::getPassRegistry()); 39 initializeGlobalizeConstantVectorsPass(*PassRegistry::getPassRegistry());
40 } 40 }
41 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 41 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
42 AU.setPreservesCFG(); 42 AU.setPreservesCFG();
43 AU.addRequired<DataLayoutPass>();
44 } 43 }
45 virtual bool runOnModule(Module &M); 44 virtual bool runOnModule(Module &M);
46 45
47 private: 46 private:
48 typedef SmallPtrSet<Constant *, 64> Constants; 47 typedef SmallPtrSet<Constant *, 64> Constants;
49 typedef std::pair<Function *, Constants> FunctionConstants; 48 typedef std::pair<Function *, Constants> FunctionConstants;
50 typedef std::vector<FunctionConstants> FunctionConstantList; 49 typedef std::vector<FunctionConstants> FunctionConstantList;
51 typedef DenseMap<Constant *, GlobalVariable *> GlobalizedConstants; 50 typedef DenseMap<Constant *, GlobalVariable *> GlobalizedConstants;
52 const DataLayout *DL; 51 const DataLayout *DL;
53 52
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 ++OI) 143 ++OI)
145 if (dyn_cast<Constant>(*OI) == C) 144 if (dyn_cast<Constant>(*OI) == C)
146 // The current operand is a use of the constant vector, replace it 145 // The current operand is a use of the constant vector, replace it
147 // with the materialized one. 146 // with the materialized one.
148 *OI = MaterializedGV; 147 *OI = MaterializedGV;
149 } 148 }
150 } 149 }
151 } 150 }
152 151
153 bool GlobalizeConstantVectors::runOnModule(Module &M) { 152 bool GlobalizeConstantVectors::runOnModule(Module &M) {
154 DL = &getAnalysis<DataLayoutPass>().getDataLayout(); 153 DL = &M.getDataLayout();
155 154
156 FunctionConstantList FCs; 155 FunctionConstantList FCs;
157 FCs.reserve(M.size()); 156 FCs.reserve(M.size());
158 for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) { 157 for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {
159 Constants Cs; 158 Constants Cs;
160 findConstantVectors(*FI, Cs); 159 findConstantVectors(*FI, Cs);
161 if (!Cs.empty()) 160 if (!Cs.empty())
162 FCs.push_back(std::make_pair(&*FI, Cs)); 161 FCs.push_back(std::make_pair(&*FI, Cs));
163 } 162 }
164 163
165 GlobalizedConstants GCs; 164 GlobalizedConstants GCs;
166 createGlobalConstantVectors(M, FCs, GCs); 165 createGlobalConstantVectors(M, FCs, GCs);
167 166
168 for (FunctionConstantList::const_iterator FCI = FCs.begin(), FCE = FCs.end(); 167 for (FunctionConstantList::const_iterator FCI = FCs.begin(), FCE = FCs.end();
169 FCI != FCE; ++FCI) 168 FCI != FCE; ++FCI)
170 materializeConstantVectors(*FCI->first, FCI->second, GCs); 169 materializeConstantVectors(*FCI->first, FCI->second, GCs);
171 170
172 return FCs.empty(); 171 return FCs.empty();
173 } 172 }
174 173
175 ModulePass *llvm::createGlobalizeConstantVectorsPass() { 174 ModulePass *llvm::createGlobalizeConstantVectorsPass() {
176 return new GlobalizeConstantVectors(); 175 return new GlobalizeConstantVectors();
177 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698