2005-07-02 06:44:09 +08:00
|
|
|
//===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-07-02 06:44:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file the shared super class printer that converts from our internal
|
|
|
|
// representation of machine-dependent LLVM code to Intel and AT&T format
|
|
|
|
// assembly language. This printer is the output mechanism used by `llc'.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef X86ASMPRINTER_H
|
|
|
|
#define X86ASMPRINTER_H
|
|
|
|
|
|
|
|
#include "X86.h"
|
2006-09-21 06:03:51 +08:00
|
|
|
#include "X86MachineFunctionInfo.h"
|
2006-03-14 07:20:37 +08:00
|
|
|
#include "X86TargetMachine.h"
|
2005-07-02 06:44:09 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2006-03-07 10:02:57 +08:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2007-01-27 05:22:28 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2006-12-07 02:14:47 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2005-07-08 08:23:26 +08:00
|
|
|
#include <set>
|
|
|
|
|
2005-07-02 06:44:09 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2006-09-07 02:34:40 +08:00
|
|
|
struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
|
|
|
|
DwarfWriter DW;
|
2007-09-11 16:27:17 +08:00
|
|
|
MachineModuleInfo *MMI;
|
2006-03-07 10:02:57 +08:00
|
|
|
|
2006-09-07 02:34:40 +08:00
|
|
|
X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
|
2006-09-08 06:06:40 +08:00
|
|
|
const TargetAsmInfo *T)
|
2007-09-11 16:27:17 +08:00
|
|
|
: AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
|
2006-05-26 05:59:08 +08:00
|
|
|
Subtarget = &TM.getSubtarget<X86Subtarget>();
|
|
|
|
}
|
2005-07-02 06:44:09 +08:00
|
|
|
|
2006-09-21 06:03:51 +08:00
|
|
|
// We have to propagate some information about MachineFunction to
|
|
|
|
// AsmPrinter. It's ok, when we're printing the function, since we have
|
2006-09-26 11:57:53 +08:00
|
|
|
// access to MachineFunction and can get the appropriate MachineFunctionInfo.
|
2006-09-21 06:03:51 +08:00
|
|
|
// Unfortunately, this is not possible when we're printing reference to
|
|
|
|
// Function (e.g. calling it and so on). Even more, there is no way to get the
|
|
|
|
// corresponding MachineFunctions: it can even be not created at all. That's
|
|
|
|
// why we should use additional structure, when we're collecting all necessary
|
|
|
|
// information.
|
2006-09-26 11:57:53 +08:00
|
|
|
//
|
2006-09-21 06:03:51 +08:00
|
|
|
// This structure is using e.g. for name decoration for stdcall & fastcall'ed
|
|
|
|
// function, since we have to use arguments' size for decoration.
|
2007-04-18 01:21:52 +08:00
|
|
|
typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
|
2006-09-21 06:03:51 +08:00
|
|
|
FMFInfoMap FunctionInfoMap;
|
|
|
|
|
|
|
|
void decorateName(std::string& Name, const GlobalValue* GV);
|
|
|
|
|
2005-07-02 06:44:09 +08:00
|
|
|
bool doInitialization(Module &M);
|
|
|
|
bool doFinalization(Module &M);
|
|
|
|
|
2006-03-07 10:02:57 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2006-10-31 16:31:24 +08:00
|
|
|
if (Subtarget->isTargetDarwin() ||
|
|
|
|
Subtarget->isTargetELF() ||
|
2007-01-03 19:43:14 +08:00
|
|
|
Subtarget->isTargetCygMing()) {
|
2007-01-27 05:22:28 +08:00
|
|
|
AU.addRequired<MachineModuleInfo>();
|
2006-07-27 09:12:23 +08:00
|
|
|
}
|
2007-09-30 21:39:29 +08:00
|
|
|
AsmPrinter::getAnalysisUsage(AU);
|
2006-03-07 10:02:57 +08:00
|
|
|
}
|
|
|
|
|
2006-05-26 05:59:08 +08:00
|
|
|
const X86Subtarget *Subtarget;
|
2005-07-02 06:44:09 +08:00
|
|
|
|
2005-07-08 08:23:26 +08:00
|
|
|
// Necessary for Darwin to print out the apprioriate types of linker stubs
|
|
|
|
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
|
|
|
|
|
2006-09-15 02:23:27 +08:00
|
|
|
// Necessary for dllexport support
|
|
|
|
std::set<std::string> DLLExportedFns, DLLExportedGVs;
|
2006-12-01 08:25:12 +08:00
|
|
|
|
2005-07-02 06:44:09 +08:00
|
|
|
inline static bool isScale(const MachineOperand &MO) {
|
|
|
|
return MO.isImmediate() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
(MO.getImm() == 1 || MO.getImm() == 2 ||
|
|
|
|
MO.getImm() == 4 || MO.getImm() == 8);
|
2005-07-02 06:44:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isMem(const MachineInstr *MI, unsigned Op) {
|
|
|
|
if (MI->getOperand(Op).isFrameIndex()) return true;
|
|
|
|
return Op+4 <= MI->getNumOperands() &&
|
|
|
|
MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
|
2006-02-25 17:56:50 +08:00
|
|
|
MI->getOperand(Op+2).isRegister() &&
|
|
|
|
(MI->getOperand(Op+3).isImmediate() ||
|
|
|
|
MI->getOperand(Op+3).isGlobalAddress() ||
|
2006-08-30 06:14:48 +08:00
|
|
|
MI->getOperand(Op+3).isConstantPoolIndex() ||
|
|
|
|
MI->getOperand(Op+3).isJumpTableIndex());
|
2005-07-02 06:44:09 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|