From 3e29671cca14f8fce1ea6b602175880cb3df7199 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 22 Mar 2012 05:44:06 +0000 Subject: Revert a series of commits to MCJIT to get the build working in CMake (and hopefully on Windows). The bots have been down most of the day because of this, and it's not clear to me what all will be required to fix it. The commits started with r153205, then r153207, r153208, and r153221. The first commit seems to be the real culprit, but I couldn't revert a smaller number of patches. When resubmitting, r153207 and r153208 should be folded into r153205, they were simple build fixes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153241 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 01a7d15..990582d 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -58,11 +58,9 @@ public: uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); - virtual void *getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure = true) { - return 0; - } - + uint8_t *startFunctionBody(const char *Name, uintptr_t &Size); + void endFunctionBody(const char *Name, uint8_t *FunctionStart, + uint8_t *FunctionEnd); }; uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size, @@ -77,6 +75,18 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); } +uint8_t *TrivialMemoryManager::startFunctionBody(const char *Name, + uintptr_t &Size) { + return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); +} + +void TrivialMemoryManager::endFunctionBody(const char *Name, + uint8_t *FunctionStart, + uint8_t *FunctionEnd) { + uintptr_t Size = FunctionEnd - FunctionStart + 1; + FunctionMemory.push_back(sys::MemoryBlock(FunctionStart, Size)); +} + static const char *ProgramName; static void Message(const char *Type, const Twine &Msg) { -- cgit v1.1 From a443e5b1f1013612950fc3c9ebfafca60a1c20df Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 23 Mar 2012 05:50:46 +0000 Subject: Remove the C backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153307 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/ExecutionDriver.cpp | 47 ++------------------ tools/bugpoint/ToolRunner.cpp | 88 -------------------------------------- 2 files changed, 3 insertions(+), 132 deletions(-) (limited to 'tools') diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index adf5587..218a559 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -28,8 +28,7 @@ namespace { // for miscompilation. // enum OutputType { - AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, RunCBE, CBE_bug, LLC_Safe, - CompileCustom, Custom + AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, LLC_Safe, CompileCustom, Custom }; cl::opt @@ -48,8 +47,6 @@ namespace { clEnumValN(RunLLC, "run-llc", "Compile with LLC"), clEnumValN(RunLLCIA, "run-llc-ia", "Compile with LLC with integrated assembler"), - clEnumValN(RunCBE, "run-cbe", "Compile with CBE"), - clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"), clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"), clEnumValN(CompileCustom, "compile-custom", "Use -compile-command to define a command to " @@ -64,7 +61,6 @@ namespace { SafeInterpreterSel(cl::desc("Specify \"safe\" i.e. known-good backend:"), cl::values(clEnumValN(AutoPick, "safe-auto", "Use best guess"), clEnumValN(RunLLC, "safe-run-llc", "Compile with LLC"), - clEnumValN(RunCBE, "safe-run-cbe", "Compile with CBE"), clEnumValN(Custom, "safe-run-custom", "Use -exec-command to define a command to execute " "the bitcode. Useful for cross-compilation."), @@ -154,10 +150,6 @@ bool BugDriver::initializeExecutionEnvironment() { switch (InterpreterSel) { case AutoPick: - InterpreterSel = RunCBE; - Interpreter = - AbstractInterpreter::createCBE(getToolName(), Message, GCCBinary, - &ToolArgv, &GCCToolArgv); if (!Interpreter) { InterpreterSel = RunJIT; Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, @@ -195,12 +187,6 @@ bool BugDriver::initializeExecutionEnvironment() { Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, &ToolArgv); break; - case RunCBE: - case CBE_bug: - Interpreter = AbstractInterpreter::createCBE(getToolName(), Message, - GCCBinary, &ToolArgv, - &GCCToolArgv); - break; case CompileCustom: Interpreter = AbstractInterpreter::createCustomCompiler(Message, CustomCompileCommand); @@ -221,17 +207,6 @@ bool BugDriver::initializeExecutionEnvironment() { std::vector SafeToolArgs = SafeToolArgv; switch (SafeInterpreterSel) { case AutoPick: - // In "cbe-bug" mode, default to using LLC as the "safe" backend. - if (!SafeInterpreter && - InterpreterSel == CBE_bug) { - SafeInterpreterSel = RunLLC; - SafeToolArgs.push_back("--relocation-model=pic"); - SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message, - GCCBinary, - &SafeToolArgs, - &GCCToolArgv); - } - // In "llc-safe" mode, default to using LLC as the "safe" backend. if (!SafeInterpreter && InterpreterSel == LLC_Safe) { @@ -243,17 +218,6 @@ bool BugDriver::initializeExecutionEnvironment() { &GCCToolArgv); } - // Pick a backend that's different from the test backend. The JIT and - // LLC backends share a lot of code, so prefer to use the CBE as the - // safe back-end when testing them. - if (!SafeInterpreter && - InterpreterSel != RunCBE) { - SafeInterpreterSel = RunCBE; - SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message, - GCCBinary, - &SafeToolArgs, - &GCCToolArgv); - } if (!SafeInterpreter && InterpreterSel != RunLLC && InterpreterSel != RunJIT) { @@ -277,11 +241,6 @@ bool BugDriver::initializeExecutionEnvironment() { &GCCToolArgv, SafeInterpreterSel == RunLLCIA); break; - case RunCBE: - SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message, - GCCBinary, &SafeToolArgs, - &GCCToolArgv); - break; case Custom: SafeInterpreter = AbstractInterpreter::createCustomExecutor(Message, CustomExecCommand); @@ -459,8 +418,8 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) { errs() << Error; if (Interpreter != SafeInterpreter) { errs() << "*** There is a bug running the \"safe\" backend. Either" - << " debug it (for example with the -run-cbe bugpoint option," - << " if CBE is being used as the \"safe\" backend), or fix the" + << " debug it (for example with the -run-jit bugpoint option," + << " if JIT is being used as the \"safe\" backend), or fix the" << " error some other way.\n"; } return false; diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index b80a5b4..25a2bae 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -623,94 +623,6 @@ AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0, return 0; } -GCC::FileType CBE::OutputCode(const std::string &Bitcode, - sys::Path &OutputCFile, std::string &Error, - unsigned Timeout, unsigned MemoryLimit) { - sys::Path uniqueFile(Bitcode+".cbe.c"); - std::string ErrMsg; - if (uniqueFile.makeUnique(true, &ErrMsg)) { - errs() << "Error making unique filename: " << ErrMsg << "\n"; - exit(1); - } - OutputCFile = uniqueFile; - std::vector LLCArgs; - LLCArgs.push_back(LLCPath.c_str()); - - // Add any extra LLC args. - for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i) - LLCArgs.push_back(ToolArgs[i].c_str()); - - LLCArgs.push_back("-o"); - LLCArgs.push_back(OutputCFile.c_str()); // Output to the C file - LLCArgs.push_back("-march=c"); // Output C language - LLCArgs.push_back(Bitcode.c_str()); // This is the input bitcode - LLCArgs.push_back(0); - - outs() << ""; outs().flush(); - DEBUG(errs() << "\nAbout to run:\t"; - for (unsigned i = 0, e = LLCArgs.size()-1; i != e; ++i) - errs() << " " << LLCArgs[i]; - errs() << "\n"; - ); - if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(), - sys::Path(), Timeout, MemoryLimit)) - Error = ProcessFailure(LLCPath, &LLCArgs[0], Timeout, MemoryLimit); - return GCC::CFile; -} - -void CBE::compileProgram(const std::string &Bitcode, std::string *Error, - unsigned Timeout, unsigned MemoryLimit) { - sys::Path OutputCFile; - OutputCode(Bitcode, OutputCFile, *Error, Timeout, MemoryLimit); - OutputCFile.eraseFromDisk(); -} - -int CBE::ExecuteProgram(const std::string &Bitcode, - const std::vector &Args, - const std::string &InputFile, - const std::string &OutputFile, - std::string *Error, - const std::vector &ArgsForGCC, - const std::vector &SharedLibs, - unsigned Timeout, - unsigned MemoryLimit) { - sys::Path OutputCFile; - OutputCode(Bitcode, OutputCFile, *Error, Timeout, MemoryLimit); - - FileRemover CFileRemove(OutputCFile.str(), !SaveTemps); - - std::vector GCCArgs(ArgsForGCC); - GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end()); - - return gcc->ExecuteProgram(OutputCFile.str(), Args, GCC::CFile, - InputFile, OutputFile, Error, GCCArgs, - Timeout, MemoryLimit); -} - -/// createCBE - Try to find the 'llc' executable -/// -CBE *AbstractInterpreter::createCBE(const char *Argv0, - std::string &Message, - const std::string &GCCBinary, - const std::vector *Args, - const std::vector *GCCArgs) { - sys::Path LLCPath = - PrependMainExecutablePath("llc", Argv0, (void *)(intptr_t)&createCBE); - if (LLCPath.isEmpty()) { - Message = - "Cannot find `llc' in executable directory!\n"; - return 0; - } - - Message = "Found llc: " + LLCPath.str() + "\n"; - GCC *gcc = GCC::create(Message, GCCBinary, GCCArgs); - if (!gcc) { - errs() << Message << "\n"; - exit(1); - } - return new CBE(LLCPath, gcc, Args); -} - //===---------------------------------------------------------------------===// // GCC abstraction // -- cgit v1.1 From d25dc3358bc81d380eb09f59b4d29dd6c53215ac Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Fri, 23 Mar 2012 10:00:42 +0000 Subject: Add soname to LLVM shared library on Linux. Probably the same stuff is necessary for *BSD. Patch from Mageia! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153324 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-shlib/Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile index 1d35670..6b358b6 100644 --- a/tools/llvm-shlib/Makefile +++ b/tools/llvm-shlib/Makefile @@ -72,6 +72,8 @@ endif ifeq ($(HOST_OS),Linux) # Don't allow unresolved symbols. LLVMLibsOptions += -Wl,--no-undefined + # Add soname to the library. + LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) endif ifeq ($(HOST_OS),SunOS) -- cgit v1.1 From 81bbdfda82a3e5528d979b2cc150e9c7e0fa4427 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 23 Mar 2012 11:49:32 +0000 Subject: Include cctype for std::isprint. This should unbreak the msvc build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153329 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/llvm-objdump.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 94becae..387f056 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -46,6 +46,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" #include +#include #include using namespace llvm; using namespace object; -- cgit v1.1 From 30fe94ea43bd122fb4fd26b84bcf62f8096d4293 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 28 Mar 2012 04:17:34 +0000 Subject: Some whitespace cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153567 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.h | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 35a0935..b7f2d5e 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -29,13 +29,12 @@ // forward references to llvm classes namespace llvm { - class MemoryBuffer; - class GlobalValue; - class Value; - class Function; + class MemoryBuffer; + class GlobalValue; + class Value; + class Function; } - // // C++ class which implements the opaque lto_module_t // @@ -43,13 +42,11 @@ struct LTOModule { static bool isBitcodeFile(const void* mem, size_t length); static bool isBitcodeFile(const char* path); - static bool isBitcodeFileForTarget(const void* mem, - size_t length, const char* triplePrefix); - + size_t length, + const char* triplePrefix); static bool isBitcodeFileForTarget(const char* path, const char* triplePrefix); - static LTOModule* makeLTOModule(const char* path, std::string& errMsg); static LTOModule* makeLTOModule(int fd, const char *path, @@ -62,16 +59,14 @@ struct LTOModule { std::string& errMsg); static LTOModule* makeLTOModule(const void* mem, size_t length, std::string& errMsg); - const char* getTargetTriple(); void setTargetTriple(const char*); uint32_t getSymbolCount(); lto_symbol_attributes getSymbolAttributes(uint32_t index); const char* getSymbolName(uint32_t index); - llvm::Module * getLLVVMModule() { return _module.get(); } const std::vector &getAsmUndefinedRefs() { - return _asm_undefines; + return _asm_undefines; } private: @@ -82,7 +77,7 @@ private: bool isFunction); void addPotentialUndefinedSymbol(llvm::GlobalValue* decl); void addDefinedFunctionSymbol(llvm::Function* f); - void addDefinedDataSymbol(llvm::GlobalValue* v); + void addDefinedDataSymbol(llvm::GlobalValue* v); bool addAsmGlobalSymbols(std::string &errMsg); void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope); @@ -94,30 +89,30 @@ private: std::string& name); static bool isTargetMatch(llvm::MemoryBuffer* memBuffer, - const char* triplePrefix); - + const char* triplePrefix); static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer, - std::string& errMsg); + std::string& errMsg); static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length); typedef llvm::StringMap StringSet; struct NameAndAttributes { - const char* name; - lto_symbol_attributes attributes; + const char* name; + lto_symbol_attributes attributes; }; llvm::OwningPtr _module; llvm::OwningPtr _target; std::vector _symbols; + // _defines and _undefines only needed to disambiguate tentative definitions StringSet _defines; llvm::StringMap _undefines; std::vector _asm_undefines; llvm::MCContext _context; + // Use mangler to add GlobalPrefix to names to match linker names. llvm::Mangler _mangler; }; #endif // LTO_MODULE_H - -- cgit v1.1 From 62cf01e4c5de703e7712c72d12f577153b373cba Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 28 Mar 2012 20:46:54 +0000 Subject: Reformat the LTOModule code to be more inline with LLVM's coding standards. Add a bunch of comments for the various functions. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153595 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 99 ++++++++++++--------------- tools/lto/LTOModule.h | 176 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 170 insertions(+), 105 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 8ce8cd2..5e51da0 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// #include "LTOModule.h" - #include "llvm/Constants.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" @@ -41,9 +40,15 @@ #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegisterInfo.h" - using namespace llvm; +LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) + : _module(m), _target(t), + _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL), + _mangler(_context, *_target->getTargetData()) {} + +/// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM +/// bitcode. bool LTOModule::isBitcodeFile(const void *mem, size_t length) { return llvm::sys::IdentifyFileType((char*)mem, length) == llvm::sys::Bitcode_FileType; @@ -53,6 +58,8 @@ bool LTOModule::isBitcodeFile(const char *path) { return llvm::sys::Path(path).isBitcodeFile(); } +/// isBitcodeFileForTarget - Returns 'true' if the file (or memory contents) is +/// LLVM bitcode for the specified triple. bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length, const char *triplePrefix) { MemoryBuffer *buffer = makeBuffer(mem, length); @@ -69,23 +76,17 @@ bool LTOModule::isBitcodeFileForTarget(const char *path, return isTargetMatch(buffer.take(), triplePrefix); } -// Takes ownership of buffer. +/// isTargetMatch - Returns 'true' if the memory buffer is for the specified +/// target triple. bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) { std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext()); delete buffer; return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0; } - -LTOModule::LTOModule(Module *m, TargetMachine *t) - : _module(m), _target(t), - _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL), - _mangler(_context, *_target->getTargetData()) -{ -} - -LTOModule *LTOModule::makeLTOModule(const char *path, - std::string &errMsg) { +/// makeLTOModule - Create an LTOModule. N.B. These methods take ownership of +/// the buffer. +LTOModule *LTOModule::makeLTOModule(const char *path, std::string &errMsg) { OwningPtr buffer; if (error_code ec = MemoryBuffer::getFile(path, buffer)) { errMsg = ec.message(); @@ -113,12 +114,6 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path, return makeLTOModule(buffer.take(), errMsg); } -/// makeBuffer - Create a MemoryBuffer from a memory range. -MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) { - const char *startPtr = (char*)mem; - return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false); -} - LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, std::string &errMsg) { OwningPtr buffer(makeBuffer(mem, length)); @@ -171,20 +166,13 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, return Ret; } -const char *LTOModule::getTargetTriple() { - return _module->getTargetTriple().c_str(); -} - -void LTOModule::setTargetTriple(const char *triple) { - _module->setTargetTriple(triple); -} - -void LTOModule::addDefinedFunctionSymbol(Function *f) { - // add to list of defined symbols - addDefinedSymbol(f, true); +/// makeBuffer - Create a MemoryBuffer from a memory range. +MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) { + const char *startPtr = (char*)mem; + return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false); } -// Get string that data pointer points to. +/// objcClassNameFromExpression - Get string that the data pointer points to. bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) { if (ConstantExpr *ce = dyn_cast(c)) { Constant *op = ce->getOperand(0); @@ -201,7 +189,7 @@ bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) { return false; } -// Parse i386/ppc ObjC class data structure. +/// addObjCClass - Parse i386/ppc ObjC class data structure. void LTOModule::addObjCClass(GlobalVariable *clgv) { ConstantStruct *c = dyn_cast(clgv->getInitializer()); if (!c) return; @@ -234,8 +222,7 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) { } } - -// Parse i386/ppc ObjC category data structure. +/// addObjCCategory - Parse i386/ppc ObjC category data structure. void LTOModule::addObjCCategory(GlobalVariable *clgv) { ConstantStruct *c = dyn_cast(clgv->getInitializer()); if (!c) return; @@ -258,8 +245,7 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) { entry.setValue(info); } - -// Parse i386/ppc ObjC class list data structure. +/// addObjCClassRef - Parse i386/ppc ObjC class list data structure. void LTOModule::addObjCClassRef(GlobalVariable *clgv) { std::string targetclassName; if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) @@ -277,7 +263,7 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) { entry.setValue(info); } - +/// addDefinedDataSymbol - Add a data symbol as defined to the list. void LTOModule::addDefinedDataSymbol(GlobalValue *v) { // Add to list of defined symbols. addDefinedSymbol(v, false); @@ -325,6 +311,13 @@ void LTOModule::addDefinedDataSymbol(GlobalValue *v) { } } +/// addDefinedFunctionSymbol - Add a function symbol as defined to the list. +void LTOModule::addDefinedFunctionSymbol(Function *f) { + // add to list of defined symbols + addDefinedSymbol(f, true); +} + +/// addDefinedSymbol - Add a defined symbol to the list. void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { // ignore all llvm.* symbols if (def->getName().startswith("llvm.")) @@ -385,6 +378,8 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { _symbols.push_back(info); } +/// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the +/// defined list. void LTOModule::addAsmGlobalSymbol(const char *name, lto_symbol_attributes scope) { StringSet::value_type &entry = _defines.GetOrCreateValue(name); @@ -403,6 +398,8 @@ void LTOModule::addAsmGlobalSymbol(const char *name, _symbols.push_back(info); } +/// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the +/// undefined list. void LTOModule::addAsmGlobalSymbolUndef(const char *name) { StringMap::value_type &entry = _undefines.GetOrCreateValue(name); @@ -422,6 +419,8 @@ void LTOModule::addAsmGlobalSymbolUndef(const char *name) { entry.setValue(info); } +/// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a +/// list to be resolved later. void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) { // ignore all llvm.* symbols if (decl->getName().startswith("llvm.")) @@ -444,6 +443,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) { NameAndAttributes info; info.name = entry.getKey().data(); + if (decl->hasExternalWeakLinkage()) info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; else @@ -607,6 +607,8 @@ namespace { }; } +/// addAsmGlobalSymbols - Add global symbols from module-level ASM to the +/// defined or undefined lists. bool LTOModule::addAsmGlobalSymbols(std::string &errMsg) { const std::string &inlineAsm = _module->getModuleInlineAsm(); if (inlineAsm.empty()) @@ -651,6 +653,7 @@ bool LTOModule::addAsmGlobalSymbols(std::string &errMsg) { return false; } +/// isDeclaration - Return 'true' if the global value is a declaration. static bool isDeclaration(const GlobalValue &V) { if (V.hasAvailableExternallyLinkage()) return true; @@ -659,10 +662,14 @@ static bool isDeclaration(const GlobalValue &V) { return V.isDeclaration(); } +/// isAliasToDeclaration - Return 'true' if the global value is an alias to a +/// declaration. static bool isAliasToDeclaration(const GlobalAlias &V) { return isDeclaration(*V.getAliasedGlobal()); } +/// ParseSymbols - Parse the symbols from the module and model-level ASM and add +/// them to either the defined or undefined lists. bool LTOModule::ParseSymbols(std::string &errMsg) { // add functions for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { @@ -706,21 +713,3 @@ bool LTOModule::ParseSymbols(std::string &errMsg) { } return false; } - -uint32_t LTOModule::getSymbolCount() { - return _symbols.size(); -} - -lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) { - if (index < _symbols.size()) - return _symbols[index].attributes; - else - return lto_symbol_attributes(0); -} - -const char *LTOModule::getSymbolName(uint32_t index) { - if (index < _symbols.size()) - return _symbols[index].name; - else - return NULL; -} diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index b7f2d5e..22f2c5a 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -29,90 +29,166 @@ // forward references to llvm classes namespace llvm { - class MemoryBuffer; + class Function; class GlobalValue; + class MemoryBuffer; class Value; - class Function; } // // C++ class which implements the opaque lto_module_t // struct LTOModule { +private: + typedef llvm::StringMap StringSet; + + struct NameAndAttributes { + enum name_type { IsFunction, IsData }; + const char* name; + lto_symbol_attributes attributes; + }; + + llvm::OwningPtr _module; + llvm::OwningPtr _target; + std::vector _symbols; + + // _defines and _undefines only needed to disambiguate tentative definitions + StringSet _defines; + llvm::StringMap _undefines; + std::vector _asm_undefines; + llvm::MCContext _context; + + // Use mangler to add GlobalPrefix to names to match linker names. + llvm::Mangler _mangler; - static bool isBitcodeFile(const void* mem, size_t length); - static bool isBitcodeFile(const char* path); - static bool isBitcodeFileForTarget(const void* mem, + LTOModule(llvm::Module *m, llvm::TargetMachine *t); +public: + /// isBitcodeFile - Returns 'true' if the file or memory contents is LLVM + /// bitcode. + static bool isBitcodeFile(const void *mem, size_t length); + static bool isBitcodeFile(const char *path); + + /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents + /// is LLVM bitcode for the specified triple. + static bool isBitcodeFileForTarget(const void *mem, size_t length, - const char* triplePrefix); - static bool isBitcodeFileForTarget(const char* path, - const char* triplePrefix); + const char *triplePrefix); + static bool isBitcodeFileForTarget(const char *path, + const char *triplePrefix); + + /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership + /// of the buffer. static LTOModule* makeLTOModule(const char* path, - std::string& errMsg); + std::string &errMsg); static LTOModule* makeLTOModule(int fd, const char *path, size_t size, - std::string& errMsg); + std::string &errMsg); static LTOModule* makeLTOModule(int fd, const char *path, size_t file_size, size_t map_size, off_t offset, std::string& errMsg); - static LTOModule* makeLTOModule(const void* mem, size_t length, - std::string& errMsg); - const char* getTargetTriple(); - void setTargetTriple(const char*); - uint32_t getSymbolCount(); - lto_symbol_attributes getSymbolAttributes(uint32_t index); - const char* getSymbolName(uint32_t index); + static LTOModule* makeLTOModule(const void *mem, size_t length, + std::string &errMsg); + + /// getTargetTriple - Return the Module's target triple. + const char* getTargetTriple() { + return _module->getTargetTriple().c_str(); + } + + /// setTargetTriple - Set the Module's target triple. + void setTargetTriple(const char *triple) { + _module->setTargetTriple(triple); + } + + /// getSymbolCount - Get the number of symbols + uint32_t getSymbolCount() { + return _symbols.size(); + } + + /// getSymbolAttributes - Get the attributes for a symbol at the specified + /// index. + lto_symbol_attributes getSymbolAttributes(uint32_t index) { + if (index < _symbols.size()) + return _symbols[index].attributes; + else + return lto_symbol_attributes(0); + } + + /// getSymbolName - Get the name of the symbol at the specified index. + const char* getSymbolName(uint32_t index) { + if (index < _symbols.size()) + return _symbols[index].name; + else + return NULL; + } + + /// getLLVVMModule - Return the Module. llvm::Module * getLLVVMModule() { return _module.get(); } + + /// getAsmUndefinedRefs - const std::vector &getAsmUndefinedRefs() { return _asm_undefines; } private: - LTOModule(llvm::Module* m, llvm::TargetMachine* t); - + /// ParseSymbols - Parse the symbols from the module and model-level ASM and + /// add them to either the defined or undefined lists. bool ParseSymbols(std::string &errMsg); - void addDefinedSymbol(llvm::GlobalValue* def, + + /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet + /// to a list to be resolved later. + void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl); + + /// addDefinedSymbol - Add a defined symbol to the list. + void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction); - void addPotentialUndefinedSymbol(llvm::GlobalValue* decl); - void addDefinedFunctionSymbol(llvm::Function* f); - void addDefinedDataSymbol(llvm::GlobalValue* v); + + /// addDefinedFunctionSymbol - Add a function symbol as defined to the list. + void addDefinedFunctionSymbol(llvm::Function *f); + + /// addDefinedDataSymbol - Add a data symbol as defined to the list. + void addDefinedDataSymbol(llvm::GlobalValue *v); + + /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the + /// defined or undefined lists. bool addAsmGlobalSymbols(std::string &errMsg); + + /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the + /// defined list. void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope); + + /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to + /// the undefined list. void addAsmGlobalSymbolUndef(const char *); - void addObjCClass(llvm::GlobalVariable* clgv); - void addObjCCategory(llvm::GlobalVariable* clgv); - void addObjCClassRef(llvm::GlobalVariable* clgv); - bool objcClassNameFromExpression(llvm::Constant* c, - std::string& name); - - static bool isTargetMatch(llvm::MemoryBuffer* memBuffer, - const char* triplePrefix); - static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer, - std::string& errMsg); - static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length); - typedef llvm::StringMap StringSet; - - struct NameAndAttributes { - const char* name; - lto_symbol_attributes attributes; - }; + /// addObjCClass - Parse i386/ppc ObjC class data structure. + void addObjCClass(llvm::GlobalVariable *clgv); - llvm::OwningPtr _module; - llvm::OwningPtr _target; - std::vector _symbols; + /// addObjCCategory - Parse i386/ppc ObjC category data structure. + void addObjCCategory(llvm::GlobalVariable *clgv); - // _defines and _undefines only needed to disambiguate tentative definitions - StringSet _defines; - llvm::StringMap _undefines; - std::vector _asm_undefines; - llvm::MCContext _context; + /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. + void addObjCClassRef(llvm::GlobalVariable *clgv); - // Use mangler to add GlobalPrefix to names to match linker names. - llvm::Mangler _mangler; + /// objcClassNameFromExpression - Get string that the data pointer points + /// to. + bool objcClassNameFromExpression(llvm::Constant* c, + std::string &name); + + /// isTargetMatch - Returns 'true' if the memory buffer is for the specified + /// target triple. + static bool isTargetMatch(llvm::MemoryBuffer *memBuffer, + const char *triplePrefix); + + /// makeLTOModule - Create an LTOModule (private version). N.B. This + /// method takes ownership of the buffer. + static LTOModule* makeLTOModule(llvm::MemoryBuffer *buffer, + std::string &errMsg); + + /// makeBuffer - Create a MemoryBuffer from a memory range. + static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length); }; #endif // LTO_MODULE_H -- cgit v1.1 From 61476d6f90b772c0e6c725308199afe10743ce0e Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 28 Mar 2012 20:48:49 +0000 Subject: Inline function into its one caller. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153598 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 5e51da0..aa5aacd 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -662,12 +662,6 @@ static bool isDeclaration(const GlobalValue &V) { return V.isDeclaration(); } -/// isAliasToDeclaration - Return 'true' if the global value is an alias to a -/// declaration. -static bool isAliasToDeclaration(const GlobalAlias &V) { - return isDeclaration(*V.getAliasedGlobal()); -} - /// ParseSymbols - Parse the symbols from the module and model-level ASM and add /// them to either the defined or undefined lists. bool LTOModule::ParseSymbols(std::string &errMsg) { @@ -695,7 +689,8 @@ bool LTOModule::ParseSymbols(std::string &errMsg) { // add aliases for (Module::alias_iterator i = _module->alias_begin(), e = _module->alias_end(); i != e; ++i) { - if (isAliasToDeclaration(*i)) + if (isDeclaration(*i->getAliasedGlobal())) + // Is an alias to a declaration. addPotentialUndefinedSymbol(i); else addDefinedDataSymbol(i); -- cgit v1.1 From 30b9e322e159df8eaabb5b194cec6e11ba99c261 Mon Sep 17 00:00:00 2001 From: Danil Malyshev Date: Wed, 28 Mar 2012 21:46:36 +0000 Subject: Move getPointerToNamedFunction() from JIT/MCJIT to JITMemoryManager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153607 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tools') diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 990582d..a21fc13 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -61,6 +61,12 @@ public: uint8_t *startFunctionBody(const char *Name, uintptr_t &Size); void endFunctionBody(const char *Name, uint8_t *FunctionStart, uint8_t *FunctionEnd); + + virtual void *getPointerToNamedFunction(const std::string &Name, + bool AbortOnFailure = true) { + return 0; + } + }; uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size, -- cgit v1.1 From 3bb17380b1c87fa23ef9fe208ce6f56d352df611 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 28 Mar 2012 23:12:18 +0000 Subject: Cleanup some whitespaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153612 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 6 +- tools/lto/LTOModule.h | 262 ++++++++++++++++++++++++------------------------ 2 files changed, 132 insertions(+), 136 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index aa5aacd..9c35fa0 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -158,7 +158,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr, Options); LTOModule *Ret = new LTOModule(m.take(), target); - if (Ret->ParseSymbols(errMsg)) { + if (Ret->parseSymbols(errMsg)) { delete Ret; return NULL; } @@ -662,9 +662,9 @@ static bool isDeclaration(const GlobalValue &V) { return V.isDeclaration(); } -/// ParseSymbols - Parse the symbols from the module and model-level ASM and add +/// parseSymbols - Parse the symbols from the module and model-level ASM and add /// them to either the defined or undefined lists. -bool LTOModule::ParseSymbols(std::string &errMsg) { +bool LTOModule::parseSymbols(std::string &errMsg) { // add functions for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { if (isDeclaration(*f)) diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 22f2c5a..157d325 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -27,7 +27,7 @@ #include -// forward references to llvm classes +// Forward references to llvm classes. namespace llvm { class Function; class GlobalValue; @@ -36,159 +36,155 @@ namespace llvm { } // -// C++ class which implements the opaque lto_module_t +// C++ class which implements the opaque lto_module_t type. // struct LTOModule { private: - typedef llvm::StringMap StringSet; + typedef llvm::StringMap StringSet; - struct NameAndAttributes { - enum name_type { IsFunction, IsData }; - const char* name; - lto_symbol_attributes attributes; - }; - - llvm::OwningPtr _module; - llvm::OwningPtr _target; - std::vector _symbols; - - // _defines and _undefines only needed to disambiguate tentative definitions - StringSet _defines; - llvm::StringMap _undefines; - std::vector _asm_undefines; - llvm::MCContext _context; - - // Use mangler to add GlobalPrefix to names to match linker names. - llvm::Mangler _mangler; - - LTOModule(llvm::Module *m, llvm::TargetMachine *t); + struct NameAndAttributes { + enum name_type { IsFunction, IsData }; + const char* name; + lto_symbol_attributes attributes; + }; + + llvm::OwningPtr _module; + llvm::OwningPtr _target; + std::vector _symbols; + + // _defines and _undefines only needed to disambiguate tentative definitions + StringSet _defines; + llvm::StringMap _undefines; + std::vector _asm_undefines; + llvm::MCContext _context; + + // Use mangler to add GlobalPrefix to names to match linker names. + llvm::Mangler _mangler; + + LTOModule(llvm::Module *m, llvm::TargetMachine *t); public: - /// isBitcodeFile - Returns 'true' if the file or memory contents is LLVM - /// bitcode. - static bool isBitcodeFile(const void *mem, size_t length); - static bool isBitcodeFile(const char *path); - - /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents - /// is LLVM bitcode for the specified triple. - static bool isBitcodeFileForTarget(const void *mem, - size_t length, - const char *triplePrefix); - static bool isBitcodeFileForTarget(const char *path, - const char *triplePrefix); - - /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership - /// of the buffer. - static LTOModule* makeLTOModule(const char* path, - std::string &errMsg); - static LTOModule* makeLTOModule(int fd, const char *path, - size_t size, - std::string &errMsg); - static LTOModule* makeLTOModule(int fd, const char *path, - size_t file_size, - size_t map_size, - off_t offset, - std::string& errMsg); - static LTOModule* makeLTOModule(const void *mem, size_t length, - std::string &errMsg); - - /// getTargetTriple - Return the Module's target triple. - const char* getTargetTriple() { - return _module->getTargetTriple().c_str(); - } - - /// setTargetTriple - Set the Module's target triple. - void setTargetTriple(const char *triple) { - _module->setTargetTriple(triple); - } - - /// getSymbolCount - Get the number of symbols - uint32_t getSymbolCount() { - return _symbols.size(); - } - - /// getSymbolAttributes - Get the attributes for a symbol at the specified - /// index. - lto_symbol_attributes getSymbolAttributes(uint32_t index) { - if (index < _symbols.size()) - return _symbols[index].attributes; - else - return lto_symbol_attributes(0); - } - - /// getSymbolName - Get the name of the symbol at the specified index. - const char* getSymbolName(uint32_t index) { - if (index < _symbols.size()) - return _symbols[index].name; - else - return NULL; - } - - /// getLLVVMModule - Return the Module. - llvm::Module * getLLVVMModule() { return _module.get(); } - - /// getAsmUndefinedRefs - - const std::vector &getAsmUndefinedRefs() { - return _asm_undefines; - } + /// isBitcodeFile - Returns 'true' if the file or memory contents is LLVM + /// bitcode. + static bool isBitcodeFile(const void *mem, size_t length); + static bool isBitcodeFile(const char *path); + + /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents + /// is LLVM bitcode for the specified triple. + static bool isBitcodeFileForTarget(const void *mem, + size_t length, + const char *triplePrefix); + static bool isBitcodeFileForTarget(const char *path, + const char *triplePrefix); + + /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership + /// of the buffer. + static LTOModule *makeLTOModule(const char* path, + std::string &errMsg); + static LTOModule *makeLTOModule(int fd, const char *path, + size_t size, std::string &errMsg); + static LTOModule *makeLTOModule(int fd, const char *path, + size_t file_size, + size_t map_size, + off_t offset, + std::string& errMsg); + static LTOModule *makeLTOModule(const void *mem, size_t length, + std::string &errMsg); + + /// getTargetTriple - Return the Module's target triple. + const char *getTargetTriple() { + return _module->getTargetTriple().c_str(); + } + + /// setTargetTriple - Set the Module's target triple. + void setTargetTriple(const char *triple) { + _module->setTargetTriple(triple); + } + + /// getSymbolCount - Get the number of symbols + uint32_t getSymbolCount() { + return _symbols.size(); + } + + /// getSymbolAttributes - Get the attributes for a symbol at the specified + /// index. + lto_symbol_attributes getSymbolAttributes(uint32_t index) { + if (index < _symbols.size()) + return _symbols[index].attributes; + else + return lto_symbol_attributes(0); + } + + /// getSymbolName - Get the name of the symbol at the specified index. + const char *getSymbolName(uint32_t index) { + if (index < _symbols.size()) + return _symbols[index].name; + else + return NULL; + } + + /// getLLVVMModule - Return the Module. + llvm::Module *getLLVVMModule() { return _module.get(); } + + /// getAsmUndefinedRefs - + const std::vector &getAsmUndefinedRefs() { + return _asm_undefines; + } private: - /// ParseSymbols - Parse the symbols from the module and model-level ASM and - /// add them to either the defined or undefined lists. - bool ParseSymbols(std::string &errMsg); + /// parseSymbols - Parse the symbols from the module and model-level ASM and + /// add them to either the defined or undefined lists. + bool parseSymbols(std::string &errMsg); - /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet - /// to a list to be resolved later. - void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl); + /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet + /// to a list to be resolved later. + void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl); - /// addDefinedSymbol - Add a defined symbol to the list. - void addDefinedSymbol(llvm::GlobalValue *def, - bool isFunction); + /// addDefinedSymbol - Add a defined symbol to the list. + void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction); - /// addDefinedFunctionSymbol - Add a function symbol as defined to the list. - void addDefinedFunctionSymbol(llvm::Function *f); + /// addDefinedFunctionSymbol - Add a function symbol as defined to the list. + void addDefinedFunctionSymbol(llvm::Function *f); - /// addDefinedDataSymbol - Add a data symbol as defined to the list. - void addDefinedDataSymbol(llvm::GlobalValue *v); + /// addDefinedDataSymbol - Add a data symbol as defined to the list. + void addDefinedDataSymbol(llvm::GlobalValue *v); - /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the - /// defined or undefined lists. - bool addAsmGlobalSymbols(std::string &errMsg); + /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the + /// defined or undefined lists. + bool addAsmGlobalSymbols(std::string &errMsg); - /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the - /// defined list. - void addAsmGlobalSymbol(const char *, - lto_symbol_attributes scope); + /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the + /// defined list. + void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope); - /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to - /// the undefined list. - void addAsmGlobalSymbolUndef(const char *); + /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to + /// the undefined list. + void addAsmGlobalSymbolUndef(const char *); - /// addObjCClass - Parse i386/ppc ObjC class data structure. - void addObjCClass(llvm::GlobalVariable *clgv); + /// addObjCClass - Parse i386/ppc ObjC class data structure. + void addObjCClass(llvm::GlobalVariable *clgv); - /// addObjCCategory - Parse i386/ppc ObjC category data structure. - void addObjCCategory(llvm::GlobalVariable *clgv); + /// addObjCCategory - Parse i386/ppc ObjC category data structure. + void addObjCCategory(llvm::GlobalVariable *clgv); - /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. - void addObjCClassRef(llvm::GlobalVariable *clgv); + /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. + void addObjCClassRef(llvm::GlobalVariable *clgv); - /// objcClassNameFromExpression - Get string that the data pointer points - /// to. - bool objcClassNameFromExpression(llvm::Constant* c, - std::string &name); + /// objcClassNameFromExpression - Get string that the data pointer points + /// to. + bool objcClassNameFromExpression(llvm::Constant* c, std::string &name); - /// isTargetMatch - Returns 'true' if the memory buffer is for the specified - /// target triple. - static bool isTargetMatch(llvm::MemoryBuffer *memBuffer, - const char *triplePrefix); + /// isTargetMatch - Returns 'true' if the memory buffer is for the specified + /// target triple. + static bool isTargetMatch(llvm::MemoryBuffer *memBuffer, + const char *triplePrefix); - /// makeLTOModule - Create an LTOModule (private version). N.B. This - /// method takes ownership of the buffer. - static LTOModule* makeLTOModule(llvm::MemoryBuffer *buffer, - std::string &errMsg); + /// makeLTOModule - Create an LTOModule (private version). N.B. This + /// method takes ownership of the buffer. + static LTOModule *makeLTOModule(llvm::MemoryBuffer *buffer, + std::string &errMsg); - /// makeBuffer - Create a MemoryBuffer from a memory range. - static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length); + /// makeBuffer - Create a MemoryBuffer from a memory range. + static llvm::MemoryBuffer *makeBuffer(const void *mem, size_t length); }; #endif // LTO_MODULE_H -- cgit v1.1 From 9f3b483b814efb536d1ad391e664443333d14179 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 29 Mar 2012 03:34:57 +0000 Subject: Cache the end() iterator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153632 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 9c35fa0..1c06f27 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -666,7 +666,7 @@ static bool isDeclaration(const GlobalValue &V) { /// them to either the defined or undefined lists. bool LTOModule::parseSymbols(std::string &errMsg) { // add functions - for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { + for (Module::iterator f = _module->begin(), e = _module->end(); f != e; ++f) { if (isDeclaration(*f)) addPotentialUndefinedSymbol(f); else @@ -697,8 +697,8 @@ bool LTOModule::parseSymbols(std::string &errMsg) { } // make symbols for all undefines - for (StringMap::iterator it=_undefines.begin(); - it != _undefines.end(); ++it) { + for (StringMap::iterator it=_undefines.begin(), + e = _undefines.end(); it != e; ++it) { // if this symbol also has a definition, then don't make an undefine // because it is a tentative definition if (_defines.count(it->getKey()) == 0) { -- cgit v1.1 From 3c6b29b7e96f4fd0c9f5aae521d52cbf2b4493c2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 29 Mar 2012 04:28:00 +0000 Subject: Cleanup whitespace. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153634 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 157d325..2c52948 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -4,10 +4,10 @@ // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // -// This file declares the LTOModule class. +// This file declares the LTOModule class. // //===----------------------------------------------------------------------===// @@ -41,11 +41,10 @@ namespace llvm { struct LTOModule { private: typedef llvm::StringMap StringSet; - - struct NameAndAttributes { - enum name_type { IsFunction, IsData }; - const char* name; - lto_symbol_attributes attributes; + + struct NameAndAttributes { + const char *name; + uint32_t attributes; }; llvm::OwningPtr _module; @@ -53,7 +52,7 @@ private: std::vector _symbols; // _defines and _undefines only needed to disambiguate tentative definitions - StringSet _defines; + StringSet _defines; llvm::StringMap _undefines; std::vector _asm_undefines; llvm::MCContext _context; @@ -70,10 +69,10 @@ public: /// isBitcodeFileForTarget - Returns 'true' if the file or memory contents /// is LLVM bitcode for the specified triple. - static bool isBitcodeFileForTarget(const void *mem, + static bool isBitcodeFileForTarget(const void *mem, size_t length, const char *triplePrefix); - static bool isBitcodeFileForTarget(const char *path, + static bool isBitcodeFileForTarget(const char *path, const char *triplePrefix); /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership @@ -109,17 +108,15 @@ public: /// index. lto_symbol_attributes getSymbolAttributes(uint32_t index) { if (index < _symbols.size()) - return _symbols[index].attributes; - else - return lto_symbol_attributes(0); + return lto_symbol_attributes(_symbols[index].attributes); + return lto_symbol_attributes(0); } /// getSymbolName - Get the name of the symbol at the specified index. const char *getSymbolName(uint32_t index) { if (index < _symbols.size()) return _symbols[index].name; - else - return NULL; + return NULL; } /// getLLVVMModule - Return the Module. -- cgit v1.1 From 24b878031d4f62baf0e9a0573aeebc9dfd54b546 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 29 Mar 2012 08:27:32 +0000 Subject: Make some headway towards compiling all of LLVM. Module-level ASM may contain definitions of functions and globals. However, we were not telling the linker that these globals had definitions. As far as it was concerned, they were just declarations. Attempt to resolve this by inserting module-level ASM functions and globals into the '_symbol' set so that the linker will know that they have values. This gets us further towards our goal of compiling LLVM, but it still has problems when linking libLTO.dylib because of the `-dead_strip' flag that's passed to the linker. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153638 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 83 +++++++++++++++++++++++++++++-------------------- tools/lto/LTOModule.h | 8 +++-- 2 files changed, 55 insertions(+), 36 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 1c06f27..97e4e54 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -204,6 +204,8 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) { const char *symbolName = entry.getKey().data(); info.name = symbolName; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + info.isFunction = false; + info.symbol = clgv; entry.setValue(info); } } @@ -213,11 +215,13 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) { if (objcClassNameFromExpression(c->getOperand(2), className)) { StringSet::value_type &entry = _defines.GetOrCreateValue(className); entry.setValue(1); + NameAndAttributes info; info.name = entry.getKey().data(); - info.attributes = lto_symbol_attributes(LTO_SYMBOL_PERMISSIONS_DATA | - LTO_SYMBOL_DEFINITION_REGULAR | - LTO_SYMBOL_SCOPE_DEFAULT); + info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | + LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT; + info.isFunction = false; + info.symbol = clgv; _symbols.push_back(info); } } @@ -242,6 +246,8 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) { const char *symbolName = entry.getKey().data(); info.name = symbolName; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + info.isFunction = false; + info.symbol = clgv; entry.setValue(info); } @@ -260,6 +266,8 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) { const char *symbolName = entry.getKey().data(); info.name = symbolName; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + info.isFunction = false; + info.symbol = clgv; entry.setValue(info); } @@ -332,9 +340,9 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0; // set permissions part - if (isFunction) + if (isFunction) { attr |= LTO_SYMBOL_PERMISSIONS_CODE; - else { + } else { GlobalVariable *gv = dyn_cast(def); if (gv && gv->isConstant()) attr |= LTO_SYMBOL_PERMISSIONS_RODATA; @@ -366,15 +374,19 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { else attr |= LTO_SYMBOL_SCOPE_INTERNAL; - // add to table of symbols - NameAndAttributes info; StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer); entry.setValue(1); + // fill information structure + NameAndAttributes info; StringRef Name = entry.getKey(); info.name = Name.data(); assert(info.name[Name.size()] == '\0'); - info.attributes = (lto_symbol_attributes)attr; + info.attributes = attr; + info.isFunction = isFunction; + info.symbol = def; + + // add to table of symbols _symbols.push_back(info); } @@ -389,13 +401,13 @@ void LTOModule::addAsmGlobalSymbol(const char *name, return; entry.setValue(1); - const char *symbolName = entry.getKey().data(); - uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR; - attr |= scope; - NameAndAttributes info; - info.name = symbolName; - info.attributes = (lto_symbol_attributes)attr; - _symbols.push_back(info); + + NameAndAttributes &info = _undefines[entry.getKey().data()]; + + if (info.isFunction) + addDefinedFunctionSymbol(cast(info.symbol)); + else + addDefinedDataSymbol(info.symbol); } /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the @@ -414,14 +426,16 @@ void LTOModule::addAsmGlobalSymbolUndef(const char *name) { attr |= LTO_SYMBOL_SCOPE_DEFAULT; NameAndAttributes info; info.name = entry.getKey().data(); - info.attributes = (lto_symbol_attributes)attr; + info.attributes = attr; + info.isFunction = false; + info.symbol = 0; entry.setValue(info); } /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet to a /// list to be resolved later. -void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) { +void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) { // ignore all llvm.* symbols if (decl->getName().startswith("llvm.")) return; @@ -449,6 +463,9 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) { else info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + info.isFunction = isFunc; + info.symbol = decl; + entry.setValue(info); } @@ -605,7 +622,7 @@ namespace { } virtual void FinishImpl() {} }; -} +} // end anonymous namespace /// addAsmGlobalSymbols - Add global symbols from module-level ASM to the /// defined or undefined lists. @@ -668,7 +685,7 @@ bool LTOModule::parseSymbols(std::string &errMsg) { // add functions for (Module::iterator f = _module->begin(), e = _module->end(); f != e; ++f) { if (isDeclaration(*f)) - addPotentialUndefinedSymbol(f); + addPotentialUndefinedSymbol(f, true); else addDefinedFunctionSymbol(f); } @@ -677,7 +694,7 @@ bool LTOModule::parseSymbols(std::string &errMsg) { for (Module::global_iterator v = _module->global_begin(), e = _module->global_end(); v != e; ++v) { if (isDeclaration(*v)) - addPotentialUndefinedSymbol(v); + addPotentialUndefinedSymbol(v, false); else addDefinedDataSymbol(v); } @@ -687,24 +704,24 @@ bool LTOModule::parseSymbols(std::string &errMsg) { return true; // add aliases - for (Module::alias_iterator i = _module->alias_begin(), - e = _module->alias_end(); i != e; ++i) { - if (isDeclaration(*i->getAliasedGlobal())) + for (Module::alias_iterator a = _module->alias_begin(), + e = _module->alias_end(); a != e; ++a) { + if (isDeclaration(*a->getAliasedGlobal())) // Is an alias to a declaration. - addPotentialUndefinedSymbol(i); + addPotentialUndefinedSymbol(a, false); else - addDefinedDataSymbol(i); + addDefinedDataSymbol(a); } // make symbols for all undefines - for (StringMap::iterator it=_undefines.begin(), - e = _undefines.end(); it != e; ++it) { - // if this symbol also has a definition, then don't make an undefine - // because it is a tentative definition - if (_defines.count(it->getKey()) == 0) { - NameAndAttributes info = it->getValue(); - _symbols.push_back(info); - } + for (StringMap::iterator u =_undefines.begin(), + e = _undefines.end(); u != e; ++u) { + // If this symbol also has a definition, then don't make an undefine because + // it is a tentative definition. + if (_defines.count(u->getKey())) continue; + NameAndAttributes info = u->getValue(); + _symbols.push_back(info); } + return false; } diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 2c52948..e5f6dea 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -43,8 +43,10 @@ private: typedef llvm::StringMap StringSet; struct NameAndAttributes { - const char *name; - uint32_t attributes; + const char *name; + uint32_t attributes; + bool isFunction; + llvm::GlobalValue *symbol; }; llvm::OwningPtr _module; @@ -134,7 +136,7 @@ private: /// addPotentialUndefinedSymbol - Add a symbol which isn't defined just yet /// to a list to be resolved later. - void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl); + void addPotentialUndefinedSymbol(llvm::GlobalValue *dcl, bool isFunc); /// addDefinedSymbol - Add a defined symbol to the list. void addDefinedSymbol(llvm::GlobalValue *def, bool isFunction); -- cgit v1.1 From 4b0b8ef1b0edc2c343145f6b029c43b00a6f5c13 Mon Sep 17 00:00:00 2001 From: Danil Malyshev Date: Thu, 29 Mar 2012 21:46:18 +0000 Subject: Re-factored RuntimeDyld. Added ExecutionEngine/MCJIT tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153694 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'tools') diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index a21fc13..01a7d15 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -58,10 +58,6 @@ public: uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); - uint8_t *startFunctionBody(const char *Name, uintptr_t &Size); - void endFunctionBody(const char *Name, uint8_t *FunctionStart, - uint8_t *FunctionEnd); - virtual void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true) { return 0; @@ -81,18 +77,6 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); } -uint8_t *TrivialMemoryManager::startFunctionBody(const char *Name, - uintptr_t &Size) { - return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); -} - -void TrivialMemoryManager::endFunctionBody(const char *Name, - uint8_t *FunctionStart, - uint8_t *FunctionEnd) { - uintptr_t Size = FunctionEnd - FunctionStart + 1; - FunctionMemory.push_back(sys::MemoryBlock(FunctionStart, Size)); -} - static const char *ProgramName; static void Message(const char *Type, const Twine &Msg) { -- cgit v1.1 From 288967dfac246c8e35dc4f85afb667e74d1d26a8 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 29 Mar 2012 23:23:59 +0000 Subject: Revert r153694. It was causing failures in the buildbots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153701 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tools') diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 01a7d15..a21fc13 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -58,6 +58,10 @@ public: uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); + uint8_t *startFunctionBody(const char *Name, uintptr_t &Size); + void endFunctionBody(const char *Name, uint8_t *FunctionStart, + uint8_t *FunctionEnd); + virtual void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true) { return 0; @@ -77,6 +81,18 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); } +uint8_t *TrivialMemoryManager::startFunctionBody(const char *Name, + uintptr_t &Size) { + return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); +} + +void TrivialMemoryManager::endFunctionBody(const char *Name, + uint8_t *FunctionStart, + uint8_t *FunctionEnd) { + uintptr_t Size = FunctionEnd - FunctionStart + 1; + FunctionMemory.push_back(sys::MemoryBlock(FunctionStart, Size)); +} + static const char *ProgramName; static void Message(const char *Type, const Twine &Msg) { -- cgit v1.1 From 8fd3fcdba8be962aad1ed48bedbfddffc238c657 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 30 Mar 2012 10:29:38 +0000 Subject: Cleanup whitespace. Doxygenize comments. And indent to llvm coding standards. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153740 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/lto.cpp | 333 +++++++++++++++++++----------------------------------- 1 file changed, 119 insertions(+), 214 deletions(-) (limited to 'tools') diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index dd658d1..ec67a93 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -4,10 +4,10 @@ // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // -// This file implements the Link Time Optimization library. This library is +// This file implements the Link Time Optimization library. This library is // intended to be used by linker to optimize code at link time. // //===----------------------------------------------------------------------===// @@ -19,277 +19,185 @@ #include "LTOCodeGenerator.h" -// holds most recent error string -// *** not thread safe *** +// Holds most recent error string. +// *** Not thread safe *** static std::string sLastErrorString; - - -// -// returns a printable string -// -extern const char* lto_get_version() -{ - return LTOCodeGenerator::getVersionString(); +/// lto_get_version - Returns a printable string. +extern const char* lto_get_version() { + return LTOCodeGenerator::getVersionString(); } -// -// returns the last error string or NULL if last operation was successful -// -const char* lto_get_error_message() -{ - return sLastErrorString.c_str(); +/// lto_get_error_message - Returns the last error string or NULL if last +/// operation was successful. +const char* lto_get_error_message() { + return sLastErrorString.c_str(); } - - -// -// validates if a file is a loadable object file -// -bool lto_module_is_object_file(const char* path) -{ - return LTOModule::isBitcodeFile(path); +/// lto_module_is_object_file - Validates if a file is a loadable object file. +bool lto_module_is_object_file(const char* path) { + return LTOModule::isBitcodeFile(path); } - -// -// validates if a file is a loadable object file compilable for requested target -// -bool lto_module_is_object_file_for_target(const char* path, - const char* target_triplet_prefix) -{ - return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix); +/// lto_module_is_object_file_for_target - Validates if a file is a loadable +/// object file compilable for requested target. +bool lto_module_is_object_file_for_target(const char* path, + const char* target_triplet_prefix) { + return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix); } - -// -// validates if a buffer is a loadable object file -// -bool lto_module_is_object_file_in_memory(const void* mem, size_t length) -{ - return LTOModule::isBitcodeFile(mem, length); +/// lto_module_is_object_file_in_memory - Validates if a buffer is a loadable +/// object file. +bool lto_module_is_object_file_in_memory(const void* mem, size_t length) { + return LTOModule::isBitcodeFile(mem, length); } - -// -// validates if a buffer is a loadable object file compilable for the target -// -bool lto_module_is_object_file_in_memory_for_target(const void* mem, - size_t length, const char* target_triplet_prefix) -{ - return LTOModule::isBitcodeFileForTarget(mem, length, target_triplet_prefix); +/// lto_module_is_object_file_in_memory_for_target - Validates if a buffer is a +/// loadable object file compilable for the target. +bool +lto_module_is_object_file_in_memory_for_target(const void* mem, + size_t length, + const char* target_triplet_prefix) { + return LTOModule::isBitcodeFileForTarget(mem, length, target_triplet_prefix); } - - -// -// loads an object file from disk -// returns NULL on error (check lto_get_error_message() for details) -// -lto_module_t lto_module_create(const char* path) -{ - return LTOModule::makeLTOModule(path, sLastErrorString); +/// lto_module_create - Loads an object file from disk. Returns NULL on error +/// (check lto_get_error_message() for details). +lto_module_t lto_module_create(const char* path) { + return LTOModule::makeLTOModule(path, sLastErrorString); } -// -// loads an object file from disk -// returns NULL on error (check lto_get_error_message() for details) -// -lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) -{ - return LTOModule::makeLTOModule(fd, path, size, sLastErrorString); +/// lto_module_create_from_fd - Loads an object file from disk. Returns NULL on +/// error (check lto_get_error_message() for details). +lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) { + return LTOModule::makeLTOModule(fd, path, size, sLastErrorString); } -// -// loads an object file from disk -// returns NULL on error (check lto_get_error_message() for details) -// +/// lto_module_create_from_fd_at_offset - Loads an object file from disk. +/// Returns NULL on error (check lto_get_error_message() for details). lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, size_t map_size, - off_t offset) -{ - return LTOModule::makeLTOModule(fd, path, file_size, map_size, - offset, sLastErrorString); + off_t offset) { + return LTOModule::makeLTOModule(fd, path, file_size, map_size, + offset, sLastErrorString); } -// -// loads an object file from memory -// returns NULL on error (check lto_get_error_message() for details) -// -lto_module_t lto_module_create_from_memory(const void* mem, size_t length) -{ - return LTOModule::makeLTOModule(mem, length, sLastErrorString); +/// lto_module_create_from_memory - Loads an object file from memory. Returns +/// NULL on error (check lto_get_error_message() for details). +lto_module_t lto_module_create_from_memory(const void* mem, size_t length) { + return LTOModule::makeLTOModule(mem, length, sLastErrorString); } - -// -// frees all memory for a module -// upon return the lto_module_t is no longer valid -// -void lto_module_dispose(lto_module_t mod) -{ - delete mod; +/// lto_module_dispose - Frees all memory for a module. Upon return the +/// lto_module_t is no longer valid. +void lto_module_dispose(lto_module_t mod) { + delete mod; } - -// -// returns triplet string which the object module was compiled under -// -const char* lto_module_get_target_triple(lto_module_t mod) -{ - return mod->getTargetTriple(); +/// lto_module_get_target_triple - Returns triplet string which the object +/// module was compiled under. +const char* lto_module_get_target_triple(lto_module_t mod) { + return mod->getTargetTriple(); } -// -// sets triple string with which the object will be codegened. -// -void lto_module_set_target_triple(lto_module_t mod, const char *triple) -{ - return mod->setTargetTriple(triple); +/// lto_module_set_target_triple - Sets triple string with which the object will +/// be codegened. +void lto_module_set_target_triple(lto_module_t mod, const char *triple) { + return mod->setTargetTriple(triple); } - -// -// returns the number of symbols in the object module -// -unsigned int lto_module_get_num_symbols(lto_module_t mod) -{ - return mod->getSymbolCount(); +/// lto_module_get_num_symbols - Returns the number of symbols in the object +/// module. +unsigned int lto_module_get_num_symbols(lto_module_t mod) { + return mod->getSymbolCount(); } -// -// returns the name of the ith symbol in the object module -// -const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) -{ - return mod->getSymbolName(index); +/// lto_module_get_symbol_name - Returns the name of the ith symbol in the +/// object module. +const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) { + return mod->getSymbolName(index); } - -// -// returns the attributes of the ith symbol in the object module -// -lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, - unsigned int index) -{ - return mod->getSymbolAttributes(index); +/// lto_module_get_symbol_attribute - Returns the attributes of the ith symbol +/// in the object module. +lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, + unsigned int index) { + return mod->getSymbolAttributes(index); } - - - - -// -// instantiates a code generator -// returns NULL if there is an error -// -lto_code_gen_t lto_codegen_create(void) -{ - return new LTOCodeGenerator(); +/// lto_codegen_create - Instantiates a code generator. Returns NULL if there +/// is an error. +lto_code_gen_t lto_codegen_create(void) { + return new LTOCodeGenerator(); } - - -// -// frees all memory for a code generator -// upon return the lto_code_gen_t is no longer valid -// -void lto_codegen_dispose(lto_code_gen_t cg) -{ - delete cg; +/// lto_codegen_dispose - Frees all memory for a code generator. Upon return the +/// lto_code_gen_t is no longer valid. +void lto_codegen_dispose(lto_code_gen_t cg) { + delete cg; } - - -// -// add an object module to the set of modules for which code will be generated -// returns true on error (check lto_get_error_message() for details) -// -bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) -{ - return cg->addModule(mod, sLastErrorString); +/// lto_codegen_add_module - Add an object module to the set of modules for +/// which code will be generated. Returns true on error (check +/// lto_get_error_message() for details). +bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) { + return cg->addModule(mod, sLastErrorString); } - -// -// sets what if any format of debug info should be generated -// returns true on error (check lto_get_error_message() for details) -// -bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) -{ - return cg->setDebugInfo(debug, sLastErrorString); +/// lto_codegen_set_debug_model - Sets what if any format of debug info should +/// be generated. Returns true on error (check lto_get_error_message() for +/// details). +bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) { + return cg->setDebugInfo(debug, sLastErrorString); } - -// -// sets what code model to generated -// returns true on error (check lto_get_error_message() for details) -// -bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) -{ +/// lto_codegen_set_pic_model - Sets what code model to generated. Returns true +/// on error (check lto_get_error_message() for details). +bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) { return cg->setCodePICModel(model, sLastErrorString); } -// -// sets the cpu to generate code for -// -void lto_codegen_set_cpu(lto_code_gen_t cg, const char* cpu) -{ +/// lto_codegen_set_cpu - Sets the cpu to generate code for. +void lto_codegen_set_cpu(lto_code_gen_t cg, const char* cpu) { return cg->setCpu(cpu); } -// -// sets the path to the assembler tool -// -void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path) -{ +/// lto_codegen_set_assembler_path - Sets the path to the assembler tool. +void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) { // In here only for backwards compatibility. We use MC now. } - -// -// sets extra arguments that libLTO should pass to the assembler -// +/// lto_codegen_set_assembler_args - Sets extra arguments that libLTO should +/// pass to the assembler. void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char** args, - int nargs) -{ + int nargs) { // In here only for backwards compatibility. We use MC now. } -// -// adds to a list of all global symbols that must exist in the final -// generated code. If a function is not listed there, it might be -// inlined into every usage and optimized away. -// -void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol) -{ +/// lto_codegen_add_must_preserve_symbol - Adds to a list of all global symbols +/// that must exist in the final generated code. If a function is not listed +/// there, it might be inlined into every usage and optimized away. +void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, + const char* symbol) { cg->addMustPreserveSymbol(symbol); } - -// -// writes a new file at the specified path that contains the -// merged contents of all modules added so far. -// returns true on error (check lto_get_error_message() for details) -// -bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) -{ +/// lto_codegen_write_merged_modules - Writes a new file at the specified path +/// that contains the merged contents of all modules added so far. Returns true +/// on error (check lto_get_error_message() for details). +bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) { return cg->writeMergedModules(path, sLastErrorString); } - -// -// Generates code for all added modules into one native object file. -// On success returns a pointer to a generated mach-o/ELF buffer and -// length set to the buffer size. The buffer is owned by the -// lto_code_gen_t and will be freed when lto_codegen_dispose() -// is called, or lto_codegen_compile() is called again. -// On failure, returns NULL (check lto_get_error_message() for details). -// +/// lto_codegen_compile - Generates code for all added modules into one native +/// object file. On success returns a pointer to a generated mach-o/ELF buffer +/// and length set to the buffer size. The buffer is owned by the lto_code_gen_t +/// object and will be freed when lto_codegen_dispose() is called, or +/// lto_codegen_compile() is called again. On failure, returns NULL (check +/// lto_get_error_message() for details). extern const void* -lto_codegen_compile(lto_code_gen_t cg, size_t* length) -{ +lto_codegen_compile(lto_code_gen_t cg, size_t* length) { return cg->compile(length, sLastErrorString); } @@ -299,12 +207,9 @@ lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) return cg->compile_to_file(name, sLastErrorString); } - -// -// Used to pass extra options to the code generator -// +/// lto_codegen_debug_options - Used to pass extra options to the code +/// generator. extern void -lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) -{ +lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) { cg->setCodeGenDebugOptions(opt); } -- cgit v1.1 From 0e4fa5ff365fccff46870b7d5d8d4d1d46e77986 Mon Sep 17 00:00:00 2001 From: Danil Malyshev Date: Fri, 30 Mar 2012 16:45:19 +0000 Subject: Re-factored RuntimeDyLd: 1. The main works will made in the RuntimeDyLdImpl with uses the ObjectFile class. RuntimeDyLdMachO and RuntimeDyLdELF now only parses relocations and resolve it. This is allows to make improvements of the RuntimeDyLd more easily. In addition the support for COFF can be easily added. 2. Added ARM relocations to RuntimeDyLdELF. 3. Added support for stub functions for the ARM, allowing to do a long branch. 4. Added support for external functions that are not loaded from the object files, but can be loaded from external libraries. Now MCJIT can correctly execute the code containing the printf, putc, and etc. 5. The sections emitted instead functions, thanks Jim Grosbach. MemoryManager.startFunctionBody() and MemoryManager.endFunctionBody() have been removed. 6. MCJITMemoryManager.allocateDataSection() and MCJITMemoryManager. allocateCodeSection() used JMM->allocateSpace() instead of JMM->allocateCodeSection() and JMM->allocateDataSection(), because I got an error: "Cannot allocate an allocated block!" with object file contains more than one code or data sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153754 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'tools') diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index a21fc13..01a7d15 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -58,10 +58,6 @@ public: uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID); - uint8_t *startFunctionBody(const char *Name, uintptr_t &Size); - void endFunctionBody(const char *Name, uint8_t *FunctionStart, - uint8_t *FunctionEnd); - virtual void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true) { return 0; @@ -81,18 +77,6 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); } -uint8_t *TrivialMemoryManager::startFunctionBody(const char *Name, - uintptr_t &Size) { - return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base(); -} - -void TrivialMemoryManager::endFunctionBody(const char *Name, - uint8_t *FunctionStart, - uint8_t *FunctionEnd) { - uintptr_t Size = FunctionEnd - FunctionStart + 1; - FunctionMemory.push_back(sys::MemoryBlock(FunctionStart, Size)); -} - static const char *ProgramName; static void Message(const char *Type, const Twine &Msg) { -- cgit v1.1 From 5ff4bc20a131cdf6fd0706b7abd80e16efc2f0e7 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 30 Mar 2012 23:26:06 +0000 Subject: * Set the scope attributes for the ASM symbol we added to be the value passed into the function. * Reorder some header files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153783 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 97e4e54..45890a5 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -16,30 +16,31 @@ #include "llvm/Constants.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Support/SystemUtils.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/MathExtras.h" -#include "llvm/Support/Host.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/system_error.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" -#include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/MC/SubtargetFeature.h" #include "llvm/MC/MCTargetAsmParser.h" +#include "llvm/MC/SubtargetFeature.h" +#include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegisterInfo.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/SystemUtils.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/system_error.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/Triple.h" + using namespace llvm; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) @@ -408,6 +409,9 @@ void LTOModule::addAsmGlobalSymbol(const char *name, addDefinedFunctionSymbol(cast(info.symbol)); else addDefinedDataSymbol(info.symbol); + + _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK; + _symbols.back().attributes |= scope; } /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the -- cgit v1.1 From 168f1428346f3d51304db0be64e1d5e4a09ca4c2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 10:44:20 +0000 Subject: Cleanup whitespace and remove unneeded 'extern' keyword on function definitions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153802 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/lto.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index ec67a93..a7e633d 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -159,7 +159,7 @@ bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) { } /// lto_codegen_set_cpu - Sets the cpu to generate code for. -void lto_codegen_set_cpu(lto_code_gen_t cg, const char* cpu) { +void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) { return cg->setCpu(cpu); } @@ -170,7 +170,7 @@ void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) { /// lto_codegen_set_assembler_args - Sets extra arguments that libLTO should /// pass to the assembler. -void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char** args, +void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, int nargs) { // In here only for backwards compatibility. We use MC now. } @@ -179,14 +179,14 @@ void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char** args, /// that must exist in the final generated code. If a function is not listed /// there, it might be inlined into every usage and optimized away. void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, - const char* symbol) { + const char *symbol) { cg->addMustPreserveSymbol(symbol); } /// lto_codegen_write_merged_modules - Writes a new file at the specified path /// that contains the merged contents of all modules added so far. Returns true /// on error (check lto_get_error_message() for details). -bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) { +bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) { return cg->writeMergedModules(path, sLastErrorString); } @@ -196,20 +196,19 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path) { /// object and will be freed when lto_codegen_dispose() is called, or /// lto_codegen_compile() is called again. On failure, returns NULL (check /// lto_get_error_message() for details). -extern const void* -lto_codegen_compile(lto_code_gen_t cg, size_t* length) { +const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) { return cg->compile(length, sLastErrorString); } -extern bool -lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) -{ +/// lto_codegen_compile_to_file - Generates code for all added modules into one +/// native object file. The name of the file is written to name. Returns true on +/// error. +bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { return cg->compile_to_file(name, sLastErrorString); } /// lto_codegen_debug_options - Used to pass extra options to the code /// generator. -extern void -lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) { +void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { cg->setCodeGenDebugOptions(opt); } -- cgit v1.1 From caf71d41851fa9f3efb04123de893c1f7961eed5 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 10:49:43 +0000 Subject: Free the codegen options when deleting LTO code generator object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153803 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 47 +++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 111f8c8..3cc13e2 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -51,24 +51,19 @@ #include #include #include - - using namespace llvm; static cl::opt DisableInline("disable-inlining", cl::desc("Do not run the inliner pass")); - -const char* LTOCodeGenerator::getVersionString() -{ +const char* LTOCodeGenerator::getVersionString() { #ifdef LLVM_VERSION_INFO - return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO; + return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO; #else - return PACKAGE_NAME " version " PACKAGE_VERSION; + return PACKAGE_NAME " version " PACKAGE_VERSION; #endif } - LTOCodeGenerator::LTOCodeGenerator() : _context(getGlobalContext()), _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), @@ -81,13 +76,14 @@ LTOCodeGenerator::LTOCodeGenerator() InitializeAllAsmPrinters(); } -LTOCodeGenerator::~LTOCodeGenerator() -{ - delete _target; - delete _nativeObjectFile; -} - +LTOCodeGenerator::~LTOCodeGenerator() { + delete _target; + delete _nativeObjectFile; + for (std::vector::iterator I = _codegenOptions.begin(), + E = _codegenOptions.end(); I != E; ++I) + free(*I); +} bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { @@ -416,16 +412,15 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, return false; // success } - -/// Optimize merged modules using various IPO passes -void LTOCodeGenerator::setCodeGenDebugOptions(const char* options) -{ - for (std::pair o = getToken(options); - !o.first.empty(); o = getToken(o.second)) { - // ParseCommandLineOptions() expects argv[0] to be program name. - // Lazily add that. - if ( _codegenOptions.empty() ) - _codegenOptions.push_back("libLTO"); - _codegenOptions.push_back(strdup(o.first.str().c_str())); - } +/// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging +/// LTO problems. +void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { + for (std::pair o = getToken(options); + !o.first.empty(); o = getToken(o.second)) { + // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add + // that. + if ( _codegenOptions.empty() ) + _codegenOptions.push_back(strdup("libLTO")); + _codegenOptions.push_back(strdup(o.first.str().c_str())); + } } -- cgit v1.1 From 76b13ed403ccda3ccbe7d17096e314ae83709b7f Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 10:50:14 +0000 Subject: Cleanup whitespace. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153804 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 3cc13e2..f8bb617 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -4,10 +4,10 @@ // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // -// This file implements the Link Time Optimization library. This library is +// This file implements the Link Time Optimization library. This library is // intended to be used by linker to optimize code at link time. // //===----------------------------------------------------------------------===// @@ -64,7 +64,7 @@ const char* LTOCodeGenerator::getVersionString() { #endif } -LTOCodeGenerator::LTOCodeGenerator() +LTOCodeGenerator::LTOCodeGenerator() : _context(getGlobalContext()), _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), @@ -95,7 +95,7 @@ bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) return ret; } - + bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg) { @@ -103,7 +103,7 @@ bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg) case LTO_DEBUG_MODEL_NONE: _emitDwarfDebugInfo = false; return false; - + case LTO_DEBUG_MODEL_DWARF: _emitDwarfDebugInfo = true; return false; @@ -112,7 +112,7 @@ bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg) } -bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, +bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, std::string& errMsg) { switch (model) { @@ -141,7 +141,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, if (determineTarget(errMsg)) return true; - // mark which symbols can not be internalized + // mark which symbols can not be internalized applyScopeRestrictions(); // create output file @@ -153,7 +153,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, errMsg += path; return true; } - + // write bitcode to it WriteBitcodeToFile(_linker.getModule(), Out.os()); Out.os().close(); @@ -164,7 +164,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, Out.os().clear_error(); return true; } - + Out.keep(); return false; } @@ -290,7 +290,7 @@ static void findUsedValues(GlobalVariable *LLVMUsed, if (Inits == 0) return; for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) - if (GlobalValue *GV = + if (GlobalValue *GV = dyn_cast(Inits->getOperand(i)->stripPointerCasts())) UsedValues.insert(GV); } @@ -303,7 +303,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { PassManager passes; passes.add(createVerifierPass()); - // mark which symbols can not be internalized + // mark which symbols can not be internalized MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL); Mangler mangler(Context, *_target->getTargetData()); std::vector mustPreserveList; @@ -312,7 +312,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { for (Module::iterator f = mergedModule->begin(), e = mergedModule->end(); f != e; ++f) applyRestriction(*f, mustPreserveList, asmUsed, mangler); - for (Module::global_iterator v = mergedModule->global_begin(), + for (Module::global_iterator v = mergedModule->global_begin(), e = mergedModule->global_end(); v != e; ++v) applyRestriction(*v, mustPreserveList, asmUsed, mangler); for (Module::alias_iterator a = mergedModule->alias_begin(), @@ -347,24 +347,24 @@ void LTOCodeGenerator::applyScopeRestrictions() { // apply scope restrictions passes.run(*mergedModule); - + _scopeRestrictionsDone = true; } /// Optimize merged modules using various IPO passes bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, std::string &errMsg) { - if ( this->determineTarget(errMsg) ) + if ( this->determineTarget(errMsg) ) return true; - // mark which symbols can not be internalized + // mark which symbols can not be internalized this->applyScopeRestrictions(); Module* mergedModule = _linker.getModule(); // if options were requested, set them if ( !_codegenOptions.empty() ) - cl::ParseCommandLineOptions(_codegenOptions.size(), + cl::ParseCommandLineOptions(_codegenOptions.size(), const_cast(&_codegenOptions[0])); // Instantiate the pass manager to organize the passes. @@ -375,7 +375,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); - + PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false, !DisableInline); -- cgit v1.1 From f2cc2ee449bf5756a10959d130414e087a16555d Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 10:51:45 +0000 Subject: These strings aren't 'const char *' but 'char *'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153805 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 2 +- tools/lto/LTOCodeGenerator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index f8bb617..3f82c52 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -80,7 +80,7 @@ LTOCodeGenerator::~LTOCodeGenerator() { delete _target; delete _nativeObjectFile; - for (std::vector::iterator I = _codegenOptions.begin(), + for (std::vector::iterator I = _codegenOptions.begin(), E = _codegenOptions.end(); I != E; ++I) free(*I); } diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index f8fd357..83ad998 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -65,7 +65,7 @@ private: StringSet _mustPreserveSymbols; StringSet _asmUndefinedRefs; llvm::MemoryBuffer* _nativeObjectFile; - std::vector _codegenOptions; + std::vector _codegenOptions; std::string _mCpu; std::string _nativeObjectPath; }; -- cgit v1.1 From ab53bc76fd0f4863c9bdccf666fe8eed3d6bf702 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 11:10:35 +0000 Subject: Cleanup whitespace and trim some of the #includes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153807 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 2 +- tools/lto/LTOCodeGenerator.h | 97 ++++++++++++++++++++++-------------------- tools/lto/LTOModule.cpp | 6 --- tools/lto/LTOModule.h | 9 ++-- 4 files changed, 54 insertions(+), 60 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 3f82c52..0562167 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "LTOModule.h" #include "LTOCodeGenerator.h" +#include "LTOModule.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Linker.h" diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index 83ad998..1b3bc09 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -4,71 +4,74 @@ // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // -// This file declares the LTOCodeGenerator class. +// This file declares the LTOCodeGenerator class. // //===----------------------------------------------------------------------===// - #ifndef LTO_CODE_GENERATOR_H #define LTO_CODE_GENERATOR_H #include "llvm/Linker.h" -#include "llvm/LLVMContext.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallPtrSet.h" - +#include "llvm-c/lto.h" #include +namespace llvm { + class LLVMContext; + class GlobalValue; + class Mangler; + class MemoryBuffer; + class TargetMachine; + class raw_ostream; +} -// -// C++ class which implements the opaque lto_code_gen_t -// - +//===----------------------------------------------------------------------===// +/// LTOCodeGenerator - C++ class which implements the opaque lto_code_gen_t +/// type. +/// struct LTOCodeGenerator { - static const char* getVersionString(); - - LTOCodeGenerator(); - ~LTOCodeGenerator(); - - bool addModule(struct LTOModule*, std::string& errMsg); - bool setDebugInfo(lto_debug_model, std::string& errMsg); - bool setCodePICModel(lto_codegen_model, std::string& errMsg); - void setCpu(const char *cpu); - void addMustPreserveSymbol(const char* sym); - bool writeMergedModules(const char* path, - std::string& errMsg); - bool compile_to_file(const char** name, std::string& errMsg); - const void* compile(size_t* length, std::string& errMsg); - void setCodeGenDebugOptions(const char *opts); + static const char *getVersionString(); + + LTOCodeGenerator(); + ~LTOCodeGenerator(); + + bool addModule(struct LTOModule*, std::string &errMsg); + bool setDebugInfo(lto_debug_model, std::string &errMsg); + bool setCodePICModel(lto_codegen_model, std::string &errMsg); + void setCpu(const char *cpu); + void addMustPreserveSymbol(const char *sym); + bool writeMergedModules(const char *path, std::string &errMsg); + bool compile_to_file(const char **name, std::string &errMsg); + const void *compile(size_t *length, std::string &errMsg); + void setCodeGenDebugOptions(const char *opts); + private: - bool generateObjectFile(llvm::raw_ostream& out, - std::string& errMsg); - void applyScopeRestrictions(); - void applyRestriction(llvm::GlobalValue &GV, - std::vector &mustPreserveList, + bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg); + void applyScopeRestrictions(); + void applyRestriction(llvm::GlobalValue &GV, + std::vector &mustPreserveList, llvm::SmallPtrSet &asmUsed, - llvm::Mangler &mangler); - bool determineTarget(std::string& errMsg); - - typedef llvm::StringMap StringSet; + llvm::Mangler &mangler); + bool determineTarget(std::string &errMsg); + + typedef llvm::StringMap StringSet; - llvm::LLVMContext& _context; - llvm::Linker _linker; - llvm::TargetMachine* _target; - bool _emitDwarfDebugInfo; - bool _scopeRestrictionsDone; - lto_codegen_model _codeModel; - StringSet _mustPreserveSymbols; - StringSet _asmUndefinedRefs; - llvm::MemoryBuffer* _nativeObjectFile; - std::vector _codegenOptions; - std::string _mCpu; - std::string _nativeObjectPath; + llvm::LLVMContext& _context; + llvm::Linker _linker; + llvm::TargetMachine* _target; + bool _emitDwarfDebugInfo; + bool _scopeRestrictionsDone; + lto_codegen_model _codeModel; + StringSet _mustPreserveSymbols; + StringSet _asmUndefinedRefs; + llvm::MemoryBuffer* _nativeObjectFile; + std::vector _codegenOptions; + std::string _mCpu; + std::string _nativeObjectPath; }; #endif // LTO_CODE_GENERATOR_H - diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 45890a5..fb66973 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -17,7 +17,6 @@ #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCStreamer.h" @@ -26,21 +25,16 @@ #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/MC/MCParser/MCAsmParser.h" -#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Support/Host.h" -#include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Process.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Support/SystemUtils.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/Triple.h" - using namespace llvm; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index e5f6dea..cafb927 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -20,13 +20,10 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringMap.h" - #include "llvm-c/lto.h" - #include #include - // Forward references to llvm classes. namespace llvm { class Function; @@ -35,9 +32,9 @@ namespace llvm { class Value; } -// -// C++ class which implements the opaque lto_module_t type. -// +//===----------------------------------------------------------------------===// +/// LTOModule - C++ class which implements the opaque lto_module_t type. +/// struct LTOModule { private: typedef llvm::StringMap StringSet; -- cgit v1.1 From c94c5626926161a9258f6af7e4243ca13b3bc988 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 11:15:43 +0000 Subject: Indent according to LLVM's style guide. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153808 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 251 ++++++++++++++++++++--------------------- 1 file changed, 121 insertions(+), 130 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 0562167..c6da960 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -20,11 +20,10 @@ #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/PassManager.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/Triple.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/Config/config.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/SubtargetFeature.h" @@ -33,6 +32,8 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegisterInfo.h" +#include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" @@ -45,9 +46,8 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" -#include "llvm/Config/config.h" -#include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Triple.h" #include #include #include @@ -65,15 +65,14 @@ const char* LTOCodeGenerator::getVersionString() { } LTOCodeGenerator::LTOCodeGenerator() - : _context(getGlobalContext()), - _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), - _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), - _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), - _nativeObjectFile(NULL) -{ - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); + : _context(getGlobalContext()), + _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), + _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), + _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), + _nativeObjectFile(NULL) { + InitializeAllTargets(); + InitializeAllTargetMCs(); + InitializeAllAsmPrinters(); } LTOCodeGenerator::~LTOCodeGenerator() { @@ -85,8 +84,7 @@ LTOCodeGenerator::~LTOCodeGenerator() { free(*I); } -bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) -{ +bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg); const std::vector &undefs = mod->getAsmUndefinedRefs(); @@ -96,46 +94,40 @@ bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) return ret; } +bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, + std::string& errMsg) { + switch (debug) { + case LTO_DEBUG_MODEL_NONE: + _emitDwarfDebugInfo = false; + return false; -bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, std::string& errMsg) -{ - switch (debug) { - case LTO_DEBUG_MODEL_NONE: - _emitDwarfDebugInfo = false; - return false; - - case LTO_DEBUG_MODEL_DWARF: - _emitDwarfDebugInfo = true; - return false; - } - llvm_unreachable("Unknown debug format!"); + case LTO_DEBUG_MODEL_DWARF: + _emitDwarfDebugInfo = true; + return false; + } + llvm_unreachable("Unknown debug format!"); } - bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, - std::string& errMsg) -{ - switch (model) { - case LTO_CODEGEN_PIC_MODEL_STATIC: - case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - _codeModel = model; - return false; - } - llvm_unreachable("Unknown PIC model!"); + std::string& errMsg) { + switch (model) { + case LTO_CODEGEN_PIC_MODEL_STATIC: + case LTO_CODEGEN_PIC_MODEL_DYNAMIC: + case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: + _codeModel = model; + return false; + } + llvm_unreachable("Unknown PIC model!"); } -void LTOCodeGenerator::setCpu(const char* mCpu) -{ +void LTOCodeGenerator::setCpu(const char* mCpu) { _mCpu = mCpu; } -void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) -{ - _mustPreserveSymbols[sym] = 1; +void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) { + _mustPreserveSymbols[sym] = 1; } - bool LTOCodeGenerator::writeMergedModules(const char *path, std::string &errMsg) { if (determineTarget(errMsg)) @@ -169,9 +161,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, return false; } - -bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) -{ +bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) { // make unique temp .o file to put generated object file sys::PathWithStatus uniqueObjPath("lto-llvm.o"); if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) { @@ -185,12 +175,14 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) tool_output_file objFile(uniqueObjPath.c_str(), errMsg); if (!errMsg.empty()) return true; + genResult = this->generateObjectFile(objFile.os(), errMsg); objFile.os().close(); if (objFile.os().has_error()) { objFile.os().clear_error(); return true; } + objFile.keep(); if ( genResult ) { uniqueObjPath.eraseFromDisk(); @@ -202,8 +194,7 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) return false; } -const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) -{ +const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) { const char *name; if (compile_to_file(&name, errMsg)) return NULL; @@ -229,48 +220,48 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) return _nativeObjectFile->getBufferStart(); } -bool LTOCodeGenerator::determineTarget(std::string& errMsg) -{ - if ( _target == NULL ) { - std::string Triple = _linker.getModule()->getTargetTriple(); - if (Triple.empty()) - Triple = sys::getDefaultTargetTriple(); - - // create target machine from info for merged modules - const Target *march = TargetRegistry::lookupTarget(Triple, errMsg); - if ( march == NULL ) - return true; - - // The relocation model is actually a static member of TargetMachine - // and needs to be set before the TargetMachine is instantiated. - Reloc::Model RelocModel = Reloc::Default; - switch( _codeModel ) { - case LTO_CODEGEN_PIC_MODEL_STATIC: - RelocModel = Reloc::Static; - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - RelocModel = Reloc::PIC_; - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - RelocModel = Reloc::DynamicNoPIC; - break; - } - - // construct LTOModule, hand over ownership of module and target - SubtargetFeatures Features; - Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); - std::string FeatureStr = Features.getString(); - TargetOptions Options; - _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options, - RelocModel); +bool LTOCodeGenerator::determineTarget(std::string& errMsg) { + if ( _target == NULL ) { + std::string Triple = _linker.getModule()->getTargetTriple(); + if (Triple.empty()) + Triple = sys::getDefaultTargetTriple(); + + // create target machine from info for merged modules + const Target *march = TargetRegistry::lookupTarget(Triple, errMsg); + if ( march == NULL ) + return true; + + // The relocation model is actually a static member of TargetMachine and + // needs to be set before the TargetMachine is instantiated. + Reloc::Model RelocModel = Reloc::Default; + switch( _codeModel ) { + case LTO_CODEGEN_PIC_MODEL_STATIC: + RelocModel = Reloc::Static; + break; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC: + RelocModel = Reloc::PIC_; + break; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: + RelocModel = Reloc::DynamicNoPIC; + break; } - return false; + + // construct LTOModule, hand over ownership of module and target + SubtargetFeatures Features; + Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); + std::string FeatureStr = Features.getString(); + TargetOptions Options; + _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options, + RelocModel); + } + return false; } -void LTOCodeGenerator::applyRestriction(GlobalValue &GV, - std::vector &mustPreserveList, - SmallPtrSet &asmUsed, - Mangler &mangler) { +void LTOCodeGenerator:: +applyRestriction(GlobalValue &GV, + std::vector &mustPreserveList, + SmallPtrSet &asmUsed, + Mangler &mangler) { SmallString<64> Buffer; mangler.getNameWithPrefix(Buffer, &GV, false); @@ -291,7 +282,7 @@ static void findUsedValues(GlobalVariable *LLVMUsed, for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) if (GlobalValue *GV = - dyn_cast(Inits->getOperand(i)->stripPointerCasts())) + dyn_cast(Inits->getOperand(i)->stripPointerCasts())) UsedValues.insert(GV); } @@ -304,7 +295,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { passes.add(createVerifierPass()); // mark which symbols can not be internalized - MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL); + MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL); Mangler mangler(Context, *_target->getTargetData()); std::vector mustPreserveList; SmallPtrSet asmUsed; @@ -354,62 +345,62 @@ void LTOCodeGenerator::applyScopeRestrictions() { /// Optimize merged modules using various IPO passes bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, std::string &errMsg) { - if ( this->determineTarget(errMsg) ) - return true; + if ( this->determineTarget(errMsg) ) + return true; - // mark which symbols can not be internalized - this->applyScopeRestrictions(); + // mark which symbols can not be internalized + this->applyScopeRestrictions(); - Module* mergedModule = _linker.getModule(); + Module* mergedModule = _linker.getModule(); - // if options were requested, set them - if ( !_codegenOptions.empty() ) - cl::ParseCommandLineOptions(_codegenOptions.size(), - const_cast(&_codegenOptions[0])); + // if options were requested, set them + if ( !_codegenOptions.empty() ) + cl::ParseCommandLineOptions(_codegenOptions.size(), + const_cast(&_codegenOptions[0])); - // Instantiate the pass manager to organize the passes. - PassManager passes; + // Instantiate the pass manager to organize the passes. + PassManager passes; - // Start off with a verification pass. - passes.add(createVerifierPass()); + // Start off with a verification pass. + passes.add(createVerifierPass()); - // Add an appropriate TargetData instance for this module... - passes.add(new TargetData(*_target->getTargetData())); + // Add an appropriate TargetData instance for this module... + passes.add(new TargetData(*_target->getTargetData())); - PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false, - !DisableInline); + PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false, + !DisableInline); - // Make sure everything is still good. - passes.add(createVerifierPass()); + // Make sure everything is still good. + passes.add(createVerifierPass()); - FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule); + FunctionPassManager *codeGenPasses = new FunctionPassManager(mergedModule); - codeGenPasses->add(new TargetData(*_target->getTargetData())); + codeGenPasses->add(new TargetData(*_target->getTargetData())); - formatted_raw_ostream Out(out); + formatted_raw_ostream Out(out); - if (_target->addPassesToEmitFile(*codeGenPasses, Out, - TargetMachine::CGFT_ObjectFile, - CodeGenOpt::Aggressive)) { - errMsg = "target file type not supported"; - return true; - } + if (_target->addPassesToEmitFile(*codeGenPasses, Out, + TargetMachine::CGFT_ObjectFile, + CodeGenOpt::Aggressive)) { + errMsg = "target file type not supported"; + return true; + } - // Run our queue of passes all at once now, efficiently. - passes.run(*mergedModule); + // Run our queue of passes all at once now, efficiently. + passes.run(*mergedModule); - // Run the code generator, and write assembly file - codeGenPasses->doInitialization(); + // Run the code generator, and write assembly file + codeGenPasses->doInitialization(); - for (Module::iterator - it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it) - if (!it->isDeclaration()) - codeGenPasses->run(*it); + for (Module::iterator + it = mergedModule->begin(), e = mergedModule->end(); it != e; ++it) + if (!it->isDeclaration()) + codeGenPasses->run(*it); - codeGenPasses->doFinalization(); - delete codeGenPasses; + codeGenPasses->doFinalization(); + delete codeGenPasses; - return false; // success + return false; // success } /// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging -- cgit v1.1 From deee238128ac2c2ddda1aa942127f9f378030306 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 11:22:30 +0000 Subject: Trim headers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153809 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index c6da960..52495da 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -35,22 +35,15 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/SystemUtils.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/Host.h" -#include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/Triple.h" -#include -#include -#include using namespace llvm; static cl::opt DisableInline("disable-inlining", -- cgit v1.1 From 7baa27d3b331c9388bc81995c819c289a3c6fe7e Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 31 Mar 2012 11:25:18 +0000 Subject: Move trivial functions into the class definition. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153810 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 8 -------- tools/lto/LTOCodeGenerator.h | 9 +++++++-- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 52495da..1d2631e 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -113,14 +113,6 @@ bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model, llvm_unreachable("Unknown PIC model!"); } -void LTOCodeGenerator::setCpu(const char* mCpu) { - _mCpu = mCpu; -} - -void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) { - _mustPreserveSymbols[sym] = 1; -} - bool LTOCodeGenerator::writeMergedModules(const char *path, std::string &errMsg) { if (determineTarget(errMsg)) diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index 1b3bc09..3081b7d 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -42,8 +42,13 @@ struct LTOCodeGenerator { bool addModule(struct LTOModule*, std::string &errMsg); bool setDebugInfo(lto_debug_model, std::string &errMsg); bool setCodePICModel(lto_codegen_model, std::string &errMsg); - void setCpu(const char *cpu); - void addMustPreserveSymbol(const char *sym); + + void setCpu(const char* mCpu) { _mCpu = mCpu; } + + void addMustPreserveSymbol(const char* sym) { + _mustPreserveSymbols[sym] = 1; + } + bool writeMergedModules(const char *path, std::string &errMsg); bool compile_to_file(const char **name, std::string &errMsg); const void *compile(size_t *length, std::string &errMsg); -- cgit v1.1 From 1fcbca05db736afc3e555aadc14ae3a5bef59198 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 2 Apr 2012 03:33:31 +0000 Subject: It could come about that we parse the inline ASM before we get a potential definition for it. In that case, we want to wait for the potential definition before we create a symbol for it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153859 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 26 ++++++++++++++++++++++++++ tools/lto/LTOModule.h | 1 + 2 files changed, 27 insertions(+) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index fb66973..3bd764c 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -399,6 +399,18 @@ void LTOModule::addAsmGlobalSymbol(const char *name, NameAndAttributes &info = _undefines[entry.getKey().data()]; + if (info.symbol == 0) { + // If we haven't seen this symbol before, save it and we may see it again. + StringMap::value_type + &asm_entry = _asm_defines.GetOrCreateValue(name); + NameAndAttributes &asm_info = _asm_defines[asm_entry.getKey().data()]; + asm_info.name = name; + asm_info.attributes = scope; + asm_info.isFunction = false; + asm_info.symbol = 0; + return; + } + if (info.isFunction) addDefinedFunctionSymbol(cast(info.symbol)); else @@ -452,6 +464,20 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) { if (entry.getValue().name) return; + StringMap::value_type &asm_entry = + _asm_defines.GetOrCreateValue(name); + + if (asm_entry.getValue().name != 0) { + if (isFunc) + addDefinedFunctionSymbol(cast(decl)); + else + addDefinedDataSymbol(decl); + + _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK; + _symbols.back().attributes |= asm_entry.getValue().attributes; + return; + } + NameAndAttributes info; info.name = entry.getKey().data(); diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index cafb927..6280c67 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -53,6 +53,7 @@ private: // _defines and _undefines only needed to disambiguate tentative definitions StringSet _defines; llvm::StringMap _undefines; + llvm::StringMap _asm_defines; std::vector _asm_undefines; llvm::MCContext _context; -- cgit v1.1 From 17463b3ef1a3d39b10619254f12e806c8c43f9e7 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 2 Apr 2012 06:09:36 +0000 Subject: Make MCInstrInfo available to the MCInstPrinter. This will be used to remove getInstructionName and the static data it contains since the same tables are already in MCInstrInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153860 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-mc/Disassembler.cpp | 14 +++++++++++--- tools/llvm-mc/llvm-mc.cpp | 2 +- tools/llvm-objdump/MachODump.cpp | 5 +++-- tools/llvm-objdump/llvm-objdump.cpp | 9 ++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index 6793d7e..a8cd7c1 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -21,6 +21,7 @@ #include "llvm/MC/MCDisassembler.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/ADT/OwningPtr.h" @@ -156,7 +157,8 @@ int Disassembler::disassemble(const Target &T, return -1; } - OwningPtr STI(T.createMCSubtargetInfo(Triple, Cpu, FeaturesStr)); + OwningPtr STI(T.createMCSubtargetInfo(Triple, Cpu, + FeaturesStr)); if (!STI) { errs() << "error: no subtarget info for target " << Triple << "\n"; return -1; @@ -174,9 +176,15 @@ int Disassembler::disassemble(const Target &T, return -1; } + OwningPtr MII(T.createMCInstrInfo()); + if (!MII) { + errs() << "error: no instruction info for target " << Triple << "\n"; + return -1; + } + int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); - OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant, - *AsmInfo, *MRI, *STI)); + OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant, *AsmInfo, + *MII, *MRI, *STI)); if (!IP) { errs() << "error: no instruction printer for target " << Triple << '\n'; return -1; diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index ceed2d6..d882e01 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -416,7 +416,7 @@ static int AssembleInput(const char *ProgName) { // FIXME: There is a bit of code duplication with addPassesToEmitFile. if (FileType == OFT_AssemblyFile) { MCInstPrinter *IP = - TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MRI, *STI); + TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI); MCCodeEmitter *CE = 0; MCAsmBackend *MAB = 0; if (ShowEncoding) { diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index b9ea041..0e7f3fd 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -260,8 +260,9 @@ void llvm::DisassembleInputMachO(StringRef Filename) { OwningPtr DisAsm(TheTarget->createMCDisassembler(*STI)); OwningPtr MRI(TheTarget->createMCRegInfo(TripleName)); int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); - OwningPtr IP(TheTarget->createMCInstPrinter( - AsmPrinterVariant, *AsmInfo, *MRI, *STI)); + OwningPtr + IP(TheTarget->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *InstrInfo, + *MRI, *STI)); if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) { errs() << "error: couldn't initialize disassembler for target " diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 387f056..5a6f94a 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -26,6 +26,7 @@ #include "llvm/MC/MCDisassembler.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/Casting.h" @@ -254,9 +255,15 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { return; } + OwningPtr MII(TheTarget->createMCInstrInfo()); + if (!MII) { + errs() << "error: no instruction info for target " << TripleName << "\n"; + return; + } + int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); OwningPtr IP(TheTarget->createMCInstPrinter( - AsmPrinterVariant, *AsmInfo, *MRI, *STI)); + AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI)); if (!IP) { errs() << "error: no instruction printer for target " << TripleName << '\n'; -- cgit v1.1 From 8ba9405c5ca9d95a61c5d575f16506ddac5d67d3 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 2 Apr 2012 10:01:21 +0000 Subject: Hack the hack. If we have a situation where an ASM object is defined but isn't reflected in the LLVM IR (as a declare or something), then treat it like a data object. N.B. This isn't 100% correct. The ASM parser should supply more information so that we know what type of object it is, and what attributes it should have. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153870 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 39 +++++++++++++++++---------------------- tools/lto/LTOModule.h | 1 - 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 3bd764c..963bb53 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -400,14 +400,23 @@ void LTOModule::addAsmGlobalSymbol(const char *name, NameAndAttributes &info = _undefines[entry.getKey().data()]; if (info.symbol == 0) { - // If we haven't seen this symbol before, save it and we may see it again. - StringMap::value_type - &asm_entry = _asm_defines.GetOrCreateValue(name); - NameAndAttributes &asm_info = _asm_defines[asm_entry.getKey().data()]; - asm_info.name = name; - asm_info.attributes = scope; - asm_info.isFunction = false; - asm_info.symbol = 0; + // FIXME: This is trying to take care of module ASM like this: + // + // module asm ".zerofill __FOO, __foo, _bar_baz_qux, 0" + // + // but is gross and its mother dresses it funny. Have the ASM parser give us + // more details for this type of situation so that we're not guessing so + // much. + + // fill information structure + info.name = name; + info.attributes = + LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope; + info.isFunction = false; + info.symbol = 0; + + // add to table of symbols + _symbols.push_back(info); return; } @@ -464,20 +473,6 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) { if (entry.getValue().name) return; - StringMap::value_type &asm_entry = - _asm_defines.GetOrCreateValue(name); - - if (asm_entry.getValue().name != 0) { - if (isFunc) - addDefinedFunctionSymbol(cast(decl)); - else - addDefinedDataSymbol(decl); - - _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK; - _symbols.back().attributes |= asm_entry.getValue().attributes; - return; - } - NameAndAttributes info; info.name = entry.getKey().data(); diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 6280c67..cafb927 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -53,7 +53,6 @@ private: // _defines and _undefines only needed to disambiguate tentative definitions StringSet _defines; llvm::StringMap _undefines; - llvm::StringMap _asm_defines; std::vector _asm_undefines; llvm::MCContext _context; -- cgit v1.1 From 3197b4453d214aa96de3a42da8f8fe189fff2077 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 2 Apr 2012 22:16:50 +0000 Subject: Add an option to turn off the expensive GVN load PRE part of GVN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153902 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 1d2631e..f0640c2 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -49,6 +49,9 @@ using namespace llvm; static cl::opt DisableInline("disable-inlining", cl::desc("Do not run the inliner pass")); +static cl::opt DisableGVNLoadPRE("disable-gvn-loadpre", + cl::desc("Do not run the GVN load PRE pass")); + const char* LTOCodeGenerator::getVersionString() { #ifdef LLVM_VERSION_INFO return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO; @@ -353,7 +356,8 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, passes.add(new TargetData(*_target->getTargetData())); PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false, - !DisableInline); + !DisableInline, + DisableGVNLoadPRE); // Make sure everything is still good. passes.add(createVerifierPass()); -- cgit v1.1 From 90e7d4f6f006672a59ff8e031a190c76f9dab4b3 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 3 Apr 2012 03:56:52 +0000 Subject: Reformatting. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153928 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 963bb53..1dbd64b 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -491,7 +491,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) { namespace { class RecordStreamer : public MCStreamer { public: - enum State { NeverSeen, Global, Defined, DefinedGlobal, Used}; + enum State { NeverSeen, Global, Defined, DefinedGlobal, Used }; private: StringMap Symbols; @@ -580,14 +580,16 @@ namespace { RecordStreamer(MCContext &Context) : MCStreamer(Context) {} - virtual void ChangeSection(const MCSection *Section) {} - virtual void InitSections() {} + virtual void EmitInstruction(const MCInst &Inst) { + // Scan for values. + for (unsigned i = Inst.getNumOperands(); i--; ) + if (Inst.getOperand(i).isExpr()) + AddValueSymbols(Inst.getOperand(i).getExpr()); + } virtual void EmitLabel(MCSymbol *Symbol) { Symbol->setSection(*getCurrentSection()); markDefined(*Symbol); } - virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {} - virtual void EmitThumbFunc(MCSymbol *Func) {} virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { // FIXME: should we handle aliases? markDefined(*Symbol); @@ -596,20 +598,26 @@ namespace { if (Attribute == MCSA_Global) markGlobal(*Symbol); } - virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {} - virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} - virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {} - virtual void EmitCOFFSymbolStorageClass(int StorageClass) {} virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, unsigned Size , unsigned ByteAlignment) { markDefined(*Symbol); } - virtual void EmitCOFFSymbolType(int Type) {} - virtual void EndCOFFSymbolDef() {} virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { markDefined(*Symbol); } + + // Noop calls. + virtual void ChangeSection(const MCSection *Section) {} + virtual void InitSections() {} + virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {} + virtual void EmitThumbFunc(MCSymbol *Func) {} + virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {} + virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} + virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {} + virtual void EmitCOFFSymbolStorageClass(int StorageClass) {} + virtual void EmitCOFFSymbolType(int Type) {} + virtual void EndCOFFSymbolDef() {} virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {} virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) {} @@ -632,13 +640,6 @@ namespace { const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize) {} - - virtual void EmitInstruction(const MCInst &Inst) { - // Scan for values. - for (unsigned i = Inst.getNumOperands(); i--; ) - if (Inst.getOperand(i).isExpr()) - AddValueSymbols(Inst.getOperand(i).getExpr()); - } virtual void FinishImpl() {} }; } // end anonymous namespace -- cgit v1.1 From 1895fc90e01c9c3f48f40d99da6ead5ee09bcea4 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Tue, 3 Apr 2012 19:48:31 +0000 Subject: Set soname for FreeBSD as well. Patch by Bernard Cafarelli! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153965 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-shlib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile index 6b358b6..0035e3a 100644 --- a/tools/llvm-shlib/Makefile +++ b/tools/llvm-shlib/Makefile @@ -67,13 +67,13 @@ ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD)) # Include everything from the .a's into the shared library. LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \ -Wl,--no-whole-archive + # Add soname to the library. + LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) endif ifeq ($(HOST_OS),Linux) # Don't allow unresolved symbols. LLVMLibsOptions += -Wl,--no-undefined - # Add soname to the library. - LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) endif ifeq ($(HOST_OS),SunOS) -- cgit v1.1 From 97d990323607d6eb50a84f672b2169ac4ba1697d Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 5 Apr 2012 21:26:44 +0000 Subject: The internalize pass can be dangerous for LTO. Consider the following program: $ cat main.c void foo(void) { } int main(int argc, char *argv[]) { foo(); return 0; } $ cat bundle.c extern void foo(void); void bar(void) { foo(); } $ clang -o main main.c $ clang -o bundle.so bundle.c -bundle -bundle_loader ./main $ nm -m bundle.so 0000000000000f40 (__TEXT,__text) external _bar (undefined) external _foo (from executable) (undefined) external dyld_stub_binder (from libSystem) $ clang -o main main.c -O4 $ clang -o bundle.so bundle.c -bundle -bundle_loader ./main Undefined symbols for architecture x86_64: "_foo", referenced from: _bar in bundle-elQN6d.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) The linker was told that the 'foo' in 'main' was 'internal' and had no uses, so it was dead stripped. Another situation is something like: define void @foo() { ret void } define void @bar() { call asm volatile "call _foo" ... ret void } The only use of 'foo' is inside of an inline ASM call. Since we don't look inside those for uses of functions, we don't specify this as a "use." Get around this by not invoking the 'internalize' pass by default. This is an admitted hack for LTO correctness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154124 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index f0640c2..0e61c2f 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -46,10 +46,13 @@ #include "llvm/ADT/StringExtras.h" using namespace llvm; -static cl::opt DisableInline("disable-inlining", +static cl::opt EnableInternalizing("enable-internalizing", cl::init(false), + cl::desc("Internalize functions during LTO")); + +static cl::opt DisableInline("disable-inlining", cl::init(false), cl::desc("Do not run the inliner pass")); -static cl::opt DisableGVNLoadPRE("disable-gvn-loadpre", +static cl::opt DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false), cl::desc("Do not run the GVN load PRE pass")); const char* LTOCodeGenerator::getVersionString() { @@ -275,6 +278,14 @@ static void findUsedValues(GlobalVariable *LLVMUsed, } void LTOCodeGenerator::applyScopeRestrictions() { + // Internalize only if specifically asked for. Otherwise, global symbols which + // exist in the final image, but which are used outside of that image + // (e.g. bundling) may be removed. This also happens when a function is used + // only in inline asm. LLVM doesn't recognize that as a "use", so it could be + // stripped. + if (!EnableInternalizing) + return; + if (_scopeRestrictionsDone) return; Module *mergedModule = _linker.getModule(); -- cgit v1.1 From 253933ee9ef2c413ecd782efeacc5d7b9bcda09a Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 8 Apr 2012 17:51:45 +0000 Subject: Teach LLVM about a PIE option which, when enabled on top of PIC, makes optimizations which are valid for position independent code being linked into a single executable, but not for such code being linked into a shared library. I discussed the design of this with Eric Christopher, and the decision was to support an optional bit rather than a completely separate relocation model. Fundamentally, this is still PIC relocation, its just that certain optimizations are only valid under a PIC relocation model when the resulting code won't be in a shared library. The simplest path to here is to expose a single bit option in the TargetOptions. If folks have different/better designs, I'm all ears. =] I've included the first optimization based upon this: changing TLS models to the *Exec models when PIE is enabled. This is the LLVM component of PR12380 and is all of the hard work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154294 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llc/llc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tools') diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 191b649..9e30ac1 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -263,6 +263,11 @@ TrapFuncName("trap-func", cl::Hidden, cl::init("")); static cl::opt +EnablePIE("enable-pie", + cl::desc("Assume the creation of a position independent executable."), + cl::init(false)); + +static cl::opt SegmentedStacks("segmented-stacks", cl::desc("Use segmented stacks if possible."), cl::init(false)); @@ -467,6 +472,7 @@ int main(int argc, char **argv) { Options.RealignStack = EnableRealignStack; Options.DisableJumpTables = DisableSwitchTables; Options.TrapFuncName = TrapFuncName; + Options.PositionIndependentExecutable = EnablePIE; Options.EnableSegmentedStacks = SegmentedStacks; std::auto_ptr -- cgit v1.1 From 3029a0c56a1e4249746ff6b54d825e88fee6cddf Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 9 Apr 2012 05:26:48 +0000 Subject: Add a hook to turn on the internalize pass through the LTO interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154306 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 5 +++-- tools/lto/LTOCodeGenerator.h | 3 +++ tools/lto/lto.cpp | 6 ++++++ tools/lto/lto.exports | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 0e61c2f..7620bcb 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -67,7 +67,7 @@ LTOCodeGenerator::LTOCodeGenerator() : _context(getGlobalContext()), _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), - _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), + _runInternalizePass(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), _nativeObjectFile(NULL) { InitializeAllTargets(); InitializeAllTargetMCs(); @@ -366,7 +366,8 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); - PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/ false, + PassManagerBuilder().populateLTOPassManager(passes, + _runInternalizePass, !DisableInline, DisableGVNLoadPRE); diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index 3081b7d..bac3e6e 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -54,6 +54,8 @@ struct LTOCodeGenerator { const void *compile(size_t *length, std::string &errMsg); void setCodeGenDebugOptions(const char *opts); + void enableInternalizePass() { _runInternalizePass = true; } + private: bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg); void applyScopeRestrictions(); @@ -70,6 +72,7 @@ private: llvm::TargetMachine* _target; bool _emitDwarfDebugInfo; bool _scopeRestrictionsDone; + bool _runInternalizePass; lto_codegen_model _codeModel; StringSet _mustPreserveSymbols; StringSet _asmUndefinedRefs; diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index a7e633d..e523eb3 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -183,6 +183,12 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, cg->addMustPreserveSymbol(symbol); } +/// lto_codegen_whole_program_optimization - Enable the internalize pass during +/// LTO optimizations. +void lto_codegen_whole_program_optimization(lto_code_gen_t cg) { + cg->enableInternalizePass(); +} + /// lto_codegen_write_merged_modules - Writes a new file at the specified path /// that contains the merged contents of all modules added so far. Returns true /// on error (check lto_get_error_message() for details). diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports index b900bfb..1726388 100644 --- a/tools/lto/lto.exports +++ b/tools/lto/lto.exports @@ -27,6 +27,7 @@ lto_codegen_set_assembler_args lto_codegen_set_assembler_path lto_codegen_set_cpu lto_codegen_compile_to_file +lto_codegen_whole_program_optimization LLVMCreateDisasm LLVMDisasmDispose LLVMDisasmInstruction -- cgit v1.1 From a3706d6754e972c4339e4495a18d803027bb9195 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 9 Apr 2012 08:32:21 +0000 Subject: s/lto_codegen_whole_program_optimization/lto_codegen_set_whole_program_optimization/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154312 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/lto.cpp | 6 +++--- tools/lto/lto.exports | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index e523eb3..addf787 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -183,9 +183,9 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, cg->addMustPreserveSymbol(symbol); } -/// lto_codegen_whole_program_optimization - Enable the internalize pass during -/// LTO optimizations. -void lto_codegen_whole_program_optimization(lto_code_gen_t cg) { +/// lto_codegen_set_whole_program_optimization - Enable the internalize pass +/// during LTO optimizations. +void lto_codegen_set_whole_program_optimization(lto_code_gen_t cg) { cg->enableInternalizePass(); } diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports index 1726388..f471f1a 100644 --- a/tools/lto/lto.exports +++ b/tools/lto/lto.exports @@ -27,7 +27,7 @@ lto_codegen_set_assembler_args lto_codegen_set_assembler_path lto_codegen_set_cpu lto_codegen_compile_to_file -lto_codegen_whole_program_optimization +lto_codegen_set_whole_program_optimization LLVMCreateDisasm LLVMDisasmDispose LLVMDisasmInstruction -- cgit v1.1 From 64d5b282c92b3599c56ef987d6f6971611d716e6 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 9 Apr 2012 22:18:01 +0000 Subject: Apply the scope restrictions after parsing the command line options. There may be some which are used in that function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154348 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 7620bcb..28ede86 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -347,9 +347,6 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, if ( this->determineTarget(errMsg) ) return true; - // mark which symbols can not be internalized - this->applyScopeRestrictions(); - Module* mergedModule = _linker.getModule(); // if options were requested, set them @@ -357,6 +354,9 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, cl::ParseCommandLineOptions(_codegenOptions.size(), const_cast(&_codegenOptions[0])); + // mark which symbols can not be internalized + this->applyScopeRestrictions(); + // Instantiate the pass manager to organize the passes. PassManager passes; -- cgit v1.1 From 64fae7587ad7cb8082ca5615fd061a4e4d3f711e Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 9 Apr 2012 23:16:51 +0000 Subject: Revert the 'EnableInitializing' flag. There is debate on whether we should run that pass by default in LTO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154356 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 28ede86..77c06a6 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -46,9 +46,6 @@ #include "llvm/ADT/StringExtras.h" using namespace llvm; -static cl::opt EnableInternalizing("enable-internalizing", cl::init(false), - cl::desc("Internalize functions during LTO")); - static cl::opt DisableInline("disable-inlining", cl::init(false), cl::desc("Do not run the inliner pass")); @@ -278,14 +275,6 @@ static void findUsedValues(GlobalVariable *LLVMUsed, } void LTOCodeGenerator::applyScopeRestrictions() { - // Internalize only if specifically asked for. Otherwise, global symbols which - // exist in the final image, but which are used outside of that image - // (e.g. bundling) may be removed. This also happens when a function is used - // only in inline asm. LLVM doesn't recognize that as a "use", so it could be - // stripped. - if (!EnableInternalizing) - return; - if (_scopeRestrictionsDone) return; Module *mergedModule = _linker.getModule(); -- cgit v1.1 From 701de8fafc8db86a0a7df61b177720b1f681c60c Mon Sep 17 00:00:00 2001 From: Dylan Noblesmith Date: Tue, 10 Apr 2012 22:44:49 +0000 Subject: llvm-stress: don't make vectors of x86_mmx type LangRef.html says: "There are no arrays, vectors or constants of this type." This was hitting assertions when passing the -generate-x86-mmx option. PR12452. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154445 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-stress/llvm-stress.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index c095059..7da80bc 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -202,11 +202,17 @@ protected: /// Pick a random vector type. Type *pickVectorType(unsigned len = (unsigned)-1) { - Type *Ty = pickScalarType(); // Pick a random vector width in the range 2**0 to 2**4. // by adding two randoms we are generating a normal-like distribution // around 2**3. unsigned width = 1<<((Ran->Rand() % 3) + (Ran->Rand() % 3)); + Type *Ty; + + // Vectors of x86mmx are illegal; keep trying till we get something else. + do { + Ty = pickScalarType(); + } while (Ty->isX86_MMXTy()); + if (len != (unsigned)-1) width = len; return VectorType::get(Ty, width); -- cgit v1.1 From 83f17f25fc560db4f756010a1bbe1f8eb1d74b12 Mon Sep 17 00:00:00 2001 From: Dylan Noblesmith Date: Tue, 10 Apr 2012 22:44:51 +0000 Subject: llvm-stress: stop abusing ConstantFP::get() ConstantFP::get(Type*, double) is unreliably host-specific: it can't handle a type like PPC128 on an x86 host. It even has a comment to that effect: "This should only be used for simple constant values like 2.0/1.0 etc, that are known-valid both as host double and as the target format." Instead, use APFloat. While we're at it, randomize the floating point value more thoroughly; it was previously limited to the range 0 to 2**19 - 1. PR12451. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154446 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-stress/llvm-stress.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index 7da80bc..d284ea5 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -60,14 +60,28 @@ class Random { public: /// C'tor Random(unsigned _seed):Seed(_seed) {} - /// Return the next random value. - unsigned Rand() { - unsigned Val = Seed + 0x000b07a1; + + /// Return a random integer, up to a + /// maximum of 2**19 - 1. + uint32_t Rand() { + uint32_t Val = Seed + 0x000b07a1; Seed = (Val * 0x3c7c0ac1); // Only lowest 19 bits are random-ish. return Seed & 0x7ffff; } + /// Return a random 32 bit integer. + uint32_t Rand32() { + uint32_t Val = Rand(); + Val &= 0xffff; + return Val | (Rand() << 16); + } + + /// Return a random 64 bit integer. + uint64_t Rand64() { + uint64_t Val = Rand32(); + return Val | (uint64_t(Rand32()) << 32); + } private: unsigned Seed; }; @@ -348,10 +362,20 @@ struct ConstModifier: public Modifier { } if (Ty->isFloatingPointTy()) { + // Generate 128 random bits, the size of the (currently) + // largest floating-point types. + uint64_t RandomBits[2]; + for (unsigned i = 0; i < 2; ++i) + RandomBits[i] = Ran->Rand64(); + + APInt RandomInt(Ty->getPrimitiveSizeInBits(), makeArrayRef(RandomBits)); + + bool isIEEE = !Ty->isX86_FP80Ty() && !Ty->isPPC_FP128Ty(); + APFloat RandomFloat(RandomInt, isIEEE); + if (Ran->Rand() & 1) return PT->push_back(ConstantFP::getNullValue(Ty)); - return PT->push_back(ConstantFP::get(Ty, - static_cast(1)/Ran->Rand())); + return PT->push_back(ConstantFP::get(Ty->getContext(), RandomFloat)); } if (Ty->isIntegerTy()) { -- cgit v1.1 From 6fc30c26b7fa9e89c4e9ab99b7feab11389cc3f4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 11 Apr 2012 15:35:36 +0000 Subject: Fix the build under Debian GNU/Hurd. Thanks to Pino Toscano for the patch git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154500 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-shlib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile index 0035e3a..2d2e2c5 100644 --- a/tools/llvm-shlib/Makefile +++ b/tools/llvm-shlib/Makefile @@ -63,7 +63,7 @@ ifeq ($(HOST_OS),Darwin) endif endif -ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD)) +ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD GNU)) # Include everything from the .a's into the shared library. LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \ -Wl,--no-whole-archive @@ -71,7 +71,7 @@ ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux FreeBSD OpenBSD)) LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) endif -ifeq ($(HOST_OS),Linux) +ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU)) # Don't allow unresolved symbols. LLVMLibsOptions += -Wl,--no-undefined endif -- cgit v1.1 From 7d719a5237d8da0aed188a400b9792b64dae5fc0 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Sun, 15 Apr 2012 20:17:14 +0000 Subject: Do not convert between fp128 <-> ppc_fp128 since there is no legal cast conversion between the two. Patch by nobled git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154772 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-stress/llvm-stress.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index d284ea5..fb05a58 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -412,7 +412,7 @@ struct ExtractElementModifier: public Modifier { Value *Val0 = getRandomVectorValue(); Value *V = ExtractElementInst::Create(Val0, ConstantInt::get(Type::getInt32Ty(BB->getContext()), - Ran->Rand() % cast(Val0->getType())->getNumElements()), + Ran->Rand() % cast(Val0->getType())->getNumElements()), "E", BB->getTerminator()); return PT->push_back(V); } @@ -476,7 +476,7 @@ struct CastModifier: public Modifier { DestTy = pickVectorType(VecTy->getNumElements()); } - // no need to casr. + // no need to cast. if (VTy == DestTy) return; // Pointers: @@ -487,9 +487,11 @@ struct CastModifier: public Modifier { new BitCastInst(V, DestTy, "PC", BB->getTerminator())); } + unsigned VSize = VTy->getScalarType()->getPrimitiveSizeInBits(); + unsigned DestSize = DestTy->getScalarType()->getPrimitiveSizeInBits(); + // Generate lots of bitcasts. - if ((Ran->Rand() & 1) && - VTy->getPrimitiveSizeInBits() == DestTy->getPrimitiveSizeInBits()) { + if ((Ran->Rand() & 1) && VSize == DestSize) { return PT->push_back( new BitCastInst(V, DestTy, "BC", BB->getTerminator())); } @@ -497,11 +499,11 @@ struct CastModifier: public Modifier { // Both types are integers: if (VTy->getScalarType()->isIntegerTy() && DestTy->getScalarType()->isIntegerTy()) { - if (VTy->getScalarType()->getPrimitiveSizeInBits() > - DestTy->getScalarType()->getPrimitiveSizeInBits()) { + if (VSize > DestSize) { return PT->push_back( new TruncInst(V, DestTy, "Tr", BB->getTerminator())); } else { + assert(VSize < DestSize && "Different int types with the same size?"); if (Ran->Rand() & 1) return PT->push_back( new ZExtInst(V, DestTy, "ZE", BB->getTerminator())); @@ -531,14 +533,15 @@ struct CastModifier: public Modifier { // Both floats. if (VTy->getScalarType()->isFloatingPointTy() && DestTy->getScalarType()->isFloatingPointTy()) { - if (VTy->getScalarType()->getPrimitiveSizeInBits() > - DestTy->getScalarType()->getPrimitiveSizeInBits()) { + if (VSize > DestSize) { return PT->push_back( new FPTruncInst(V, DestTy, "Tr", BB->getTerminator())); - } else { + } else if (VSize < DestSize) { return PT->push_back( new FPExtInst(V, DestTy, "ZE", BB->getTerminator())); } + // If VSize == DestSize, then the two types must be fp128 and ppc_fp128, + // for which there is no defined conversion. So do nothing. } } -- cgit v1.1 From fb22ede033f792196643bad0ceafe473366ddf41 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 15 Apr 2012 22:00:22 +0000 Subject: Make member variables of AsmToken private. Remove unnecessary forward declarations. Remove an unnecessary include. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154775 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-mc/llvm-mc.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index d882e01..89d72b2 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -15,6 +15,7 @@ #include "llvm/MC/MCParser/AsmLexer.h" #include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCAsmBackend.h" +#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCInstPrinter.h" -- cgit v1.1 From 4d2e9d9a1c213db144785f386ce661914d17afb6 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 16 Apr 2012 10:58:38 +0000 Subject: Remove lto_codegen_set_whole_program_optimization. It is a work in progress, so we don't want it to show up in the stable 3.1 interface. While at it, add a comment about why LTOCodeGenerator manually creates the internalize pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154807 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOCodeGenerator.cpp | 8 +++++--- tools/lto/LTOCodeGenerator.h | 2 -- tools/lto/lto.cpp | 6 ------ tools/lto/lto.exports | 1 - 4 files changed, 5 insertions(+), 12 deletions(-) (limited to 'tools') diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 77c06a6..6382a3f 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -64,7 +64,7 @@ LTOCodeGenerator::LTOCodeGenerator() : _context(getGlobalContext()), _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), - _runInternalizePass(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), + _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), _nativeObjectFile(NULL) { InitializeAllTargets(); InitializeAllTargetMCs(); @@ -355,8 +355,10 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); - PassManagerBuilder().populateLTOPassManager(passes, - _runInternalizePass, + // Enabling internalize here would use its AllButMain variant. It + // keeps only main if it exists and does nothing for libraries. Instead + // we create the pass ourselves with the symbol list provided by the linker. + PassManagerBuilder().populateLTOPassManager(passes, /*Internalize=*/false, !DisableInline, DisableGVNLoadPRE); diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index bac3e6e..032dc37 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -54,8 +54,6 @@ struct LTOCodeGenerator { const void *compile(size_t *length, std::string &errMsg); void setCodeGenDebugOptions(const char *opts); - void enableInternalizePass() { _runInternalizePass = true; } - private: bool generateObjectFile(llvm::raw_ostream &out, std::string &errMsg); void applyScopeRestrictions(); diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index addf787..a7e633d 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -183,12 +183,6 @@ void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, cg->addMustPreserveSymbol(symbol); } -/// lto_codegen_set_whole_program_optimization - Enable the internalize pass -/// during LTO optimizations. -void lto_codegen_set_whole_program_optimization(lto_code_gen_t cg) { - cg->enableInternalizePass(); -} - /// lto_codegen_write_merged_modules - Writes a new file at the specified path /// that contains the merged contents of all modules added so far. Returns true /// on error (check lto_get_error_message() for details). diff --git a/tools/lto/lto.exports b/tools/lto/lto.exports index f471f1a..b900bfb 100644 --- a/tools/lto/lto.exports +++ b/tools/lto/lto.exports @@ -27,7 +27,6 @@ lto_codegen_set_assembler_args lto_codegen_set_assembler_path lto_codegen_set_cpu lto_codegen_compile_to_file -lto_codegen_set_whole_program_optimization LLVMCreateDisasm LLVMDisasmDispose LLVMDisasmInstruction -- cgit v1.1 From d0c478d95f440b4db76279fe47d6cf734a28fa9a Mon Sep 17 00:00:00 2001 From: Richard Barton Date: Mon, 16 Apr 2012 11:32:10 +0000 Subject: Add -disassemble support for -show-inst and -show-encode capability llvm-mc. Also refactor so all MC paraphernalia are created once for all uses as much as possible. The test change is to account for the fact that the default disassembler behaviour has changed with regards to specifying the assembly syntax to use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154809 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-mc/Disassembler.cpp | 67 ++++------------ tools/llvm-mc/Disassembler.h | 15 ++-- tools/llvm-mc/llvm-mc.cpp | 172 ++++++++++++++--------------------------- 3 files changed, 80 insertions(+), 174 deletions(-) (limited to 'tools') diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index a8cd7c1..5f2fdb8 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -17,21 +17,18 @@ #include "../../lib/MC/MCDisassembler/EDInst.h" #include "../../lib/MC/MCDisassembler/EDOperand.h" #include "../../lib/MC/MCDisassembler/EDToken.h" -#include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCDisassembler.h" #include "llvm/MC/MCInst.h" -#include "llvm/MC/MCInstPrinter.h" -#include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/Triple.h" -#include "llvm/ADT/Twine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryObject.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" + using namespace llvm; typedef std::vector > ByteArrayTy; @@ -56,8 +53,9 @@ public: } static bool PrintInsts(const MCDisassembler &DisAsm, - MCInstPrinter &Printer, const ByteArrayTy &Bytes, - SourceMgr &SM, raw_ostream &Out) { + const ByteArrayTy &Bytes, + SourceMgr &SM, raw_ostream &Out, + MCStreamer &Streamer) { // Wrap the vector in a MemoryObject. VectorMemoryObject memoryObject(Bytes); @@ -87,8 +85,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm, // Fall through case MCDisassembler::Success: - Printer.printInst(&Inst, Out, ""); - Out << "\n"; + Streamer.EmitInstruction(Inst); break; } } @@ -145,56 +142,22 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray, int Disassembler::disassemble(const Target &T, const std::string &Triple, - const std::string &Cpu, - const std::string &FeaturesStr, + MCSubtargetInfo &STI, + MCStreamer &Streamer, MemoryBuffer &Buffer, + SourceMgr &SM, raw_ostream &Out) { - // Set up disassembler. - OwningPtr AsmInfo(T.createMCAsmInfo(Triple)); - - if (!AsmInfo) { - errs() << "error: no assembly info for target " << Triple << "\n"; - return -1; - } - - OwningPtr STI(T.createMCSubtargetInfo(Triple, Cpu, - FeaturesStr)); - if (!STI) { - errs() << "error: no subtarget info for target " << Triple << "\n"; - return -1; - } - - OwningPtr DisAsm(T.createMCDisassembler(*STI)); + OwningPtr DisAsm(T.createMCDisassembler(STI)); if (!DisAsm) { errs() << "error: no disassembler for target " << Triple << "\n"; return -1; } - OwningPtr MRI(T.createMCRegInfo(Triple)); - if (!MRI) { - errs() << "error: no register info for target " << Triple << "\n"; - return -1; - } - - OwningPtr MII(T.createMCInstrInfo()); - if (!MII) { - errs() << "error: no instruction info for target " << Triple << "\n"; - return -1; - } - - int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); - OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant, *AsmInfo, - *MII, *MRI, *STI)); - if (!IP) { - errs() << "error: no instruction printer for target " << Triple << '\n'; - return -1; - } + // Set up initial section manually here + Streamer.InitSections(); bool ErrorOccurred = false; - SourceMgr SM; - SM.AddNewSourceBuffer(&Buffer, SMLoc()); - // Convert the input to a vector for disassembly. ByteArrayTy ByteArray; StringRef Str = Buffer.getBuffer(); @@ -202,7 +165,7 @@ int Disassembler::disassemble(const Target &T, ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM); if (!ByteArray.empty()) - ErrorOccurred |= PrintInsts(*DisAsm, *IP, ByteArray, SM, Out); + ErrorOccurred |= PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer); return ErrorOccurred; } @@ -236,12 +199,10 @@ static int verboseEvaluator(uint64_t *V, unsigned R, void *Arg) { int Disassembler::disassembleEnhanced(const std::string &TS, MemoryBuffer &Buffer, + SourceMgr &SM, raw_ostream &Out) { ByteArrayTy ByteArray; StringRef Str = Buffer.getBuffer(); - SourceMgr SM; - - SM.AddNewSourceBuffer(&Buffer, SMLoc()); if (ByteArrayFromString(ByteArray, Str, SM)) { return -1; diff --git a/tools/llvm-mc/Disassembler.h b/tools/llvm-mc/Disassembler.h index e8cd92d..17d622f 100644 --- a/tools/llvm-mc/Disassembler.h +++ b/tools/llvm-mc/Disassembler.h @@ -22,18 +22,23 @@ namespace llvm { class MemoryBuffer; class Target; class raw_ostream; +class SourceMgr; +class MCSubtargetInfo; +class MCStreamer; class Disassembler { public: - static int disassemble(const Target &target, - const std::string &tripleString, - const std::string &Cpu, - const std::string &FeaturesStr, - MemoryBuffer &buffer, + static int disassemble(const Target &T, + const std::string &Triple, + MCSubtargetInfo &STI, + MCStreamer &Streamer, + MemoryBuffer &Buffer, + SourceMgr &SM, raw_ostream &Out); static int disassembleEnhanced(const std::string &tripleString, MemoryBuffer &buffer, + SourceMgr &SM, raw_ostream &Out); }; diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 89d72b2..36a482e 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -243,37 +243,11 @@ static void setDwarfDebugFlags(int argc, char **argv) { } } -static int AsLexInput(const char *ProgName) { - OwningPtr BufferPtr; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) { - errs() << ProgName << ": " << ec.message() << '\n'; - return 1; - } - MemoryBuffer *Buffer = BufferPtr.take(); - - SourceMgr SrcMgr; - - // Tell SrcMgr about this buffer, which is what TGParser will pick up. - SrcMgr.AddNewSourceBuffer(Buffer, SMLoc()); - - // Record the location of the include directories so that the lexer can find - // it later. - SrcMgr.setIncludeDirs(IncludeDirs); - - const Target *TheTarget = GetTarget(ProgName); - if (!TheTarget) - return 1; - - llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(TripleName)); - assert(MAI && "Unable to create target asm info!"); +static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, tool_output_file *Out) { - AsmLexer Lexer(*MAI); + AsmLexer Lexer(MAI); Lexer.setBuffer(SrcMgr.getMemoryBuffer(0)); - OwningPtr Out(GetOutputStream()); - if (!Out) - return 1; - bool Error = false; while (Lexer.Lex().isNot(AsmToken::Eof)) { AsmToken Tok = Lexer.getTok(); @@ -347,13 +321,49 @@ static int AsLexInput(const char *ProgName) { Out->os() << "\")\n"; } - // Keep output if no errors. - if (Error == 0) Out->keep(); - return Error; } -static int AssembleInput(const char *ProgName) { +static int AssembleInput(const char *ProgName, const Target *TheTarget, + SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str, + MCAsmInfo &MAI, MCSubtargetInfo &STI) { + OwningPtr Parser(createMCAsmParser(SrcMgr, Ctx, + Str, MAI)); + OwningPtr TAP(TheTarget->createMCAsmParser(STI, *Parser)); + if (!TAP) { + errs() << ProgName + << ": error: this target does not support assembly parsing.\n"; + return 1; + } + + Parser->setShowParsedOperands(ShowInstOperands); + Parser->setTargetParser(*TAP.get()); + + int Res = Parser->Run(NoInitialTextSection); + + return Res; +} + +int main(int argc, char **argv) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc, argv); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + + // Initialize targets and assembly printers/parsers. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + // Register the target printer for --version. + cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); + + cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); + TripleName = Triple::normalize(TripleName); + setDwarfDebugFlags(argc, argv); + + const char *ProgName = argv[0]; const Target *TheTarget = GetTarget(ProgName); if (!TheTarget) return 1; @@ -414,7 +424,6 @@ static int AssembleInput(const char *ProgName) { OwningPtr STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); - // FIXME: There is a bit of code duplication with addPassesToEmitFile. if (FileType == OFT_AssemblyFile) { MCInstPrinter *IP = TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI); @@ -441,93 +450,24 @@ static int AssembleInput(const char *ProgName) { NoExecStack)); } - OwningPtr Parser(createMCAsmParser(SrcMgr, Ctx, - *Str.get(), *MAI)); - OwningPtr TAP(TheTarget->createMCAsmParser(*STI, *Parser)); - if (!TAP) { - errs() << ProgName - << ": error: this target does not support assembly parsing.\n"; - return 1; - } - - Parser->setShowParsedOperands(ShowInstOperands); - Parser->setTargetParser(*TAP.get()); - - int Res = Parser->Run(NoInitialTextSection); - - // Keep output if no errors. - if (Res == 0) Out->keep(); - - return Res; -} - -static int DisassembleInput(const char *ProgName, bool Enhanced) { - const Target *TheTarget = GetTarget(ProgName); - if (!TheTarget) - return 0; - - OwningPtr Buffer; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, Buffer)) { - errs() << ProgName << ": " << ec.message() << '\n'; - return 1; - } - - OwningPtr Out(GetOutputStream()); - if (!Out) - return 1; - - int Res; - if (Enhanced) { - Res = - Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os()); - } else { - // Package up features to be passed to target/subtarget - std::string FeaturesStr; - if (MAttrs.size()) { - SubtargetFeatures Features; - for (unsigned i = 0; i != MAttrs.size(); ++i) - Features.AddFeature(MAttrs[i]); - FeaturesStr = Features.getString(); - } - - Res = Disassembler::disassemble(*TheTarget, TripleName, MCPU, FeaturesStr, - *Buffer.take(), Out->os()); - } - - // Keep output if no errors. - if (Res == 0) Out->keep(); - - return Res; -} - - -int main(int argc, char **argv) { - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(); - PrettyStackTraceProgram X(argc, argv); - llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - - // Initialize targets and assembly printers/parsers. - llvm::InitializeAllTargetInfos(); - llvm::InitializeAllTargetMCs(); - llvm::InitializeAllAsmParsers(); - llvm::InitializeAllDisassemblers(); - - // Register the target printer for --version. - cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); - - cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); - TripleName = Triple::normalize(TripleName); - setDwarfDebugFlags(argc, argv); - + int Res = 1; switch (Action) { case AC_AsLex: - return AsLexInput(argv[0]); + Res = AsLexInput(SrcMgr, *MAI, Out.get()); + break; case AC_Assemble: - return AssembleInput(argv[0]); + Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI); + break; case AC_Disassemble: - return DisassembleInput(argv[0], false); + Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, + *Buffer, SrcMgr, Out->os()); + break; case AC_EDisassemble: - return DisassembleInput(argv[0], true); + Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, SrcMgr, Out->os()); + break; } + + // Keep output if no errors. + if (Res == 0) Out->keep(); + return Res; } -- cgit v1.1 From e652b521f97ed0c60cb5ad533dfcf477863ac0b1 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 17 Apr 2012 23:05:48 +0000 Subject: allow opt to take a -mtriple option git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154959 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/opt/opt.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tools') diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 30da863..a5b0511 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -114,6 +114,9 @@ static cl::opt OptLevelO3("O3", cl::desc("Optimization level 3. Similar to llvm-gcc -O3")); +static cl::opt +TargetTriple("mtriple", cl::desc("Override target triple for module")); + static cl::opt UnitAtATime("funit-at-a-time", cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"), @@ -512,6 +515,10 @@ int main(int argc, char **argv) { return 1; } + // If we are supposed to override the target triple, do so now. + if (!TargetTriple.empty()) + M->setTargetTriple(Triple::normalize(TargetTriple)); + // Figure out what stream we are supposed to write to... OwningPtr Out; if (NoOutput) { -- cgit v1.1 From 9a1484165cd7cc3b95f5f65f845257c44f55a5b3 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Wed, 18 Apr 2012 08:34:12 +0000 Subject: Move the JIT flags from llc to lli. These flags showed up as part of moving backend flags in TargetOptions.h into their own class in r145714. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154993 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llc/llc.cpp | 26 -------------------------- tools/lli/lli.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 26 deletions(-) (limited to 'tools') diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 9e30ac1..ceff8a6 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -210,29 +210,6 @@ DontPlaceZerosInBSS("nozero-initialized-in-bss", cl::init(false)); static cl::opt -EnableJITExceptionHandling("jit-enable-eh", - cl::desc("Emit exception handling information"), - cl::init(false)); - -// In debug builds, make this default to true. -#ifdef NDEBUG -#define EMIT_DEBUG false -#else -#define EMIT_DEBUG true -#endif -static cl::opt -EmitJitDebugInfo("jit-emit-debug", - cl::desc("Emit debug information to debugger"), - cl::init(EMIT_DEBUG)); -#undef EMIT_DEBUG - -static cl::opt -EmitJitDebugInfoToDisk("jit-emit-debug-to-disk", - cl::Hidden, - cl::desc("Emit debug info objfiles to disk"), - cl::init(false)); - -static cl::opt EnableGuaranteedTailCallOpt("tailcallopt", cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."), cl::init(false)); @@ -463,9 +440,6 @@ int main(int argc, char **argv) { if (FloatABIForCalls != FloatABI::Default) Options.FloatABIType = FloatABIForCalls; Options.NoZerosInBSS = DontPlaceZerosInBSS; - Options.JITExceptionHandling = EnableJITExceptionHandling; - Options.JITEmitDebugInfo = EmitJitDebugInfo; - Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk; Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; Options.DisableTailCalls = DisableTailCalls; Options.StackAlignmentOverride = OverrideStackAlignment; diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index efcc1f5..2e2bf7d 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -141,6 +141,28 @@ namespace { "Large code model"), clEnumValEnd)); + cl::opt + EnableJITExceptionHandling("jit-enable-eh", + cl::desc("Emit exception handling information"), + cl::init(false)); + + cl::opt +// In debug builds, make this default to true. +#ifdef NDEBUG +#define EMIT_DEBUG false +#else +#define EMIT_DEBUG true +#endif + EmitJitDebugInfo("jit-emit-debug", + cl::desc("Emit debug information to debugger"), + cl::init(EMIT_DEBUG)); +#undef EMIT_DEBUG + + static cl::opt + EmitJitDebugInfoToDisk("jit-emit-debug-to-disk", + cl::Hidden, + cl::desc("Emit debug info objfiles to disk"), + cl::init(false)); } static ExecutionEngine *EE = 0; @@ -229,6 +251,12 @@ int main(int argc, char **argv, char * const *envp) { } builder.setOptLevel(OLvl); + TargetOptions Options; + Options.JITExceptionHandling = EnableJITExceptionHandling; + Options.JITEmitDebugInfo = EmitJitDebugInfo; + Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk; + builder.setTargetOptions(Options); + EE = builder.create(); if (!EE) { if (!ErrorMsg.empty()) -- cgit v1.1