1 //===- llvm/Analysis/MemoryBuiltins.h- Calls to memory builtins -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This family of functions identifies calls to builtin functions that allocate
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H
16 #define LLVM_ANALYSIS_MEMORYBUILTINS_H
26 //===----------------------------------------------------------------------===//
27 // malloc Call Utility Functions.
30 /// isMalloc - Returns true if the value is either a malloc call or a bitcast of
31 /// the result of a malloc call
32 bool isMalloc(const Value* I);
34 /// extractMallocCall - Returns the corresponding CallInst if the instruction
35 /// is a malloc call. Since CallInst::CreateMalloc() only creates calls, we
36 /// ignore InvokeInst here.
37 const CallInst* extractMallocCall(const Value* I);
38 CallInst* extractMallocCall(Value* I);
40 /// extractMallocCallFromBitCast - Returns the corresponding CallInst if the
41 /// instruction is a bitcast of the result of a malloc call.
42 const CallInst* extractMallocCallFromBitCast(const Value* I);
43 CallInst* extractMallocCallFromBitCast(Value* I);
45 /// isArrayMalloc - Returns the corresponding CallInst if the instruction
46 /// is a call to malloc whose array size can be determined and the array size
47 /// is not constant 1. Otherwise, return NULL.
48 CallInst* isArrayMalloc(Value* I, LLVMContext &Context, const TargetData* TD);
49 const CallInst* isArrayMalloc(const Value* I, LLVMContext &Context,
50 const TargetData* TD);
52 /// getMallocType - Returns the PointerType resulting from the malloc call.
53 /// The PointerType depends on the number of bitcast uses of the malloc call:
54 /// 0: PointerType is the malloc calls' return type.
55 /// 1: PointerType is the bitcast's result type.
56 /// >1: Unique PointerType cannot be determined, return NULL.
57 const PointerType* getMallocType(const CallInst* CI);
59 /// getMallocAllocatedType - Returns the Type allocated by malloc call.
60 /// The Type depends on the number of bitcast uses of the malloc call:
61 /// 0: PointerType is the malloc calls' return type.
62 /// 1: PointerType is the bitcast's result type.
63 /// >1: Unique PointerType cannot be determined, return NULL.
64 const Type* getMallocAllocatedType(const CallInst* CI);
66 /// getMallocArraySize - Returns the array size of a malloc call. If the
67 /// argument passed to malloc is a multiple of the size of the malloced type,
68 /// then return that multiple. For non-array mallocs, the multiple is
69 /// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
71 Value* getMallocArraySize(CallInst* CI, LLVMContext &Context,
72 const TargetData* TD);
74 //===----------------------------------------------------------------------===//
75 // free Call Utility Functions.
78 /// isFreeCall - Returns true if the the value is a call to the builtin free()
79 bool isFreeCall(const Value* I);
81 } // End llvm namespace