summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2011-07-17 15:36:56 +0000
committerdim <dim@FreeBSD.org>2011-07-17 15:36:56 +0000
commit1176aa52646fe641a4243a246aa7f960c708a274 (patch)
treec8086addb211fa670a9d2b1038d8c2e453229755 /tools
parentece02cd5829cea836e9365b0845a8ef042d17b0a (diff)
downloadFreeBSD-src-1176aa52646fe641a4243a246aa7f960c708a274.zip
FreeBSD-src-1176aa52646fe641a4243a246aa7f960c708a274.tar.gz
Vendor import of llvm trunk r135360:
http://llvm.org/svn/llvm-project/llvm/trunk@135360
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt5
-rw-r--r--tools/bugpoint/ExtractFunction.cpp17
-rw-r--r--tools/bugpoint/Miscompilation.cpp10
-rw-r--r--tools/llc/llc.cpp11
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp68
-rw-r--r--tools/llvm-dis/llvm-dis.cpp2
-rw-r--r--tools/llvm-extract/llvm-extract.cpp1
-rw-r--r--tools/llvm-mc/Disassembler.cpp6
-rw-r--r--tools/llvm-mc/Disassembler.h2
-rw-r--r--tools/llvm-mc/llvm-mc.cpp61
-rw-r--r--tools/llvm-nm/llvm-nm.cpp40
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp126
-rw-r--r--tools/llvmc/src/Hooks.cpp1
-rw-r--r--tools/lto/LTOCodeGenerator.cpp8
-rw-r--r--tools/lto/LTOModule.cpp33
15 files changed, 212 insertions, 179 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index c9072a7..8851a0b 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -59,7 +59,10 @@ if( LLVM_ENABLE_PIC )
endif()
if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/clang/CMakeLists.txt )
- add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/clang )
+ option(LLVM_BUILD_CLANG "Whether to build Clang as part of LLVM" ON)
+ if (${LLVM_BUILD_CLANG})
+ add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/clang )
+ endif()
endif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/clang/CMakeLists.txt )
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index 593765c..9941add 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -116,8 +116,6 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
else
CleanupPasses.push_back("deadargelim");
- CleanupPasses.push_back("deadtypeelim");
-
Module *New = runPassesOn(M, CleanupPasses);
if (New == 0) {
errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n";
@@ -175,13 +173,16 @@ void llvm::DeleteFunctionBody(Function *F) {
static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
assert(!TorList.empty() && "Don't create empty tor list!");
std::vector<Constant*> ArrayElts;
+ Type *Int32Ty = Type::getInt32Ty(TorList[0].first->getContext());
+
+ const StructType *STy =
+ StructType::get(Int32Ty, TorList[0].first->getType(), NULL);
for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
- std::vector<Constant*> Elts;
- Elts.push_back(ConstantInt::get(
- Type::getInt32Ty(TorList[i].first->getContext()), TorList[i].second));
- Elts.push_back(TorList[i].first);
- ArrayElts.push_back(ConstantStruct::get(TorList[i].first->getContext(),
- Elts, false));
+ Constant *Elts[] = {
+ ConstantInt::get(Int32Ty, TorList[i].second),
+ TorList[i].first
+ };
+ ArrayElts.push_back(ConstantStruct::get(STy, Elts));
}
return ConstantArray::get(ArrayType::get(ArrayElts[0]->getType(),
ArrayElts.size()),
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index 1834fe1..d645dfb 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -794,8 +794,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Call the old main function and return its result
BasicBlock *BB = BasicBlock::Create(Safe->getContext(), "entry", newMain);
- CallInst *call = CallInst::Create(oldMainProto, args.begin(), args.end(),
- "", BB);
+ CallInst *call = CallInst::Create(oldMainProto, args, "", BB);
// If the type of old function wasn't void, return value of call
ReturnInst::Create(Safe->getContext(), call, BB);
@@ -873,8 +872,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
//
// call resolver(GetElementPtr...)
CallInst *Resolver =
- CallInst::Create(resolverFunc, ResolverArgs.begin(),
- ResolverArgs.end(), "resolver", LookupBB);
+ CallInst::Create(resolverFunc, ResolverArgs, "resolver", LookupBB);
// Cast the result from the resolver to correctly-typed function.
CastInst *CastedResolver =
@@ -899,10 +897,10 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Pass on the arguments to the real function, return its result
if (F->getReturnType()->isVoidTy()) {
- CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
+ CallInst::Create(FuncPtr, Args, "", DoCallBB);
ReturnInst::Create(F->getContext(), DoCallBB);
} else {
- CallInst *Call = CallInst::Create(FuncPtr, Args.begin(), Args.end(),
+ CallInst *Call = CallInst::Create(FuncPtr, Args,
"retval", DoCallBB);
ReturnInst::Create(F->getContext(),Call, DoCallBB);
}
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 162d6c8..b36e941 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/Config/config.h"
+#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
@@ -31,7 +32,6 @@
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/Signals.h"
-#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegistry.h"
@@ -201,6 +201,9 @@ int main(int argc, char **argv) {
// Initialize targets first, so that --version shows registered targets.
InitializeAllTargets();
+ InitializeAllMCAsmInfos();
+ InitializeAllMCInstrInfos();
+ InitializeAllMCSubtargetInfos();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
@@ -261,16 +264,16 @@ int main(int argc, char **argv) {
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
- if (MCPU.size() || MAttrs.size()) {
+ if (MAttrs.size()) {
SubtargetFeatures Features;
- Features.setCPU(MCPU);
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
std::auto_ptr<TargetMachine>
- target(TheTarget->createTargetMachine(TheTriple.getTriple(), FeaturesStr));
+ target(TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU,
+ FeaturesStr));
assert(target.get() && "Could not allocate target machine!");
TargetMachine &Target = *target.get();
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 9a92671..4ada64a 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -102,10 +102,11 @@ static const char *GetBlockName(unsigned BlockID,
default: return 0;
case bitc::MODULE_BLOCK_ID: return "MODULE_BLOCK";
case bitc::PARAMATTR_BLOCK_ID: return "PARAMATTR_BLOCK";
- case bitc::TYPE_BLOCK_ID: return "TYPE_BLOCK";
+ case bitc::TYPE_BLOCK_ID_OLD: return "TYPE_BLOCK_ID_OLD";
+ case bitc::TYPE_BLOCK_ID_NEW: return "TYPE_BLOCK_ID";
case bitc::CONSTANTS_BLOCK_ID: return "CONSTANTS_BLOCK";
case bitc::FUNCTION_BLOCK_ID: return "FUNCTION_BLOCK";
- case bitc::TYPE_SYMTAB_BLOCK_ID: return "TYPE_SYMTAB";
+ case bitc::TYPE_SYMTAB_BLOCK_ID_OLD: return "TYPE_SYMTAB_OLD";
case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB";
case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK";
case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK";
@@ -162,25 +163,29 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
default: return 0;
case bitc::PARAMATTR_CODE_ENTRY: return "ENTRY";
}
- case bitc::TYPE_BLOCK_ID:
+ case bitc::TYPE_BLOCK_ID_OLD:
+ case bitc::TYPE_BLOCK_ID_NEW:
switch (CodeID) {
default: return 0;
- case bitc::TYPE_CODE_NUMENTRY: return "NUMENTRY";
- case bitc::TYPE_CODE_VOID: return "VOID";
- case bitc::TYPE_CODE_FLOAT: return "FLOAT";
- case bitc::TYPE_CODE_DOUBLE: return "DOUBLE";
- case bitc::TYPE_CODE_LABEL: return "LABEL";
- case bitc::TYPE_CODE_OPAQUE: return "OPAQUE";
- case bitc::TYPE_CODE_INTEGER: return "INTEGER";
- case bitc::TYPE_CODE_POINTER: return "POINTER";
- case bitc::TYPE_CODE_FUNCTION: return "FUNCTION";
- case bitc::TYPE_CODE_STRUCT: return "STRUCT";
- case bitc::TYPE_CODE_ARRAY: return "ARRAY";
- case bitc::TYPE_CODE_VECTOR: return "VECTOR";
- case bitc::TYPE_CODE_X86_FP80: return "X86_FP80";
- case bitc::TYPE_CODE_FP128: return "FP128";
- case bitc::TYPE_CODE_PPC_FP128: return "PPC_FP128";
- case bitc::TYPE_CODE_METADATA: return "METADATA";
+ case bitc::TYPE_CODE_NUMENTRY: return "NUMENTRY";
+ case bitc::TYPE_CODE_VOID: return "VOID";
+ case bitc::TYPE_CODE_FLOAT: return "FLOAT";
+ case bitc::TYPE_CODE_DOUBLE: return "DOUBLE";
+ case bitc::TYPE_CODE_LABEL: return "LABEL";
+ case bitc::TYPE_CODE_OPAQUE: return "OPAQUE";
+ case bitc::TYPE_CODE_INTEGER: return "INTEGER";
+ case bitc::TYPE_CODE_POINTER: return "POINTER";
+ case bitc::TYPE_CODE_FUNCTION: return "FUNCTION";
+ case bitc::TYPE_CODE_STRUCT_OLD: return "STRUCT_OLD";
+ case bitc::TYPE_CODE_ARRAY: return "ARRAY";
+ case bitc::TYPE_CODE_VECTOR: return "VECTOR";
+ case bitc::TYPE_CODE_X86_FP80: return "X86_FP80";
+ case bitc::TYPE_CODE_FP128: return "FP128";
+ case bitc::TYPE_CODE_PPC_FP128: return "PPC_FP128";
+ case bitc::TYPE_CODE_METADATA: return "METADATA";
+ case bitc::TYPE_CODE_STRUCT_ANON: return "STRUCT_ANON";
+ case bitc::TYPE_CODE_STRUCT_NAME: return "STRUCT_NAME";
+ case bitc::TYPE_CODE_STRUCT_NAMED: return "STRUCT_NAMED";
}
case bitc::CONSTANTS_BLOCK_ID:
@@ -230,25 +235,19 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::FUNC_CODE_INST_UNREACHABLE: return "INST_UNREACHABLE";
case bitc::FUNC_CODE_INST_PHI: return "INST_PHI";
- case bitc::FUNC_CODE_INST_MALLOC: return "INST_MALLOC";
- case bitc::FUNC_CODE_INST_FREE: return "INST_FREE";
case bitc::FUNC_CODE_INST_ALLOCA: return "INST_ALLOCA";
case bitc::FUNC_CODE_INST_LOAD: return "INST_LOAD";
- case bitc::FUNC_CODE_INST_STORE: return "INST_STORE";
- case bitc::FUNC_CODE_INST_CALL: return "INST_CALL";
case bitc::FUNC_CODE_INST_VAARG: return "INST_VAARG";
- case bitc::FUNC_CODE_INST_STORE2: return "INST_STORE2";
- case bitc::FUNC_CODE_INST_GETRESULT: return "INST_GETRESULT";
+ case bitc::FUNC_CODE_INST_STORE: return "INST_STORE";
case bitc::FUNC_CODE_INST_EXTRACTVAL: return "INST_EXTRACTVAL";
case bitc::FUNC_CODE_INST_INSERTVAL: return "INST_INSERTVAL";
case bitc::FUNC_CODE_INST_CMP2: return "INST_CMP2";
case bitc::FUNC_CODE_INST_VSELECT: return "INST_VSELECT";
- case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: return "DEBUG_LOC_AGAIN";
- case bitc::FUNC_CODE_INST_CALL2: return "INST_CALL2";
- case bitc::FUNC_CODE_DEBUG_LOC2: return "DEBUG_LOC2";
+ case bitc::FUNC_CODE_INST_CALL: return "INST_CALL";
+ case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
}
- case bitc::TYPE_SYMTAB_BLOCK_ID:
+ case bitc::TYPE_SYMTAB_BLOCK_ID_OLD:
switch (CodeID) {
default: return 0;
case bitc::TST_CODE_ENTRY: return "ENTRY";
@@ -262,22 +261,17 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::METADATA_ATTACHMENT_ID:
switch(CodeID) {
default:return 0;
- case bitc::METADATA_ATTACHMENT: return "METADATA_ATTACHMENT";
- case bitc::METADATA_ATTACHMENT2: return "METADATA_ATTACHMENT2";
+ case bitc::METADATA_ATTACHMENT: return "METADATA_ATTACHMENT";
}
case bitc::METADATA_BLOCK_ID:
switch(CodeID) {
default:return 0;
case bitc::METADATA_STRING: return "METADATA_STRING";
+ case bitc::METADATA_NAME: return "METADATA_NAME";
+ case bitc::METADATA_KIND: return "METADATA_KIND";
case bitc::METADATA_NODE: return "METADATA_NODE";
case bitc::METADATA_FN_NODE: return "METADATA_FN_NODE";
- case bitc::METADATA_NAME: return "METADATA_NAME";
case bitc::METADATA_NAMED_NODE: return "METADATA_NAMED_NODE";
- case bitc::METADATA_KIND: return "METADATA_KIND";
- case bitc::METADATA_ATTACHMENT: return "METADATA_ATTACHMENT";
- case bitc::METADATA_NODE2: return "METADATA_NODE2";
- case bitc::METADATA_FN_NODE2: return "METADATA_FN_NODE2";
- case bitc::METADATA_NAMED_NODE2: return "METADATA_NAMED_NODE2";
}
}
}
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 7453d9e..9020a52 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -74,7 +74,7 @@ public:
if (!V.getType()->isVoidTy()) {
OS.PadToColumn(50);
Padded = true;
- OS << "; [#uses=" << V.getNumUses() << " type=" << V.getType()->getDescription() << "]"; // Output # uses and type
+ OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]"; // Output # uses and type
}
if (const Instruction *I = dyn_cast<Instruction>(&V)) {
const DebugLoc &DL = I->getDebugLoc();
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 8c2f43a..a6c229f 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -149,7 +149,6 @@ int main(int argc, char **argv) {
if (!DeleteFn)
Passes.add(createGlobalDCEPass()); // Delete unreachable globals
Passes.add(createStripDeadDebugInfoPass()); // Remove dead debug info
- Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
std::string ErrorInfo;
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp
index 93b9723..c389f6a 100644
--- a/tools/llvm-mc/Disassembler.cpp
+++ b/tools/llvm-mc/Disassembler.cpp
@@ -127,12 +127,12 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
return false;
}
-int Disassembler::disassemble(const Target &T, TargetMachine &TM,
+int Disassembler::disassemble(const Target &T,
const std::string &Triple,
MemoryBuffer &Buffer,
raw_ostream &Out) {
// Set up disassembler.
- OwningPtr<const MCAsmInfo> AsmInfo(T.createAsmInfo(Triple));
+ OwningPtr<const MCAsmInfo> AsmInfo(T.createMCAsmInfo(Triple));
if (!AsmInfo) {
errs() << "error: no assembly info for target " << Triple << "\n";
@@ -146,7 +146,7 @@ int Disassembler::disassemble(const Target &T, TargetMachine &TM,
}
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
- OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(TM, AsmPrinterVariant,
+ OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant,
*AsmInfo));
if (!IP) {
errs() << "error: no instruction printer for target " << Triple << '\n';
diff --git a/tools/llvm-mc/Disassembler.h b/tools/llvm-mc/Disassembler.h
index d738ee7..433e71b 100644
--- a/tools/llvm-mc/Disassembler.h
+++ b/tools/llvm-mc/Disassembler.h
@@ -21,13 +21,11 @@ namespace llvm {
class MemoryBuffer;
class Target;
-class TargetMachine;
class raw_ostream;
class Disassembler {
public:
static int disassemble(const Target &target,
- TargetMachine &TM,
const std::string &tripleString,
MemoryBuffer &buffer,
raw_ostream &Out);
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index eb23a1a..334bf32 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -17,13 +17,15 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Target/TargetAsmBackend.h"
#include "llvm/Target/TargetAsmParser.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetRegistry.h"
-#include "llvm/Target/SubtargetFeature.h" // FIXME.
#include "llvm/Target/TargetAsmInfo.h" // FIXME.
#include "llvm/Target/TargetLowering.h" // FIXME.
#include "llvm/Target/TargetLoweringObjectFile.h" // FIXME.
@@ -97,7 +99,7 @@ IncludeDirs("I", cl::desc("Directory of include files"),
static cl::opt<std::string>
ArchName("arch", cl::desc("Target arch to assemble for, "
- "see -version for available targets"));
+ "see -version for available targets"));
static cl::opt<std::string>
TripleName("triple", cl::desc("Target triple to assemble for, "
@@ -110,12 +112,11 @@ MCPU("mcpu",
cl::init(""));
static cl::opt<bool>
-NoInitialTextSection("n", cl::desc(
- "Don't assume assembly file starts in the text section"));
+NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
+ "in the text section"));
static cl::opt<bool>
-SaveTempLabels("L", cl::desc(
- "Don't discard temporary labels"));
+SaveTempLabels("L", cl::desc("Don't discard temporary labels"));
enum ActionType {
AC_AsLex,
@@ -195,7 +196,7 @@ static int AsLexInput(const char *ProgName) {
if (!TheTarget)
return 1;
- llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createAsmInfo(TripleName));
+ llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TripleName));
assert(MAI && "Unable to create target asm info!");
AsmLexer Lexer(*MAI);
@@ -305,22 +306,18 @@ static int AssembleInput(const char *ProgName) {
SrcMgr.setIncludeDirs(IncludeDirs);
- llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createAsmInfo(TripleName));
+ llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TripleName));
assert(MAI && "Unable to create target asm info!");
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
- if (MCPU.size()) {
- SubtargetFeatures Features;
- Features.setCPU(MCPU);
- FeaturesStr = Features.getString();
- }
// FIXME: We shouldn't need to do this (and link in codegen).
// When we split this out, we should do it in a way that makes
// it straightforward to switch subtargets on the fly (.e.g,
// the .cpu and .code16 directives).
OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
+ MCPU,
FeaturesStr));
if (!TM) {
@@ -345,14 +342,18 @@ static int AssembleInput(const char *ProgName) {
TM->getTargetLowering()->getObjFileLowering();
const_cast<TargetLoweringObjectFile&>(TLOF).Initialize(Ctx, *TM);
+ OwningPtr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
+ OwningPtr<MCSubtargetInfo>
+ STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
+
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
if (FileType == OFT_AssemblyFile) {
MCInstPrinter *IP =
- TheTarget->createMCInstPrinter(*TM, OutputAsmVariant, *MAI);
+ TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI);
MCCodeEmitter *CE = 0;
TargetAsmBackend *TAB = 0;
if (ShowEncoding) {
- CE = TheTarget->createCodeEmitter(*TM, Ctx);
+ CE = TheTarget->createCodeEmitter(*MCII, *STI, Ctx);
TAB = TheTarget->createAsmBackend(TripleName);
}
Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true,
@@ -363,7 +364,7 @@ static int AssembleInput(const char *ProgName) {
Str.reset(createNullStreamer(Ctx));
} else {
assert(FileType == OFT_ObjectFile && "Invalid file type!");
- MCCodeEmitter *CE = TheTarget->createCodeEmitter(*TM, Ctx);
+ MCCodeEmitter *CE = TheTarget->createCodeEmitter(*MCII, *STI, Ctx);
TargetAsmBackend *TAB = TheTarget->createAsmBackend(TripleName);
Str.reset(TheTarget->createObjectStreamer(TripleName, Ctx, *TAB,
FOS, CE, RelaxAll,
@@ -376,7 +377,7 @@ static int AssembleInput(const char *ProgName) {
OwningPtr<MCAsmParser> Parser(createMCAsmParser(*TheTarget, SrcMgr, Ctx,
*Str.get(), *MAI));
- OwningPtr<TargetAsmParser> TAP(TheTarget->createAsmParser(*Parser, *TM));
+ OwningPtr<TargetAsmParser> TAP(TheTarget->createAsmParser(*STI, *Parser));
if (!TAP) {
errs() << ProgName
<< ": error: this target does not support assembly parsing.\n";
@@ -414,28 +415,7 @@ static int DisassembleInput(const char *ProgName, bool Enhanced) {
Res =
Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os());
} else {
- // Package up features to be passed to target/subtarget
- std::string FeaturesStr;
- if (MCPU.size()) {
- SubtargetFeatures Features;
- Features.setCPU(MCPU);
- FeaturesStr = Features.getString();
- }
-
- // FIXME: We shouldn't need to do this (and link in codegen).
- // When we split this out, we should do it in a way that makes
- // it straightforward to switch subtargets on the fly (.e.g,
- // the .cpu and .code16 directives).
- OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
- FeaturesStr));
-
- if (!TM) {
- errs() << ProgName << ": error: could not create target for triple '"
- << TripleName << "'.\n";
- return 1;
- }
-
- Res = Disassembler::disassemble(*TheTarget, *TM, TripleName,
+ Res = Disassembler::disassemble(*TheTarget, TripleName,
*Buffer.take(), Out->os());
}
@@ -456,6 +436,9 @@ int main(int argc, char **argv) {
llvm::InitializeAllTargetInfos();
// FIXME: We shouldn't need to initialize the Target(Machine)s.
llvm::InitializeAllTargets();
+ llvm::InitializeAllMCAsmInfos();
+ llvm::InitializeAllMCInstrInfos();
+ llvm::InitializeAllMCSubtargetInfos();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();
llvm::InitializeAllDisassemblers();
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index 1afa503..014cb29 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -143,6 +143,14 @@ namespace {
StringRef CurrentFilename;
typedef std::vector<NMSymbol> SymbolListT;
SymbolListT SymbolList;
+
+ bool error(error_code ec) {
+ if (!ec) return false;
+
+ outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
+ outs().flush();
+ return true;
+ }
}
static void SortAndPrintSymbolList() {
@@ -261,23 +269,29 @@ static void DumpSymbolNamesFromModule(Module *M) {
}
static void DumpSymbolNamesFromObject(ObjectFile *obj) {
+ error_code ec;
for (ObjectFile::symbol_iterator i = obj->begin_symbols(),
- e = obj->end_symbols(); i != e; ++i) {
- if (!DebugSyms && i->isInternal())
+ e = obj->end_symbols();
+ i != e; i.increment(ec)) {
+ if (error(ec)) break;
+ bool internal;
+ if (error(i->isInternal(internal))) break;
+ if (!DebugSyms && internal)
continue;
NMSymbol s;
s.Size = object::UnknownAddressOrSize;
s.Address = object::UnknownAddressOrSize;
- if (PrintSize || SizeSort)
- s.Size = i->getSize();
+ if (PrintSize || SizeSort) {
+ if (error(i->getSize(s.Size))) break;
+ }
if (PrintAddress)
- s.Address = i->getAddress();
- s.TypeChar = i->getNMTypeChar();
- s.Name = i->getName();
+ if (error(i->getAddress(s.Address))) break;
+ if (error(i->getNMTypeChar(s.TypeChar))) break;
+ if (error(i->getName(s.Name))) break;
SymbolList.push_back(s);
}
- CurrentFilename = obj->getFilename();
+ CurrentFilename = obj->getFileName();
SortAndPrintSymbolList();
}
@@ -317,13 +331,13 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
MultipleFiles = true;
std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule);
} else if (aPath.isObjectFile()) {
- std::auto_ptr<ObjectFile> obj(ObjectFile::createObjectFile(aPath.str()));
- if (!obj.get()) {
- errs() << ToolName << ": " << Filename << ": "
- << "Failed to open object file\n";
+ OwningPtr<Binary> obj;
+ if (error_code ec = object::createBinary(aPath.str(), obj)) {
+ errs() << ToolName << ": " << Filename << ": " << ec.message() << ".\n";
return;
}
- DumpSymbolNamesFromObject(obj.get());
+ if (object::ObjectFile *o = dyn_cast<ObjectFile>(obj.get()))
+ DumpSymbolNamesFromObject(o);
} else {
errs() << ToolName << ": " << Filename << ": "
<< "unrecognizable file type\n";
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index a17624a..4079e4a 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -14,14 +14,9 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/ObjectFile.h"
-// This config must be included before llvm-config.h.
-#include "llvm/Config/config.h"
-#include "../../lib/MC/MCDisassembler/EDDisassembler.h"
-#include "../../lib/MC/MCDisassembler/EDInst.h"
-#include "../../lib/MC/MCDisassembler/EDOperand.h"
-#include "../../lib/MC/MCDisassembler/EDToken.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCDisassembler.h"
#include "llvm/MC/MCInst.h"
@@ -38,12 +33,9 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
-#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetSelect.h"
#include <algorithm>
-#include <cctype>
-#include <cerrno>
#include <cstring>
using namespace llvm;
using namespace object;
@@ -69,6 +61,14 @@ namespace {
"see -version for available targets"));
StringRef ToolName;
+
+ bool error(error_code ec) {
+ if (!ec) return false;
+
+ outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
+ outs().flush();
+ return true;
+ }
}
static const Target *GetTarget(const ObjectFile *Obj = NULL) {
@@ -159,17 +159,46 @@ static void DisassembleInput(const StringRef &Filename) {
outs() << '\n';
outs() << Filename
- << ":\tfile format " << Obj->getFileFormatName() << "\n\n\n";
+ << ":\tfile format " << Obj->getFileFormatName() << "\n\n";
+ error_code ec;
for (ObjectFile::section_iterator i = Obj->begin_sections(),
e = Obj->end_sections();
- i != e; ++i) {
- if (!i->isText())
- continue;
- outs() << "Disassembly of section " << i->getName() << ":\n\n";
+ i != e; i.increment(ec)) {
+ if (error(ec)) break;
+ bool text;
+ if (error(i->isText(text))) break;
+ if (!text) continue;
+
+ // Make a list of all the symbols in this section.
+ std::vector<std::pair<uint64_t, StringRef> > Symbols;
+ for (ObjectFile::symbol_iterator si = Obj->begin_symbols(),
+ se = Obj->end_symbols();
+ si != se; si.increment(ec)) {
+ bool contains;
+ if (!error(i->containsSymbol(*si, contains)) && contains) {
+ uint64_t Address;
+ if (error(si->getAddress(Address))) break;
+ StringRef Name;
+ if (error(si->getName(Name))) break;
+ Symbols.push_back(std::make_pair(Address, Name));
+ }
+ }
+
+ // Sort the symbols by address, just in case they didn't come in that way.
+ array_pod_sort(Symbols.begin(), Symbols.end());
+
+ StringRef name;
+ if (error(i->getName(name))) break;
+ outs() << "Disassembly of section " << name << ':';
+
+ // If the section has no symbols just insert a dummy one and disassemble
+ // the whole section.
+ if (Symbols.empty())
+ Symbols.push_back(std::make_pair(0, name));
// Set up disassembler.
- OwningPtr<const MCAsmInfo> AsmInfo(TheTarget->createAsmInfo(TripleName));
+ OwningPtr<const MCAsmInfo> AsmInfo(TheTarget->createMCAsmInfo(TripleName));
if (!AsmInfo) {
errs() << "error: no assembly info for target " << TripleName << "\n";
@@ -182,49 +211,49 @@ static void DisassembleInput(const StringRef &Filename) {
return;
}
- // FIXME: We shouldn't need to do this (and link in codegen).
- // When we split this out, we should do it in a way that makes
- // it straightforward to switch subtargets on the fly (.e.g,
- // the .cpu and .code16 directives).
- std::string FeaturesStr;
- OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
- FeaturesStr));
- if (!TM) {
- errs() << "error: could not create target for triple " << TripleName << "\n";
- return;
- }
-
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
OwningPtr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
- *TM, AsmPrinterVariant, *AsmInfo));
+ AsmPrinterVariant, *AsmInfo));
if (!IP) {
errs() << "error: no instruction printer for target " << TripleName << '\n';
return;
}
- StringRef Bytes = i->getContents();
+ StringRef Bytes;
+ if (error(i->getContents(Bytes))) break;
StringRefMemoryObject memoryObject(Bytes);
uint64_t Size;
uint64_t Index;
-
- for (Index = 0; Index < Bytes.size(); Index += Size) {
- MCInst Inst;
-
-# ifndef NDEBUG
- raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
-# else
- raw_ostream &DebugOut = nulls();
-# endif
-
- if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, DebugOut)) {
- outs() << format("%8x:\t", i->getAddress() + Index);
- DumpBytes(StringRef(Bytes.data() + Index, Size));
- IP->printInst(&Inst, outs());
- outs() << "\n";
- } else {
- errs() << ToolName << ": warning: invalid instruction encoding\n";
- if (Size == 0)
- Size = 1; // skip illegible bytes
+ uint64_t SectSize;
+ if (error(i->getSize(SectSize))) break;
+
+ // Disassemble symbol by symbol.
+ for (unsigned si = 0, se = Symbols.size(); si != se; ++si) {
+ uint64_t Start = Symbols[si].first;
+ uint64_t End = si == se-1 ? SectSize : Symbols[si + 1].first - 1;
+ outs() << '\n' << Symbols[si].second << ":\n";
+
+ for (Index = Start; Index < End; Index += Size) {
+ MCInst Inst;
+
+#ifndef NDEBUG
+ raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
+#else
+ raw_ostream &DebugOut = nulls();
+#endif
+
+ if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, DebugOut)) {
+ uint64_t addr;
+ if (error(i->getAddress(addr))) break;
+ outs() << format("%8x:\t", addr + Index);
+ DumpBytes(StringRef(Bytes.data() + Index, Size));
+ IP->printInst(&Inst, outs());
+ outs() << "\n";
+ } else {
+ errs() << ToolName << ": warning: invalid instruction encoding\n";
+ if (Size == 0)
+ Size = 1; // skip illegible bytes
+ }
}
}
}
@@ -240,6 +269,7 @@ int main(int argc, char **argv) {
llvm::InitializeAllTargetInfos();
// FIXME: We shouldn't need to initialize the Target(Machine)s.
llvm::InitializeAllTargets();
+ llvm::InitializeAllMCAsmInfos();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();
llvm::InitializeAllDisassemblers();
diff --git a/tools/llvmc/src/Hooks.cpp b/tools/llvmc/src/Hooks.cpp
index 5aa250e..ddad08a 100644
--- a/tools/llvmc/src/Hooks.cpp
+++ b/tools/llvmc/src/Hooks.cpp
@@ -47,7 +47,6 @@ const unsigned MArchMapSize = NextHighestPowerOf2(MArchNumKeysARM);
const char* MArchMCpuKeysARM[] = { "iwmmxt", "ep9312" };
const char* MArchMCpuValuesARM[] = { "iwmmxt", "ep9312"};
const unsigned MArchMCpuNumKeysARM = NUM_KEYS(MArchMCpuKeysARM);
-const unsigned MArchMCpuMapSize = NextHighestPowerOf2(MArchMCpuNumKeysARM);
void FillInArgMap(ArgMap& Args, const char* Keys[],
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 3abd641..14594cf 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -26,8 +26,8 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Target/Mangler.h"
-#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
@@ -73,6 +73,8 @@ LTOCodeGenerator::LTOCodeGenerator()
_nativeObjectFile(NULL)
{
InitializeAllTargets();
+ InitializeAllMCAsmInfos();
+ InitializeAllMCSubtargetInfos();
InitializeAllAsmPrinters();
}
@@ -262,9 +264,9 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
// construct LTModule, hand over ownership of module and target
SubtargetFeatures Features;
- Features.getDefaultSubtargetFeatures(_mCpu, llvm::Triple(Triple));
+ Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
std::string FeatureStr = Features.getString();
- _target = march->createTargetMachine(Triple, FeatureStr);
+ _target = march->createTargetMachine(Triple, _mCpu, FeatureStr);
}
return false;
}
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 8f2b1f4..dc99b94 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -29,14 +29,15 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/system_error.h"
#include "llvm/Target/Mangler.h"
-#include "llvm/Target/SubtargetFeature.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.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/Target/TargetAsmParser.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegistry.h"
@@ -134,6 +135,8 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
static bool Initialized = false;
if (!Initialized) {
InitializeAllTargets();
+ InitializeAllMCAsmInfos();
+ InitializeAllMCSubtargetInfos();
InitializeAllAsmParsers();
Initialized = true;
}
@@ -157,9 +160,10 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
- Features.getDefaultSubtargetFeatures("" /* cpu */, llvm::Triple(Triple));
+ Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
std::string FeatureStr = Features.getString();
- TargetMachine *target = march->createTargetMachine(Triple, FeatureStr);
+ std::string CPU;
+ TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr);
LTOModule *Ret = new LTOModule(m.take(), target);
bool Err = Ret->ParseSymbols();
if (Err) {
@@ -191,7 +195,7 @@ bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) {
Constant *cn = gvn->getInitializer();
if (ConstantArray *ca = dyn_cast<ConstantArray>(cn)) {
if (ca->isCString()) {
- name = ".objc_class_name_" + ca->getAsString();
+ name = ".objc_class_name_" + ca->getAsCString();
return true;
}
}
@@ -208,7 +212,7 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) {
if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
NameAndAttributes info;
StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(superclassName.c_str());
+ _undefines.GetOrCreateValue(superclassName);
if (!entry.getValue().name) {
const char *symbolName = entry.getKey().data();
info.name = symbolName;
@@ -220,7 +224,7 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) {
std::string className;
if (objcClassNameFromExpression(c->getOperand(2), className)) {
StringSet::value_type &entry =
- _defines.GetOrCreateValue(className.c_str());
+ _defines.GetOrCreateValue(className);
entry.setValue(1);
NameAndAttributes info;
info.name = entry.getKey().data();
@@ -243,7 +247,7 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) {
NameAndAttributes info;
StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(targetclassName.c_str());
+ _undefines.GetOrCreateValue(targetclassName);
if (entry.getValue().name)
return;
@@ -264,7 +268,7 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
NameAndAttributes info;
StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(targetclassName.c_str());
+ _undefines.GetOrCreateValue(targetclassName);
if (entry.getValue().name)
return;
@@ -375,7 +379,7 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
// add to table of symbols
NameAndAttributes info;
- StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer.c_str());
+ StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer);
entry.setValue(1);
StringRef Name = entry.getKey();
@@ -436,7 +440,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
mangler.getNameWithPrefix(name, decl, false);
StringMap<NameAndAttributes>::value_type &entry =
- _undefines.GetOrCreateValue(name.c_str());
+ _undefines.GetOrCreateValue(name);
// we already have the symbol
if (entry.getValue().name)
@@ -595,7 +599,8 @@ namespace {
virtual void EmitFileDirective(StringRef Filename) {}
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
const MCSymbol *LastLabel,
- const MCSymbol *Label) {}
+ const MCSymbol *Label,
+ unsigned PointerSize) {}
virtual void EmitInstruction(const MCInst &Inst) {
// Scan for values.
@@ -617,8 +622,12 @@ bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
OwningPtr<MCAsmParser> Parser(createMCAsmParser(_target->getTarget(), SrcMgr,
Context, *Streamer,
*_target->getMCAsmInfo()));
+ OwningPtr<MCSubtargetInfo> STI(_target->getTarget().
+ createMCSubtargetInfo(_target->getTargetTriple(),
+ _target->getTargetCPU(),
+ _target->getTargetFeatureString()));
OwningPtr<TargetAsmParser>
- TAP(_target->getTarget().createAsmParser(*Parser.get(), *_target.get()));
+ TAP(_target->getTarget().createAsmParser(*STI, *Parser.get()));
Parser->setTargetParser(*TAP);
int Res = Parser->Run(false);
if (Res)
OpenPOWER on IntegriCloud