From 3c3bc48d331db26aaff3ff4f7a61f60a17fea112 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sun, 17 Aug 2008 13:53:59 +0000 Subject: [PATCH] Move X86 assembler printers into separate directory. This allows JIT-only users not to link it in (use 'x86codegen' llvm-config arg for this) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54886 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/AsmPrinter/Makefile | 15 +++++++++++++ .../X86/{ => AsmPrinter}/X86ATTAsmPrinter.cpp | 0 .../X86/{ => AsmPrinter}/X86ATTAsmPrinter.h | 0 .../X86/{ => AsmPrinter}/X86AsmPrinter.cpp | 8 +++++++ .../X86/{ => AsmPrinter}/X86AsmPrinter.h | 0 .../{ => AsmPrinter}/X86IntelAsmPrinter.cpp | 0 .../X86/{ => AsmPrinter}/X86IntelAsmPrinter.h | 0 lib/Target/X86/Makefile | 4 +++- lib/Target/X86/X86TargetMachine.cpp | 22 ++++++++++++++----- lib/Target/X86/X86TargetMachine.h | 14 ++++++++++-- tools/lli/Makefile | 2 +- tools/llvm-config/llvm-config.in.in | 9 ++++++++ 12 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 lib/Target/X86/AsmPrinter/Makefile rename lib/Target/X86/{ => AsmPrinter}/X86ATTAsmPrinter.cpp (100%) rename lib/Target/X86/{ => AsmPrinter}/X86ATTAsmPrinter.h (100%) rename lib/Target/X86/{ => AsmPrinter}/X86AsmPrinter.cpp (89%) rename lib/Target/X86/{ => AsmPrinter}/X86AsmPrinter.h (100%) rename lib/Target/X86/{ => AsmPrinter}/X86IntelAsmPrinter.cpp (100%) rename lib/Target/X86/{ => AsmPrinter}/X86IntelAsmPrinter.h (100%) diff --git a/lib/Target/X86/AsmPrinter/Makefile b/lib/Target/X86/AsmPrinter/Makefile new file mode 100644 index 00000000000..ba75b43a8ae --- /dev/null +++ b/lib/Target/X86/AsmPrinter/Makefile @@ -0,0 +1,15 @@ +##===- lib/Target/X86/Makefile -----------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../../.. +LIBRARYNAME = LLVMX86AsmPrinter + +# Hack: we need to include 'main' x86 target directory to grab private headers +CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. + +include $(LEVEL)/Makefile.common diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp similarity index 100% rename from lib/Target/X86/X86ATTAsmPrinter.cpp rename to lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp diff --git a/lib/Target/X86/X86ATTAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h similarity index 100% rename from lib/Target/X86/X86ATTAsmPrinter.h rename to lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp similarity index 89% rename from lib/Target/X86/X86AsmPrinter.cpp rename to lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index 5659282ff10..8144ee85a9e 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -33,3 +33,11 @@ FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o, return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo()); } } + +namespace { + static struct Register { + Register() { + X86TargetMachine::registerAsmPrinter(createX86CodePrinterPass); + } + } Registrator; +} diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/AsmPrinter/X86AsmPrinter.h similarity index 100% rename from lib/Target/X86/X86AsmPrinter.h rename to lib/Target/X86/AsmPrinter/X86AsmPrinter.h diff --git a/lib/Target/X86/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp similarity index 100% rename from lib/Target/X86/X86IntelAsmPrinter.cpp rename to lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp diff --git a/lib/Target/X86/X86IntelAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h similarity index 100% rename from lib/Target/X86/X86IntelAsmPrinter.h rename to lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h diff --git a/lib/Target/X86/Makefile b/lib/Target/X86/Makefile index c6af978a734..cb3f0ac299f 100644 --- a/lib/Target/X86/Makefile +++ b/lib/Target/X86/Makefile @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## LEVEL = ../../.. -LIBRARYNAME = LLVMX86 +LIBRARYNAME = LLVMX86CodeGen TARGET = X86 # Make sure that tblgen is run, first thing. @@ -18,4 +18,6 @@ BUILT_SOURCES = X86GenRegisterInfo.h.inc X86GenRegisterNames.inc \ X86GenFastISel.inc \ X86GenCallingConv.inc X86GenSubtarget.inc +DIRS = AsmPrinter + include $(LEVEL)/Makefile.common diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp index fdf9bdfba3a..ba3314c6e77 100644 --- a/lib/Target/X86/X86TargetMachine.cpp +++ b/lib/Target/X86/X86TargetMachine.cpp @@ -35,6 +35,9 @@ X("x86", " 32-bit X86: Pentium-Pro and above"); static RegisterTarget Y("x86-64", " 64-bit X86: EM64T and AMD64"); +// No assembler printer by default +X86TargetMachine::AsmPrinterCtorFn X86TargetMachine::AsmPrinterCtor = 0; + const TargetAsmInfo *X86TargetMachine::createTargetAsmInfo() const { if (Subtarget.isFlavorIntel()) return new X86WinTargetAsmInfo(*this); @@ -187,7 +190,9 @@ bool X86TargetMachine::addPostRegAlloc(PassManagerBase &PM, bool Fast) { bool X86TargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, std::ostream &Out) { - PM.add(createX86CodePrinterPass(Out, *this)); + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(Out, *this)); return false; } @@ -210,8 +215,11 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast, } PM.add(createX86CodeEmitterPass(*this, MCE)); - if (DumpAsm) - PM.add(createX86CodePrinterPass(*cerr.stream(), *this)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(*cerr.stream(), *this)); + } return false; } @@ -219,7 +227,11 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast, bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast, bool DumpAsm, MachineCodeEmitter &MCE) { PM.add(createX86CodeEmitterPass(*this, MCE)); - if (DumpAsm) - PM.add(createX86CodePrinterPass(*cerr.stream(), *this)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(*cerr.stream(), *this)); + } + return false; } diff --git a/lib/Target/X86/X86TargetMachine.h b/lib/Target/X86/X86TargetMachine.h index 5f814ea7040..94b756671c4 100644 --- a/lib/Target/X86/X86TargetMachine.h +++ b/lib/Target/X86/X86TargetMachine.h @@ -38,7 +38,13 @@ class X86TargetMachine : public LLVMTargetMachine { protected: virtual const TargetAsmInfo *createTargetAsmInfo() const; - + + // To avoid having target depend on the asmprinter stuff libraries, asmprinter + // set this functions to ctor pointer at startup time if they are linked in. + typedef FunctionPass *(*AsmPrinterCtorFn)(std::ostream &o, + X86TargetMachine &tm); + static AsmPrinterCtorFn AsmPrinterCtor; + public: X86TargetMachine(const Module &M, const std::string &FS, bool is64Bit); @@ -59,7 +65,11 @@ public: static unsigned getModuleMatchQuality(const Module &M); static unsigned getJITMatchQuality(); - + + static void registerAsmPrinter(AsmPrinterCtorFn F) { + AsmPrinterCtor = F; + } + // Set up the pass pipeline. virtual bool addInstSelector(PassManagerBase &PM, bool Fast); virtual bool addPreRegAlloc(PassManagerBase &PM, bool Fast); diff --git a/tools/lli/Makefile b/tools/lli/Makefile index b070cee2714..8f6eeed486b 100644 --- a/tools/lli/Makefile +++ b/tools/lli/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. TOOLNAME := lli -LINK_COMPONENTS := jit interpreter native bitreader selectiondag +LINK_COMPONENTS := jit interpreter nativecodegen bitreader selectiondag # Enable JIT support include $(LEVEL)/Makefile.common diff --git a/tools/llvm-config/llvm-config.in.in b/tools/llvm-config/llvm-config.in.in index 296ba4266d0..36b5112bb67 100644 --- a/tools/llvm-config/llvm-config.in.in +++ b/tools/llvm-config/llvm-config.in.in @@ -326,8 +326,17 @@ sub build_name_map { } } + # Add target-specific entries + foreach my $target (@TARGETS_BUILT) { + # FIXME: Temporary, until we don't switch all targets + if (defined $NAME_MAP{$target.'asmprinter'}) { + $NAME_MAP{$target} = [$target.'asmprinter', $target.'codegen'] + } + } + # Add virtual entries. $NAME_MAP{'native'} = have_native_backend() ? [$ARCH] : []; + $NAME_MAP{'nativecodegen'} = have_native_backend() ? [$ARCH.'codegen'] : []; $NAME_MAP{'backend'} = have_native_backend() ? ['native'] : ['cbackend']; $NAME_MAP{'engine'} = find_best_engine; $NAME_MAP{'all'} = [name_map_entries]; # Must be last.