2002-01-22 00:13:51 +00:00
|
|
|
//===- llvm/Transforms/ChangeAllocations.h -----------------------*- C++ -*--=//
|
2001-10-15 17:31:51 +00:00
|
|
|
//
|
2002-01-22 00:13:51 +00:00
|
|
|
// This file defines two passes that convert malloc and free instructions to
|
|
|
|
// calls to and from %malloc & %free function calls. The LowerAllocations
|
|
|
|
// transformation is a target dependant tranformation because it depends on the
|
|
|
|
// size of data types and alignment constraints.
|
2001-10-15 17:31:51 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-01-22 00:13:51 +00:00
|
|
|
#ifndef LLVM_TRANSFORMS_CHANGEALLOCATIONS_H
|
|
|
|
#define LLVM_TRANSFORMS_CHANGEALLOCATIONS_H
|
2001-10-15 17:31:51 +00:00
|
|
|
|
2001-10-18 20:19:09 +00:00
|
|
|
#include "llvm/Pass.h"
|
2001-10-15 17:31:51 +00:00
|
|
|
class TargetData;
|
|
|
|
|
2002-01-22 00:13:51 +00:00
|
|
|
// LowerAllocations - Turn malloc and free instructions into %malloc and %free
|
|
|
|
// calls.
|
|
|
|
//
|
2002-01-21 23:34:02 +00:00
|
|
|
class LowerAllocations : public BasicBlockPass {
|
2001-10-15 17:31:51 +00:00
|
|
|
Method *MallocMeth; // Methods in the module we are processing
|
2002-01-22 00:13:51 +00:00
|
|
|
Method *FreeMeth; // Initialized by doInitialization
|
2001-10-15 17:31:51 +00:00
|
|
|
|
|
|
|
const TargetData &DataLayout;
|
|
|
|
public:
|
|
|
|
inline LowerAllocations(const TargetData &TD) : DataLayout(TD) {
|
|
|
|
MallocMeth = FreeMeth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// doPassInitialization - For the lower allocations pass, this ensures that a
|
|
|
|
// module contains a declaration for a malloc and a free function.
|
|
|
|
//
|
2002-01-21 07:31:50 +00:00
|
|
|
bool doInitialization(Module *M);
|
2001-10-15 17:31:51 +00:00
|
|
|
|
2002-01-21 23:34:02 +00:00
|
|
|
// runOnBasicBlock - This method does the actual work of converting
|
2001-10-15 17:31:51 +00:00
|
|
|
// instructions over, assuming that the pass has already been initialized.
|
|
|
|
//
|
2002-01-21 23:34:02 +00:00
|
|
|
bool runOnBasicBlock(BasicBlock *BB);
|
2001-10-15 17:31:51 +00:00
|
|
|
};
|
|
|
|
|
2002-01-22 00:13:51 +00:00
|
|
|
// RaiseAllocations - Turn %malloc and %free calls into the appropriate
|
|
|
|
// instruction.
|
|
|
|
//
|
|
|
|
class RaiseAllocations : public BasicBlockPass {
|
|
|
|
Method *MallocMeth; // Methods in the module we are processing
|
|
|
|
Method *FreeMeth; // Initialized by doPassInitializationVirt
|
|
|
|
public:
|
|
|
|
inline RaiseAllocations() : MallocMeth(0), FreeMeth(0) {}
|
|
|
|
|
|
|
|
// doPassInitialization - For the raise allocations pass, this finds a
|
|
|
|
// declaration for malloc and free if they exist.
|
|
|
|
//
|
|
|
|
bool doInitialization(Module *M);
|
|
|
|
|
|
|
|
// runOnBasicBlock - This method does the actual work of converting
|
|
|
|
// instructions over, assuming that the pass has already been initialized.
|
|
|
|
//
|
|
|
|
bool runOnBasicBlock(BasicBlock *BB);
|
|
|
|
};
|
|
|
|
|
2001-10-15 17:31:51 +00:00
|
|
|
#endif
|