From 457624792803e26136889b8cf17e8aa7b84e58b4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 3 Feb 2010 21:24:49 +0000 Subject: [PATCH] stub out a new X86 encoder, which can be tried with -enable-new-x86-encoder until its stable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95256 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/CMakeLists.txt | 1 + lib/Target/X86/X86.h | 1 + lib/Target/X86/X86CodeEmitter.cpp | 13 ++++++++- lib/Target/X86/X86MCCodeEmitter.cpp | 41 +++++++++++++++++++++++++++++ lib/Target/X86/X86TargetMachine.cpp | 1 + 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 lib/Target/X86/X86MCCodeEmitter.cpp diff --git a/lib/Target/X86/CMakeLists.txt b/lib/Target/X86/CMakeLists.txt index 4186fecf4e3..8f4ff1701ed 100644 --- a/lib/Target/X86/CMakeLists.txt +++ b/lib/Target/X86/CMakeLists.txt @@ -25,6 +25,7 @@ set(sources X86InstrInfo.cpp X86JITInfo.cpp X86MCAsmInfo.cpp + X86MCCodeEmitter.cpp X86RegisterInfo.cpp X86Subtarget.cpp X86TargetMachine.cpp diff --git a/lib/Target/X86/X86.h b/lib/Target/X86/X86.h index 001a1893319..e39551b9943 100644 --- a/lib/Target/X86/X86.h +++ b/lib/Target/X86/X86.h @@ -50,6 +50,7 @@ FunctionPass *createX86JITCodeEmitterPass(X86TargetMachine &TM, JITCodeEmitter &JCE); MCCodeEmitter *createHeinousX86MCCodeEmitter(const Target &, TargetMachine &TM); +MCCodeEmitter *createX86MCCodeEmitter(const Target &, TargetMachine &TM); /// createX86EmitCodeToMemory - Returns a pass that converts a register /// allocated function into raw machine code in a dynamically diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp index 567f180ced0..304613a2df5 100644 --- a/lib/Target/X86/X86CodeEmitter.cpp +++ b/lib/Target/X86/X86CodeEmitter.cpp @@ -1099,8 +1099,19 @@ public: }; } +#include "llvm/Support/CommandLine.h" + +static cl::opt EnableNewEncoder("enable-new-x86-encoder", + cl::ReallyHidden); + + // Ok, now you can look. -MCCodeEmitter *llvm::createHeinousX86MCCodeEmitter(const Target &, +MCCodeEmitter *llvm::createHeinousX86MCCodeEmitter(const Target &T, TargetMachine &TM) { + + // FIXME: Remove the heinous one when the new one works. + if (EnableNewEncoder) + return createX86MCCodeEmitter(T, TM); + return new X86MCCodeEmitter(static_cast(TM)); } diff --git a/lib/Target/X86/X86MCCodeEmitter.cpp b/lib/Target/X86/X86MCCodeEmitter.cpp new file mode 100644 index 00000000000..0578c6d8c88 --- /dev/null +++ b/lib/Target/X86/X86MCCodeEmitter.cpp @@ -0,0 +1,41 @@ +//===-- X86/X86MCCodeEmitter.cpp - Convert X86 code to machine code -------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the X86MCCodeEmitter class. +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "x86-emitter" +#include "X86.h" +#include "X86TargetMachine.h" +#include "llvm/MC/MCCodeEmitter.h" +using namespace llvm; + +namespace { +class X86MCCodeEmitter : public MCCodeEmitter { + X86MCCodeEmitter(const X86MCCodeEmitter &); // DO NOT IMPLEMENT + void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT + X86TargetMachine &TM; +public: + X86MCCodeEmitter(X86TargetMachine &tm) : TM(tm) { + } + + ~X86MCCodeEmitter() {} + + void EncodeInstruction(const MCInst &MI, raw_ostream &OS) const { + } +}; + +} // end anonymous namespace + + +MCCodeEmitter *llvm::createX86MCCodeEmitter(const Target &, + TargetMachine &TM) { + return new X86MCCodeEmitter(static_cast(TM)); +} diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp index d6ad48ec3d1..2e7febcdbb3 100644 --- a/lib/Target/X86/X86TargetMachine.cpp +++ b/lib/Target/X86/X86TargetMachine.cpp @@ -48,6 +48,7 @@ extern "C" void LLVMInitializeX86Target() { RegisterAsmInfoFn B(TheX86_64Target, createMCAsmInfo); // Register the code emitter. + // FIXME: Remove the heinous one when the new one works. TargetRegistry::RegisterCodeEmitter(TheX86_32Target, createHeinousX86MCCodeEmitter); TargetRegistry::RegisterCodeEmitter(TheX86_64Target,