MemoryBuiltins.h revision 90f48e7c91a8faa875ba889ca66b137ffd46e34a
1//===- llvm/Analysis/MemoryBuiltins.h- Calls to memory builtins -*- 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// This family of functions identifies calls to builtin functions that allocate 11// or free memory. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H 16#define LLVM_ANALYSIS_MEMORYBUILTINS_H 17 18namespace llvm { 19class CallInst; 20class LLVMContext; 21class PointerType; 22class TargetData; 23class Type; 24class Value; 25 26//===----------------------------------------------------------------------===// 27// malloc Call Utility Functions. 28// 29 30/// isMalloc - Returns true if the value is either a malloc call or a bitcast of 31/// the result of a malloc call 32bool isMalloc(const Value* I); 33 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. 37const CallInst* extractMallocCall(const Value* I); 38CallInst* extractMallocCall(Value* I); 39 40/// extractMallocCallFromBitCast - Returns the corresponding CallInst if the 41/// instruction is a bitcast of the result of a malloc call. 42const CallInst* extractMallocCallFromBitCast(const Value* I); 43CallInst* extractMallocCallFromBitCast(Value* I); 44 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. 48CallInst* isArrayMalloc(Value* I, LLVMContext &Context, const TargetData* TD); 49const CallInst* isArrayMalloc(const Value* I, LLVMContext &Context, 50 const TargetData* TD); 51 52/// getMallocType - Returns the PointerType resulting from the malloc call. 53/// This PointerType is the result type of the call's only bitcast use. 54/// If there is no unique bitcast use, then return NULL. 55const PointerType* getMallocType(const CallInst* CI); 56 57/// getMallocAllocatedType - Returns the Type allocated by malloc call. This 58/// Type is the result type of the call's only bitcast use. If there is no 59/// unique bitcast use, then return NULL. 60const Type* getMallocAllocatedType(const CallInst* CI); 61 62/// getMallocArraySize - Returns the array size of a malloc call. If the 63/// argument passed to malloc is a multiple of the size of the malloced type, 64/// then return that multiple. For non-array mallocs, the multiple is 65/// constant 1. Otherwise, return NULL for mallocs whose array size cannot be 66/// determined. 67Value* getMallocArraySize(CallInst* CI, LLVMContext &Context, 68 const TargetData* TD); 69 70//===----------------------------------------------------------------------===// 71// free Call Utility Functions. 72// 73 74/// isFreeCall - Returns true if the the value is a call to the builtin free() 75bool isFreeCall(const Value* I); 76 77} // End llvm namespace 78 79#endif 80