mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-30 19:55:11 +00:00
The function that does nothing but call malloc is noalias return.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62956 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1902a129a5
commit
9d4979123e
@ -44,11 +44,11 @@ static RegisterPass<IndMemRemPass>
|
|||||||
X("indmemrem","Indirect Malloc and Free Removal");
|
X("indmemrem","Indirect Malloc and Free Removal");
|
||||||
|
|
||||||
bool IndMemRemPass::runOnModule(Module &M) {
|
bool IndMemRemPass::runOnModule(Module &M) {
|
||||||
//in Theory, all direct calls of malloc and free should be promoted
|
// In theory, all direct calls of malloc and free should be promoted
|
||||||
//to intrinsics. Therefor, this goes through and finds where the
|
// to intrinsics. Therefore, this goes through and finds where the
|
||||||
//address of free or malloc are taken and replaces those with bounce
|
// address of free or malloc are taken and replaces those with bounce
|
||||||
//functions, ensuring that all malloc and free that might happen
|
// functions, ensuring that all malloc and free that might happen
|
||||||
//happen through intrinsics.
|
// happen through intrinsics.
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if (Function* F = M.getFunction("free")) {
|
if (Function* F = M.getFunction("free")) {
|
||||||
if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
|
if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
|
||||||
@ -69,6 +69,7 @@ bool IndMemRemPass::runOnModule(Module &M) {
|
|||||||
Function* FN = Function::Create(F->getFunctionType(),
|
Function* FN = Function::Create(F->getFunctionType(),
|
||||||
GlobalValue::LinkOnceLinkage,
|
GlobalValue::LinkOnceLinkage,
|
||||||
"malloc_llvm_bounce", &M);
|
"malloc_llvm_bounce", &M);
|
||||||
|
FN->setDoesNotAlias(0);
|
||||||
BasicBlock* bb = BasicBlock::Create("entry",FN);
|
BasicBlock* bb = BasicBlock::Create("entry",FN);
|
||||||
Instruction* c = CastInst::CreateIntegerCast(
|
Instruction* c = CastInst::CreateIntegerCast(
|
||||||
FN->arg_begin(), Type::Int32Ty, false, "c", bb);
|
FN->arg_begin(), Type::Int32Ty, false, "c", bb);
|
||||||
|
11
test/Transforms/IndMemRem/2009-01-24-Noalias.ll
Normal file
11
test/Transforms/IndMemRem/2009-01-24-Noalias.ll
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
; RUN: llvm-as < %s | opt -indmemrem | llvm-dis | grep bounce | grep noalias
|
||||||
|
|
||||||
|
declare i8* @malloc(i32)
|
||||||
|
|
||||||
|
@g = external global i8*
|
||||||
|
|
||||||
|
define void @test() {
|
||||||
|
%A = bitcast i8* (i32) * @malloc to i8*
|
||||||
|
store i8* %A, i8** @g
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user