[vmkit-commits] [vmkit] r200339 - Continue the debugging of the inlining pass.
Gael Thomas
gael.thomas at lip6.fr
Tue Jan 28 13:18:09 PST 2014
Author: gthomas
Date: Tue Jan 28 15:18:08 2014
New Revision: 200339
URL: http://llvm.org/viewvc/llvm-project?rev=200339&view=rev
Log:
Continue the debugging of the inlining pass.
Modified:
vmkit/branches/mcjit/include/j3/j3method.h
vmkit/branches/mcjit/lib/j3/vm/j3method.cc
vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc
vmkit/branches/mcjit/lib/vmkit/inliner.cc
Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=200339&r1=200338&r2=200339&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Tue Jan 28 15:18:08 2014
@@ -45,6 +45,7 @@ namespace j3 {
void* volatile _virtualTrampoline;
J3ObjectHandle* volatile _javaMethod;
+ J3Value internalInvoke(J3Value* args);
J3Value internalInvoke(J3ObjectHandle* handle, va_list va);
J3Value internalInvoke(J3ObjectHandle* handle, J3Value* args);
void buildLLVMNames(J3Class* from);
Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=200339&r1=200338&r2=200339&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Jan 28 15:18:08 2014
@@ -36,7 +36,7 @@ vmkit::CompilationUnit* J3Method::unit()
}
uint64_t J3Method::inlineWeight() {
- if(J3Thread::get()->vm()->options()->enableInlining)
+ if(0 && J3Thread::get()->vm()->options()->enableInlining)
return vmkit::Symbol::inlineWeight();
else
return (uint64_t)-1;
@@ -116,6 +116,22 @@ J3Method* J3Method::resolve(J3ObjectHand
return obj->vt()->type()->asObjectType()->findMethod(0, name(), signature());
}
+J3Value J3Method::internalInvoke(J3Value* args) {
+#if 1
+ return cxxCaller()(fnPtr(), args);
+#else
+ J3Value res;
+ try {
+ res = cxxCaller()(fnPtr(), args);
+ } catch(void* e) {
+ fprintf(stderr, " catch exception %p during the execution of %s::%s%s\n",
+ e, cl()->name()->cStr(), name()->cStr(), signature()->name()->cStr());
+ throw e;
+ }
+ return res;
+#endif
+}
+
J3Value J3Method::internalInvoke(J3ObjectHandle* handle, J3Value* inArgs) {
cl()->initialise();
ensureCompiled(J3CodeGen::WithMethod | J3CodeGen::WithCaller); /* force the generation of the code and thus of the functionType */
@@ -129,15 +145,7 @@ J3Value J3Method::internalInvoke(J3Objec
} else
reIn = inArgs;
- J3Value res;
- try {
- res = cxxCaller()(fnPtr(), reIn);
- } catch(void* e) {
- fprintf(stderr, " catch exception e: %p during the execution of %s::%s%s\n",
- e, cl()->name()->cStr(), name()->cStr(), signature()->name()->cStr());
- throw e;
- }
- return res;
+ return internalInvoke(reIn);
}
J3Value J3Method::internalInvoke(J3ObjectHandle* handle, va_list va) {
@@ -165,7 +173,7 @@ J3Value J3Method::internalInvoke(J3Objec
#undef doIt
}
- return cxxCaller()(fnPtr(), args);
+ return internalInvoke(args);
}
J3Value J3Method::invokeStatic(J3Value* args) {
Modified: vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc?rev=200339&r1=200338&r2=200339&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc Tue Jan 28 15:18:08 2014
@@ -57,7 +57,8 @@ namespace vmkit {
return 1;
}
- if(linkage == llvm::GlobalValue::PrivateLinkage) {
+
+ if(linkage == llvm::GlobalValue::PrivateLinkage && !memcmp(gv->getName().data(), ".str", 4)) {
size_t len = strlen(gv->getName().data());
if(len > reserved) {
reserved = (len << 2);
Modified: vmkit/branches/mcjit/lib/vmkit/inliner.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/inliner.cc?rev=200339&r1=200338&r2=200339&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/inliner.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/inliner.cc Tue Jan 28 15:18:08 2014
@@ -76,7 +76,7 @@ namespace vmkit {
return (!bc->hasFnAttribute(llvm::Attribute::NoInline)
&& (bc->hasFnAttribute(llvm::Attribute::AlwaysInline) ||
- (0 && !onlyAlwaysInline && (uint64_t)(symbol->inlineWeight()-1) < inlineThreshold))) ? symbol : 0;
+ (!onlyAlwaysInline && (uint64_t)(symbol->inlineWeight()-1) < inlineThreshold))) ? symbol : 0;
}
bool visitBB(llvm::BasicBlock* bb) {
@@ -110,7 +110,7 @@ namespace vmkit {
function->getParent()->getOrInsertGlobal(gv->getName().data(), gv->getType()->getContainedType(0));
//fprintf(stderr, "<<<reimporting>>>: %s\n", gv->getName().data());
- gv->replaceAllUsesWith(copy);
+ insn->setOperand(i, copy);
}
}
}
@@ -130,23 +130,23 @@ namespace vmkit {
if(symbol) {
llvm::Function* bc = symbol->llvmFunction();
-
- if(bc != callee)
- callee->replaceAllUsesWith(bc);
- fprintf(stderr, " inlining %s in %s\n", bc->getName().data(), function->getName().data());
+ //fprintf(stderr, " inlining %s in %s\n", bc->getName().data(), function->getName().data());
if(llvm::isa<llvm::TerminatorInst>(insn)) {
llvm::TerminatorInst* terminator = llvm::cast<llvm::TerminatorInst>(insn);
for(unsigned i=0; i<terminator->getNumSuccessors(); i++)
- push(symbol, terminator->getSuccessor(i));
+ push(curSymbol, terminator->getSuccessor(i));
} else {
size_t len = strlen(bc->getName().data());
- char buf[len + 16];
+ char buf[len + 14];
memcpy(buf, bc->getName().data(), len);
memcpy(buf+len, ".after-inline", 14);
- push(symbol, bb->splitBasicBlock(insn->getNextNode(), buf));
+ push(curSymbol, bb->splitBasicBlock(insn->getNextNode(), buf));
}
+
+ if(bc != callee)
+ call.setCalledFunction(bc);
llvm::InlineFunctionInfo ifi(0);
bool isInlined = llvm::InlineFunction(call, ifi, false);
@@ -164,7 +164,7 @@ namespace vmkit {
} else {
symbol->markAsNeverInline();
if(bc != callee)
- bc->replaceAllUsesWith(callee);
+ call.setCalledFunction(callee);
}
}
}
@@ -214,17 +214,9 @@ namespace vmkit {
}
virtual const char* getPassName() const { return "VMKit inliner"; }
- bool ensureLocal(llvm::Function* function, llvm::Function* callee);
- Symbol* tryInline(llvm::Function* function, llvm::Function* callee);
- bool runOnBB(llvm::BasicBlock* bb);
- bool runOnFunction0(llvm::Function& function);
bool runOnFunction(llvm::Function& function) {
-#if 0
- return runOnFunction0(function);
-#else
FunctionInliner inliner(unit, &function, inlineThreshold, onlyAlwaysInline);
return inliner.proceed();
-#endif
}
};
@@ -232,106 +224,6 @@ namespace vmkit {
#if 0
llvm::RegisterPass<FunctionInlinerPass> X("FunctionInlinerPass",
- "Inlining Pass that inlines evaluator's functions.");
-#endif
-
- //FunctionInlinerPass() : FunctionPass(ID) {}
-
- bool FunctionInlinerPass::ensureLocal(llvm::Function* function, llvm::Function* callee) {
- /* prevent exernal references because some llvm passes don't like that */
- if(callee->getParent() != function->getParent()) {
- //fprintf(stderr, " rewrite local\n");
- llvm::Function* local = (llvm::Function*)function->getParent()->getOrInsertFunction(callee->getName().data(),
- callee->getFunctionType());
- callee->replaceAllUsesWith(local);
- callee = local;
- return 1;
- } else
- return 0;
- }
-
- //llvm::SmallPtrSet<const Function*, 16> NeverInline;
-
- bool FunctionInlinerPass::runOnBB(llvm::BasicBlock* bb) {
- fprintf(stderr, " process basic block %s\n", bb->getName().data());
-
- //SmallPtrSet<const BasicBlock*, 8> Visited;
-
- return 0;
- }
-
- bool FunctionInlinerPass::runOnFunction0(llvm::Function& function) {
- bool changed = false;
-
- //fprintf(stderr, "Analyzing: %s\n", function.getName().data());
-
- restart:
- for (llvm::Function::iterator bit=function.begin(); bit!=function.end(); bit++) {
- llvm::BasicBlock* bb = bit;
- uint32_t prof = 0;
-
- for(llvm::BasicBlock::iterator it=bb->begin(), prev=0; it!=bb->end() && prof<42; prev=it++) {
- llvm::Instruction *insn = it;
-
- //fprintf(stderr, " process: ");
- //insn->dump();
-
-#if 0
- if(insn->getOpcode() == llvm::Instruction::LandingPad) {
- llvm::LandingPadInst* lp = (llvm::LandingPadInst*)insn;
- ensureLocal(&function, (llvm::Function*)lp->getPersonalityFn());
- continue;
- }
-#endif
-
- if (insn->getOpcode() != llvm::Instruction::Call &&
- insn->getOpcode() != llvm::Instruction::Invoke) {
- continue;
- }
-
- llvm::CallSite call(insn);
- llvm::Function* callee = call.getCalledFunction();
-
- if(!callee)
- continue;
-
- Symbol* symbol = tryInline(&function, callee);
- llvm::Function* bc;
-
- if(symbol && (bc = symbol->llvmFunction()) != &function) {
- if(bc != callee)
- callee->replaceAllUsesWith(bc);
-
- //fprintf(stderr, " inlining: %s\n", bc->getName().data());
- //bc->dump();
- llvm::InlineFunctionInfo ifi(0);
- bool isInlined = llvm::InlineFunction(call, ifi, false);
- changed |= isInlined;
-
- if(isInlined) {
- prof++;
- //it = prev ? prev : bb->begin();
- //continue;
- //fprintf(stderr, "... restart ....\n");
- goto restart;
- }
- } else
- changed |= ensureLocal(&function, callee);
- }
- }
-
- //#if 0
- if(changed) {
- //function.dump();
- //abort();
- }
- //#endif
-
- return changed;
- }
-
-#if 0
- llvm::RegisterPass<FunctionInlinerPass> X("FunctionInlinerPass",
"Inlining Pass that inlines evaluator's functions.");
#endif
More information about the vmkit-commits
mailing list