[vmkit-commits] [vmkit] r200657 - Store inline information in safepoints.

Gael Thomas gael.thomas at lip6.fr
Sun Feb 2 13:58:26 PST 2014


Author: gthomas
Date: Sun Feb  2 15:58:26 2014
New Revision: 200657

URL: http://llvm.org/viewvc/llvm-project?rev=200657&view=rev
Log:
Store inline information in safepoints.

Modified:
    vmkit/branches/mcjit/include/vmkit/safepoint.h
    vmkit/branches/mcjit/lib/vmkit/compiler.cc
    vmkit/branches/mcjit/lib/vmkit/safepoint.cc

Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=200657&r1=200656&r2=200657&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/safepoint.h (original)
+++ vmkit/branches/mcjit/include/vmkit/safepoint.h Sun Feb  2 15:58:26 2014
@@ -2,6 +2,7 @@
 #define _SAFEPOINT_H_
 
 #include <stdint.h>
+#include <stdio.h>
 
 namespace llvm {
 	class Module;
@@ -12,20 +13,31 @@ namespace vmkit {
 
 	class Safepoint { /* Warning: directly generated by safepoint.cc in the data sections */
 		void*            _addr;
-		const char*      _functionName;
 		CompilationUnit* _unit;
-		uint32_t         _sourceIndex;
+
 		uint32_t         _nbLives;
+		uint32_t         _inlineDepth;
 
 	public:
 		void              setUnit(CompilationUnit* unit) { _unit = unit; }
 
 		CompilationUnit*  unit() { return _unit; }
 		void*             addr() { return _addr; }
-		const char*       functionName() { return _functionName; }
-		uint32_t          sourceIndex() { return _sourceIndex; }
 		uint32_t          nbLives() { return _nbLives; }
-		uint32_t          liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; }
+		uint32_t          inlineDepth() { return _inlineDepth; }
+
+		uint32_t          liveAt(uint32_t i) { 
+			return ((uint32_t*)(this + 1))[i]; 
+		}
+
+		const char*       functionName(uint32_t i=0) { 
+			return *(char**)((uintptr_t)this + sizeof(Safepoint) + _nbLives*sizeof(uint32_t) + i*(sizeof(const char*)+sizeof(uint32_t)));
+		}
+
+		uint32_t          sourceIndex(uint32_t i=0) { 
+			return *(uint32_t*)((uintptr_t)this + sizeof(Safepoint) + _nbLives*sizeof(uint32_t) + 
+													sizeof(const char*) + i*(sizeof(const char*)+sizeof(uint32_t)));
+		}
 
 		Safepoint*        getNext();
 		void              dump();

Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=200657&r1=200656&r2=200657&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Feb  2 15:58:26 2014
@@ -187,7 +187,7 @@ void CompilationUnit::compileModule(llvm
 		sf->setUnit(this);
 		vm->addSafepoint(sf);
 
-		Thread::get()->vm()->getSafepoint(sf->addr())->dump();
+		//Thread::get()->vm()->getSafepoint(sf->addr())->dump();
 		sf = sf->getNext();
 	}
 }

Modified: vmkit/branches/mcjit/lib/vmkit/safepoint.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safepoint.cc?rev=200657&r1=200656&r2=200657&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/safepoint.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/safepoint.cc Sun Feb  2 15:58:26 2014
@@ -141,47 +141,72 @@ void VmkitGCMetadataPrinter::finishAssem
 
 			for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) {
 				llvm::DebugLoc* debug = &safepoint->Loc;
+				uint32_t  kind = safepoint->Kind;
+
+				const llvm::MCExpr* address = llvm::MCSymbolRefExpr::Create(safepoint->Label, AP.OutStreamer.getContext());
+				if (debug->getCol() == 1) {
+					const llvm::MCExpr* one = llvm::MCConstantExpr::Create(1, AP.OutStreamer.getContext());
+					address = llvm::MCBinaryExpr::CreateAdd(address, one, AP.OutStreamer.getContext());
+				}
+
 				llvm::MDNode* inlinedAt = debug->getInlinedAt(getModule().getContext());
 
+				uint32_t inlineDepth = 1;
+
 				if(inlinedAt) {
-					fprintf(stderr, "find inline location in %s\n", gcInfo->getFunction().getName().data());
-					llvm::DISubprogram sub(debug->getScope(getModule().getContext()));
-					fprintf(stderr, "Inlined:                %s::%d\n", sub.getName().data(), debug->getLine());
 					llvm::DILocation cur(inlinedAt);
 					while(cur.getScope()) {
-						llvm::DISubprogram il(cur.getScope());
-						fprintf(stderr, "    =>                  %s::%d\n", il.getName().data(), cur.getLineNumber());
+						inlineDepth++;
 						cur = cur.getOrigLocation();
 					};
-
-					llvm::DILocation   loc(inlinedAt);
-					llvm::DISubprogram il(loc.getScope());
-
-					if(strcmp(gcInfo->getFunction().getName().data(), il.getName().data()))
-						abort();
-				}
-
-				uint32_t  kind = safepoint->Kind;
-
-				const llvm::MCExpr* address = llvm::MCSymbolRefExpr::Create(safepoint->Label, AP.OutStreamer.getContext());
-				if (debug->getCol() == 1) {
-					const llvm::MCExpr* one = llvm::MCConstantExpr::Create(1, AP.OutStreamer.getContext());
-					address = llvm::MCBinaryExpr::CreateAdd(address, one, AP.OutStreamer.getContext());
 				}
 
 				AP.OutStreamer.EmitValue(address, IntPtrSize);
-				AP.OutStreamer.EmitValue(funcName, IntPtrSize);
-				//				AP.EmitGlobalConstant(&gcInfo->getFunction());
+				/* CompilationUnit* */
 				AP.EmitInt32(0);
 				if(IntPtrSize == 8)
 					AP.EmitInt32(0);
-				AP.EmitInt32(debug->getLine());
+
+				/* number of live roots */
 				AP.EmitInt32(gcInfo->live_size(safepoint));
+				/* inline stack depth */
+				AP.EmitInt32(inlineDepth);
 
 				//fprintf(stderr, "emitting %lu lives\n", gcInfo->live_size(safepoint));
-				for(llvm::GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++) {
+				for(llvm::GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++)
 					AP.EmitInt32(live->StackOffset);
+
+				/* function names stack */
+				if(inlinedAt) {
+					//fprintf(stderr, "find inline location in %s: %d\n", gcInfo->getFunction().getName().data(), inlineDepth);
+					llvm::DISubprogram sub(debug->getScope(getModule().getContext()));
+
+					//fprintf(stderr, "Inlined:                %s::%d\n", sub.getName().data(), debug->getLine());
+					AP.OutStreamer.EmitValue(emitName(AP, sub.getName().data(), &funcNumber), IntPtrSize);
+					AP.EmitInt32(debug->getLine());
+
+					llvm::DILocation cur(inlinedAt);
+					while(cur.getScope()) {
+						llvm::DISubprogram il(cur.getScope());
+						//fprintf(stderr, "    =>                  %s::%d\n", il.getName().data(), cur.getLineNumber());
+						if(strcmp(il.getName().data(), gcInfo->getFunction().getName().data()))
+							AP.OutStreamer.EmitValue(emitName(AP, il.getName().data(), &funcNumber), IntPtrSize);
+						else
+							AP.OutStreamer.EmitValue(funcName, IntPtrSize);
+						AP.EmitInt32(cur.getLineNumber());
+						cur = cur.getOrigLocation();
+					};
+
+					llvm::DILocation   loc(inlinedAt);
+					llvm::DISubprogram il(loc.getScope());
+
+					//if(strcmp(gcInfo->getFunction().getName().data(), il.getName().data()))
+					//abort();
+				} else {
+					AP.OutStreamer.EmitValue(funcName, IntPtrSize);
+					AP.EmitInt32(debug->getLine());
 				}
+
 				AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
 			}
 		}
@@ -194,7 +219,8 @@ void VmkitGCMetadataPrinter::finishAssem
  *    Safepoint
  */
 Safepoint* Safepoint::getNext() {
-	uintptr_t next = (uintptr_t)this + sizeof(Safepoint) + nbLives()*sizeof(uint32_t);
+	uintptr_t next = (uintptr_t)this + sizeof(Safepoint) + nbLives()*sizeof(uint32_t) + 
+		inlineDepth()*(sizeof(const char*)+sizeof(uint32_t));
 	return (Safepoint*)(((next - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t));
 }
 
@@ -208,6 +234,12 @@ Safepoint* Safepoint::get(CompilationUni
 
 void Safepoint::dump() {
 	fprintf(stderr, "  [%p] safepoint at %p for %s::%d\n", this, addr(), functionName(), sourceIndex());
+
+	for(uint32_t i=1; i<inlineDepth(); i++)
+		fprintf(stderr, "          inlined in %s::%d\n", functionName(i), sourceIndex(i));
 	for(uint32_t i=0; i<nbLives(); i++)
 		fprintf(stderr, "    live at %d\n", liveAt(i));
+
+	if(inlineDepth() == 4)
+		abort();
 }





More information about the vmkit-commits mailing list