add a long-overdue AllocaInst::isStaticAlloca method.
authorChris Lattner <sabre@nondot.org>
Wed, 26 Nov 2008 02:54:17 +0000 (02:54 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 26 Nov 2008 02:54:17 +0000 (02:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60080 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index 6ee18313a221969afe8cc1726eb16b55e0847df6..bc4abc9797bf90c404a2316826e06d13616e644a 100644 (file)
@@ -167,6 +167,11 @@ public:
     : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
 
   virtual AllocaInst *clone() const;
+  
+  /// isStaticAlloca - Return true if this alloca is in the entry block of the
+  /// function and is a constant size.  If so, the code generator will fold it
+  /// into the prolog/epilog code, so it is basically free.
+  bool isStaticAlloca() const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const AllocaInst *) { return true; }
index 66caf5f9f0e58c067be68737da3072bd5553f877..5b271d6a31c354e63f3cdfcd02d9d24584e1589d 100644 (file)
@@ -732,6 +732,18 @@ AllocaInst::AllocaInst(const AllocaInst &AI)
                    Instruction::Alloca, AI.getAlignment()) {
 }
 
+/// isStaticAlloca - Return true if this alloca is in the entry block of the
+/// function and is a constant size.  If so, the code generator will fold it
+/// into the prolog/epilog code, so it is basically free.
+bool AllocaInst::isStaticAlloca() const {
+  // Must be constant size.
+  if (!isa<ConstantInt>(getArraySize())) return false;
+  
+  // Must be in the entry block.
+  const BasicBlock *Parent = getParent();
+  return Parent == &Parent->getParent()->front();
+}
+
 MallocInst::MallocInst(const MallocInst &MI)
   : AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0),
                    Instruction::Malloc, MI.getAlignment()) {