From 803fa2c60544aeba1df310d9aa5e46839517234f Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 18 Jul 2011 04:16:27 +0000 Subject: LLC doesn't need to create MCInstrInfo's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135369 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llc/llc.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index b36e941..c40298c 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -202,7 +202,6 @@ int main(int argc, char **argv) { // Initialize targets first, so that --version shows registered targets. InitializeAllTargets(); InitializeAllMCAsmInfos(); - InitializeAllMCInstrInfos(); InitializeAllMCSubtargetInfos(); InitializeAllAsmPrinters(); InitializeAllAsmParsers(); -- cgit v1.1 From db125cfaf57cc83e7dd7453de2d509bc8efd0e5e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 18 Jul 2011 04:54:35 +0000 Subject: land David Blaikie's patch to de-constify Type, with a few tweaks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135375 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/ExtractFunction.cpp | 2 +- tools/bugpoint/Miscompilation.cpp | 6 +++--- tools/lto/LTOCodeGenerator.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 9941add..73b65ca 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -175,7 +175,7 @@ static Constant *GetTorInit(std::vector > &TorList) { std::vector ArrayElts; Type *Int32Ty = Type::getInt32Ty(TorList[0].first->getContext()); - const StructType *STy = + StructType *STy = StructType::get(Int32Ty, TorList[0].first->getType(), NULL); for (unsigned i = 0, e = TorList.size(); i != e; ++i) { Constant *Elts[] = { diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index d645dfb..4da444b 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -384,7 +384,7 @@ static bool ExtractLoops(BugDriver &BD, outs() << "*** Loop extraction successful!\n"; - std::vector > MisCompFunctions; + std::vector > MisCompFunctions; for (Module::iterator I = ToOptimizeLoopExtracted->begin(), E = ToOptimizeLoopExtracted->end(); I != E; ++I) if (!I->isDeclaration()) @@ -569,7 +569,7 @@ static bool ExtractBlocks(BugDriver &BD, // together. delete ToExtract; - std::vector > MisCompFunctions; + std::vector > MisCompFunctions; for (Module::iterator I = Extracted->begin(), E = Extracted->end(); I != E; ++I) if (!I->isDeclaration()) @@ -850,7 +850,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, NullPtr,F->getName()+".fpcache"); // Construct a new stub function that will re-route calls to F - const FunctionType *FuncTy = F->getFunctionType(); + FunctionType *FuncTy = F->getFunctionType(); Function *FuncWrapper = Function::Create(FuncTy, GlobalValue::InternalLinkage, F->getName() + "_wrapper", diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 14594cf..68cd2bb 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -329,7 +329,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { if (LLVMCompilerUsed) LLVMCompilerUsed->eraseFromParent(); - const llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context); + llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context); std::vector asmUsed2; for (SmallPtrSet::const_iterator i = asmUsed.begin(), e = asmUsed.end(); i !=e; ++i) { -- cgit v1.1 From 0e6a052331f674dd70e28af41f654a7874405eab Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 18 Jul 2011 20:57:22 +0000 Subject: Sink getDwarfRegNum, getLLVMRegNum, getSEHRegNum from TargetRegisterInfo down to MCRegisterInfo. Also initialize the mapping at construction time. This patch eliminate TargetRegisterInfo from TargetAsmInfo. It's another step towards fixing the layering violation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135424 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-mc/llvm-mc.cpp | 6 +++++- tools/lto/LTOCodeGenerator.cpp | 5 ++++- tools/lto/LTOModule.cpp | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 334bf32..1633ae3 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -309,6 +309,9 @@ static int AssembleInput(const char *ProgName) { llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(TripleName)); assert(MAI && "Unable to create target asm info!"); + llvm::OwningPtr MRI(TheTarget->createMCRegInfo(TripleName)); + assert(MRI && "Unable to create target register info!"); + // Package up features to be passed to target/subtarget std::string FeaturesStr; @@ -327,7 +330,7 @@ static int AssembleInput(const char *ProgName) { } const TargetAsmInfo *tai = new TargetAsmInfo(*TM); - MCContext Ctx(*MAI, tai); + MCContext Ctx(*MAI, *MRI, tai); if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); @@ -438,6 +441,7 @@ int main(int argc, char **argv) { llvm::InitializeAllTargets(); llvm::InitializeAllMCAsmInfos(); llvm::InitializeAllMCInstrInfos(); + llvm::InitializeAllMCRegisterInfos(); llvm::InitializeAllMCSubtargetInfos(); llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmParsers(); diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 68cd2bb..3fce456 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -31,6 +31,7 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetSelect.h" #include "llvm/Support/CommandLine.h" @@ -74,6 +75,7 @@ LTOCodeGenerator::LTOCodeGenerator() { InitializeAllTargets(); InitializeAllMCAsmInfos(); + InitializeAllMCRegisterInfos(); InitializeAllMCSubtargetInfos(); InitializeAllAsmPrinters(); } @@ -308,7 +310,8 @@ void LTOCodeGenerator::applyScopeRestrictions() { passes.add(createVerifierPass()); // mark which symbols can not be internalized - MCContext Context(*_target->getMCAsmInfo(), NULL); + MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), + NULL); Mangler mangler(Context, *_target->getTargetData()); std::vector mustPreserveList; SmallPtrSet asmUsed; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index dc99b94..92b2e9a 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -40,6 +40,7 @@ #include "llvm/MC/SubtargetFeature.h" #include "llvm/Target/TargetAsmParser.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetSelect.h" @@ -662,7 +663,8 @@ static bool isAliasToDeclaration(const GlobalAlias &V) { bool LTOModule::ParseSymbols() { // Use mangler to add GlobalPrefix to names to match linker names. - MCContext Context(*_target->getMCAsmInfo(), NULL); + MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), + NULL); Mangler mangler(Context, *_target->getTargetData()); // add functions -- cgit v1.1 From 439661395fd2a2a832dba01c65bc88718528313c Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 19 Jul 2011 06:37:02 +0000 Subject: Introduce MCCodeGenInfo, which keeps information that can affect codegen (including compilation, assembly). Move relocation model Reloc::Model from TargetMachine to MCCodeGenInfo so it's accessible even without TargetMachine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135468 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llc/llc.cpp | 18 +++++++++++++++++- tools/lli/lli.cpp | 16 ++++++++++++++++ tools/llvm-mc/llvm-mc.cpp | 19 ++++++++++++++++++- tools/llvm-objdump/llvm-objdump.cpp | 1 + tools/lto/LTOCodeGenerator.cpp | 11 +++++++---- tools/lto/LTOModule.cpp | 1 + 6 files changed, 60 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index c40298c..f1d4dbc 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -76,6 +76,21 @@ MAttrs("mattr", cl::desc("Target specific attributes (-mattr=help for details)"), cl::value_desc("a1,+a2,-a3,...")); +static cl::opt +RelocModel("relocation-model", + cl::desc("Choose relocation model"), + cl::init(Reloc::Default), + cl::values( + clEnumValN(Reloc::Default, "default", + "Target default relocation model"), + clEnumValN(Reloc::Static, "static", + "Non-relocatable code"), + clEnumValN(Reloc::PIC_, "pic", + "Fully relocatable, position independent code"), + clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", + "Relocatable external references, non-relocatable code"), + clEnumValEnd)); + static cl::opt RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, " @@ -202,6 +217,7 @@ int main(int argc, char **argv) { // Initialize targets first, so that --version shows registered targets. InitializeAllTargets(); InitializeAllMCAsmInfos(); + InitializeAllMCCodeGenInfos(); InitializeAllMCSubtargetInfos(); InitializeAllAsmPrinters(); InitializeAllAsmParsers(); @@ -272,7 +288,7 @@ int main(int argc, char **argv) { std::auto_ptr target(TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, - FeaturesStr)); + FeaturesStr, RelocModel)); assert(target.get() && "Could not allocate target machine!"); TargetMachine &Target = *target.get(); diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 014925c..da03ddd 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -108,6 +108,21 @@ namespace { NoLazyCompilation("disable-lazy-compilation", cl::desc("Disable JIT lazy compilation"), cl::init(false)); + + cl::opt + RelocModel("relocation-model", + cl::desc("Choose relocation model"), + cl::init(Reloc::Default), + cl::values( + clEnumValN(Reloc::Default, "default", + "Target default relocation model"), + clEnumValN(Reloc::Static, "static", + "Non-relocatable code"), + clEnumValN(Reloc::PIC_, "pic", + "Fully relocatable, position independent code"), + clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", + "Relocatable external references, non-relocatable code"), + clEnumValEnd)); } static ExecutionEngine *EE = 0; @@ -164,6 +179,7 @@ int main(int argc, char **argv, char * const *envp) { builder.setMArch(MArch); builder.setMCPU(MCPU); builder.setMAttrs(MAttrs); + builder.setRelocationModel(RelocModel); builder.setErrorStr(&ErrorMsg); builder.setEngineKind(ForceInterpreter ? EngineKind::Interpreter diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 1633ae3..e2de055 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -111,6 +111,21 @@ MCPU("mcpu", cl::value_desc("cpu-name"), cl::init("")); +static cl::opt +RelocModel("relocation-model", + cl::desc("Choose relocation model"), + cl::init(Reloc::Default), + cl::values( + clEnumValN(Reloc::Default, "default", + "Target default relocation model"), + clEnumValN(Reloc::Static, "static", + "Non-relocatable code"), + clEnumValN(Reloc::PIC_, "pic", + "Fully relocatable, position independent code"), + clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", + "Relocatable external references, non-relocatable code"), + clEnumValEnd)); + static cl::opt NoInitialTextSection("n", cl::desc("Don't assume assembly file starts " "in the text section")); @@ -321,7 +336,8 @@ static int AssembleInput(const char *ProgName) { // the .cpu and .code16 directives). OwningPtr TM(TheTarget->createTargetMachine(TripleName, MCPU, - FeaturesStr)); + FeaturesStr, + RelocModel)); if (!TM) { errs() << ProgName << ": error: could not create target for triple '" @@ -440,6 +456,7 @@ int main(int argc, char **argv) { // FIXME: We shouldn't need to initialize the Target(Machine)s. llvm::InitializeAllTargets(); llvm::InitializeAllMCAsmInfos(); + llvm::InitializeAllMCCodeGenInfos(); llvm::InitializeAllMCInstrInfos(); llvm::InitializeAllMCRegisterInfos(); llvm::InitializeAllMCSubtargetInfos(); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 4079e4a..59586ce 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -270,6 +270,7 @@ int main(int argc, char **argv) { // FIXME: We shouldn't need to initialize the Target(Machine)s. llvm::InitializeAllTargets(); llvm::InitializeAllMCAsmInfos(); + llvm::InitializeAllMCCodeGenInfos(); llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmParsers(); llvm::InitializeAllDisassemblers(); diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 3fce456..28cfa9c 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -75,6 +75,7 @@ LTOCodeGenerator::LTOCodeGenerator() { InitializeAllTargets(); InitializeAllMCAsmInfos(); + InitializeAllMCCodeGenInfos(); InitializeAllMCRegisterInfos(); InitializeAllMCSubtargetInfos(); InitializeAllAsmPrinters(); @@ -252,15 +253,16 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) // 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: - TargetMachine::setRelocationModel(Reloc::Static); + RelocModel = Reloc::Static; break; case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - TargetMachine::setRelocationModel(Reloc::PIC_); + RelocModel = Reloc::PIC_; break; case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - TargetMachine::setRelocationModel(Reloc::DynamicNoPIC); + RelocModel = Reloc::DynamicNoPIC; break; } @@ -268,7 +270,8 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) SubtargetFeatures Features; Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); std::string FeatureStr = Features.getString(); - _target = march->createTargetMachine(Triple, _mCpu, FeatureStr); + _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, + RelocModel); } return false; } diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 92b2e9a..0ca96bc 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -136,6 +136,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, static bool Initialized = false; if (!Initialized) { InitializeAllTargets(); + InitializeAllMCCodeGenInfos(); InitializeAllMCAsmInfos(); InitializeAllMCSubtargetInfos(); InitializeAllAsmParsers(); -- cgit v1.1 From 14c92467e79f5f151b4b53ab2b1a7fd0f7881041 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 19 Jul 2011 22:59:25 +0000 Subject: Fix off-by-one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135533 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/llvm-objdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 59586ce..8f6e9df 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -107,7 +107,7 @@ public: uint64_t getExtent() const { return Bytes.size(); } int readByte(uint64_t Addr, uint8_t *Byte) const { - if (Addr > getExtent()) + if (Addr >= getExtent()) return -1; *Byte = Bytes[Addr]; return 0; -- cgit v1.1 From e76a33b9567d78a5744dc52fcec3a6056d6fb576 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 20 Jul 2011 05:58:47 +0000 Subject: Add MCObjectFileInfo and sink the MCSections initialization code from TargetLoweringObjectFileImpl down to MCObjectFileInfo. TargetAsmInfo is done to one last method. It's *almost* gone! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135569 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-mc/llvm-mc.cpp | 9 ++++++++- tools/lto/LTOCodeGenerator.cpp | 2 +- tools/lto/LTOModule.cpp | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index e2de055..d930aea 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -18,6 +18,8 @@ #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" @@ -346,7 +348,12 @@ static int AssembleInput(const char *ProgName) { } const TargetAsmInfo *tai = new TargetAsmInfo(*TM); - MCContext Ctx(*MAI, *MRI, tai); + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and + // MCObjectFileInfo needs a MCContext reference in order to initialize itself. + OwningPtr MOFI(new MCObjectFileInfo()); + MCContext Ctx(*MAI, *MRI, MOFI.get(), tai); + MOFI->InitMCObjectFileInfo(TripleName, RelocModel, Ctx); + if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 28cfa9c..2f02847 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -314,7 +314,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { // mark which symbols can not be internalized MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), - NULL); + NULL, NULL); Mangler mangler(Context, *_target->getTargetData()); std::vector mustPreserveList; SmallPtrSet asmUsed; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 0ca96bc..661674c 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -665,7 +665,7 @@ static bool isAliasToDeclaration(const GlobalAlias &V) { bool LTOModule::ParseSymbols() { // Use mangler to add GlobalPrefix to names to match linker names. MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), - NULL); + NULL, NULL); Mangler mangler(Context, *_target->getTargetData()); // add functions -- cgit v1.1