LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NVPTXAllocaHoisting.cpp
Go to the documentation of this file.
1 //===-- AllocaHoisting.cpp - Hoist allocas to the entry block --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Hoist the alloca instructions in the non-entry blocks to the entry blocks.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "NVPTXAllocaHoisting.h"
15 #include "llvm/IR/Constants.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Instructions.h"
18 
19 namespace llvm {
20 
22  bool functionModified = false;
23  Function::iterator I = function.begin();
24  TerminatorInst *firstTerminatorInst = (I++)->getTerminator();
25 
26  for (Function::iterator E = function.end(); I != E; ++I) {
27  for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
28  AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
29  if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
30  allocaInst->moveBefore(firstTerminatorInst);
31  functionModified = true;
32  }
33  }
34  }
35 
36  return functionModified;
37 }
38 
41 X("alloca-hoisting", "Hoisting alloca instructions in non-entry "
42  "blocks to the entry block");
43 
45 
46 } // end namespace llvm
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:181
virtual bool runOnFunction(Function &function)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
FunctionPass * createAllocaHoisting()
#define I(x, y, z)
Definition: MD5.cpp:54
const Value * getArraySize() const
Definition: Instructions.h:86
void moveBefore(Instruction *MovePos)
Definition: Instruction.cpp:91
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")