2009-10-27 20:05:49 +00:00
|
|
|
//===- llvm/Analysis/MemoryBuiltins.h- Calls to memory builtins -*- C++ -*-===//
|
2009-09-10 04:36:43 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-10-27 20:05:49 +00:00
|
|
|
// This family of functions identifies calls to builtin functions that allocate
|
|
|
|
// or free memory.
|
2009-09-10 04:36:43 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-27 20:05:49 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H
|
|
|
|
#define LLVM_ANALYSIS_MEMORYBUILTINS_H
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class CallInst;
|
|
|
|
class PointerType;
|
2009-09-18 19:20:02 +00:00
|
|
|
class TargetData;
|
2009-09-10 04:36:43 +00:00
|
|
|
class Type;
|
|
|
|
class Value;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// malloc Call Utility Functions.
|
|
|
|
//
|
|
|
|
|
2009-10-24 04:23:03 +00:00
|
|
|
/// isMalloc - Returns true if the value is either a malloc call or a bitcast of
|
|
|
|
/// the result of a malloc call
|
2009-11-06 04:27:31 +00:00
|
|
|
bool isMalloc(const Value *I);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
/// extractMallocCall - Returns the corresponding CallInst if the instruction
|
|
|
|
/// is a malloc call. Since CallInst::CreateMalloc() only creates calls, we
|
|
|
|
/// ignore InvokeInst here.
|
2009-11-06 04:27:31 +00:00
|
|
|
const CallInst* extractMallocCall(const Value *I);
|
|
|
|
CallInst* extractMallocCall(Value *I);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
/// extractMallocCallFromBitCast - Returns the corresponding CallInst if the
|
|
|
|
/// instruction is a bitcast of the result of a malloc call.
|
2009-11-06 04:27:31 +00:00
|
|
|
const CallInst* extractMallocCallFromBitCast(const Value *I);
|
|
|
|
CallInst* extractMallocCallFromBitCast(Value *I);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
/// isArrayMalloc - Returns the corresponding CallInst if the instruction
|
2009-10-28 20:18:55 +00:00
|
|
|
/// is a call to malloc whose array size can be determined and the array size
|
|
|
|
/// is not constant 1. Otherwise, return NULL.
|
2009-11-06 04:27:31 +00:00
|
|
|
CallInst* isArrayMalloc(Value *I, const TargetData *TD);
|
|
|
|
const CallInst* isArrayMalloc(const Value *I,
|
|
|
|
const TargetData *TD);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
/// getMallocType - Returns the PointerType resulting from the malloc call.
|
2009-11-06 01:33:24 +00:00
|
|
|
/// This PointerType is the result type of the call's only bitcast use.
|
|
|
|
/// If there is no unique bitcast use, then return NULL.
|
2009-11-06 04:27:31 +00:00
|
|
|
const PointerType* getMallocType(const CallInst *CI);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
2009-11-06 01:33:24 +00:00
|
|
|
/// getMallocAllocatedType - Returns the Type allocated by malloc call. This
|
|
|
|
/// Type is the result type of the call's only bitcast use. If there is no
|
|
|
|
/// unique bitcast use, then return NULL.
|
2009-11-06 04:27:31 +00:00
|
|
|
const Type* getMallocAllocatedType(const CallInst *CI);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
2009-10-28 20:18:55 +00:00
|
|
|
/// getMallocArraySize - Returns the array size of a malloc call. If the
|
|
|
|
/// argument passed to malloc is a multiple of the size of the malloced type,
|
|
|
|
/// then return that multiple. For non-array mallocs, the multiple is
|
|
|
|
/// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
|
2009-10-15 20:14:52 +00:00
|
|
|
/// determined.
|
2009-11-06 04:27:31 +00:00
|
|
|
Value* getMallocArraySize(CallInst *CI, const TargetData *TD);
|
2009-10-24 04:23:03 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// free Call Utility Functions.
|
|
|
|
//
|
|
|
|
|
|
|
|
/// isFreeCall - Returns true if the the value is a call to the builtin free()
|
|
|
|
bool isFreeCall(const Value* I);
|
2009-09-10 04:36:43 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|