mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-04 01:43:06 +00:00
Make intel asmprinter child of generic asmprinter, not x86 shared asm printer. This leads to some code duplication, which will be resolved later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52858 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
271329af24
commit
1c4b5eaa46
@ -73,23 +73,6 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
|
||||
|
||||
// Necessary for dllexport support
|
||||
StringSet<> DLLExportedFns, DLLExportedGVs;
|
||||
|
||||
inline static bool isScale(const MachineOperand &MO) {
|
||||
return MO.isImmediate() &&
|
||||
(MO.getImm() == 1 || MO.getImm() == 2 ||
|
||||
MO.getImm() == 4 || MO.getImm() == 8);
|
||||
}
|
||||
|
||||
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)) &&
|
||||
MI->getOperand(Op+2).isRegister() &&
|
||||
(MI->getOperand(Op+3).isImmediate() ||
|
||||
MI->getOperand(Op+3).isGlobalAddress() ||
|
||||
MI->getOperand(Op+3).isConstantPoolIndex() ||
|
||||
MI->getOperand(Op+3).isJumpTableIndex());
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
@ -227,6 +227,23 @@ namespace X86II {
|
||||
};
|
||||
}
|
||||
|
||||
inline static bool isScale(const MachineOperand &MO) {
|
||||
return MO.isImmediate() &&
|
||||
(MO.getImm() == 1 || MO.getImm() == 2 ||
|
||||
MO.getImm() == 4 || MO.getImm() == 8);
|
||||
}
|
||||
|
||||
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)) &&
|
||||
MI->getOperand(Op+2).isRegister() &&
|
||||
(MI->getOperand(Op+3).isImmediate() ||
|
||||
MI->getOperand(Op+3).isGlobalAddress() ||
|
||||
MI->getOperand(Op+3).isConstantPoolIndex() ||
|
||||
MI->getOperand(Op+3).isJumpTableIndex());
|
||||
}
|
||||
|
||||
class X86InstrInfo : public TargetInstrInfoImpl {
|
||||
X86TargetMachine &TM;
|
||||
const X86RegisterInfo RI;
|
||||
|
@ -15,20 +15,109 @@
|
||||
|
||||
#define DEBUG_TYPE "asm-printer"
|
||||
#include "X86IntelAsmPrinter.h"
|
||||
#include "X86InstrInfo.h"
|
||||
#include "X86TargetAsmInfo.h"
|
||||
#include "X86.h"
|
||||
#include "llvm/CallingConv.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Support/Mangler.h"
|
||||
#include "llvm/Target/TargetAsmInfo.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
using namespace llvm;
|
||||
|
||||
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||
|
||||
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
|
||||
const TargetData *TD) {
|
||||
X86MachineFunctionInfo Info;
|
||||
uint64_t Size = 0;
|
||||
|
||||
switch (F->getCallingConv()) {
|
||||
case CallingConv::X86_StdCall:
|
||||
Info.setDecorationStyle(StdCall);
|
||||
break;
|
||||
case CallingConv::X86_FastCall:
|
||||
Info.setDecorationStyle(FastCall);
|
||||
break;
|
||||
default:
|
||||
return Info;
|
||||
}
|
||||
|
||||
unsigned argNum = 1;
|
||||
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
|
||||
AI != AE; ++AI, ++argNum) {
|
||||
const Type* Ty = AI->getType();
|
||||
|
||||
// 'Dereference' type in case of byval parameter attribute
|
||||
if (F->paramHasAttr(argNum, ParamAttr::ByVal))
|
||||
Ty = cast<PointerType>(Ty)->getElementType();
|
||||
|
||||
// Size should be aligned to DWORD boundary
|
||||
Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
|
||||
}
|
||||
|
||||
// We're not supporting tooooo huge arguments :)
|
||||
Info.setBytesToPopOnReturn((unsigned int)Size);
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
/// decorateName - Query FunctionInfoMap and use this information for various
|
||||
/// name decoration.
|
||||
void X86IntelAsmPrinter::decorateName(std::string &Name,
|
||||
const GlobalValue *GV) {
|
||||
const Function *F = dyn_cast<Function>(GV);
|
||||
if (!F) return;
|
||||
|
||||
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
||||
unsigned CC = F->getCallingConv();
|
||||
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
||||
return;
|
||||
|
||||
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
||||
|
||||
const X86MachineFunctionInfo *Info;
|
||||
if (info_item == FunctionInfoMap.end()) {
|
||||
// Calculate apropriate function info and populate map
|
||||
FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
|
||||
Info = &FunctionInfoMap[F];
|
||||
} else {
|
||||
Info = &info_item->second;
|
||||
}
|
||||
|
||||
const FunctionType *FT = F->getFunctionType();
|
||||
switch (Info->getDecorationStyle()) {
|
||||
case None:
|
||||
break;
|
||||
case StdCall:
|
||||
// "Pure" variadic functions do not receive @0 suffix.
|
||||
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
||||
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
||||
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
||||
break;
|
||||
case FastCall:
|
||||
// "Pure" variadic functions do not receive @0 suffix.
|
||||
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
||||
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
||||
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
||||
|
||||
if (Name[0] == '_')
|
||||
Name[0] = '@';
|
||||
else
|
||||
Name = '@' + Name;
|
||||
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Unsupported DecorationStyle");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string X86IntelAsmPrinter::getSectionForFunction(const Function &F) const {
|
||||
// Intel asm always emits functions to _text.
|
||||
return "_text";
|
||||
@ -53,7 +142,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
||||
if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
|
||||
FunctionInfoMap[F] = *MF.getInfo<X86MachineFunctionInfo>();
|
||||
|
||||
X86SharedAsmPrinter::decorateName(CurrentFnName, F);
|
||||
decorateName(CurrentFnName, F);
|
||||
|
||||
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
||||
|
||||
@ -162,7 +251,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
|
||||
GlobalValue *GV = MO.getGlobal();
|
||||
std::string Name = Mang->getValueName(GV);
|
||||
|
||||
X86SharedAsmPrinter::decorateName(Name, GV);
|
||||
decorateName(Name, GV);
|
||||
|
||||
if (!isMemOp && !isCallOp) O << "OFFSET ";
|
||||
if (GV->hasDLLImportLinkage()) {
|
||||
@ -328,7 +417,7 @@ bool X86IntelAsmPrinter::doInitialization(Module &M) {
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
if (I->isDeclaration()) {
|
||||
std::string Name = Mang->getValueName(I);
|
||||
X86SharedAsmPrinter::decorateName(Name, I);
|
||||
decorateName(Name, I);
|
||||
|
||||
O << "\textern " ;
|
||||
if (I->hasDLLImportLinkage()) {
|
||||
|
@ -14,16 +14,19 @@
|
||||
#ifndef X86INTELASMPRINTER_H
|
||||
#define X86INTELASMPRINTER_H
|
||||
|
||||
#include "X86AsmPrinter.h"
|
||||
#include "llvm/CodeGen/ValueTypes.h"
|
||||
#include "llvm/Target/TargetRegisterInfo.h"
|
||||
#include "X86.h"
|
||||
#include "X86MachineFunctionInfo.h"
|
||||
#include "X86TargetMachine.h"
|
||||
#include "llvm/CodeGen/AsmPrinter.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public X86SharedAsmPrinter {
|
||||
struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
|
||||
X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM,
|
||||
const TargetAsmInfo *T)
|
||||
: X86SharedAsmPrinter(O, TM, T) {
|
||||
: AsmPrinter(O, TM, T) {
|
||||
}
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
@ -110,12 +113,31 @@ struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public X86SharedAsmPrinter {
|
||||
bool runOnMachineFunction(MachineFunction &F);
|
||||
bool doInitialization(Module &M);
|
||||
bool doFinalization(Module &M);
|
||||
|
||||
|
||||
// We have to propagate some information about MachineFunction to
|
||||
// AsmPrinter. It's ok, when we're printing the function, since we have
|
||||
// access to MachineFunction and can get the appropriate MachineFunctionInfo.
|
||||
// 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.
|
||||
//
|
||||
// This structure is using e.g. for name decoration for stdcall & fastcall'ed
|
||||
// function, since we have to use arguments' size for decoration.
|
||||
typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
|
||||
FMFInfoMap FunctionInfoMap;
|
||||
|
||||
void decorateName(std::string& Name, const GlobalValue* GV);
|
||||
|
||||
/// getSectionForFunction - Return the section that we should emit the
|
||||
/// specified function body into.
|
||||
virtual std::string getSectionForFunction(const Function &F) const;
|
||||
|
||||
virtual void EmitString(const ConstantArray *CVA) const;
|
||||
|
||||
// Necessary for dllexport support
|
||||
StringSet<> DLLExportedFns, DLLExportedGVs;
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
Loading…
Reference in New Issue
Block a user