[llvm-commits] CVS: llvm/lib/Target/CBackend/CBackend.cpp
Bill Wendling
isanbard at gmail.com
Fri Feb 23 14:45:30 PST 2007
Changes in directory llvm/lib/Target/CBackend:
CBackend.cpp updated: 1.327 -> 1.328
---
Log message:
PR1164: http://llvm.org/PR1164 :
Generate local names with a "llvm_cbe_" prefix using the actual name of the
variable instead of a temporary name.
---
Diffs of the changes: (+52 -22)
CBackend.cpp | 74 +++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 52 insertions(+), 22 deletions(-)
Index: llvm/lib/Target/CBackend/CBackend.cpp
diff -u llvm/lib/Target/CBackend/CBackend.cpp:1.327 llvm/lib/Target/CBackend/CBackend.cpp:1.328
--- llvm/lib/Target/CBackend/CBackend.cpp:1.327 Wed Feb 14 21:39:18 2007
+++ llvm/lib/Target/CBackend/CBackend.cpp Fri Feb 23 16:45:08 2007
@@ -239,7 +239,7 @@
}
void outputLValue(Instruction *I) {
- Out << " " << Mang->getValueName(I) << " = ";
+ Out << " " << GetValueName(I) << " = ";
}
bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To);
@@ -249,6 +249,8 @@
unsigned Indent);
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
gep_type_iterator E);
+
+ std::string GetValueName(const Value *Operand);
};
}
@@ -1080,6 +1082,34 @@
printConstant(CPV);
}
+std::string CWriter::GetValueName(const Value *Operand) {
+ std::string Name;
+
+ if (!isa<GlobalValue>(Operand) && Operand->getName() != "") {
+ std::string VarName;
+
+ Name = Operand->getName();
+ VarName.reserve(Name.capacity());
+
+ for (std::string::iterator I = Name.begin(), E = Name.end();
+ I != E; ++I) {
+ char ch = *I;
+
+ if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
+ (ch >= '0' && ch <= '9') || ch == '_'))
+ VarName += '_';
+ else
+ VarName += ch;
+ }
+
+ Name = "llvm_cbe_" + VarName;
+ } else {
+ Name = Mang->getValueName(Operand);
+ }
+
+ return Name;
+}
+
void CWriter::writeOperandInternal(Value *Operand) {
if (Instruction *I = dyn_cast<Instruction>(Operand))
if (isInlinableInst(*I) && !isDirectAlloca(I)) {
@@ -1091,11 +1121,11 @@
}
Constant* CPV = dyn_cast<Constant>(Operand);
- if (CPV && !isa<GlobalValue>(CPV)) {
+
+ if (CPV && !isa<GlobalValue>(CPV))
printConstant(CPV);
- } else {
- Out << Mang->getValueName(Operand);
- }
+ else
+ Out << GetValueName(Operand);
}
void CWriter::writeOperandRaw(Value *Operand) {
@@ -1103,7 +1133,7 @@
if (CPV && !isa<GlobalValue>(CPV)) {
printConstant(CPV);
} else {
- Out << Mang->getValueName(Operand);
+ Out << GetValueName(Operand);
}
}
@@ -1472,17 +1502,17 @@
if (I->hasExternalLinkage()) {
Out << "extern ";
printType(Out, I->getType()->getElementType(), false,
- Mang->getValueName(I));
+ GetValueName(I));
Out << ";\n";
} else if (I->hasDLLImportLinkage()) {
Out << "__declspec(dllimport) ";
printType(Out, I->getType()->getElementType(), false,
- Mang->getValueName(I));
+ GetValueName(I));
Out << ";\n";
} else if (I->hasExternalWeakLinkage()) {
Out << "extern ";
printType(Out, I->getType()->getElementType(), false,
- Mang->getValueName(I));
+ GetValueName(I));
Out << " __EXTERNAL_WEAK__ ;\n";
}
}
@@ -1533,7 +1563,7 @@
else
Out << "extern ";
printType(Out, I->getType()->getElementType(), false,
- Mang->getValueName(I));
+ GetValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
@@ -1565,7 +1595,7 @@
Out << "__declspec(dllexport) ";
printType(Out, I->getType()->getElementType(), false,
- Mang->getValueName(I));
+ GetValueName(I));
if (I->hasLinkOnceLinkage())
Out << " __attribute__((common))";
else if (I->hasWeakLinkage())
@@ -1772,7 +1802,7 @@
std::stringstream FunctionInnards;
// Print out the name...
- FunctionInnards << Mang->getValueName(F) << '(';
+ FunctionInnards << GetValueName(F) << '(';
bool PrintedArg = false;
if (!F->isDeclaration()) {
@@ -1791,7 +1821,7 @@
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
if (I->hasName() || !Prototype)
- ArgName = Mang->getValueName(I);
+ ArgName = GetValueName(I);
else
ArgName = "";
printType(FunctionInnards, I->getType(),
@@ -1874,7 +1904,7 @@
Out << " ";
printType(Out, F.arg_begin()->getType(), false,
- Mang->getValueName(F.arg_begin()));
+ GetValueName(F.arg_begin()));
Out << " = &StructReturn;\n";
}
@@ -1884,18 +1914,18 @@
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(), false, Mang->getValueName(AI));
+ printType(Out, AI->getAllocatedType(), false, GetValueName(AI));
Out << "; /* Address-exposed local */\n";
PrintedVar = true;
} else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) {
Out << " ";
- printType(Out, I->getType(), false, Mang->getValueName(&*I));
+ printType(Out, I->getType(), false, GetValueName(&*I));
Out << ";\n";
if (isa<PHINode>(*I)) { // Print out PHI node temporaries as well...
Out << " ";
printType(Out, I->getType(), false,
- Mang->getValueName(&*I)+"__PHI_TEMPORARY");
+ GetValueName(&*I)+"__PHI_TEMPORARY");
Out << ";\n";
}
PrintedVar = true;
@@ -1904,7 +1934,7 @@
// of a union to do the BitCast. This is separate from the need for a
// variable to hold the result of the BitCast.
if (isFPIntBitCast(*I)) {
- Out << " llvmBitCastUnion " << Mang->getValueName(&*I)
+ Out << " llvmBitCastUnion " << GetValueName(&*I)
<< "__BITCAST_TEMPORARY;\n";
PrintedVar = true;
}
@@ -1958,7 +1988,7 @@
break;
}
- if (NeedsLabel) Out << Mang->getValueName(BB) << ":\n";
+ if (NeedsLabel) Out << GetValueName(BB) << ":\n";
// Output all of the instructions in the basic block...
for (BasicBlock::iterator II = BB->begin(), E = --BB->end(); II != E;
@@ -2054,7 +2084,7 @@
Value *IV = PN->getIncomingValueForBlock(CurBlock);
if (!isa<UndefValue>(IV)) {
Out << std::string(Indent, ' ');
- Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = ";
+ Out << " " << GetValueName(I) << "__PHI_TEMPORARY = ";
writeOperand(IV);
Out << "; /* for PHI node */\n";
}
@@ -2281,10 +2311,10 @@
Out << '(';
if (isFPIntBitCast(I)) {
// These int<->float and long<->double casts need to be handled specially
- Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY."
+ Out << GetValueName(&I) << "__BITCAST_TEMPORARY."
<< getFloatBitCastField(I.getOperand(0)->getType()) << " = ";
writeOperand(I.getOperand(0));
- Out << ", " << Mang->getValueName(&I) << "__BITCAST_TEMPORARY."
+ Out << ", " << GetValueName(&I) << "__BITCAST_TEMPORARY."
<< getFloatBitCastField(I.getType());
} else {
printCast(I.getOpcode(), SrcTy, DstTy);
More information about the llvm-commits
mailing list