OLD | NEW |
1 //===- ExpandVarArgs.cpp - Expand out variable argument function calls-----===// | 1 //===- ExpandVarArgs.cpp - Expand out variable argument function calls-----===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This pass expands out all use of variable argument functions. | 10 // This pass expands out all use of variable argument functions. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 // In order to change the function's arguments, we have to recreate | 81 // In order to change the function's arguments, we have to recreate |
82 // the function. | 82 // the function. |
83 Function *NewFunc = Function::Create(NFTy, Func->getLinkage()); | 83 Function *NewFunc = Function::Create(NFTy, Func->getLinkage()); |
84 NewFunc->copyAttributesFrom(Func); | 84 NewFunc->copyAttributesFrom(Func); |
85 Func->getParent()->getFunctionList().insert(Func, NewFunc); | 85 Func->getParent()->getFunctionList().insert(Func, NewFunc); |
86 NewFunc->takeName(Func); | 86 NewFunc->takeName(Func); |
87 NewFunc->getBasicBlockList().splice(NewFunc->begin(), | 87 NewFunc->getBasicBlockList().splice(NewFunc->begin(), |
88 Func->getBasicBlockList()); | 88 Func->getBasicBlockList()); |
89 | 89 |
| 90 // Declare the new argument as "noalias". |
| 91 NewFunc->setAttributes( |
| 92 Func->getAttributes().addAttribute( |
| 93 Func->getContext(), FTy->getNumParams() + 1, Attribute::NoAlias)); |
| 94 |
90 // Move the arguments across to the new function. | 95 // Move the arguments across to the new function. |
91 for (Function::arg_iterator Arg = Func->arg_begin(), E = Func->arg_end(), | 96 for (Function::arg_iterator Arg = Func->arg_begin(), E = Func->arg_end(), |
92 NewArg = NewFunc->arg_begin(); | 97 NewArg = NewFunc->arg_begin(); |
93 Arg != E; ++Arg, ++NewArg) { | 98 Arg != E; ++Arg, ++NewArg) { |
94 Arg->replaceAllUsesWith(NewArg); | 99 Arg->replaceAllUsesWith(NewArg); |
95 NewArg->takeName(Arg); | 100 NewArg->takeName(Arg); |
96 } | 101 } |
97 | 102 |
98 Func->replaceAllUsesWith( | 103 Func->replaceAllUsesWith( |
99 ConstantExpr::getBitCast(NewFunc, FTy->getPointerTo())); | 104 ConstantExpr::getBitCast(NewFunc, FTy->getPointerTo())); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 ExpandVarArgFunc(Func); | 335 ExpandVarArgFunc(Func); |
331 } | 336 } |
332 } | 337 } |
333 | 338 |
334 return Changed; | 339 return Changed; |
335 } | 340 } |
336 | 341 |
337 ModulePass *llvm::createExpandVarArgsPass() { | 342 ModulePass *llvm::createExpandVarArgsPass() { |
338 return new ExpandVarArgs(); | 343 return new ExpandVarArgs(); |
339 } | 344 } |
OLD | NEW |