diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:11:02 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:11:02 +0000 |
commit | 750ce4d809c7e2a298a389a512a17652ff5be3f2 (patch) | |
tree | 70fbd90da02177c8e6ef82adba9fa8ace285a5e3 /lib/ExecutionEngine | |
parent | 5f970ec96e421f64db6b1c6509a902ea73d98cc7 (diff) | |
download | FreeBSD-src-750ce4d809c7e2a298a389a512a17652ff5be3f2.zip FreeBSD-src-750ce4d809c7e2a298a389a512a17652ff5be3f2.tar.gz |
Update LLVM to r103004.
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 18 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 4 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp | 10 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Interpreter.h | 4 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/Intercept.cpp | 2 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 12 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp | 2 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp | 18 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 99 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 8 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp | 55 |
11 files changed, 125 insertions, 107 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index da21c2d..b17827e 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -379,27 +379,27 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, switch (NumArgs) { case 3: if (FTy->getParamType(2) != PPInt8Ty) { - llvm_report_error("Invalid type for third argument of main() supplied"); + report_fatal_error("Invalid type for third argument of main() supplied"); } // FALLS THROUGH case 2: if (FTy->getParamType(1) != PPInt8Ty) { - llvm_report_error("Invalid type for second argument of main() supplied"); + report_fatal_error("Invalid type for second argument of main() supplied"); } // FALLS THROUGH case 1: if (!FTy->getParamType(0)->isIntegerTy(32)) { - llvm_report_error("Invalid type for first argument of main() supplied"); + report_fatal_error("Invalid type for first argument of main() supplied"); } // FALLS THROUGH case 0: if (!FTy->getReturnType()->isIntegerTy() && !FTy->getReturnType()->isVoidTy()) { - llvm_report_error("Invalid return type of main() supplied"); + report_fatal_error("Invalid return type of main() supplied"); } break; default: - llvm_report_error("Invalid number of arguments of main() supplied"); + report_fatal_error("Invalid number of arguments of main() supplied"); } ArgvArray CArgv; @@ -771,7 +771,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { std::string msg; raw_string_ostream Msg(msg); Msg << "ConstantExpr not handled: " << *CE; - llvm_report_error(Msg.str()); + report_fatal_error(Msg.str()); } GenericValue Result; @@ -807,7 +807,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { std::string msg; raw_string_ostream Msg(msg); Msg << "ERROR: Constant unimplemented for type: " << *C->getType(); - llvm_report_error(Msg.str()); + report_fatal_error(Msg.str()); } return Result; } @@ -935,7 +935,7 @@ void ExecutionEngine::LoadValueFromMemory(GenericValue &Result, std::string msg; raw_string_ostream Msg(msg); Msg << "Cannot load value of type " << *Ty << "!"; - llvm_report_error(Msg.str()); + report_fatal_error(Msg.str()); } } @@ -1051,7 +1051,7 @@ void ExecutionEngine::emitGlobals() { sys::DynamicLibrary::SearchForAddressOfSymbol(I->getName())) addGlobalMapping(I, SymAddr); else { - llvm_report_error("Could not resolve external global address: " + report_fatal_error("Could not resolve external global address: " +I->getName()); } } diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index a2aad5a..0748b54 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -631,7 +631,7 @@ void Interpreter::visitUnwindInst(UnwindInst &I) { do { ECStack.pop_back(); if (ECStack.empty()) - llvm_report_error("Empty stack during unwind!"); + report_fatal_error("Empty stack during unwind!"); Inst = ECStack.back().Caller.getInstruction(); } while (!(Inst && isa<InvokeInst>(Inst))); @@ -644,7 +644,7 @@ void Interpreter::visitUnwindInst(UnwindInst &I) { } void Interpreter::visitUnreachableInst(UnreachableInst &I) { - llvm_report_error("Program executed an 'unreachable' instruction!"); + report_fatal_error("Program executed an 'unreachable' instruction!"); } void Interpreter::visitBranchInst(BranchInst &I) { diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 3ba783b..26a53b5 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -126,7 +126,7 @@ static ffi_type *ffiTypeFor(const Type *Ty) { default: break; } // TODO: Support other types such as StructTyID, ArrayTyID, OpaqueTyID, etc. - llvm_report_error("Type could not be mapped for use with libffi."); + report_fatal_error("Type could not be mapped for use with libffi."); return NULL; } @@ -174,7 +174,7 @@ static void *ffiValueFor(const Type *Ty, const GenericValue &AV, default: break; } // TODO: Support other types such as StructTyID, ArrayTyID, OpaqueTyID, etc. - llvm_report_error("Type value could not be mapped for use with libffi."); + report_fatal_error("Type value could not be mapped for use with libffi."); return NULL; } @@ -188,7 +188,7 @@ static bool ffiInvoke(RawFunc Fn, Function *F, // TODO: We don't have type information about the remaining arguments, because // this information is never passed into ExecutionEngine::runFunction(). if (ArgVals.size() > NumArgs && F->isVarArg()) { - llvm_report_error("Calling external var arg function '" + F->getName() + report_fatal_error("Calling external var arg function '" + F->getName() + "' is not supported by the Interpreter."); } @@ -284,7 +284,7 @@ GenericValue Interpreter::callExternalFunction(Function *F, errs() << "Tried to execute an unknown external function: " << F->getType()->getDescription() << " __main\n"; else - llvm_report_error("Tried to execute an unknown external function: " + + report_fatal_error("Tried to execute an unknown external function: " + F->getType()->getDescription() + " " +F->getName()); #ifndef USE_LIBFFI errs() << "Recompiling LLVM with --enable-libffi might help.\n"; @@ -325,7 +325,7 @@ GenericValue lle_X_exit(const FunctionType *FT, GenericValue lle_X_abort(const FunctionType *FT, const std::vector<GenericValue> &Args) { //FIXME: should we report or raise here? - //llvm_report_error("Interpreted program raised SIGABRT"); + //report_fatal_error("Interpreted program raised SIGABRT"); raise (SIGABRT); return GenericValue(); } diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h index bc4200b..564e9ab 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -190,12 +190,10 @@ public: return &(ECStack.back ().VarArgs[0]); } - //FIXME: private: -public: +private: // Helper functions GenericValue executeGEPOperation(Value *Ptr, gep_type_iterator I, gep_type_iterator E, ExecutionContext &SF); -private: // Helper functions // SwitchToNewBasicBlock - Start execution in a new basic block and run any // PHI nodes in the top of the block. This is used for intraprocedural // control flow. diff --git a/lib/ExecutionEngine/JIT/Intercept.cpp b/lib/ExecutionEngine/JIT/Intercept.cpp index c00b60a..b367033 100644 --- a/lib/ExecutionEngine/JIT/Intercept.cpp +++ b/lib/ExecutionEngine/JIT/Intercept.cpp @@ -142,7 +142,7 @@ void *JIT::getPointerToNamedFunction(const std::string &Name, return RP; if (AbortOnFailure) { - llvm_report_error("Program used external function '"+Name+ + report_fatal_error("Program used external function '"+Name+ "' which could not be resolved!"); } return 0; diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index dd74d73..546d2b2 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -304,7 +304,7 @@ JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, // Turn the machine code intermediate representation into bytes in memory that // may be executed. if (TM.addPassesToEmitMachineCode(PM, *JCE, OptLevel)) { - llvm_report_error("Target does not support machine code emission!"); + report_fatal_error("Target does not support machine code emission!"); } // Register routine for informing unwinding runtime about new EH frames @@ -352,7 +352,7 @@ void JIT::addModule(Module *M) { // Turn the machine code intermediate representation into bytes in memory // that may be executed. if (TM.addPassesToEmitMachineCode(PM, *JCE, CodeGenOpt::Default)) { - llvm_report_error("Target does not support machine code emission!"); + report_fatal_error("Target does not support machine code emission!"); } // Initialize passes. @@ -383,7 +383,7 @@ bool JIT::removeModule(Module *M) { // Turn the machine code intermediate representation into bytes in memory // that may be executed. if (TM.addPassesToEmitMachineCode(PM, *JCE, CodeGenOpt::Default)) { - llvm_report_error("Target does not support machine code emission!"); + report_fatal_error("Target does not support machine code emission!"); } // Initialize passes. @@ -665,7 +665,7 @@ void *JIT::getPointerToFunction(Function *F) { // exists in this Module. std::string ErrorMsg; if (F->Materialize(&ErrorMsg)) { - llvm_report_error("Error reading function '" + F->getName()+ + report_fatal_error("Error reading function '" + F->getName()+ "' from bitcode file: " + ErrorMsg); } @@ -704,7 +704,7 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { #endif Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName()); if (Ptr == 0) { - llvm_report_error("Could not resolve external global address: " + report_fatal_error("Could not resolve external global address: " +GV->getName()); } addGlobalMapping(GV, Ptr); @@ -754,7 +754,7 @@ char* JIT::getMemoryForGV(const GlobalVariable* GV) { // situation. It's returned in the same block of memory as code which may // not be writable. if (isGVCompilationDisabled() && !GV->isConstant()) { - llvm_report_error("Compilation of non-internal GlobalValue is disabled!"); + report_fatal_error("Compilation of non-internal GlobalValue is disabled!"); } // Some applications require globals and code to live together, so they may diff --git a/lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp b/lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp index 68471bd..749a57d 100644 --- a/lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp +++ b/lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp @@ -80,7 +80,7 @@ std::string JITDebugRegisterer::MakeELF(const Function *F, DebugInfo &I) { // Copy the binary into the .text section. This isn't necessary, but it's // useful to be able to disassemble the ELF by hand. - ELFSection &Text = EW.getTextSection((Function *)F); + ELFSection &Text = EW.getTextSection(const_cast<Function *>(F)); Text.Addr = (uint64_t)I.FnStart; // TODO: We could eliminate this copy if we somehow used a pointer/size pair // instead of a vector. diff --git a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp index 2f42e6b..4b3ca87 100644 --- a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp @@ -52,7 +52,7 @@ unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F, unsigned char* Result = 0; - const std::vector<Function *> Personalities = MMI->getPersonalities(); + const std::vector<const Function *> Personalities = MMI->getPersonalities(); EHFramePtr = EmitCommonEHFrame(Personalities[MMI->getPersonalityIndex()]); Result = EmitEHFrame(Personalities[MMI->getPersonalityIndex()], EHFramePtr, @@ -75,7 +75,7 @@ JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr, MCSymbol *Label = Move.getLabel(); // Throw out move if the label is invalid. - if (Label && !Label->isDefined()) + if (Label && (*JCE->getLabelLocations())[Label] == 0) continue; intptr_t LabelPtr = 0; @@ -199,9 +199,9 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF, assert(MMI && "MachineModuleInfo not registered!"); // Map all labels and get rid of any dead landing pads. - MMI->TidyLandingPads(); + MMI->TidyLandingPads(JCE->getLabelLocations()); - const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); + const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); if (PadInfos.empty()) return 0; @@ -450,7 +450,7 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF, // Emit the type ids. for (unsigned M = TypeInfos.size(); M; --M) { - GlobalVariable *GV = TypeInfos[M - 1]; + const GlobalVariable *GV = TypeInfos[M - 1]; if (GV) { if (TD->getPointerSize() == sizeof(int32_t)) @@ -609,7 +609,7 @@ unsigned JITDwarfEmitter::GetDwarfTableSizeInBytes(MachineFunction& F, FinalSize += GetExceptionTableSizeInBytes(&F); - const std::vector<Function *> Personalities = MMI->getPersonalities(); + const std::vector<const Function *> Personalities = MMI->getPersonalities(); FinalSize += GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]); @@ -711,7 +711,7 @@ JITDwarfEmitter::GetFrameMovesSizeInBytes(intptr_t BaseLabelPtr, MCSymbol *Label = Move.getLabel(); // Throw out move if the label is invalid. - if (Label && !Label->isDefined()) + if (Label && (*JCE->getLabelLocations())[Label] == 0) continue; intptr_t LabelPtr = 0; @@ -780,9 +780,9 @@ JITDwarfEmitter::GetExceptionTableSizeInBytes(MachineFunction* MF) const { unsigned FinalSize = 0; // Map all labels and get rid of any dead landing pads. - MMI->TidyLandingPads(); + MMI->TidyLandingPads(JCE->getLabelLocations()); - const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); + const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); if (PadInfos.empty()) return 0; diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 7b8ab9e..e3855b2 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -23,6 +23,7 @@ #include "llvm/Analysis/DebugInfo.h" #include "llvm/CodeGen/JITCodeEmitter.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" @@ -30,8 +31,8 @@ #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/ExecutionEngine/JITMemoryManager.h" -#include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetJITInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" @@ -43,7 +44,6 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/System/Disassembler.h" #include "llvm/System/Memory.h" -#include "llvm/Target/TargetInstrInfo.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" @@ -369,7 +369,7 @@ namespace { ValueMap<const Function *, EmittedCode, EmittedFunctionConfig> EmittedFunctions; - DILocation PrevDLT; + DebugLoc PrevDL; /// Instance of the JIT JIT *TheJIT; @@ -377,14 +377,14 @@ namespace { public: JITEmitter(JIT &jit, JITMemoryManager *JMM, TargetMachine &TM) : SizeEstimate(0), Resolver(jit, *this), MMI(0), CurFn(0), - EmittedFunctions(this), PrevDLT(NULL), TheJIT(&jit) { + EmittedFunctions(this), TheJIT(&jit) { MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager(); if (jit.getJITInfo().needsGOT()) { MemMgr->AllocateGOT(); DEBUG(dbgs() << "JIT is managing a GOT\n"); } - if (DwarfExceptionHandling || JITEmitDebugInfo) { + if (JITExceptionHandling || JITEmitDebugInfo) { DE.reset(new JITDwarfEmitter(jit)); } if (JITEmitDebugInfo) { @@ -463,6 +463,10 @@ namespace { LabelLocations[Label] = getCurrentPCValue(); } + virtual DenseMap<MCSymbol*, uintptr_t> *getLabelLocations() { + return &LabelLocations; + } + virtual uintptr_t getLabelAddress(MCSymbol *Label) const { assert(LabelLocations.count(Label) && "Label not emitted!"); return LabelLocations.find(Label)->second; @@ -737,7 +741,7 @@ void *JITResolver::JITCompilerFn(void *Stub) { // If lazy compilation is disabled, emit a useful error message and abort. if (!JR->TheJIT->isCompilingLazily()) { - llvm_report_error("LLVM JIT requested to do lazy compilation of function '" + report_fatal_error("LLVM JIT requested to do lazy compilation of function '" + F->getName() + "' when lazy compiles are disabled!"); } @@ -823,19 +827,17 @@ void *JITEmitter::getPointerToGVIndirectSym(GlobalValue *V, void *Reference) { void JITEmitter::processDebugLoc(DebugLoc DL, bool BeforePrintingInsn) { if (DL.isUnknown()) return; if (!BeforePrintingInsn) return; - - // FIXME: This is horribly inefficient. - DILocation CurDLT(DL.getAsMDNode( - EmissionDetails.MF->getFunction()->getContext())); - if (CurDLT.getScope().getNode() != 0 && PrevDLT.getNode() !=CurDLT.getNode()){ + const LLVMContext& Context = EmissionDetails.MF->getFunction()->getContext(); + + if (DL.getScope(Context) != 0 && PrevDL != DL) { JITEvent_EmittedFunctionDetails::LineStart NextLine; NextLine.Address = getCurrentPCValue(); NextLine.Loc = DL; EmissionDetails.LineStarts.push_back(NextLine); } - PrevDLT = CurDLT; + PrevDL = DL; } static unsigned GetConstantPoolSizeInBytes(MachineConstantPool *MCP, @@ -945,7 +947,7 @@ unsigned JITEmitter::addSizeOfGlobalsInConstantVal( std::string msg; raw_string_ostream Msg(msg); Msg << "ConstantExpr not handled: " << *CE; - llvm_report_error(Msg.str()); + report_fatal_error(Msg.str()); } } } @@ -997,12 +999,13 @@ unsigned JITEmitter::GetSizeOfGlobalsInBytes(MachineFunction &MF) { for (unsigned CurOp = 0; CurOp < NumOps; CurOp++) { const MachineOperand &MO = MI.getOperand(CurOp); if (MO.isGlobal()) { - GlobalValue* V = MO.getGlobal(); + const GlobalValue* V = MO.getGlobal(); const GlobalVariable *GV = dyn_cast<const GlobalVariable>(V); if (!GV) continue; // If seen in previous function, it will have an entry here. - if (TheJIT->getPointerToGlobalIfAvailable(GV)) + if (TheJIT->getPointerToGlobalIfAvailable( + const_cast<GlobalVariable *>(GV))) continue; // If seen earlier in this function, it will have an entry here. // FIXME: it should be possible to combine these tables, by @@ -1212,6 +1215,9 @@ bool JITEmitter::finishFunction(MachineFunction &F) { TheJIT->NotifyFunctionEmitted(*F.getFunction(), FnStart, FnEnd-FnStart, EmissionDetails); + // Reset the previous debug location. + PrevDL = DebugLoc(); + DEBUG(dbgs() << "JIT: Finished CodeGen of [" << (void*)FnStart << "] Function: " << F.getFunction()->getName() << ": " << (FnEnd-FnStart) << " bytes of text, " @@ -1223,45 +1229,44 @@ bool JITEmitter::finishFunction(MachineFunction &F) { // Mark code region readable and executable if it's not so already. MemMgr->setMemoryExecutable(); - DEBUG( - if (sys::hasDisassembler()) { - dbgs() << "JIT: Disassembled code:\n"; - dbgs() << sys::disassembleBuffer(FnStart, FnEnd-FnStart, - (uintptr_t)FnStart); - } else { - dbgs() << "JIT: Binary code:\n"; - uint8_t* q = FnStart; - for (int i = 0; q < FnEnd; q += 4, ++i) { - if (i == 4) - i = 0; - if (i == 0) - dbgs() << "JIT: " << (long)(q - FnStart) << ": "; - bool Done = false; - for (int j = 3; j >= 0; --j) { - if (q + j >= FnEnd) - Done = true; - else - dbgs() << (unsigned short)q[j]; + DEBUG({ + if (sys::hasDisassembler()) { + dbgs() << "JIT: Disassembled code:\n"; + dbgs() << sys::disassembleBuffer(FnStart, FnEnd-FnStart, + (uintptr_t)FnStart); + } else { + dbgs() << "JIT: Binary code:\n"; + uint8_t* q = FnStart; + for (int i = 0; q < FnEnd; q += 4, ++i) { + if (i == 4) + i = 0; + if (i == 0) + dbgs() << "JIT: " << (long)(q - FnStart) << ": "; + bool Done = false; + for (int j = 3; j >= 0; --j) { + if (q + j >= FnEnd) + Done = true; + else + dbgs() << (unsigned short)q[j]; + } + if (Done) + break; + dbgs() << ' '; + if (i == 3) + dbgs() << '\n'; } - if (Done) - break; - dbgs() << ' '; - if (i == 3) - dbgs() << '\n'; + dbgs()<< '\n'; } - dbgs()<< '\n'; - } - ); + }); - if (DwarfExceptionHandling || JITEmitDebugInfo) { + if (JITExceptionHandling || JITEmitDebugInfo) { uintptr_t ActualSize = 0; SavedBufferBegin = BufferBegin; SavedBufferEnd = BufferEnd; SavedCurBufferPtr = CurBufferPtr; - if (MemMgr->NeedsExactSize()) { + if (MemMgr->NeedsExactSize()) ActualSize = DE->GetDwarfTableSizeInBytes(F, *this, FnStart, FnEnd); - } BufferBegin = CurBufferPtr = MemMgr->startExceptionTable(F.getFunction(), ActualSize); @@ -1277,7 +1282,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) { BufferEnd = SavedBufferEnd; CurBufferPtr = SavedCurBufferPtr; - if (DwarfExceptionHandling) { + if (JITExceptionHandling) { TheJIT->RegisterTable(FrameRegister); } @@ -1375,7 +1380,7 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) { ConstPoolAddresses.push_back(CAddr); if (CPE.isMachineConstantPoolEntry()) { // FIXME: add support to lower machine constant pool values into bytes! - llvm_report_error("Initialize memory with machine specific constant pool" + report_fatal_error("Initialize memory with machine specific constant pool" "entry has not been implemented!"); } TheJIT->InitializeMemory(CPE.Val.ConstVal, (void*)CAddr); diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index a17caa1..653e6f1 100644 --- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp @@ -15,6 +15,7 @@ #include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/Twine.h" #include "llvm/GlobalValue.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Compiler.h" @@ -22,12 +23,9 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Memory.h" -#include <map> #include <vector> #include <cassert> #include <climits> -#include <cstdio> -#include <cstdlib> #include <cstring> using namespace llvm; @@ -614,8 +612,8 @@ sys::MemoryBlock DefaultJITMemoryManager::allocateNewSlab(size_t size) { sys::MemoryBlock *LastSlabPtr = LastSlab.base() ? &LastSlab : 0; sys::MemoryBlock B = sys::Memory::AllocateRWX(size, LastSlabPtr, &ErrMsg); if (B.base() == 0) { - llvm_report_error("Allocation failed when allocating new memory in the" - " JIT\n" + ErrMsg); + report_fatal_error("Allocation failed when allocating new memory in the" + " JIT\n" + Twine(ErrMsg)); } LastSlab = B; ++NumSlabs; diff --git a/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp b/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp index 9c01b73..1ca084b 100644 --- a/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp +++ b/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp @@ -114,26 +114,43 @@ void OProfileJITEventListener::NotifyFunctionEmitted( return; } - // Now we convert the line number information from the address/DebugLoc format - // in Details to the address/filename/lineno format that OProfile expects. - // OProfile 0.9.4 (and maybe later versions) has a bug that causes it to - // ignore line numbers for addresses above 4G. - FilenameCache Filenames; - std::vector<debug_line_info> LineInfo; - LineInfo.reserve(1 + Details.LineStarts.size()); - if (!Details.MF->getDefaultDebugLoc().isUnknown()) { - LineInfo.push_back(LineStartToOProfileFormat( - *Details.MF, Filenames, - reinterpret_cast<uintptr_t>(FnStart), - Details.MF->getDefaultDebugLoc())); - } - for (std::vector<EmittedFunctionDetails::LineStart>::const_iterator + if (!Details.LineStarts.empty()) { + // Now we convert the line number information from the address/DebugLoc + // format in Details to the address/filename/lineno format that OProfile + // expects. Note that OProfile 0.9.4 has a bug that causes it to ignore + // line numbers for addresses above 4G. + FilenameCache Filenames; + std::vector<debug_line_info> LineInfo; + LineInfo.reserve(1 + Details.LineStarts.size()); + + DebugLoc FirstLoc = Details.LineStarts[0].Loc; + assert(!FirstLoc.isUnknown() + && "LineStarts should not contain unknown DebugLocs"); + MDNode *FirstLocScope = FirstLoc.getScope(F.getContext()); + DISubprogram FunctionDI = getDISubprogram(FirstLocScope); + if (FunctionDI.Verify()) { + // If we have debug info for the function itself, use that as the line + // number of the first several instructions. Otherwise, after filling + // LineInfo, we'll adjust the address of the first line number to point at + // the start of the function. + debug_line_info line_info; + line_info.vma = reinterpret_cast<uintptr_t>(FnStart); + line_info.lineno = FunctionDI.getLineNumber(); + line_info.filename = Filenames.getFilename(FirstLocScope); + LineInfo.push_back(line_info); + } + + for (std::vector<EmittedFunctionDetails::LineStart>::const_iterator I = Details.LineStarts.begin(), E = Details.LineStarts.end(); - I != E; ++I) { - LineInfo.push_back(LineStartToOProfileFormat( - *Details.MF, Filenames, I->Address, I->Loc)); - } - if (!LineInfo.empty()) { + I != E; ++I) { + LineInfo.push_back(LineStartToOProfileFormat( + *Details.MF, Filenames, I->Address, I->Loc)); + } + + // In case the function didn't have line info of its own, adjust the first + // line info's address to include the start of the function. + LineInfo[0].vma = reinterpret_cast<uintptr_t>(FnStart); + if (op_write_debug_line_info(Agent, FnStart, LineInfo.size(), &*LineInfo.begin()) == -1) { DEBUG(dbgs() |