blob: 7b89cedf831f3d266e647bba6728769ec85da1d2 [file] [log] [blame]
Shih-wei Liao42b88c32012-08-16 01:18:46 -07001/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef BCC_ABC_EXPAND_VAARG_H
18#define BCC_ABC_EXPAND_VAARG_H
19
20#include "bcc/AndroidBitcode/ABCExpandVAArgPass.h"
21
22#include <llvm/Instructions.h>
23#include <llvm/Support/InstIterator.h>
24
25namespace bcc {
26
27char ABCExpandVAArgPass::ID = 0;
28
29bool ABCExpandVAArgPass::runOnFunction(llvm::Function &pFunc) {
30 bool changed = false;
31
32 mContext = &pFunc.getContext();
33
34 // process va_arg inst
35 for (llvm::inst_iterator inst = llvm::inst_begin(pFunc),
36 inst_end = llvm::inst_end(pFunc); inst != inst_end; inst++) {
37 if (inst->getOpcode() == llvm::Instruction::VAArg) {
38 llvm::Value *v = expandVAArg(&*inst);
39 inst->replaceAllUsesWith(v);
40 inst->eraseFromParent();
41 changed = true;
42 continue;
43 }
44 }
45 return changed;
46}
47
48} // end bcc namespace
49
50#endif // BCC_ABC_EXPAND_VAARG_H