OLD | NEW |
1 //===- BackendCanonicalize.cpp --------------------------------------------===// | 1 //===- BackendCanonicalize.cpp --------------------------------------------===// |
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 // Clean up some toolchain-side PNaCl ABI simplification passes. These passes | 10 // Clean up some toolchain-side PNaCl ABI simplification passes. These passes |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "llvm/Analysis/ConstantFolding.h" | 30 #include "llvm/Analysis/ConstantFolding.h" |
31 #include "llvm/IR/BasicBlock.h" | 31 #include "llvm/IR/BasicBlock.h" |
32 #include "llvm/IR/DataLayout.h" | 32 #include "llvm/IR/DataLayout.h" |
33 #include "llvm/IR/IRBuilder.h" | 33 #include "llvm/IR/IRBuilder.h" |
34 #include "llvm/IR/Instruction.h" | 34 #include "llvm/IR/Instruction.h" |
35 #include "llvm/IR/Instructions.h" | 35 #include "llvm/IR/Instructions.h" |
36 #include "llvm/IR/Operator.h" | 36 #include "llvm/IR/Operator.h" |
37 #include "llvm/IR/InstVisitor.h" | 37 #include "llvm/IR/InstVisitor.h" |
38 #include "llvm/Pass.h" | 38 #include "llvm/Pass.h" |
39 #include "llvm/Target/TargetLibraryInfo.h" | 39 #include "llvm/Analysis/TargetLibraryInfo.h" |
40 #include "llvm/Transforms/NaCl.h" | 40 #include "llvm/Transforms/NaCl.h" |
41 #include "llvm/Transforms/Utils/Local.h" | 41 #include "llvm/Transforms/Utils/Local.h" |
42 | 42 |
43 using namespace llvm; | 43 using namespace llvm; |
44 | 44 |
45 // ============================================================================= | 45 // ============================================================================= |
46 // TODO(jfb) The following functions are as-is from instcombine. Make them | 46 // TODO(jfb) The following functions are as-is from instcombine. Make them |
47 // reusable instead. | 47 // reusable instead. |
48 | 48 |
49 /// CollectSingleShuffleElements - If V is a shuffle of values that ONLY returns | 49 /// CollectSingleShuffleElements - If V is a shuffle of values that ONLY returns |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 namespace { | 218 namespace { |
219 | 219 |
220 class BackendCanonicalize : public FunctionPass, | 220 class BackendCanonicalize : public FunctionPass, |
221 public InstVisitor<BackendCanonicalize, bool> { | 221 public InstVisitor<BackendCanonicalize, bool> { |
222 public: | 222 public: |
223 static char ID; // Pass identification, replacement for typeid | 223 static char ID; // Pass identification, replacement for typeid |
224 BackendCanonicalize() : FunctionPass(ID), DL(0), TLI(0) { | 224 BackendCanonicalize() : FunctionPass(ID), DL(0), TLI(0) { |
225 initializeBackendCanonicalizePass(*PassRegistry::getPassRegistry()); | 225 initializeBackendCanonicalizePass(*PassRegistry::getPassRegistry()); |
226 } | 226 } |
227 virtual void getAnalysisUsage(AnalysisUsage &AU) const { | 227 virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
228 AU.addRequired<DataLayoutPass>(); | 228 AU.addRequired<TargetLibraryInfoWrapperPass>(); |
229 AU.addRequired<TargetLibraryInfo>(); | |
230 FunctionPass::getAnalysisUsage(AU); | 229 FunctionPass::getAnalysisUsage(AU); |
231 } | 230 } |
232 | 231 |
233 virtual bool runOnFunction(Function &F); | 232 virtual bool runOnFunction(Function &F); |
234 | 233 |
235 // InstVisitor implementation. Unhandled instructions stay as-is. | 234 // InstVisitor implementation. Unhandled instructions stay as-is. |
236 bool visitInstruction(Instruction &I) { return false; } | 235 bool visitInstruction(Instruction &I) { return false; } |
237 bool visitInsertElementInst(InsertElementInst &IE); | 236 bool visitInsertElementInst(InsertElementInst &IE); |
238 bool visitBitCastInst(BitCastInst &C); | 237 bool visitBitCastInst(BitCastInst &C); |
239 bool visitLoadInst(LoadInst &L); | 238 bool visitLoadInst(LoadInst &L); |
(...skipping 15 matching lines...) Expand all Loading... |
255 }; | 254 }; |
256 | 255 |
257 } // anonymous namespace | 256 } // anonymous namespace |
258 | 257 |
259 char BackendCanonicalize::ID = 0; | 258 char BackendCanonicalize::ID = 0; |
260 INITIALIZE_PASS(BackendCanonicalize, "backend-canonicalize", | 259 INITIALIZE_PASS(BackendCanonicalize, "backend-canonicalize", |
261 "Canonicalize PNaCl bitcode for LLVM backends", false, false) | 260 "Canonicalize PNaCl bitcode for LLVM backends", false, false) |
262 | 261 |
263 bool BackendCanonicalize::runOnFunction(Function &F) { | 262 bool BackendCanonicalize::runOnFunction(Function &F) { |
264 bool Modified = false; | 263 bool Modified = false; |
265 DL = &getAnalysis<DataLayoutPass>().getDataLayout(); | 264 DL = &F.getParent()->getDataLayout(); |
266 TLI = &getAnalysis<TargetLibraryInfo>(); | 265 TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); |
267 | 266 |
268 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) | 267 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) |
269 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) | 268 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) |
270 Modified |= visit(&*BI); | 269 Modified |= visit(&*BI); |
271 emptyKillList(Kill); | 270 emptyKillList(Kill); |
272 return Modified; | 271 return Modified; |
273 } | 272 } |
274 | 273 |
275 // This function is *almost* as-is from instcombine, avoiding silly | 274 // This function is *almost* as-is from instcombine, avoiding silly |
276 // cases that should already have been optimized. | 275 // cases that should already have been optimized. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 335 |
337 bool BackendCanonicalize::visitBitCastInst(BitCastInst &B) { | 336 bool BackendCanonicalize::visitBitCastInst(BitCastInst &B) { |
338 return visitConstantFoldableInstruction(&B); | 337 return visitConstantFoldableInstruction(&B); |
339 } | 338 } |
340 | 339 |
341 bool BackendCanonicalize::visitLoadInst(LoadInst &L) { | 340 bool BackendCanonicalize::visitLoadInst(LoadInst &L) { |
342 return visitConstantFoldableInstruction(&L); | 341 return visitConstantFoldableInstruction(&L); |
343 } | 342 } |
344 | 343 |
345 bool BackendCanonicalize::visitConstantFoldableInstruction(Instruction *I) { | 344 bool BackendCanonicalize::visitConstantFoldableInstruction(Instruction *I) { |
346 if (Constant *Folded = ConstantFoldInstruction(I, DL, TLI)) { | 345 if (Constant *Folded = ConstantFoldInstruction(I, *DL, TLI)) { |
347 I->replaceAllUsesWith(Folded); | 346 I->replaceAllUsesWith(Folded); |
348 Kill.push_back(I); | 347 Kill.push_back(I); |
349 return true; | 348 return true; |
350 } | 349 } |
351 return false; | 350 return false; |
352 } | 351 } |
353 | 352 |
354 void BackendCanonicalize::emptyKillList(KillList &Kill) { | 353 void BackendCanonicalize::emptyKillList(KillList &Kill) { |
355 while (!Kill.empty()) | 354 while (!Kill.empty()) |
356 RecursivelyDeleteTriviallyDeadInstructions(Kill.pop_back_val()); | 355 RecursivelyDeleteTriviallyDeadInstructions(Kill.pop_back_val()); |
357 } | 356 } |
358 | 357 |
359 FunctionPass *llvm::createBackendCanonicalizePass() { | 358 FunctionPass *llvm::createBackendCanonicalizePass() { |
360 return new BackendCanonicalize(); | 359 return new BackendCanonicalize(); |
361 } | 360 } |
OLD | NEW |