Various random and minor code cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30608 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-09-26 03:57:53 +00:00
parent 6961329c47
commit e87e1154a1
6 changed files with 39 additions and 56 deletions

View File

@ -48,9 +48,8 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Populate function information map. Actually, We don't want to populate // Populate function information map. Actually, We don't want to populate
// non-stdcall or non-fastcall functions' information right now. // non-stdcall or non-fastcall functions' information right now.
if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall) { if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
FunctionInfoMap[F] = *(MF.getInfo<X86FunctionInfo>()); FunctionInfoMap[F] = *MF.getInfo<X86FunctionInfo>();
}
X86SharedAsmPrinter::decorateName(CurrentFnName, F); X86SharedAsmPrinter::decorateName(CurrentFnName, F);
@ -200,7 +199,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
bool isExt = (GV->isExternal() || GV->hasWeakLinkage() || bool isExt = (GV->isExternal() || GV->hasWeakLinkage() ||
GV->hasLinkOnceLinkage()); GV->hasLinkOnceLinkage());
X86SharedAsmPrinter::decorateName(Name, (Function*)GV); X86SharedAsmPrinter::decorateName(Name, GV);
if (X86PICStyle == PICStyle::Stub && if (X86PICStyle == PICStyle::Stub &&
TM.getRelocationModel() != Reloc::Static) { TM.getRelocationModel() != Reloc::Static) {

View File

@ -33,88 +33,75 @@ using namespace llvm;
Statistic<> llvm::EmittedInsts("asm-printer", Statistic<> llvm::EmittedInsts("asm-printer",
"Number of machine instrs printed"); "Number of machine instrs printed");
static X86FunctionInfo calculateFunctionInfo(const Function* F, static X86FunctionInfo calculateFunctionInfo(const Function *F,
const TargetData* TD) const TargetData *TD) {
{
X86FunctionInfo Info; X86FunctionInfo Info;
uint64_t size = 0; uint64_t Size = 0;
switch (F->getCallingConv()) { switch (F->getCallingConv()) {
case CallingConv::X86_StdCall: case CallingConv::X86_StdCall:
Info.setDecorationStyle(StdCall); Info.setDecorationStyle(StdCall);
break; break;
case CallingConv::X86_FastCall: case CallingConv::X86_FastCall:
Info.setDecorationStyle(FastCall); Info.setDecorationStyle(FastCall);
break; break;
default: default:
return Info; return Info;
} }
for (Function::const_arg_iterator AI = F->arg_begin(), for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AE = F->arg_end(); AI != AE; ++AI)
AI != AE; Size += TD->getTypeSize(AI->getType());
++AI) {
size += TD->getTypeSize(AI->getType());
}
// We're not supporting tooooo huge arguments :) // We're not supporting tooooo huge arguments :)
Info.setBytesToPopOnReturn((unsigned int)size); Info.setBytesToPopOnReturn((unsigned int)Size);
return Info; return Info;
} }
// Query FunctionInfoMap and use this information for various name decoration /// decorateName - Query FunctionInfoMap and use this information for various
void X86SharedAsmPrinter::decorateName(std::string& Name, const GlobalValue* GV) /// name decoration.
{ void X86SharedAsmPrinter::decorateName(std::string &Name,
const X86FunctionInfo* Info; const GlobalValue *GV) {
const Function* F; const Function *F = dyn_cast<Function>(GV);
if (!F) return;
if ((F = dyn_cast<Function>(GV)) == NULL) {
return;
}
unsigned CC = F->getCallingConv();
// 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
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall) { unsigned CC = F->getCallingConv();
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
return; return;
}
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F); FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
const X86FunctionInfo *Info;
if (info_item == FunctionInfoMap.end()) { if (info_item == FunctionInfoMap.end()) {
// Calculate apropriate function info and populate map // Calculate apropriate function info and populate map
FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData()); FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
Info = &FunctionInfoMap[F]; Info = &FunctionInfoMap[F];
} else { } else {
Info = &(info_item->second); Info = &info_item->second;
} }
switch (Info->getDecorationStyle()) { switch (Info->getDecorationStyle()) {
case None: case None:
break; break;
case StdCall: case StdCall:
if (!F->isVarArg()) { if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
// Variadic functions do not receive @0 suffix
Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
}
break; break;
case FastCall: case FastCall:
if (!F->isVarArg()) { if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
// Variadic functions do not receive @0 suffix
Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
}
if (Name[0] == '_') { if (Name[0] == '_') {
Name[0] = '@'; Name[0] = '@';
} else { } else {
Name = '@' + Name; Name = '@' + Name;
} }
break; break;
default: default:
assert(0 && "Unsupported DecorationStyle"); assert(0 && "Unsupported DecorationStyle");
} }
} }
/// doInitialization /// doInitialization

View File

@ -46,19 +46,18 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
Subtarget = &TM.getSubtarget<X86Subtarget>(); Subtarget = &TM.getSubtarget<X86Subtarget>();
} }
typedef std::map<const Function*, X86FunctionInfo> FMFInfoMap ;
// We have to propagate some information about MachineFunction to // We have to propagate some information about MachineFunction to
// AsmPrinter. It's ok, when we're printing the function, since we have // AsmPrinter. It's ok, when we're printing the function, since we have
// access to MachineFunction and can get the appropriate MachineFunctionInfo. // access to MachineFunction and can get the appropriate MachineFunctionInfo.
// Unfortunately, this is not possible when we're printing reference to // 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 // 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 // corresponding MachineFunctions: it can even be not created at all. That's
// why we should use additional structure, when we're collecting all necessary // why we should use additional structure, when we're collecting all necessary
// information. // information.
//
// This structure is using e.g. for name decoration for stdcall & fastcall'ed // This structure is using e.g. for name decoration for stdcall & fastcall'ed
// function, since we have to use arguments' size for decoration. // function, since we have to use arguments' size for decoration.
typedef std::map<const Function*, X86FunctionInfo> FMFInfoMap;
FMFInfoMap FunctionInfoMap; FMFInfoMap FunctionInfoMap;
void decorateName(std::string& Name, const GlobalValue* GV); void decorateName(std::string& Name, const GlobalValue* GV);

View File

@ -1523,9 +1523,8 @@ X86TargetLowering::LowerFastCCArguments(SDOperand Op, SelectionDAG &DAG) {
return DAG.getNode(ISD::MERGE_VALUES, RetVTs, &ArgValues[0],ArgValues.size()); return DAG.getNode(ISD::MERGE_VALUES, RetVTs, &ArgValues[0],ArgValues.size());
} }
SDOperand X86TargetLowering::LowerFastCCCallTo(SDOperand Op, SDOperand X86TargetLowering::LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG,
SelectionDAG &DAG, bool isFastCall) {
bool isFastCall){
SDOperand Chain = Op.getOperand(0); SDOperand Chain = Op.getOperand(0);
unsigned CallingConv= cast<ConstantSDNode>(Op.getOperand(1))->getValue(); unsigned CallingConv= cast<ConstantSDNode>(Op.getOperand(1))->getValue();
bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;

View File

@ -36,14 +36,13 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
EmitConstantPool(MF.getConstantPool()); EmitConstantPool(MF.getConstantPool());
// Print out labels for the function. // Print out labels for the function.
const Function* F = MF.getFunction(); const Function *F = MF.getFunction();
unsigned CC = F->getCallingConv(); unsigned CC = F->getCallingConv();
// Populate function information map. Actually, We don't want to populate // Populate function information map. Actually, We don't want to populate
// non-stdcall or non-fastcall functions' information right now. // non-stdcall or non-fastcall functions' information right now.
if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall) { if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
FunctionInfoMap[F] = *(MF.getInfo<X86FunctionInfo>()); FunctionInfoMap[F] = *MF.getInfo<X86FunctionInfo>();
}
X86SharedAsmPrinter::decorateName(CurrentFnName, F); X86SharedAsmPrinter::decorateName(CurrentFnName, F);

View File

@ -46,7 +46,7 @@ public:
BytesToPopOnReturn(0), BytesToPopOnReturn(0),
DecorationStyle(None) {} DecorationStyle(None) {}
X86FunctionInfo(MachineFunction& MF) : ForceFramePointer(false), X86FunctionInfo(MachineFunction &MF) : ForceFramePointer(false),
BytesToPopOnReturn(0), BytesToPopOnReturn(0),
DecorationStyle(None) {} DecorationStyle(None) {}