mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-16 11:30:51 +00:00
9d0b704e3e
Here is the original commit message: This commit updates malloc optimizations to operate on malloc calls that have constant int size arguments. Update CreateMalloc so that its callers specify the size to allocate: MallocInst-autoupgrade users use non-TargetData-computed allocation sizes. Optimization uses use TargetData to compute the allocation size. Now that malloc calls can have constant sizes, update isArrayMallocHelper() to use TargetData to determine the size of the malloced type and the size of malloced arrays. Extend getMallocType() to support malloc calls that have non-bitcast uses. Update OptimizeGlobalAddressOfMalloc() to optimize malloc calls that have non-bitcast uses. The bitcast use of a malloc call has to be treated specially here because the uses of the bitcast need to be replaced and the bitcast needs to be erased (just like the malloc call) for OptimizeGlobalAddressOfMalloc() to work correctly. Update PerformHeapAllocSRoA() to optimize malloc calls that have non-bitcast uses. The bitcast use of the malloc is not handled specially here because ReplaceUsesOfMallocWithGlobal replaces through the bitcast use. Update OptimizeOnceStoredGlobal() to not care about the malloc calls' bitcast use. Update all globalopt malloc tests to not rely on autoupgraded-MallocInsts, but instead use explicit malloc calls with correct allocation sizes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86311 91177308-0d34-0410-b5e6-96231b3b80d8
82 lines
3.2 KiB
C++
82 lines
3.2 KiB
C++
//===- llvm/Analysis/MemoryBuiltins.h- Calls to memory builtins -*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This family of functions identifies calls to builtin functions that allocate
|
|
// or free memory.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H
|
|
#define LLVM_ANALYSIS_MEMORYBUILTINS_H
|
|
|
|
namespace llvm {
|
|
class CallInst;
|
|
class PointerType;
|
|
class TargetData;
|
|
class Type;
|
|
class Value;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// malloc Call Utility Functions.
|
|
//
|
|
|
|
/// isMalloc - Returns true if the value is either a malloc call or a bitcast of
|
|
/// the result of a malloc call
|
|
bool isMalloc(const Value *I);
|
|
|
|
/// extractMallocCall - Returns the corresponding CallInst if the instruction
|
|
/// is a malloc call. Since CallInst::CreateMalloc() only creates calls, we
|
|
/// ignore InvokeInst here.
|
|
const CallInst *extractMallocCall(const Value *I);
|
|
CallInst *extractMallocCall(Value *I);
|
|
|
|
/// extractMallocCallFromBitCast - Returns the corresponding CallInst if the
|
|
/// instruction is a bitcast of the result of a malloc call.
|
|
const CallInst *extractMallocCallFromBitCast(const Value *I);
|
|
CallInst *extractMallocCallFromBitCast(Value *I);
|
|
|
|
/// isArrayMalloc - Returns the corresponding CallInst if the instruction
|
|
/// is a call to malloc whose array size can be determined and the array size
|
|
/// is not constant 1. Otherwise, return NULL.
|
|
CallInst *isArrayMalloc(Value *I, const TargetData *TD);
|
|
const CallInst *isArrayMalloc(const Value *I,
|
|
const TargetData *TD);
|
|
|
|
/// getMallocType - Returns the PointerType resulting from the malloc call.
|
|
/// The PointerType depends on the number of bitcast uses of the malloc call:
|
|
/// 0: PointerType is the malloc calls' return type.
|
|
/// 1: PointerType is the bitcast's result type.
|
|
/// >1: Unique PointerType cannot be determined, return NULL.
|
|
const PointerType *getMallocType(const CallInst *CI);
|
|
|
|
/// getMallocAllocatedType - Returns the Type allocated by malloc call.
|
|
/// The Type depends on the number of bitcast uses of the malloc call:
|
|
/// 0: PointerType is the malloc calls' return type.
|
|
/// 1: PointerType is the bitcast's result type.
|
|
/// >1: Unique PointerType cannot be determined, return NULL.
|
|
const Type *getMallocAllocatedType(const CallInst *CI);
|
|
|
|
/// 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
|
|
/// determined.
|
|
Value *getMallocArraySize(CallInst *CI, const TargetData *TD);
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// free Call Utility Functions.
|
|
//
|
|
|
|
/// isFreeCall - Returns true if the the value is a call to the builtin free()
|
|
bool isFreeCall(const Value *I);
|
|
|
|
} // End llvm namespace
|
|
|
|
#endif
|