LLVM API Documentation
00001 //===-- AllocaHoisting.cpp - Hoist allocas to the entry block --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Hoist the alloca instructions in the non-entry blocks to the entry blocks. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "NVPTXAllocaHoisting.h" 00015 #include "llvm/IR/Constants.h" 00016 #include "llvm/IR/Function.h" 00017 #include "llvm/IR/Instructions.h" 00018 00019 namespace llvm { 00020 00021 bool NVPTXAllocaHoisting::runOnFunction(Function &function) { 00022 bool functionModified = false; 00023 Function::iterator I = function.begin(); 00024 TerminatorInst *firstTerminatorInst = (I++)->getTerminator(); 00025 00026 for (Function::iterator E = function.end(); I != E; ++I) { 00027 for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) { 00028 AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++); 00029 if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) { 00030 allocaInst->moveBefore(firstTerminatorInst); 00031 functionModified = true; 00032 } 00033 } 00034 } 00035 00036 return functionModified; 00037 } 00038 00039 char NVPTXAllocaHoisting::ID = 1; 00040 static RegisterPass<NVPTXAllocaHoisting> 00041 X("alloca-hoisting", "Hoisting alloca instructions in non-entry " 00042 "blocks to the entry block"); 00043 00044 FunctionPass *createAllocaHoisting() { return new NVPTXAllocaHoisting(); } 00045 00046 } // end namespace llvm