[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Thu Aug 5 11:57:06 PDT 2004
Changes in directory llvm-java/lib/Compiler:
Compiler.cpp updated: 1.77 -> 1.78
---
Log message:
Refactor function calling code into makeCall().
---
Diffs of the changes: (+20 -26)
Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.77 llvm-java/lib/Compiler/Compiler.cpp:1.78
--- llvm-java/lib/Compiler/Compiler.cpp:1.77 Thu Aug 5 13:22:43 2004
+++ llvm-java/lib/Compiler/Compiler.cpp Thu Aug 5 13:56:55 2004
@@ -909,6 +909,22 @@
new StoreInst(v, getField(bcI, index, p), getBBAt(bcI));
}
+ void makeCall(Value* fun, BasicBlock* bb) {
+ const PointerType* funPtrTy = cast<PointerType>(fun->getType());
+ const FunctionType* funTy = cast<FunctionType>(funPtrTy->getElementType());
+ std::vector<Value*> params(funTy->getNumParams(), NULL);
+ for (unsigned i = 0, e = funTy->getNumParams(); i != e; ++i) {
+ Value* p = opStack_.top(); opStack_.pop();
+ const Type* paramTy = funTy->getParamType(i);
+ params[i] =
+ p->getType() == paramTy ? p : new CastInst(p, paramTy, TMP, bb);
+ }
+
+ Value* r = new CallInst(fun, params, TMP, bb);
+ if (funTy->getReturnType() != Type::VoidTy)
+ opStack_.push(r);
+ }
+
void do_invokevirtual(unsigned bcI, unsigned index) {
ConstantMethodRef* methodRef =
(ConstantMethodRef*)(cf_->getConstantPool()[index]);
@@ -934,22 +950,9 @@
"could not find slot for virtual function!");
unsigned vSlot = vi.m2iMap.find(methodDescr)->second;
indices.push_back(ConstantUInt::get(Type::UIntTy, vSlot));
- Value* vfun = new LoadInst
- (new GetElementPtrInst(vtable, indices, TMP, getBBAt(bcI)), TMP,
- getBBAt(bcI));
-
- const FunctionType* vfunTy = cast<FunctionType>
- (cast<PointerType>(vfun->getType())->getElementType());
- std::vector<Value*> params(vfunTy->getNumParams(), NULL);
- for (unsigned i = 0, e = vfunTy->getNumParams(); i != e; ++i) {
- Value* p = opStack_.top(); opStack_.pop();
- const Type* paramTy = vfunTy->getParamType(i);
- params[i] = p->getType() == paramTy ? p :
- new CastInst(p, paramTy, TMP, getBBAt(bcI));
- }
-
- Value* r = new CallInst(vfun, params, TMP, getBBAt(bcI));
- opStack_.push(r);
+ Value* vfunPtr = new GetElementPtrInst(vtable, indices, TMP, getBBAt(bcI));
+ Value* vfun = new LoadInst(vfunPtr, TMP, getBBAt(bcI));
+ makeCall(vfun, getBBAt(bcI));
}
void do_invokespecial(unsigned bcI, unsigned index) {
@@ -968,18 +971,9 @@
FunctionType* funcType =
cast<FunctionType>(getType(nameAndType->getDescriptor()));
- std::vector<Value*> params(funcType->getNumParams(), NULL);
- for (unsigned i = 0, e = funcType->getNumParams(); i != e; ++i) {
- Value* p = opStack_.top(); opStack_.pop();
- const Type* paramTy = funcType->getParamType(i);
- params[i] = p->getType() == paramTy ? p :
- new CastInst(p, paramTy, TMP, getBBAt(bcI));
- }
-
Function* function = module_->getOrInsertFunction(funcName, funcType);
toCompileFunctions_.insert(function);
- Value* r = new CallInst(function, params, TMP, getBBAt(bcI));
- opStack_.push(r);
+ makeCall(function, getBBAt(bcI));
}
void do_invokeinterface(unsigned bcI, unsigned index) {
More information about the llvm-commits
mailing list