| 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. |
| 11 // | 11 // |
| 12 // This pass replaces a varargs function call with a function call in | 12 // This pass replaces a varargs function call with a function call in |
| 13 // which a pointer to the variable arguments is passed explicitly. | 13 // which a pointer to the variable arguments is passed explicitly. |
| 14 // The callee explicitly allocates space for the variable arguments on | 14 // The callee explicitly allocates space for the variable arguments on |
| 15 // the stack using "alloca". | 15 // the stack using "alloca". |
| 16 // | 16 // |
| 17 // Alignment: | 17 // Alignment: |
| 18 // | 18 // |
| 19 // This pass does not add any alignment padding between the arguments | 19 // This pass does not add any alignment padding between the arguments |
| 20 // that are copied onto the stack. We assume that the only argument | 20 // that are copied onto the stack. This means that if the argument |
| 21 // types that need to be handled are 32-bit and 64-bit -- i32, i64, | 21 // list contains a mixture of, say, 1-byte and 4-byte values, the code |
| 22 // pointers and double: | 22 // generated by this pass might be inefficient due to the memory |
| 23 // accesses being unaligned. |
| 23 // | 24 // |
| 24 // * We won't see i1, i8, i16 and float as varargs arguments because | 25 // This should only be an issue when passing structs as varargs |
| 25 // the C standard requires the compiler to promote these to the | 26 // arguments. We won't see i1, i8, i16 and float as varargs arguments |
| 26 // types "int" and "double". | 27 // because the C standard requires the compiler to promote these to |
| 27 // | 28 // the types "int" and "double". |
| 28 // * We won't see va_arg instructions of struct type because Clang | |
| 29 // does not yet support them in PNaCl mode. See | |
| 30 // https://code.google.com/p/nativeclient/issues/detail?id=2381 | |
| 31 // | |
| 32 // If such arguments do appear in the input, this pass will generate | |
| 33 // correct, working code, but this code might be inefficient due to | |
| 34 // using unaligned memory accesses. | |
| 35 // | 29 // |
| 36 //===----------------------------------------------------------------------===// | 30 //===----------------------------------------------------------------------===// |
| 37 | 31 |
| 38 #include "llvm/ADT/SmallVector.h" | 32 #include "llvm/ADT/SmallVector.h" |
| 39 #include "llvm/IR/DataLayout.h" | 33 #include "llvm/IR/DataLayout.h" |
| 40 #include "llvm/IR/Function.h" | 34 #include "llvm/IR/Function.h" |
| 41 #include "llvm/IR/IRBuilder.h" | 35 #include "llvm/IR/IRBuilder.h" |
| 42 #include "llvm/IR/Instructions.h" | 36 #include "llvm/IR/Instructions.h" |
| 43 #include "llvm/IR/IntrinsicInst.h" | 37 #include "llvm/IR/IntrinsicInst.h" |
| 44 #include "llvm/IR/Module.h" | 38 #include "llvm/IR/Module.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 ExpandVarArgFunc(Func); | 323 ExpandVarArgFunc(Func); |
| 330 } | 324 } |
| 331 } | 325 } |
| 332 | 326 |
| 333 return Changed; | 327 return Changed; |
| 334 } | 328 } |
| 335 | 329 |
| 336 ModulePass *llvm::createExpandVarArgsPass() { | 330 ModulePass *llvm::createExpandVarArgsPass() { |
| 337 return new ExpandVarArgs(); | 331 return new ExpandVarArgs(); |
| 338 } | 332 } |
| OLD | NEW |