[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp
Reid Spencer
reid at x10sys.com
Sat Jan 6 19:25:03 PST 2007
Changes in directory llvm/lib/Target/CBackend:
Writer.cpp updated: 1.303 -> 1.304
---
Log message:
For PR1086: http://llvm.org/PR1086 :
Parameter attributes do have to be specially handled in the CBE. Implement
their handling.
---
Diffs of the changes: (+54 -30)
Writer.cpp | 84 +++++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 54 insertions(+), 30 deletions(-)
Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.303 llvm/lib/Target/CBackend/Writer.cpp:1.304
--- llvm/lib/Target/CBackend/Writer.cpp:1.303 Sat Jan 6 01:24:43 2007
+++ llvm/lib/Target/CBackend/Writer.cpp Sat Jan 6 21:24:48 2007
@@ -114,7 +114,8 @@
return false;
}
- std::ostream &printType(std::ostream &Out, const Type *Ty,
+ std::ostream &printType(std::ostream &Out, const Type *Ty,
+ bool isSigned = true,
const std::string &VariableName = "",
bool IgnoreName = false);
std::ostream &printPrimitiveType(std::ostream &Out, const Type *Ty,
@@ -342,10 +343,12 @@
FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end();
const Type *RetTy = cast<PointerType>(I->get())->getElementType();
+ unsigned Idx = 1;
for (++I; I != E; ++I) {
if (PrintedType)
FunctionInnards << ", ";
- printType(FunctionInnards, *I, "");
+ printType(FunctionInnards, *I,
+ /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
PrintedType = true;
}
if (FTy->isVarArg()) {
@@ -356,7 +359,8 @@
}
FunctionInnards << ')';
std::string tstr = FunctionInnards.str();
- printType(Out, RetTy, tstr);
+ printType(Out, RetTy,
+ /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
}
std::ostream &
@@ -386,13 +390,13 @@
// declaration.
//
std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
- const std::string &NameSoFar,
+ bool isSigned, const std::string &NameSoFar,
bool IgnoreName) {
if (Ty->isPrimitiveType()) {
// FIXME:Signedness. When integer types are signless, this should just
// always pass "false" for the sign of the primitive type. The instructions
// will figure out how the value is to be interpreted.
- printPrimitiveType(Out, Ty, true, NameSoFar);
+ printPrimitiveType(Out, Ty, isSigned, NameSoFar);
return Out;
}
@@ -407,11 +411,14 @@
const FunctionType *FTy = cast<FunctionType>(Ty);
std::stringstream FunctionInnards;
FunctionInnards << " (" << NameSoFar << ") (";
+ unsigned Idx = 1;
for (FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
FunctionInnards << ", ";
- printType(FunctionInnards, *I, "");
+ printType(FunctionInnards, *I,
+ /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+ ++Idx;
}
if (FTy->isVarArg()) {
if (FTy->getNumParams())
@@ -421,7 +428,8 @@
}
FunctionInnards << ')';
std::string tstr = FunctionInnards.str();
- printType(Out, FTy->getReturnType(), tstr);
+ printType(Out, FTy->getReturnType(),
+ /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
return Out;
}
case Type::StructTyID: {
@@ -431,7 +439,7 @@
for (StructType::element_iterator I = STy->element_begin(),
E = STy->element_end(); I != E; ++I) {
Out << " ";
- printType(Out, *I, "field" + utostr(Idx++));
+ printType(Out, *I, true, "field" + utostr(Idx++));
Out << ";\n";
}
return Out << '}';
@@ -445,14 +453,14 @@
isa<PackedType>(PTy->getElementType()))
ptrName = "(" + ptrName + ")";
- return printType(Out, PTy->getElementType(), ptrName);
+ return printType(Out, PTy->getElementType(), true, ptrName);
}
case Type::ArrayTyID: {
const ArrayType *ATy = cast<ArrayType>(Ty);
unsigned NumElements = ATy->getNumElements();
if (NumElements == 0) NumElements = 1;
- return printType(Out, ATy->getElementType(),
+ return printType(Out, ATy->getElementType(), true,
NameSoFar + "[" + utostr(NumElements) + "]");
}
@@ -460,7 +468,7 @@
const PackedType *PTy = cast<PackedType>(Ty);
unsigned NumElements = PTy->getNumElements();
if (NumElements == 0) NumElements = 1;
- return printType(Out, PTy->getElementType(),
+ return printType(Out, PTy->getElementType(), true,
NameSoFar + "[" + utostr(NumElements) + "]");
}
@@ -1431,15 +1439,18 @@
I != E; ++I) {
if (I->hasExternalLinkage()) {
Out << "extern ";
- printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ printType(Out, I->getType()->getElementType(), true,
+ Mang->getValueName(I));
Out << ";\n";
} else if (I->hasDLLImportLinkage()) {
Out << "__declspec(dllimport) ";
- printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ printType(Out, I->getType()->getElementType(), true,
+ Mang->getValueName(I));
Out << ";\n";
} else if (I->hasExternalWeakLinkage()) {
Out << "extern ";
- printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ printType(Out, I->getType()->getElementType(), true,
+ Mang->getValueName(I));
Out << " __EXTERNAL_WEAK__ ;\n";
}
}
@@ -1487,7 +1498,8 @@
Out << "static ";
else
Out << "extern ";
- printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ printType(Out, I->getType()->getElementType(), true,
+ Mang->getValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
@@ -1516,7 +1528,8 @@
else if (I->hasDLLExportLinkage())
Out << "__declspec(dllexport) ";
- printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+ printType(Out, I->getType()->getElementType(), true,
+ Mang->getValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
else if (I->hasWeakLinkage())
@@ -1623,7 +1636,7 @@
const Type *Ty = cast<Type>(I->second);
std::string Name = "l_" + Mang->makeNameProper(I->first);
Out << "typedef ";
- printType(Out, Ty, Name);
+ printType(Out, Ty, true, Name);
Out << ";\n";
}
@@ -1662,7 +1675,7 @@
if (StructPrinted.insert(STy).second) {
// Print structure type out.
std::string Name = TypeNames[STy];
- printType(Out, STy, Name, true);
+ printType(Out, STy, true, Name, true);
Out << ";\n\n";
}
}
@@ -1705,14 +1718,18 @@
}
std::string ArgName;
+ unsigned Idx = 1;
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
if (I->hasName() || !Prototype)
ArgName = Mang->getValueName(I);
else
ArgName = "";
- printType(FunctionInnards, I->getType(), ArgName);
+ printType(FunctionInnards, I->getType(),
+ /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute),
+ ArgName);
PrintedArg = true;
+ ++Idx;
}
}
} else {
@@ -1726,10 +1743,13 @@
++I;
}
+ unsigned Idx = 1;
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
- printType(FunctionInnards, *I);
+ printType(FunctionInnards, *I,
+ /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute));
PrintedArg = true;
+ ++Idx;
}
}
@@ -1754,7 +1774,8 @@
}
// Print out the return type and the signature built above.
- printType(Out, RetTy, FunctionInnards.str());
+ printType(Out, RetTy, FT->paramHasAttr(0, FunctionType::SExtAttribute),
+ FunctionInnards.str());
}
static inline bool isFPIntBitCast(const Instruction &I) {
@@ -1775,11 +1796,12 @@
const Type *StructTy =
cast<PointerType>(F.arg_begin()->getType())->getElementType();
Out << " ";
- printType(Out, StructTy, "StructReturn");
+ printType(Out, StructTy, true, "StructReturn");
Out << "; /* Struct return temporary */\n";
Out << " ";
- printType(Out, F.arg_begin()->getType(), Mang->getValueName(F.arg_begin()));
+ printType(Out, F.arg_begin()->getType(), true,
+ Mang->getValueName(F.arg_begin()));
Out << " = &StructReturn;\n";
}
@@ -1789,17 +1811,17 @@
for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) {
if (const AllocaInst *AI = isDirectAlloca(&*I)) {
Out << " ";
- printType(Out, AI->getAllocatedType(), Mang->getValueName(AI));
+ printType(Out, AI->getAllocatedType(), true, Mang->getValueName(AI));
Out << "; /* Address-exposed local */\n";
PrintedVar = true;
} else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) {
Out << " ";
- printType(Out, I->getType(), Mang->getValueName(&*I));
+ printType(Out, I->getType(), true, Mang->getValueName(&*I));
Out << ";\n";
if (isa<PHINode>(*I)) { // Print out PHI node temporaries as well...
Out << " ";
- printType(Out, I->getType(),
+ printType(Out, I->getType(), true,
Mang->getValueName(&*I)+"__PHI_TEMPORARY");
Out << ";\n";
}
@@ -2428,12 +2450,14 @@
}
bool PrintedArg = false;
- for (; AI != AE; ++AI, ++ArgNo) {
+ unsigned Idx = 1;
+ for (; AI != AE; ++AI, ++ArgNo, ++Idx) {
if (PrintedArg) Out << ", ";
if (ArgNo < NumDeclaredParams &&
(*AI)->getType() != FTy->getParamType(ArgNo)) {
Out << '(';
- printType(Out, FTy->getParamType(ArgNo));
+ printType(Out, FTy->getParamType(ArgNo),
+ /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute));
Out << ')';
}
writeOperand(*AI);
@@ -2650,7 +2674,7 @@
Out << '*';
if (I.isVolatile()) {
Out << "((";
- printType(Out, I.getType(), "volatile*");
+ printType(Out, I.getType(), true, "volatile*");
Out << ")";
}
@@ -2664,7 +2688,7 @@
Out << '*';
if (I.isVolatile()) {
Out << "((";
- printType(Out, I.getOperand(0)->getType(), " volatile*");
+ printType(Out, I.getOperand(0)->getType(), true, " volatile*");
Out << ")";
}
writeOperand(I.getPointerOperand());
More information about the llvm-commits
mailing list