mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
Currently in LLVM, names of libcalls are assigned during TargetLowering
object construction. There is no provision to change them when the code for a function generated. So we have to change these names while printing assembly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97213 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -158,6 +158,7 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
// printOperand - print operand of insn.
|
// printOperand - print operand of insn.
|
||||||
void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
|
void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
|
||||||
const MachineOperand &MO = MI->getOperand(opNum);
|
const MachineOperand &MO = MI->getOperand(opNum);
|
||||||
|
const Function *F = MI->getParent()->getParent()->getFunction();
|
||||||
|
|
||||||
switch (MO.getType()) {
|
switch (MO.getType()) {
|
||||||
case MachineOperand::MO_Register:
|
case MachineOperand::MO_Register:
|
||||||
@@ -190,19 +191,18 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
|
|||||||
}
|
}
|
||||||
case MachineOperand::MO_ExternalSymbol: {
|
case MachineOperand::MO_ExternalSymbol: {
|
||||||
const char *Sname = MO.getSymbolName();
|
const char *Sname = MO.getSymbolName();
|
||||||
|
std::string Printname = Sname;
|
||||||
|
|
||||||
// If its a libcall name, record it to decls section.
|
// Intrinsic stuff needs to be renamed if we are printing IL fn.
|
||||||
if (PAN::getSymbolTag(Sname) == PAN::LIBCALL)
|
if (PAN::isIntrinsicStuff(Printname)) {
|
||||||
LibcallDecls.push_back(Sname);
|
if (PAN::isISR(F->getSection())) {
|
||||||
|
Printname = PAN::Rename(Sname);
|
||||||
// Record a call to intrinsic to print the extern declaration for it.
|
}
|
||||||
std::string Sym = Sname;
|
// Record these decls, we need to print them in asm as extern.
|
||||||
if (PAN::isMemIntrinsic(Sym)) {
|
LibcallDecls.push_back(createESName(Printname));
|
||||||
Sym = PAN::addPrefix(Sym);
|
|
||||||
LibcallDecls.push_back(createESName(Sym));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
O << Sym;
|
O << Printname;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineOperand::MO_MachineBasicBlock:
|
case MachineOperand::MO_MachineBasicBlock:
|
||||||
|
@@ -178,18 +178,21 @@ namespace llvm {
|
|||||||
return Func1 + tag;
|
return Func1 + tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the retval label for the given function.
|
||||||
static std::string getRetvalLabel(const std::string &Func) {
|
static std::string getRetvalLabel(const std::string &Func) {
|
||||||
std::string Func1 = addPrefix(Func);
|
std::string Func1 = addPrefix(Func);
|
||||||
std::string tag = getTagName(RET_LABEL);
|
std::string tag = getTagName(RET_LABEL);
|
||||||
return Func1 + tag;
|
return Func1 + tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the argument label for the given function.
|
||||||
static std::string getArgsLabel(const std::string &Func) {
|
static std::string getArgsLabel(const std::string &Func) {
|
||||||
std::string Func1 = addPrefix(Func);
|
std::string Func1 = addPrefix(Func);
|
||||||
std::string tag = getTagName(ARGS_LABEL);
|
std::string tag = getTagName(ARGS_LABEL);
|
||||||
return Func1 + tag;
|
return Func1 + tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the tempdata label for the given function.
|
||||||
static std::string getTempdataLabel(const std::string &Func) {
|
static std::string getTempdataLabel(const std::string &Func) {
|
||||||
std::string Func1 = addPrefix(Func);
|
std::string Func1 = addPrefix(Func);
|
||||||
std::string tag = getTagName(TEMPS_LABEL);
|
std::string tag = getTagName(TEMPS_LABEL);
|
||||||
@@ -263,6 +266,7 @@ namespace llvm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline static bool isMemIntrinsic (const std::string &Name) {
|
inline static bool isMemIntrinsic (const std::string &Name) {
|
||||||
if (Name.compare("@memcpy") == 0 || Name.compare("@memset") == 0 ||
|
if (Name.compare("@memcpy") == 0 || Name.compare("@memset") == 0 ||
|
||||||
Name.compare("@memmove") == 0) {
|
Name.compare("@memmove") == 0) {
|
||||||
@@ -272,6 +276,41 @@ namespace llvm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently names of libcalls are assigned during TargetLowering
|
||||||
|
// object construction. There is no provision to change the when the
|
||||||
|
// code for a function IL function being generated.
|
||||||
|
// So we have to change these names while printing assembly.
|
||||||
|
// We need to do that mainly for names related to intrinsics. This
|
||||||
|
// function returns true if a name needs to be cloned.
|
||||||
|
inline static bool isIntrinsicStuff(const std::string &Name) {
|
||||||
|
// Return true if the name contains LIBCALL marker, or a MemIntrinisc.
|
||||||
|
// these are mainly ARGS_LABEL, RET_LABEL, and the LIBCALL name itself.
|
||||||
|
if ((Name.find(getTagName(LIBCALL)) != std::string::npos)
|
||||||
|
|| isMemIntrinsic(Name))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename the name for IL.
|
||||||
|
inline static std::string Rename(const std::string &Name) {
|
||||||
|
std::string Newname;
|
||||||
|
// If its a label (LIBCALL+Func+LABEL), change it to
|
||||||
|
// (LIBCALL+Func+IL+LABEL).
|
||||||
|
TAGS id = getSymbolTag(Name);
|
||||||
|
if (id == ARGS_LABEL || id == RET_LABEL) {
|
||||||
|
std::size_t pos = Name.find(getTagName(id));
|
||||||
|
Newname = Name.substr(0, pos) + ".IL" + getTagName(id);
|
||||||
|
return Newname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else, just append IL to name.
|
||||||
|
return Name + ".IL";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline static bool isLocalToFunc (std::string &Func, std::string &Var) {
|
inline static bool isLocalToFunc (std::string &Func, std::string &Var) {
|
||||||
if (! isLocalName(Var)) return false;
|
if (! isLocalName(Var)) return false;
|
||||||
|
|
||||||
|
@@ -218,8 +218,8 @@ void PIC16Cloner::cloneSharedFunctions(CallGraphNode *CGN) {
|
|||||||
// Such a case may occur when the function has been declarated
|
// Such a case may occur when the function has been declarated
|
||||||
// in the C source code but its body exists in assembly file.
|
// in the C source code but its body exists in assembly file.
|
||||||
if (!CalledF->isDeclaration()) {
|
if (!CalledF->isDeclaration()) {
|
||||||
cloneFunction(CalledF);
|
Function *cf = cloneFunction(CalledF);
|
||||||
// FIXME: remap all the call sites here.
|
remapAllSites(CGN->getFunction(), CalledF, cf);
|
||||||
} else {
|
} else {
|
||||||
// It is called only from ISR. Still mark it as we need this info
|
// It is called only from ISR. Still mark it as we need this info
|
||||||
// in code gen while calling intrinsics.Function is not marked.
|
// in code gen while calling intrinsics.Function is not marked.
|
||||||
|
Reference in New Issue
Block a user