LLVM  6.0.0svn
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"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Instructions.h"
19 using namespace llvm;
20 
21 namespace {
22 // Hoisting the alloca instructions in the non-entry blocks to the entry
23 // block.
24 class NVPTXAllocaHoisting : public FunctionPass {
25 public:
26  static char ID; // Pass ID
27  NVPTXAllocaHoisting() : FunctionPass(ID) {}
28 
29  void getAnalysisUsage(AnalysisUsage &AU) const override {
31  }
32 
33  StringRef getPassName() const override {
34  return "NVPTX specific alloca hoisting";
35  }
36 
37  bool runOnFunction(Function &function) override;
38 };
39 } // namespace
40 
41 bool NVPTXAllocaHoisting::runOnFunction(Function &function) {
42  bool functionModified = false;
43  Function::iterator I = function.begin();
44  TerminatorInst *firstTerminatorInst = (I++)->getTerminator();
45 
46  for (Function::iterator E = function.end(); I != E; ++I) {
47  for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
48  AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
49  if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
50  allocaInst->moveBefore(firstTerminatorInst);
51  functionModified = true;
52  }
53  }
54  }
55 
56  return functionModified;
57 }
58 
60 
61 namespace llvm {
63 }
64 
66  NVPTXAllocaHoisting, "alloca-hoisting",
67  "Hoisting alloca instructions in non-entry blocks to the entry block",
68  false, false)
69 
70 FunctionPass *llvm::createAllocaHoisting() { return new NVPTXAllocaHoisting; }
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
FunctionPass * createAllocaHoisting()
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:54
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
void initializeNVPTXAllocaHoistingPass(PassRegistry &)
const Value * getArraySize() const
Get the number of elements allocated.
Definition: Instructions.h:93
Iterator for intrusive lists based on ilist_node.
INITIALIZE_PASS(NVPTXAllocaHoisting, "alloca-hoisting", "Hoisting alloca instructions in non-entry blocks to the entry block", false, false) FunctionPass *llvm
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:88
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
an instruction to allocate memory on the stack
Definition: Instructions.h:60