mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-27 12:26:08 +00:00
rearrange some code, export a SmallString version of DecorateCygMingName.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81502 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -23,8 +23,6 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/ADT/StringExtras.h"
|
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
@@ -36,6 +34,8 @@
|
|||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/Target/TargetLoweringObjectFile.h"
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
#include "llvm/ADT/Statistic.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||||
@@ -94,23 +94,23 @@ static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
|
|||||||
|
|
||||||
/// DecorateCygMingName - Query FunctionInfoMap and use this information for
|
/// DecorateCygMingName - Query FunctionInfoMap and use this information for
|
||||||
/// various name decorations for Cygwin and MingW.
|
/// various name decorations for Cygwin and MingW.
|
||||||
void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
|
void X86ATTAsmPrinter::DecorateCygMingName(SmallVectorImpl<char> &Name,
|
||||||
const GlobalValue *GV) {
|
const GlobalValue *GV) {
|
||||||
assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw");
|
assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw");
|
||||||
|
|
||||||
const Function *F = dyn_cast<Function>(GV);
|
const Function *F = dyn_cast<Function>(GV);
|
||||||
if (!F) return;
|
if (!F) return;
|
||||||
|
|
||||||
// Save function name for later type emission.
|
// Save function name for later type emission.
|
||||||
if (F->isDeclaration())
|
if (F->isDeclaration())
|
||||||
CygMingStubs.insert(Name);
|
CygMingStubs.insert(StringRef(Name.data(), Name.size()));
|
||||||
|
|
||||||
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
||||||
CallingConv::ID CC = F->getCallingConv();
|
CallingConv::ID CC = F->getCallingConv();
|
||||||
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
const X86MachineFunctionInfo *Info;
|
const X86MachineFunctionInfo *Info;
|
||||||
|
|
||||||
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
||||||
@@ -121,32 +121,30 @@ void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
|
|||||||
} else {
|
} else {
|
||||||
Info = &info_item->second;
|
Info = &info_item->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Info->getDecorationStyle() == None) return;
|
||||||
const FunctionType *FT = F->getFunctionType();
|
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] == '_') {
|
// "Pure" variadic functions do not receive @0 suffix.
|
||||||
|
if (!FT->isVarArg() || FT->getNumParams() == 0 ||
|
||||||
|
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
||||||
|
raw_svector_ostream(Name) << '@' << Info->getBytesToPopOnReturn();
|
||||||
|
|
||||||
|
if (Info->getDecorationStyle() == FastCall) {
|
||||||
|
if (Name[0] == '_')
|
||||||
Name[0] = '@';
|
Name[0] = '@';
|
||||||
} else {
|
else
|
||||||
Name = '@' + Name;
|
Name.insert(Name.begin(), '@');
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
llvm_unreachable("Unsupported DecorationStyle");
|
/// DecorateCygMingName - Query FunctionInfoMap and use this information for
|
||||||
}
|
/// various name decorations for Cygwin and MingW.
|
||||||
|
void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
|
||||||
|
const GlobalValue *GV) {
|
||||||
|
SmallString<128> NameStr(Name.begin(), Name.end());
|
||||||
|
DecorateCygMingName(NameStr, GV);
|
||||||
|
Name.assign(NameStr.begin(), NameStr.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
||||||
|
@@ -236,6 +236,7 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
|
|||||||
FMFInfoMap FunctionInfoMap;
|
FMFInfoMap FunctionInfoMap;
|
||||||
|
|
||||||
void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
|
void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
|
||||||
|
void DecorateCygMingName(SmallVectorImpl<char> &Name, const GlobalValue *GV);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
@@ -39,26 +39,6 @@ MCSymbol *X86ATTAsmPrinter::GetPICBaseSymbol() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void lower_subreg32(MCInst *MI, unsigned OpNo) {
|
|
||||||
// Convert registers in the addr mode according to subreg32.
|
|
||||||
unsigned Reg = MI->getOperand(OpNo).getReg();
|
|
||||||
if (Reg != 0)
|
|
||||||
MI->getOperand(OpNo).setReg(getX86SubSuperRegister(Reg, MVT::i32));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
|
|
||||||
// Convert registers in the addr mode according to subreg64.
|
|
||||||
for (unsigned i = 0; i != 4; ++i) {
|
|
||||||
if (!MI->getOperand(OpNo+i).isReg()) continue;
|
|
||||||
|
|
||||||
unsigned Reg = MI->getOperand(OpNo+i).getReg();
|
|
||||||
if (Reg == 0) continue;
|
|
||||||
|
|
||||||
MI->getOperand(OpNo+i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
|
/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
|
||||||
/// MCOperand.
|
/// MCOperand.
|
||||||
MCSymbol *X86ATTAsmPrinter::GetGlobalAddressSymbol(const MachineOperand &MO) {
|
MCSymbol *X86ATTAsmPrinter::GetGlobalAddressSymbol(const MachineOperand &MO) {
|
||||||
@@ -264,6 +244,28 @@ MCOperand X86ATTAsmPrinter::LowerSymbolOperand(const MachineOperand &MO,
|
|||||||
return MCOperand::CreateExpr(Expr);
|
return MCOperand::CreateExpr(Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void lower_subreg32(MCInst *MI, unsigned OpNo) {
|
||||||
|
// Convert registers in the addr mode according to subreg32.
|
||||||
|
unsigned Reg = MI->getOperand(OpNo).getReg();
|
||||||
|
if (Reg != 0)
|
||||||
|
MI->getOperand(OpNo).setReg(getX86SubSuperRegister(Reg, MVT::i32));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
|
||||||
|
// Convert registers in the addr mode according to subreg64.
|
||||||
|
for (unsigned i = 0; i != 4; ++i) {
|
||||||
|
if (!MI->getOperand(OpNo+i).isReg()) continue;
|
||||||
|
|
||||||
|
unsigned Reg = MI->getOperand(OpNo+i).getReg();
|
||||||
|
if (Reg == 0) continue;
|
||||||
|
|
||||||
|
MI->getOperand(OpNo+i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void X86ATTAsmPrinter::
|
void X86ATTAsmPrinter::
|
||||||
printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||||
MCInst TmpInst;
|
MCInst TmpInst;
|
||||||
@@ -345,9 +347,9 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
|||||||
TmpInst.addOperand(MCOp);
|
TmpInst.addOperand(MCOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle a few special cases to eliminate operand modifiers.
|
||||||
switch (TmpInst.getOpcode()) {
|
switch (TmpInst.getOpcode()) {
|
||||||
case X86::LEA64_32r:
|
case X86::LEA64_32r: // Handle 'subreg rewriting' for the lea64_32mem operand.
|
||||||
// Handle the 'subreg rewriting' for the lea64_32mem operand.
|
|
||||||
lower_lea64_32mem(&TmpInst, 1);
|
lower_lea64_32mem(&TmpInst, 1);
|
||||||
break;
|
break;
|
||||||
case X86::MOV16r0:
|
case X86::MOV16r0:
|
||||||
|
Reference in New Issue
Block a user