[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2005-11-02 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.245 -> 1.246
---
Log message:

Fix a QOI issue noticed by Markus F.X.J. Oberhumer.
This fixes PR641: http://llvm.cs.uiuc.edu/PR641 


---
Diffs of the changes:  (+1 -0)

 Writer.cpp |1 +
 1 files changed, 1 insertion(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.245 
llvm/lib/Target/CBackend/Writer.cpp:1.246
--- llvm/lib/Target/CBackend/Writer.cpp:1.245   Tue Sep 27 15:52:44 2005
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Nov  2 11:42:58 2005
@@ -1731,6 +1731,7 @@
   PM.add(createLowerGCPass());
   PM.add(createLowerAllocationsPass(true));
   PM.add(createLowerInvokePass());
+  PM.add(createCFGSimplificationPass());   // clean up after lower invoke.
   PM.add(new CBackendNameAllUsedStructs());
   PM.add(new CWriter(o, getIntrinsicLowering()));
   return false;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2005-11-10 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.247 -> 1.248
---
Log message:

Call this method with the object we have


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.247 
llvm/lib/Target/CBackend/Writer.cpp:1.248
--- llvm/lib/Target/CBackend/Writer.cpp:1.247   Mon Nov  7 20:11:51 2005
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Nov 10 12:53:25 2005
@@ -999,7 +999,7 @@
   Out << "/* Structure forward decls */\n";
   for (; I != End; ++I)
 if (const Type *STy = dyn_cast(I->second)) {
-  std::string Name = "struct l_" + Mangler::makeNameProper(I->first);
+  std::string Name = "struct l_" + Mang->makeNameProper(I->first);
   Out << Name << ";\n";
   TypeNames.insert(std::make_pair(STy, Name));
 }
@@ -1010,7 +1010,7 @@
   Out << "/* Typedefs */\n";
   for (I = ST.type_begin(); I != End; ++I) {
 const Type *Ty = cast(I->second);
-std::string Name = "l_" + Mangler::makeNameProper(I->first);
+std::string Name = "l_" + Mang->makeNameProper(I->first);
 Out << "typedef ";
 printType(Out, Ty, Name);
 Out << ";\n";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2005-11-10 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.248 -> 1.249
---
Log message:

do not allow '.' in symbol names


---
Diffs of the changes:  (+1 -0)

 Writer.cpp |1 +
 1 files changed, 1 insertion(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.248 
llvm/lib/Target/CBackend/Writer.cpp:1.249
--- llvm/lib/Target/CBackend/Writer.cpp:1.248   Thu Nov 10 12:53:25 2005
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Nov 10 15:39:29 2005
@@ -834,6 +834,7 @@
 
   // Ensure that all structure types have names...
   Mang = new Mangler(M);
+  Mang->markCharUnacceptable('.');
 
   // get declaration for alloca
   Out << "/* Provide Declarations */\n";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2005-12-27 Thread Duraid Madina


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.249 -> 1.250
---
Log message:

yet more C++ standards-compliance stuff.



---
Diffs of the changes:  (+1 -0)

 Writer.cpp |1 +
 1 files changed, 1 insertion(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.249 
llvm/lib/Target/CBackend/Writer.cpp:1.250
--- llvm/lib/Target/CBackend/Writer.cpp:1.249   Thu Nov 10 15:39:29 2005
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Dec 27 04:40:34 2005
@@ -39,6 +39,7 @@
 #include "llvm/Config/config.h"
 #include 
 #include 
+#include 
 #include 
 using namespace llvm;
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-01-20 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.250 -> 1.251
---
Log message:

Simplify CWriter::printContainedStructs, also allowing it to work with 
PackedTypes as a side-effect.


---
Diffs of the changes:  (+11 -18)

 Writer.cpp |   29 +++--
 1 files changed, 11 insertions(+), 18 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.250 
llvm/lib/Target/CBackend/Writer.cpp:1.251
--- llvm/lib/Target/CBackend/Writer.cpp:1.250   Tue Dec 27 04:40:34 2005
+++ llvm/lib/Target/CBackend/Writer.cpp Fri Jan 20 12:57:03 2006
@@ -1037,29 +1037,22 @@
 // this one depends on.
 void CWriter::printContainedStructs(const Type *Ty,
 std::set 
&StructPrinted){
+  // Don't walk through pointers.
+  if (isa(Ty) || Ty->isPrimitiveType()) return;
+  
+  // Print all contained types first.
+  for (Type::subtype_iterator I = Ty->subtype_begin(),
+   E = Ty->subtype_end(); I != E; ++I)
+printContainedStructs(*I, StructPrinted);
+  
   if (const StructType *STy = dyn_cast(Ty)) {
-//Check to see if we have already printed this struct
-if (StructPrinted.count(STy) == 0) {
-  // Print all contained types first...
-  for (StructType::element_iterator I = STy->element_begin(),
- E = STy->element_end(); I != E; ++I) {
-const Type *Ty1 = I->get();
-if (isa(Ty1) || isa(Ty1))
-  printContainedStructs(*I, StructPrinted);
-  }
-
-  //Print structure type out..
-  StructPrinted.insert(STy);
+// Check to see if we have already printed this struct.
+if (StructPrinted.insert(STy).second) {
+  // Print structure type out.
   std::string Name = TypeNames[STy];
   printType(Out, STy, Name, true);
   Out << ";\n\n";
 }
-
-// If it is an array, check contained types and continue
-  } else if (const ArrayType *ATy = dyn_cast(Ty)){
-const Type *Ty1 = ATy->getElementType();
-if (isa(Ty1) || isa(Ty1))
-  printContainedStructs(Ty1, StructPrinted);
   }
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-01-20 Thread Robert L. Bocchino Jr.


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.251 -> 1.252
---
Log message:

Make the C writer work with packed types.  printContainedStructs is
still not quite right and will be fixed later.



---
Diffs of the changes:  (+49 -4)

 Writer.cpp |   53 +
 1 files changed, 49 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.251 
llvm/lib/Target/CBackend/Writer.cpp:1.252
--- llvm/lib/Target/CBackend/Writer.cpp:1.251   Fri Jan 20 12:57:03 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Fri Jan 20 14:43:57 2006
@@ -132,6 +132,7 @@
 
 void printConstant(Constant *CPV);
 void printConstantArray(ConstantArray *CPA);
+void printConstantPacked(ConstantPacked *CP);
 
 // isInlinableInst - Attempt to inline instructions into their uses to 
build
 // trees as much as possible.  To do this, we have to consistently decide
@@ -329,7 +330,8 @@
 const PointerType *PTy = cast(Ty);
 std::string ptrName = "*" + NameSoFar;
 
-if (isa(PTy->getElementType()))
+if (isa(PTy->getElementType()) ||
+isa(PTy->getElementType()))
   ptrName = "(" + ptrName + ")";
 
 return printType(Out, PTy->getElementType(), ptrName);
@@ -343,6 +345,14 @@
  NameSoFar + "[" + utostr(NumElements) + "]");
   }
 
+  case Type::PackedTyID: {
+const PackedType *PTy = cast(Ty);
+unsigned NumElements = PTy->getNumElements();
+if (NumElements == 0) NumElements = 1;
+return printType(Out, PTy->getElementType(),
+ NameSoFar + "[" + utostr(NumElements) + "]");
+  }
+
   case Type::OpaqueTyID: {
 static int Count = 0;
 std::string TyName = "struct opaque_" + itostr(Count++);
@@ -426,6 +436,19 @@
   }
 }
 
+void CWriter::printConstantPacked(ConstantPacked *CP) {
+  Out << '{';
+  if (CP->getNumOperands()) {
+Out << ' ';
+printConstant(cast(CP->getOperand(0)));
+for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
+  Out << ", ";
+  printConstant(cast(CP->getOperand(i)));
+}
+  }
+  Out << " }";
+}
+
 // isFPCSafeToPrint - Returns true if we may assume that CFP may be written out
 // textually as a double (rather than as a reference to a stack-allocated
 // variable). We decide this by converting CFP to a string and back into a
@@ -641,6 +664,25 @@
 }
 break;
 
+  case Type::PackedTyID:
+if (isa(CPV) || isa(CPV)) {
+  const PackedType *AT = cast(CPV->getType());
+  Out << '{';
+  if (AT->getNumElements()) {
+Out << ' ';
+Constant *CZ = Constant::getNullValue(AT->getElementType());
+printConstant(CZ);
+for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) {
+  Out << ", ";
+  printConstant(CZ);
+}
+  }
+  Out << " }";
+} else {
+  printConstantPacked(cast(CPV));
+}
+break;
+
   case Type::StructTyID:
 if (isa(CPV) || isa(CPV)) {
   const StructType *ST = cast(CPV->getType());
@@ -936,7 +978,8 @@
   // the compiler figure out the rest of the zeros.
   Out << " = " ;
   if (isa(I->getInitializer()->getType()) ||
-  isa(I->getInitializer()->getType())) {
+  isa(I->getInitializer()->getType()) ||
+  isa(I->getInitializer()->getType())) {
 Out << "{ 0 }";
   } else {
 // Just print it out normally.
@@ -987,7 +1030,7 @@
 
 
 /// printSymbolTable - Run through symbol table looking for type names.  If a
-/// type name is found, emit it's declaration...
+/// type name is found, emit its declaration...
 ///
 void CWriter::printModuleTypes(const SymbolTable &ST) {
   // We are only interested in the type plane of the symbol table.
@@ -1035,6 +1078,9 @@
 
 // Push the struct onto the stack and recursively push all structs
 // this one depends on.
+//
+// TODO:  Make this work properly with packed types
+//
 void CWriter::printContainedStructs(const Type *Ty,
 std::set 
&StructPrinted){
   // Don't walk through pointers.
@@ -1055,7 +1101,6 @@
 }
   }
 }
-
 
 void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   if (F->hasInternalLinkage()) Out << "static ";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-02-13 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.252 -> 1.253
---
Log message:

Another hack due to allowing multiple symbols with the same name.


---
Diffs of the changes:  (+52 -11)

 Writer.cpp |   63 ++---
 1 files changed, 52 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.252 
llvm/lib/Target/CBackend/Writer.cpp:1.253
--- llvm/lib/Target/CBackend/Writer.cpp:1.252   Fri Jan 20 14:43:57 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Feb 13 16:22:42 2006
@@ -47,10 +47,11 @@
   // Register the target.
   RegisterTarget X("c", "  C backend");
 
-  /// NameAllUsedStructs - This pass inserts names for any unnamed structure
-  /// types that are used by the program.
+  /// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for
+  /// any unnamed structure types that are used by the program, and merges
+  /// external functions with the same name.
   ///
-  class CBackendNameAllUsedStructs : public ModulePass {
+  class CBackendNameAllUsedStructsAndMergeFunctions : public ModulePass {
 void getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired();
 }
@@ -119,7 +120,6 @@
   private :
 void lowerIntrinsics(Function &F);
 
-bool nameAllUsedStructureTypes(Module &M);
 void printModule(Module *M);
 void printModuleTypes(const SymbolTable &ST);
 void printContainedStructs(const Type *Ty, std::set &);
@@ -224,7 +224,7 @@
 /// the program, and removes names from structure types that are not used by 
the
 /// program.
 ///
-bool CBackendNameAllUsedStructs::runOnModule(Module &M) {
+bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
   // Get a set of types that are used by the program...
   std::set UT = getAnalysis().getTypes();
 
@@ -256,6 +256,44 @@
 ++RenameCounter;
   Changed = true;
 }
+  
+  
+  // Loop over all external functions and globals.  If we have two with
+  // identical names, merge them.
+  // FIXME: This code should disappear when we don't allow values with the same
+  // names when they have different types!
+  std::map ExtSymbols;
+  for (Module::iterator I = M.begin(), E = M.end(); I != E;) {
+Function *GV = I++;
+if (GV->isExternal() && GV->hasName()) {
+  std::pair::iterator, bool> X
+= ExtSymbols.insert(std::make_pair(GV->getName(), GV));
+  if (!X.second) {
+// Found a conflict, replace this global with the previous one.
+GlobalValue *OldGV = X.first->second;
+GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+GV->eraseFromParent();
+Changed = true;
+  }
+}
+  }
+  // Do the same for globals.
+  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+   I != E;) {
+GlobalVariable *GV = I++;
+if (GV->isExternal() && GV->hasName()) {
+  std::pair::iterator, bool> X
+= ExtSymbols.insert(std::make_pair(GV->getName(), GV));
+  if (!X.second) {
+// Found a conflict, replace this global with the previous one.
+GlobalValue *OldGV = X.first->second;
+GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+GV->eraseFromParent();
+Changed = true;
+  }
+}
+  }
+  
   return Changed;
 }
 
@@ -845,7 +883,8 @@
   << "#define LLVM_NANSF(NanStr) __builtin_nansf(NanStr) /* Float */\n"
   << "#define LLVM_INF   __builtin_inf() /* Double */\n"
   << "#define LLVM_INFF  __builtin_inff()/* Float */\n"
-  << "#define LLVM_PREFETCH(addr,rw,locality)  
__builtin_prefetch(addr,rw,locality)\n"
+  << "#define LLVM_PREFETCH(addr,rw,locality) "
+  "__builtin_prefetch(addr,rw,locality)\n"
   << "#else\n"
   << "#define LLVM_NAN(NanStr)   ((double)0.0)   /* Double */\n"
   << "#define LLVM_NANF(NanStr)  0.0F/* Float */\n"
@@ -905,7 +944,8 @@
   // Global variable declarations...
   if (!M.global_empty()) {
 Out << "\n/* External Global Variable Declarations */\n";
-for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I 
!= E; ++I) {
+for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+ I != E; ++I) {
   if (I->hasExternalLinkage()) {
 Out << "extern ";
 printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
@@ -935,7 +975,8 @@
   // Output the global variable declarations
   if (!M.global_empty()) {
 Out << "\n\n/* Global Variable Declarations */\n";
-for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I 
!= E; ++I)
+for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+ I != E; ++I)
   if (!I->isExternal()) {
 if (I->hasInternalLinkage())
   Out << "static ";
@@ -954,7 +995,8 @@

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-03-07 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.253 -> 1.254
---
Log message:

Two things:
1. Don't emit debug info, or other llvm.metadata to the .cbe.c file.
2. Mark static ctors/dtors as such, so that bugpoint works on C++ code
   compiled with the new CFE.


---
Diffs of the changes:  (+89 -12)

 Writer.cpp |  101 +
 1 files changed, 89 insertions(+), 12 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.253 
llvm/lib/Target/CBackend/Writer.cpp:1.254
--- llvm/lib/Target/CBackend/Writer.cpp:1.253   Mon Feb 13 16:22:42 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Mar  7 16:58:23 2006
@@ -797,7 +797,7 @@
 // directives to cater to specific compilers as need be.
 //
 static void generateCompilerSpecificCode(std::ostream& Out) {
-  // Alloca is hard to get, and we don't want to include stdlib.h here...
+  // Alloca is hard to get, and we don't want to include stdlib.h here.
   Out << "/* get a declaration for alloca */\n"
   << "#if defined(__CYGWIN__)\n"
   << "extern void *_alloca(unsigned long);\n"
@@ -885,6 +885,8 @@
   << "#define LLVM_INFF  __builtin_inff()/* Float */\n"
   << "#define LLVM_PREFETCH(addr,rw,locality) "
   "__builtin_prefetch(addr,rw,locality)\n"
+  << "#define __ATTRIBUTE_CTOR__ __attribute__((constructor))\n"
+  << "#define __ATTRIBUTE_DTOR__ __attribute__((destructor))\n"
   << "#else\n"
   << "#define LLVM_NAN(NanStr)   ((double)0.0)   /* Double */\n"
   << "#define LLVM_NANF(NanStr)  0.0F/* Float */\n"
@@ -893,6 +895,8 @@
   << "#define LLVM_INF   ((double)0.0)   /* Double */\n"
   << "#define LLVM_INFF  0.0F/* Float */\n"
   << "#define LLVM_PREFETCH(addr,rw,locality)/* PREFETCH */\n"
+  << "#define __ATTRIBUTE_CTOR__\n"
+  << "#define __ATTRIBUTE_DTOR__\n"
   << "#endif\n\n";
 
   // Output target-specific code that should be inserted into main.
@@ -908,6 +912,53 @@
 
 }
 
+/// FindStaticTors - Given a static ctor/dtor list, unpack its contents into
+/// the StaticTors set.
+static void FindStaticTors(GlobalVariable *GV, std::set 
&StaticTors){
+  ConstantArray *InitList = dyn_cast(GV->getInitializer());
+  if (!InitList) return;
+  
+  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
+if (ConstantStruct *CS = 
dyn_cast(InitList->getOperand(i))){
+  if (CS->getNumOperands() != 2) return;  // Not array of 2-element 
structs.
+  
+  if (CS->getOperand(1)->isNullValue())
+return;  // Found a null terminator, exit printing.
+  Constant *FP = CS->getOperand(1);
+  if (ConstantExpr *CE = dyn_cast(FP))
+if (CE->getOpcode() == Instruction::Cast)
+  FP = CE->getOperand(0);
+  if (Function *F = dyn_cast(FP))
+StaticTors.insert(F);
+}
+}
+
+enum SpecialGlobalClass {
+  NotSpecial = 0,
+  GlobalCtors, GlobalDtors,
+  NotPrinted
+};
+
+/// getGlobalVariableClass - If this is a global that is specially recognized
+/// by LLVM, return a code that indicates how we should handle it.
+static SpecialGlobalClass getGlobalVariableClass(const GlobalVariable *GV) {
+  // If this is a global ctors/dtors list, handle it now.
+  if (GV->hasAppendingLinkage() && GV->use_empty()) {
+if (GV->getName() == "llvm.global_ctors")
+  return GlobalCtors;
+else if (GV->getName() == "llvm.global_dtors")
+  return GlobalDtors;
+  }
+  
+  // Otherwise, it it is other metadata, don't print it.  This catches things
+  // like debug information.
+  if (GV->getSection() == "llvm.metadata")
+return NotPrinted;
+  
+  return NotSpecial;
+}
+
+
 bool CWriter::doInitialization(Module &M) {
   // Initialize
   TheModule = &M;
@@ -918,6 +969,22 @@
   Mang = new Mangler(M);
   Mang->markCharUnacceptable('.');
 
+  // Keep track of which functions are static ctors/dtors so they can have
+  // an attribute added to their prototypes.
+  std::set StaticCtors, StaticDtors;
+  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+   I != E; ++I) {
+switch (getGlobalVariableClass(I)) {
+default: break;
+case GlobalCtors:
+  FindStaticTors(I, StaticCtors);
+  break;
+case GlobalDtors:
+  FindStaticTors(I, StaticDtors);
+  break;
+}
+  }
+  
   // get declaration for alloca
   Out << "/* Provide Declarations */\n";
   Out << "#include \n";  // Varargs support
@@ -955,20 +1022,22 @@
   }
 
   // Function declarations
+  Out << "\n/* Function Declarations */\n";
   Out << "double fmod(double, double);\n";   // Support for FP rem
   Out << "float fmodf(float, float);\n";
   
-  if (!M.empty()) {
-Out << "\n/* Function Declarations */\n";
-for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
-  // Don't print declarations for intrinsi

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-03-08 Thread Jim Laskey


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.254 -> 1.255
---
Log message:

Add #line support for CBE.


---
Diffs of the changes:  (+17 -0)

 Writer.cpp |   17 +
 1 files changed, 17 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.254 
llvm/lib/Target/CBackend/Writer.cpp:1.255
--- llvm/lib/Target/CBackend/Writer.cpp:1.254   Tue Mar  7 16:58:23 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Mar  8 13:31:15 2006
@@ -1598,6 +1598,7 @@
   case Intrinsic::setjmp:
   case Intrinsic::longjmp:
   case Intrinsic::prefetch:
+  case Intrinsic::dbg_stoppoint:
 // We directly implement these intrinsics
 break;
   default:
@@ -1687,6 +1688,22 @@
 writeOperand(I.getOperand(3));
 Out << ")";
 return;
+  case Intrinsic::dbg_stoppoint: {
+// If we use writeOperand directly we get a "u" suffix which is 
rejected
+// by gcc.
+ConstantUInt *SI = cast(I.getOperand(2));
+GlobalVariable *GV = cast(I.getOperand(4));
+ConstantStruct *CS = cast(GV->getInitializer());
+std::string FileName = CS->getOperand(4)->getStringValue();
+std::string Directory = CS->getOperand(5)->getStringValue();
+
+Out << "\n#line "
+<< SI->getValue()
+<< " \"" << Directory << FileName << "\"\n";
+// Need to set result.
+Out << "0";
+return;
+  }
   }
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-03-13 Thread Jim Laskey


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.255 -> 1.256
---
Log message:

Handle the removal of the debug chain.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.255 
llvm/lib/Target/CBackend/Writer.cpp:1.256
--- llvm/lib/Target/CBackend/Writer.cpp:1.255   Wed Mar  8 13:31:15 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Mar 13 07:07:37 2006
@@ -1691,8 +1691,8 @@
   case Intrinsic::dbg_stoppoint: {
 // If we use writeOperand directly we get a "u" suffix which is 
rejected
 // by gcc.
-ConstantUInt *SI = cast(I.getOperand(2));
-GlobalVariable *GV = cast(I.getOperand(4));
+ConstantUInt *SI = cast(I.getOperand(1));
+GlobalVariable *GV = cast(I.getOperand(3));
 ConstantStruct *CS = cast(GV->getInitializer());
 std::string FileName = CS->getOperand(4)->getStringValue();
 std::string Directory = CS->getOperand(5)->getStringValue();



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-03-13 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.256 -> 1.257
---
Log message:

Handle builtins that directly correspond to GCC builtins.


---
Diffs of the changes:  (+25 -2)

 Writer.cpp |   27 +--
 1 files changed, 25 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.256 
llvm/lib/Target/CBackend/Writer.cpp:1.257
--- llvm/lib/Target/CBackend/Writer.cpp:1.256   Mon Mar 13 07:07:37 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Mar 13 17:09:05 2006
@@ -1602,6 +1602,15 @@
 // We directly implement these intrinsics
 break;
   default:
+// If this is an intrinsic that directly corresponds to a GCC
+// builtin, we handle it.
+const char *BuiltinName = "";
+#define GET_GCC_BUILTIN_NAME
+#include "llvm/Intrinsics.gen"
+#undef GET_GCC_BUILTIN_NAME
+// If we handle it, don't lower it.
+if (BuiltinName[0]) break;
+
 // All other intrinsic calls we must lower.
 Instruction *Before = 0;
 if (CI != &BB->front())
@@ -1613,17 +1622,32 @@
 } else {
   I = BB->begin();
 }
+break;
   }
 }
 
 
 
 void CWriter::visitCallInst(CallInst &I) {
+  bool WroteCallee = false;
+
   // Handle intrinsic function calls first...
   if (Function *F = I.getCalledFunction())
 if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
   switch (ID) {
-  default: assert(0 && "Unknown LLVM intrinsic!");
+  default: {
+// If this is an intrinsic that directly corresponds to a GCC
+// builtin, we emit it here.
+const char *BuiltinName = "";
+#define GET_GCC_BUILTIN_NAME
+#include "llvm/Intrinsics.gen"
+#undef GET_GCC_BUILTIN_NAME
+assert(BuiltinName[0] && "Unknown LLVM intrinsic!");
+
+Out << BuiltinName;
+WroteCallee = true;
+break;
+  }
   case Intrinsic::vastart:
 Out << "0; ";
 
@@ -1720,7 +1744,6 @@
   // in the common case, we handle casts where the number of arguments passed
   // match exactly.
   //
-  bool WroteCallee = false;
   if (I.isTailCall()) Out << " /*tail*/ ";
   if (ConstantExpr *CE = dyn_cast(Callee))
 if (CE->getOpcode() == Instruction::Cast)



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-03-23 Thread Jim Laskey


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.258 -> 1.259
---
Log message:

Modify how CBE handles #lines.


---
Diffs of the changes:  (+5 -9)

 Writer.cpp |   14 +-
 1 files changed, 5 insertions(+), 9 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.258 
llvm/lib/Target/CBackend/Writer.cpp:1.259
--- llvm/lib/Target/CBackend/Writer.cpp:1.258   Wed Mar 22 23:43:15 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Mar 23 12:08:29 2006
@@ -21,6 +21,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Analysis/ConstantsScanner.h"
 #include "llvm/Analysis/FindUsedTypes.h"
 #include "llvm/Analysis/LoopInfo.h"
@@ -1715,17 +1716,12 @@
   case Intrinsic::dbg_stoppoint: {
 // If we use writeOperand directly we get a "u" suffix which is 
rejected
 // by gcc.
-ConstantUInt *SI = cast(I.getOperand(1));
-GlobalVariable *GV = cast(I.getOperand(3));
-ConstantStruct *CS = cast(GV->getInitializer());
-std::string FileName = CS->getOperand(4)->getStringValue();
-std::string Directory = CS->getOperand(5)->getStringValue();
+DbgStopPointInst &SPI = cast(I);
 
 Out << "\n#line "
-<< SI->getValue()
-<< " \"" << Directory << FileName << "\"\n";
-// Need to set result.
-Out << "0";
+<< SPI.getLine()
+<< " \"" << SPI.getDirectory()
+<< SPI.getFileName() << "\"\n";
 return;
   }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-01 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.276 -> 1.277
---
Log message:

For PR950: http://llvm.org/PR950 :
Replace the REM instruction with UREM, SREM and FREM.


---
Diffs of the changes:  (+28 -10)

 Writer.cpp |   38 --
 1 files changed, 28 insertions(+), 10 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.276 
llvm/lib/Target/CBackend/Writer.cpp:1.277
--- llvm/lib/Target/CBackend/Writer.cpp:1.276   Thu Oct 26 01:17:40 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Nov  1 19:53:58 2006
@@ -593,7 +593,9 @@
 case Instruction::SDiv:
 case Instruction::UDiv:
 case Instruction::FDiv:
-case Instruction::Rem:
+case Instruction::URem:
+case Instruction::SRem:
+case Instruction::FRem:
 case Instruction::And:
 case Instruction::Or:
 case Instruction::Xor:
@@ -613,10 +615,12 @@
   case Instruction::Add: Out << " + "; break;
   case Instruction::Sub: Out << " - "; break;
   case Instruction::Mul: Out << " * "; break;
+  case Instruction::URem:
+  case Instruction::SRem: 
+  case Instruction::FRem: Out << " % "; break;
   case Instruction::UDiv: 
   case Instruction::SDiv: 
   case Instruction::FDiv: Out << " / "; break;
-  case Instruction::Rem: Out << " % "; break;
   case Instruction::And: Out << " & "; break;
   case Instruction::Or:  Out << " | "; break;
   case Instruction::Xor: Out << " ^ "; break;
@@ -825,8 +829,12 @@
   bool Result = false;
   const Type* Ty = CE->getOperand(0)->getType();
   switch (CE->getOpcode()) {
-  case Instruction::UDiv: Result = Ty->isSigned(); break;
-  case Instruction::SDiv: Result = Ty->isUnsigned(); break;
+  case Instruction::UDiv: 
+  case Instruction::URem: 
+Result = Ty->isSigned(); break;
+  case Instruction::SDiv: 
+  case Instruction::SRem: 
+Result = Ty->isUnsigned(); break;
   default: break;
   }
   if (Result) {
@@ -856,13 +864,16 @@
   // for most instructions, it doesn't matter
   break; 
 case Instruction::UDiv:
-  // For UDiv to have unsigned operands
+case Instruction::URem:
+  // For UDiv/URem get correct type
   if (OpTy->isSigned()) {
 OpTy = OpTy->getUnsignedVersion();
 shouldCast = true;
   }
   break;
 case Instruction::SDiv:
+case Instruction::SRem:
+  // For SDiv/SRem get correct type
   if (OpTy->isUnsigned()) {
 OpTy = OpTy->getSignedVersion();
 shouldCast = true;
@@ -919,8 +930,12 @@
   bool Result = false;
   const Type* Ty = I.getOperand(0)->getType();
   switch (I.getOpcode()) {
-  case Instruction::UDiv: Result = Ty->isSigned(); break;
-  case Instruction::SDiv: Result = Ty->isUnsigned(); break;
+  case Instruction::UDiv: 
+  case Instruction::URem: 
+Result = Ty->isSigned(); break;
+  case Instruction::SDiv: 
+  case Instruction::SRem: 
+Result = Ty->isUnsigned(); break;
   default: break;
   }
   if (Result) {
@@ -950,6 +965,7 @@
   // for most instructions, it doesn't matter
   break; 
 case Instruction::UDiv:
+case Instruction::URem:
   // For UDiv to have unsigned operands
   if (OpTy->isSigned()) {
 OpTy = OpTy->getUnsignedVersion();
@@ -957,6 +973,7 @@
   }
   break;
 case Instruction::SDiv:
+case Instruction::SRem:
   if (OpTy->isUnsigned()) {
 OpTy = OpTy->getSignedVersion();
 shouldCast = true;
@@ -1774,8 +1791,7 @@
 Out << "-(";
 writeOperand(BinaryOperator::getNegArgument(cast(&I)));
 Out << ")";
-  } else if (I.getOpcode() == Instruction::Rem && 
- I.getType()->isFloatingPoint()) {
+  } else if (I.getOpcode() == Instruction::FRem) {
 // Output a call to fmod/fmodf instead of emitting a%b
 if (I.getType() == Type::FloatTy)
   Out << "fmodf(";
@@ -1800,10 +1816,12 @@
 case Instruction::Add: Out << " + "; break;
 case Instruction::Sub: Out << " - "; break;
 case Instruction::Mul: Out << '*'; break;
+case Instruction::URem:
+case Instruction::SRem:
+case Instruction::FRem: Out << '%'; break;
 case Instruction::UDiv:
 case Instruction::SDiv: 
 case Instruction::FDiv: Out << '/'; break;
-case Instruction::Rem: Out << '%'; break;
 case Instruction::And: Out << " & "; break;
 case Instruction::Or: Out << " | "; break;
 case Instruction::Xor: Out << " ^ "; break;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-02 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.277 -> 1.278
---
Log message:

For PR786: http://llvm.org/PR786 :
Turn on -Wunused and -Wno-unused-parameter. Clean up most of the resulting
fall out by removing unused variables. Remaining warnings have to do with
unused functions (I didn't want to delete code without review) and unused
variables in generated code. Maintainers should clean up the remaining 
issues when they see them. All changes pass DejaGnu tests and Olden.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.277 
llvm/lib/Target/CBackend/Writer.cpp:1.278
--- llvm/lib/Target/CBackend/Writer.cpp:1.277   Wed Nov  1 19:53:58 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Nov  2 14:25:49 2006
@@ -702,7 +702,7 @@
 // The prefix for a quiet NaN is 0x7FF8. For a signalling NaN,
 // it's 0x7ff4.
 const unsigned long QuietNaN = 0x7ff8UL;
-const unsigned long SignalNaN = 0x7ff4UL;
+//const unsigned long SignalNaN = 0x7ff4UL;
 
 // We need to grab the first part of the FP #
 char Buffer[100];
@@ -2140,7 +2140,7 @@
   gep_type_iterator E) {
   bool HasImplicitAddress = false;
   // If accessing a global value with no indexing, avoid *(&GV) syndrome
-  if (GlobalValue *V = dyn_cast(Ptr)) {
+  if (isa(Ptr)) {
 HasImplicitAddress = true;
   } else if (isDirectAlloca(Ptr)) {
 HasImplicitAddress = true;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-05 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.278 -> 1.279
---
Log message:

Implement the -enabled-cbe-printf-a feature.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.278 
llvm/lib/Target/CBackend/Writer.cpp:1.279
--- llvm/lib/Target/CBackend/Writer.cpp:1.278   Thu Nov  2 14:25:49 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Nov  5 11:09:41 2006
@@ -534,7 +534,7 @@
 // only deal in IEEE FP).
 //
 static bool isFPCSafeToPrint(const ConstantFP *CFP) {
-#if HAVE_PRINTF_A
+#if HAVE_PRINTF_A & ENABLED_CBE_PRINTF_A
   char Buffer[100];
   sprintf(Buffer, "%a", CFP->getValue());
 
@@ -726,7 +726,7 @@
 << " /*inf*/ ";
   } else {
 std::string Num;
-#if HAVE_PRINTF_A
+#if HAVE_PRINTF_A & ENABLE_CBE_PRINTF_A
 // Print out the constant as a floating point number.
 char Buffer[100];
 sprintf(Buffer, "%a", FPC->getValue());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-05 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.279 -> 1.280
---
Log message:

Fix a bug in the last patch and convert to && instead of & for logical expr.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.279 
llvm/lib/Target/CBackend/Writer.cpp:1.280
--- llvm/lib/Target/CBackend/Writer.cpp:1.279   Sun Nov  5 11:09:41 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Nov  5 13:26:37 2006
@@ -534,7 +534,7 @@
 // only deal in IEEE FP).
 //
 static bool isFPCSafeToPrint(const ConstantFP *CFP) {
-#if HAVE_PRINTF_A & ENABLED_CBE_PRINTF_A
+#if HAVE_PRINTF_A && ENABLE_CBE_PRINTF_A
   char Buffer[100];
   sprintf(Buffer, "%a", CFP->getValue());
 
@@ -726,7 +726,7 @@
 << " /*inf*/ ";
   } else {
 std::string Num;
-#if HAVE_PRINTF_A & ENABLE_CBE_PRINTF_A
+#if HAVE_PRINTF_A && ENABLE_CBE_PRINTF_A
 // Print out the constant as a floating point number.
 char Buffer[100];
 sprintf(Buffer, "%a", FPC->getValue());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-07 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.280 -> 1.281
---
Log message:

For PR950: http://llvm.org/PR950 :
This patch converts the old SHR instruction into two instructions, 
AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not
dependent on the sign of their operands.


---
Diffs of the changes:  (+24 -17)

 Writer.cpp |   41 -
 1 files changed, 24 insertions(+), 17 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.280 
llvm/lib/Target/CBackend/Writer.cpp:1.281
--- llvm/lib/Target/CBackend/Writer.cpp:1.280   Sun Nov  5 13:26:37 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Nov  8 00:47:33 2006
@@ -606,7 +606,8 @@
 case Instruction::SetGT:
 case Instruction::SetGE:
 case Instruction::Shl:
-case Instruction::Shr:
+case Instruction::LShr:
+case Instruction::AShr:
 {
   Out << '(';
   bool NeedsClosingParens = printConstExprCast(CE); 
@@ -631,7 +632,8 @@
   case Instruction::SetGT: Out << " > "; break;
   case Instruction::SetGE: Out << " >= "; break;
   case Instruction::Shl: Out << " << "; break;
-  case Instruction::Shr: Out << " >> "; break;
+  case Instruction::LShr:
+  case Instruction::AShr: Out << " >> "; break;
   default: assert(0 && "Illegal opcode here!");
   }
   printConstantWithCast(CE->getOperand(1), CE->getOpcode());
@@ -826,23 +828,23 @@
 // because their operands were casted to the expected type. This function takes
 // care of detecting that case and printing the cast for the ConstantExpr.
 bool CWriter::printConstExprCast(const ConstantExpr* CE) {
-  bool Result = false;
+  bool NeedsExplicitCast = false;
   const Type* Ty = CE->getOperand(0)->getType();
   switch (CE->getOpcode()) {
-  case Instruction::UDiv: 
+  case Instruction::LShr:
   case Instruction::URem: 
-Result = Ty->isSigned(); break;
-  case Instruction::SDiv: 
+  case Instruction::UDiv: NeedsExplicitCast = Ty->isSigned(); break;
+  case Instruction::AShr:
   case Instruction::SRem: 
-Result = Ty->isUnsigned(); break;
+  case Instruction::SDiv: NeedsExplicitCast = Ty->isUnsigned(); break;
   default: break;
   }
-  if (Result) {
+  if (NeedsExplicitCast) {
 Out << "((";
 printType(Out, Ty);
 Out << ")(";
   }
-  return Result;
+  return NeedsExplicitCast;
 }
 
 //  Print a constant assuming that it is the operand for a given Opcode. The
@@ -863,6 +865,7 @@
 default:
   // for most instructions, it doesn't matter
   break; 
+case Instruction::LShr:
 case Instruction::UDiv:
 case Instruction::URem:
   // For UDiv/URem get correct type
@@ -871,6 +874,7 @@
 shouldCast = true;
   }
   break;
+case Instruction::AShr:
 case Instruction::SDiv:
 case Instruction::SRem:
   // For SDiv/SRem get correct type
@@ -927,23 +931,23 @@
 // This function takes care of detecting that case and printing the cast 
 // for the Instruction.
 bool CWriter::writeInstructionCast(const Instruction &I) {
-  bool Result = false;
+  bool NeedsExplicitCast = false;
   const Type* Ty = I.getOperand(0)->getType();
   switch (I.getOpcode()) {
-  case Instruction::UDiv: 
+  case Instruction::LShr:
   case Instruction::URem: 
-Result = Ty->isSigned(); break;
-  case Instruction::SDiv: 
+  case Instruction::UDiv: NeedsExplicitCast = Ty->isSigned(); break;
+  case Instruction::AShr:
   case Instruction::SRem: 
-Result = Ty->isUnsigned(); break;
+  case Instruction::SDiv: NeedsExplicitCast = Ty->isUnsigned(); break;
   default: break;
   }
-  if (Result) {
+  if (NeedsExplicitCast) {
 Out << "((";
 printType(Out, Ty);
 Out << ")(";
   }
-  return Result;
+  return NeedsExplicitCast;
 }
 
 // Write the operand with a cast to another type based on the Opcode being 
used.
@@ -964,6 +968,7 @@
 default:
   // for most instructions, it doesn't matter
   break; 
+case Instruction::LShr:
 case Instruction::UDiv:
 case Instruction::URem:
   // For UDiv to have unsigned operands
@@ -972,6 +977,7 @@
 shouldCast = true;
   }
   break;
+case Instruction::AShr:
 case Instruction::SDiv:
 case Instruction::SRem:
   if (OpTy->isUnsigned()) {
@@ -1832,7 +1838,8 @@
 case Instruction::SetLT: Out << " < "; break;
 case Instruction::SetGT: Out << " > "; break;
 case Instruction::Shl : Out << " << "; break;
-case Instruction::Shr : Out << " >> "; break;
+case Instruction::LShr:
+case Instruction::AShr: Out << " >> "; break;
 default: std::cerr << "Invalid operator type!" << I; abort();
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-15 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.281 -> 1.282
---
Log message:

Simplify IntrinsicLowering and clarify that it is only for use by the
CBE and interpreter.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.281 
llvm/lib/Target/CBackend/Writer.cpp:1.282
--- llvm/lib/Target/CBackend/Writer.cpp:1.281   Wed Nov  8 00:47:33 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Nov 15 12:00:10 2006
@@ -69,7 +69,7 @@
   /// module to a C translation unit.
   class CWriter : public FunctionPass, public InstVisitor {
 std::ostream &Out;
-DefaultIntrinsicLowering IL;
+IntrinsicLowering IL;
 Mangler *Mang;
 LoopInfo *LI;
 const Module *TheModule;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-26 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.282 -> 1.283
---
Log message:

For PR950: http://llvm.org/PR950 :
The long awaited CAST patch. This introduces 12 new instructions into LLVM
to replace the cast instruction. Corresponding changes throughout LLVM are
provided. This passes llvm-test, llvm/test, and SPEC CPUINT2000 with the
exception of 175.vpr which fails only on a slight floating point output
difference.


---
Diffs of the changes:  (+123 -28)

 Writer.cpp |  151 +
 1 files changed, 123 insertions(+), 28 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.282 
llvm/lib/Target/CBackend/Writer.cpp:1.283
--- llvm/lib/Target/CBackend/Writer.cpp:1.282   Wed Nov 15 12:00:10 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Nov 26 19:05:10 2006
@@ -137,6 +137,7 @@
 void printBasicBlock(BasicBlock *BB);
 void printLoop(Loop *L);
 
+void printCast(unsigned opcode, const Type *SrcTy, const Type *DstTy);
 void printConstant(Constant *CPV);
 void printConstantWithCast(Constant *CPV, unsigned Opcode);
 bool printConstExprCast(const ConstantExpr *CE);
@@ -560,15 +561,76 @@
 #endif
 }
 
+/// Print out the casting for a cast operation. This does the double casting
+/// necessary for conversion to the destination type, if necessary. 
+/// @returns true if a closing paren is necessary
+/// @brief Print a cast
+void CWriter::printCast(unsigned opc, const Type *SrcTy, const Type *DstTy) {
+  Out << '(';
+  printType(Out, DstTy);
+  Out << ')';
+  switch (opc) {
+case Instruction::UIToFP:
+case Instruction::ZExt:
+  if (SrcTy->isSigned()) {
+Out << '(';
+printType(Out, SrcTy->getUnsignedVersion());
+Out << ')';
+  }
+  break;
+case Instruction::SIToFP:
+case Instruction::SExt:
+  if (SrcTy->isUnsigned()) {
+Out << '(';
+printType(Out, SrcTy->getSignedVersion());
+Out << ')';
+  }
+  break;
+case Instruction::IntToPtr:
+case Instruction::PtrToInt:
+// Avoid "cast to pointer from integer of different size" warnings
+Out << "(unsigned long)";
+break;
+case Instruction::Trunc:
+case Instruction::BitCast:
+case Instruction::FPExt:
+case Instruction::FPTrunc:
+case Instruction::FPToSI:
+case Instruction::FPToUI:
+default:
+  break;
+  }
+}
+
 // printConstant - The LLVM Constant to C Constant converter.
 void CWriter::printConstant(Constant *CPV) {
   if (const ConstantExpr *CE = dyn_cast(CPV)) {
 switch (CE->getOpcode()) {
-case Instruction::Cast:
-  Out << "((";
-  printType(Out, CPV->getType());
-  Out << ')';
+case Instruction::Trunc:
+case Instruction::ZExt:
+case Instruction::SExt:
+case Instruction::FPTrunc:
+case Instruction::FPExt:
+case Instruction::UIToFP:
+case Instruction::SIToFP:
+case Instruction::FPToUI:
+case Instruction::FPToSI:
+case Instruction::PtrToInt:
+case Instruction::IntToPtr:
+case Instruction::BitCast:
+  Out << "(";
+  printCast(CE->getOpcode(), CE->getOperand(0)->getType(), CE->getType());
+  if (CE->getOpcode() == Instruction::SExt &&
+  CE->getOperand(0)->getType() == Type::BoolTy) {
+// Make sure we really sext from bool here by subtracting from 0
+Out << "0-";
+  }
   printConstant(CE->getOperand(0));
+  if (CE->getOpcode() == Instruction::Trunc && 
+  CE->getType() == Type::BoolTy) {
+// Make sure we really truncate to bool here by anding with 1
+Out << "&1u";
+  }
   Out << ')';
   return;
 
@@ -829,14 +891,31 @@
 // care of detecting that case and printing the cast for the ConstantExpr.
 bool CWriter::printConstExprCast(const ConstantExpr* CE) {
   bool NeedsExplicitCast = false;
-  const Type* Ty = CE->getOperand(0)->getType();
+  const Type *Ty = CE->getOperand(0)->getType();
   switch (CE->getOpcode()) {
   case Instruction::LShr:
   case Instruction::URem: 
-  case Instruction::UDiv: NeedsExplicitCast = Ty->isSigned(); break;
+  case Instruction::UDiv: 
+NeedsExplicitCast = Ty->isSigned(); break;
   case Instruction::AShr:
   case Instruction::SRem: 
-  case Instruction::SDiv: NeedsExplicitCast = Ty->isUnsigned(); break;
+  case Instruction::SDiv: 
+NeedsExplicitCast = Ty->isUnsigned(); break;
+  case Instruction::ZExt:
+  case Instruction::SExt:
+  case Instruction::Trunc:
+  case Instruction::FPTrunc:
+  case Instruction::FPExt:
+  case Instruction::UIToFP:
+  case Instruction::SIToFP:
+  case Instruction::FPToUI:
+  case Instruction::FPToSI:
+  case Instruction::PtrToInt:
+  case Instruction::IntToPtr:
+  case Instruction::BitCast:
+Ty = CE->getType();
+NeedsExplicitCast = true;
+break;
   default: break;
   }
   if (NeedsExplicitCast) {
@@ -860,7 +939,8 @@
 
   // Based on the Opcode for which this Co

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-27 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.283 -> 1.284
---
Log message:

When truncating to bool, it is necessary to & with 1 for all casts that
can result in a bool. Previously PtrToInt, FPToUI and FPToSI were missing
this operation.


---
Diffs of the changes:  (+10 -3)

 Writer.cpp |   13 ++---
 1 files changed, 10 insertions(+), 3 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.283 
llvm/lib/Target/CBackend/Writer.cpp:1.284
--- llvm/lib/Target/CBackend/Writer.cpp:1.283   Sun Nov 26 19:05:10 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Nov 27 12:51:06 2006
@@ -626,8 +626,11 @@
 Out << "0-";
   }
   printConstant(CE->getOperand(0));
-  if (CE->getOpcode() == Instruction::Trunc && 
-  CE->getType() == Type::BoolTy) {
+  if (CE->getType() == Type::BoolTy &&
+  (CE->getOpcode() == Instruction::Trunc ||
+   CE->getOpcode() == Instruction::FPToUI ||
+   CE->getOpcode() == Instruction::FPToSI ||
+   CE->getOpcode() == Instruction::PtrToInt)) {
 // Make sure we really truncate to bool here by anding with 1
 Out << "&1u";
   }
@@ -1960,7 +1963,11 @@
 Out << "0-";
   }
   writeOperand(I.getOperand(0));
-  if (I.getOpcode() == Instruction::Trunc && DstTy == Type::BoolTy) {
+  if (DstTy == Type::BoolTy && 
+  (I.getOpcode() == Instruction::Trunc ||
+   I.getOpcode() == Instruction::FPToUI ||
+   I.getOpcode() == Instruction::FPToSI ||
+   I.getOpcode() == Instruction::PtrToInt)) {
 // Make sure we really get a trunc to bool by anding the operand with 1 
 Out << "&1u";
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-27 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.284 -> 1.285
---
Log message:

Preliminary support for inline asm in the cbe.  The target specific ugliness
is still in Writer, but issolated to a single function. This might be split
into something in each target directory.  This is sufficient to get through
archie and an strcpy impl on linux-x86.

Module level asm is not handled.



---
Diffs of the changes:  (+164 -2)

 Writer.cpp |  166 -
 1 files changed, 164 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.284 
llvm/lib/Target/CBackend/Writer.cpp:1.285
--- llvm/lib/Target/CBackend/Writer.cpp:1.284   Mon Nov 27 12:51:06 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Nov 27 17:50:49 2006
@@ -23,6 +23,7 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/IntrinsicInst.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Analysis/ConstantsScanner.h"
 #include "llvm/Analysis/FindUsedTypes.h"
 #include "llvm/Analysis/LoopInfo.h"
@@ -120,6 +121,7 @@
   const PointerType *Ty);
 
 void writeOperand(Value *Operand);
+void writeOperandRaw(Value *Operand);
 void writeOperandInternal(Value *Operand);
 void writeOperandWithCast(Value* Operand, unsigned Opcode);
 bool writeInstructionCast(const Instruction &I);
@@ -162,6 +164,9 @@
 // Don't inline a load across a store or other bad things!
 return false;
 
+  // Must not be used in inline asm
+  if (I.hasOneUse() && isInlineAsm(*I.use_back())) return false;
+
   // Only inline instruction it it's use is in the same BB as the inst.
   return I.getParent() == cast(I.use_back())->getParent();
 }
@@ -179,7 +184,14 @@
 return 0;
   return AI;
 }
-
+
+// isInlineAsm - Check if the instruction is a call to an inline asm chunk
+static bool isInlineAsm(const Instruction& I) {
+  if (isa(&I) && isa(I.getOperand(0)))
+return true;
+  return false;
+}
+
 // Instruction visitation functions
 friend class InstVisitor;
 
@@ -201,6 +213,7 @@
 void visitCastInst (CastInst &I);
 void visitSelectInst(SelectInst &I);
 void visitCallInst (CallInst &I);
+void visitInlineAsm(CallInst &I);
 void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
 
 void visitMallocInst(MallocInst &I);
@@ -999,6 +1012,15 @@
   }
 }
 
+void CWriter::writeOperandRaw(Value *Operand) {
+  Constant* CPV = dyn_cast(Operand);
+  if (CPV && !isa(CPV)) {
+printConstant(CPV);
+  } else {
+Out << Mang->getValueName(Operand);
+  }
+}
+
 void CWriter::writeOperand(Value *Operand) {
   if (isa(Operand) || isDirectAlloca(Operand))
 Out << "(&";  // Global variables are referenced as their addresses by llvm
@@ -1727,7 +1749,7 @@
   for (BasicBlock::iterator II = BB->begin(), E = --BB->end(); II != E;
++II) {
 if (!isInlinableInst(*II) && !isDirectAlloca(II)) {
-  if (II->getType() != Type::VoidTy)
+  if (II->getType() != Type::VoidTy && !isInlineAsm(*II))
 outputLValue(II);
   else
 Out << "  ";
@@ -2033,6 +2055,12 @@
 
 
 void CWriter::visitCallInst(CallInst &I) {
+  //check if we have inline asm
+  if (isInlineAsm(I)) {
+visitInlineAsm(I);
+return;
+  }
+
   bool WroteCallee = false;
 
   // Handle intrinsic function calls first...
@@ -2224,6 +2252,140 @@
   Out << ')';
 }
 
+
+//This converts the llvm constraint string to something gcc is expecting.
+//This could be broken into a bunch of peices and spread accross the 
+//targets, but this information is only useful here.
+//TODO: work out platform independent constraints and factor those out
+static std::string InterpretConstraint(const std::string& target, 
+   InlineAsm::ConstraintInfo& c) {
+
+  assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
+
+  //catch numeric constraints
+  if (c.Codes[0].find_first_not_of("0123456789") >= c.Codes[0].size())
+return c.Codes[0];
+  
+  static const char* x86_table[] = {"{si}", "S",
+"{di}", "D",
+"{ax}", "a",
+"{cx}", "c",
+"q","q",
+"r","r",
+"m","m",
+"{memory}", "memory",
+"{flags}", "",
+"{dirflag}", "",
+"{fpsr}", "",
+"{cc}", "cc"
+  };
+
+  const char** table = 0;
+  int tbl_len = 0;
+  if (target == "i686-pc-linux-gnu") {
+table = x86_table;
+tbl_len = sizeof(x86_table) / sizeof(char*);
+  }
+  for (int i = 0; i < tbl_len &&

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-28 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.285 -> 1.286
---
Log message:

Get the asminfo for the target most closely matching the module and use that 
for inline asm

---
Diffs of the changes:  (+26 -28)

 Writer.cpp |   54 ++
 1 files changed, 26 insertions(+), 28 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.285 
llvm/lib/Target/CBackend/Writer.cpp:1.286
--- llvm/lib/Target/CBackend/Writer.cpp:1.285   Mon Nov 27 17:50:49 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Nov 28 13:53:36 2006
@@ -30,6 +30,7 @@
 #include "llvm/CodeGen/IntrinsicLowering.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Target/TargetMachineRegistry.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
@@ -74,11 +75,12 @@
 Mangler *Mang;
 LoopInfo *LI;
 const Module *TheModule;
+const TargetAsmInfo* TAsm;
 std::map TypeNames;
 
 std::map FPConstantMap;
   public:
-CWriter(std::ostream &o) : Out(o) {}
+CWriter(std::ostream &o) : Out(o), TAsm(0) {}
 
 virtual const char *getPassName() const { return "C backend"; }
 
@@ -127,6 +129,8 @@
 bool writeInstructionCast(const Instruction &I);
 
   private :
+std::string InterpretASMConstraint(InlineAsm::ConstraintInfo& c);
+
 void lowerIntrinsics(Function &F);
 
 void printModule(Module *M);
@@ -2257,47 +2261,42 @@
 //This could be broken into a bunch of peices and spread accross the 
 //targets, but this information is only useful here.
 //TODO: work out platform independent constraints and factor those out
-static std::string InterpretConstraint(const std::string& target, 
-   InlineAsm::ConstraintInfo& c) {
+std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) {
 
   assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
 
   //catch numeric constraints
   if (c.Codes[0].find_first_not_of("0123456789") >= c.Codes[0].size())
 return c.Codes[0];
-  
-  static const char* x86_table[] = {"{si}", "S",
-"{di}", "D",
-"{ax}", "a",
-"{cx}", "c",
-"q","q",
-"r","r",
-"m","m",
-"{memory}", "memory",
-"{flags}", "",
-"{dirflag}", "",
-"{fpsr}", "",
-"{cc}", "cc"
-  };
 
   const char** table = 0;
-  int tbl_len = 0;
-  if (target == "i686-pc-linux-gnu") {
-table = x86_table;
-tbl_len = sizeof(x86_table) / sizeof(char*);
+  
+  //Grab the translation table from TargetAsmInfo if it exists
+  if (!TAsm) {
+std::string E;
+const TargetMachineRegistry::Entry* Match = 
+  TargetMachineRegistry::getClosestStaticTargetForModule(*TheModule, E);
+if (Match) {
+  //Per platform Target Machines don't exist, so create it
+  // this must be done only once
+  const TargetMachine* TM = Match->CtorFn(*TheModule, "");
+  TAsm = TM->getTargetAsmInfo();
+}
   }
-  for (int i = 0; i < tbl_len && table; i += 2)
+  if (TAsm)
+table = TAsm->getAsmCBE();
+
+  //Search the translation table if it exists
+  for (int i = 0; table && table[i]; i += 2)
 if (c.Codes[0] == table[i])
   return table[i+1];
 
-  std::cerr << target << "\n";
-  std::cerr << c.Codes[0] << "\n";
   assert(0 && "Unknown Asm Constraint");
   return "";
 }
 
 //TODO: import logic from AsmPrinter.cpp
-static std::string gccifyAsm(const std::string& target, std::string asmstr) {
+static std::string gccifyAsm(std::string asmstr) {
   for (std::string::size_type i = 0; i != asmstr.size(); ++i)
 if (asmstr[i] == '\n')
   asmstr.replace(i, 1, "\\n");
@@ -2323,7 +2322,6 @@
 
 void CWriter::visitInlineAsm(CallInst &CI) {
   InlineAsm* as = cast(CI.getOperand(0));
-  const std::string& target = TheModule->getTargetTriple();
   std::vector Constraints = as->ParseConstraints();
   std::vector > Input;
   std::vector > Output;
@@ -2333,7 +2331,7 @@
  E = Constraints.end(); I != E; ++I) {
 assert(I->Codes.size() == 1 && "Too many asm constraint codes to handle");
 std::string c = 
-  InterpretConstraint(target, *I);
+  InterpretASMConstraint(*I);
 switch(I->Type) {
 default:
   assert(0 && "Unknown asm constraint");
@@ -2362,7 +2360,7 @@
   }
   
   //fix up the asm string for gcc
-  std::string asmstr = gccifyAsm(target, as->getAsmString());
+  std::string asmstr = gccifyAsm(as->getAsmString());
   
   Out << "__asm__ volatile (\"" << asmstr << "\"\n";
   Out << ":";




[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-28 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.286 -> 1.287
---
Log message:

update comments

---
Diffs of the changes:  (+4 -2)

 Writer.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.286 
llvm/lib/Target/CBackend/Writer.cpp:1.287
--- llvm/lib/Target/CBackend/Writer.cpp:1.286   Tue Nov 28 13:53:36 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Nov 28 13:56:02 2006
@@ -2258,9 +2258,9 @@
 
 
 //This converts the llvm constraint string to something gcc is expecting.
-//This could be broken into a bunch of peices and spread accross the 
-//targets, but this information is only useful here.
 //TODO: work out platform independent constraints and factor those out
+//  of the per target tables
+//  handle multiple constraint codes
 std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) {
 
   assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
@@ -2320,6 +2320,8 @@
   return asmstr;
 }
 
+//TODO: assumptions about what consume arguments from the call are likely wrong
+//  handle communitivity
 void CWriter::visitInlineAsm(CallInst &CI) {
   InlineAsm* as = cast(CI.getOperand(0));
   std::vector Constraints = as->ParseConstraints();



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-28 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.287 -> 1.288
---
Log message:

Make identity default, and fix PR1020: http://llvm.org/PR1020 

---
Diffs of the changes:  (+3 -7)

 Writer.cpp |   10 +++---
 1 files changed, 3 insertions(+), 7 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.287 
llvm/lib/Target/CBackend/Writer.cpp:1.288
--- llvm/lib/Target/CBackend/Writer.cpp:1.287   Tue Nov 28 13:56:02 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Nov 28 16:25:32 2006
@@ -2265,10 +2265,6 @@
 
   assert(c.Codes.size() == 1 && "Too many asm constraint codes to handle");
 
-  //catch numeric constraints
-  if (c.Codes[0].find_first_not_of("0123456789") >= c.Codes[0].size())
-return c.Codes[0];
-
   const char** table = 0;
   
   //Grab the translation table from TargetAsmInfo if it exists
@@ -2291,8 +2287,8 @@
 if (c.Codes[0] == table[i])
   return table[i+1];
 
-  assert(0 && "Unknown Asm Constraint");
-  return "";
+  //default is identity
+  return c.Codes[0];
 }
 
 //TODO: import logic from AsmPrinter.cpp
@@ -2383,7 +2379,7 @@
 if (I + 1 != E)
   Out << ",";
   }
-  Out << "\n:" << Clobber.substr(1) << ")\n";
+  Out << "\n:" << (Clobber.size() ? Clobber.substr(1) : "") << ")\n";
 }
 
 void CWriter::visitMallocInst(MallocInst &I) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-28 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.288 -> 1.289
---
Log message:

gcc doesn't like an empty colbber list

---
Diffs of the changes:  (+3 -1)

 Writer.cpp |4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.288 
llvm/lib/Target/CBackend/Writer.cpp:1.289
--- llvm/lib/Target/CBackend/Writer.cpp:1.288   Tue Nov 28 16:25:32 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Nov 28 17:07:32 2006
@@ -2379,7 +2379,9 @@
 if (I + 1 != E)
   Out << ",";
   }
-  Out << "\n:" << (Clobber.size() ? Clobber.substr(1) : "") << ")\n";
+  if (Clobber.size())
+Out << "\n:" << Clobber.substr(1);
+  Out << ")";
 }
 
 void CWriter::visitMallocInst(MallocInst &I) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-11-30 Thread Anton Korobeynikov


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.289 -> 1.290
---
Log message:

Introducing external weak linkage. Darwin codegen should be added later.


---
Diffs of the changes:  (+11 -4)

 Writer.cpp |   15 +++
 1 files changed, 11 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.289 
llvm/lib/Target/CBackend/Writer.cpp:1.290
--- llvm/lib/Target/CBackend/Writer.cpp:1.289   Tue Nov 28 17:07:32 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Nov 30 18:25:12 2006
@@ -1157,8 +1157,6 @@
   << "#define __attribute__(X)\n"
   << "#endif\n\n";
 
-#if 0
-  // At some point, we should support "external weak" vs. "weak" linkages.
   // On Mac OS X, "external weak" is spelled "__attribute__((weak_import))".
   Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
   << "#define __EXTERNAL_WEAK__ __attribute__((weak_import))\n"
@@ -1167,7 +1165,6 @@
   << "#else\n"
   << "#define __EXTERNAL_WEAK__\n"
   << "#endif\n\n";
-#endif
 
   // For now, turn off the weak linkage attribute on Mac OS X. (See above.)
   Out << "#if defined(__GNUC__) && defined(__APPLE_CC__)\n"
@@ -1357,7 +1354,11 @@
 Out << "__declspec(dllimport) ";
 printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
 Out << ";\n";
-  }  
+  } else if (I->hasExternalWeakLinkage()) {
+Out << "extern ";
+printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+Out << " __EXTERNAL_WEAK__ ;\n";
+  }
 }
   }
 
@@ -1370,9 +1371,13 @@
 // Don't print declarations for intrinsic functions.
 if (!I->getIntrinsicID() && I->getName() != "setjmp" && 
 I->getName() != "longjmp" && I->getName() != "_setjmp") {
+  if (I->hasExternalWeakLinkage())
+Out << "extern ";
   printFunctionSignature(I, true);
   if (I->hasWeakLinkage() || I->hasLinkOnceLinkage()) 
 Out << " __ATTRIBUTE_WEAK__";
+  if (I->hasExternalWeakLinkage())
+Out << " __EXTERNAL_WEAK__";
   if (StaticCtors.count(I))
 Out << " __ATTRIBUTE_CTOR__";
   if (StaticDtors.count(I))
@@ -1405,6 +1410,8 @@
   Out << " __attribute__((common))";
 else if (I->hasWeakLinkage())
   Out << " __ATTRIBUTE_WEAK__";
+else if (I->hasExternalWeakLinkage())
+  Out << " __EXTERNAL_WEAK__";
 Out << ";\n";
   }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-06 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.290 -> 1.291
---
Log message:

Adjust to new ConstantIntegral interface for Max/Min tests.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.290 
llvm/lib/Target/CBackend/Writer.cpp:1.291
--- llvm/lib/Target/CBackend/Writer.cpp:1.290   Thu Nov 30 18:25:12 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Dec  6 14:45:15 2006
@@ -753,7 +753,7 @@
 break;
 
   case Type::LongTyID:
-if (cast(CPV)->isMinValue())
+if (cast(CPV)->isMinValue(CPV->getType()->isSigned()))
   Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
 else
   Out << cast(CPV)->getSExtValue() << "ll";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-06 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.291 -> 1.292
---
Log message:

Always pass "true" to isMaxValue(bool) because we know the type is LongTy.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.291 
llvm/lib/Target/CBackend/Writer.cpp:1.292
--- llvm/lib/Target/CBackend/Writer.cpp:1.291   Wed Dec  6 14:45:15 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed Dec  6 15:27:07 2006
@@ -753,7 +753,7 @@
 break;
 
   case Type::LongTyID:
-if (cast(CPV)->isMinValue(CPV->getType()->isSigned()))
+if (cast(CPV)->isMinValue(true))
   Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
 else
   Out << cast(CPV)->getSExtValue() << "ll";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-07 Thread Bill Wendling


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.292 -> 1.293
---
Log message:

What should be the last unnecessary s in the library.


---
Diffs of the changes:  (+9 -11)

 Writer.cpp |   20 +---
 1 files changed, 9 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.292 
llvm/lib/Target/CBackend/Writer.cpp:1.293
--- llvm/lib/Target/CBackend/Writer.cpp:1.292   Wed Dec  6 15:27:07 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Dec  7 16:21:48 2006
@@ -42,9 +42,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Config/config.h"
 #include 
-#include 
 #include 
-#include 
 using namespace llvm;
 
 namespace {
@@ -229,7 +227,7 @@
 void visitVAArgInst (VAArgInst &I);
 
 void visitInstruction(Instruction &I) {
-  std::cerr << "C Writer does not know about " << I;
+  cerr << "C Writer does not know about " << I;
   abort();
 }
 
@@ -375,7 +373,7 @@
 case Type::FloatTyID:  return Out << "float "  << NameSoFar;
 case Type::DoubleTyID: return Out << "double " << NameSoFar;
 default :
-  std::cerr << "Unknown primitive type: " << *Ty << "\n";
+  cerr << "Unknown primitive type: " << *Ty << "\n";
   abort();
 }
 
@@ -726,8 +724,8 @@
 }
 
 default:
-  std::cerr << "CWriter Error: Unhandled constant expression: "
-<< *CE << "\n";
+  cerr << "CWriter Error: Unhandled constant expression: "
+   << *CE << "\n";
   abort();
 }
   } else if (isa(CPV) && CPV->getType()->isFirstClassType()) {
@@ -901,7 +899,7 @@
 }
 // FALL THROUGH
   default:
-std::cerr << "Unknown constant type: " << *CPV << "\n";
+cerr << "Unknown constant type: " << *CPV << "\n";
 abort();
   }
 }
@@ -1973,7 +1971,7 @@
 case Instruction::Shl : Out << " << "; break;
 case Instruction::LShr:
 case Instruction::AShr: Out << " >> "; break;
-default: std::cerr << "Invalid operator type!" << I; abort();
+default: cerr << "Invalid operator type!" << I; abort();
 }
 
 writeOperandWithCast(I.getOperand(1), I.getOpcode());
@@ -2099,9 +2097,9 @@
 Out << ", ";
 // Output the last argument to the enclosing function...
 if (I.getParent()->getParent()->arg_empty()) {
-  std::cerr << "The C backend does not currently support zero "
-<< "argument varargs functions, such as '"
-<< I.getParent()->getParent()->getName() << "'!\n";
+  cerr << "The C backend does not currently support zero "
+   << "argument varargs functions, such as '"
+   << I.getParent()->getParent()->getName() << "'!\n";
   abort();
 }
 writeOperand(--I.getParent()->getParent()->arg_end());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-07 Thread Bill Wendling


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.293 -> 1.294
---
Log message:

Don't use  in Streams.h but  instead.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.293 
llvm/lib/Target/CBackend/Writer.cpp:1.294
--- llvm/lib/Target/CBackend/Writer.cpp:1.293   Thu Dec  7 16:21:48 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Dec  7 17:41:45 2006
@@ -42,7 +42,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Config/config.h"
 #include 
-#include 
+#include 
 using namespace llvm;
 
 namespace {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-11 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.295 -> 1.296
---
Log message:

Implement correct bitcast of int<->float and long<->double by using a
union to perform the bitcast. 


---
Diffs of the changes:  (+58 -14)

 Writer.cpp |   72 +
 1 files changed, 58 insertions(+), 14 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.295 
llvm/lib/Target/CBackend/Writer.cpp:1.296
--- llvm/lib/Target/CBackend/Writer.cpp:1.295   Sun Dec 10 17:12:42 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Dec 11 14:39:15 2006
@@ -169,7 +169,7 @@
   // Must not be used in inline asm
   if (I.hasOneUse() && isInlineAsm(*I.use_back())) return false;
 
-  // Only inline instruction it it's use is in the same BB as the inst.
+  // Only inline instruction it if it's use is in the same BB as the inst.
   return I.getParent() == cast(I.use_back())->getParent();
 }
 
@@ -1508,6 +1508,16 @@
 /// type name is found, emit its declaration...
 ///
 void CWriter::printModuleTypes(const SymbolTable &ST) {
+  Out << "/* Helper union for bitcasts */\n";
+  Out << "typedef union {\n";
+  Out << "  unsigned int  UInt;\n";
+  Out << "signed int  SInt;\n";
+  Out << "  unsigned long ULong;\n";
+  Out << "signed long SLong;\n";
+  Out << "  float Float;\n";
+  Out << " double Double;\n";
+  Out << "} llvmBitCastUnion;\n";
+
   // We are only interested in the type plane of the symbol table.
   SymbolTable::type_const_iterator I   = ST.type_begin();
   SymbolTable::type_const_iterator End = ST.type_end();
@@ -1704,6 +1714,15 @@
 Out << ";\n";
   }
   PrintedVar = true;
+} else if (isa(*I) && 
+   ((I->getType()->isFloatingPoint() && 
+ I->getOperand(0)->getType()->isInteger()) ||
+(I->getType()->isInteger() && 
+ I->getOperand(0)->getType()->isFloatingPoint( {
+  // We need a temporary for the BitCast to use so it can pluck a 
+  // value out of a union to do the BitCast.
+  Out << "  llvmBitCastUnion " << Mang->getValueName(&*I)
+  << "__BITCAST_TEMPORARY;\n";
 }
 
   if (PrintedVar)
@@ -1986,23 +2005,48 @@
   }
 }
 
+static const char * getFloatBitCastField(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+default: assert(0 && "Invalid Type");
+case Type::FloatTyID: return "Float";
+case Type::UIntTyID:  return "UInt";
+case Type::IntTyID:   return "SInt";
+case Type::DoubleTyID:return "Double";
+case Type::ULongTyID: return "ULong";
+case Type::LongTyID:  return "SLong";
+  }
+}
+
 void CWriter::visitCastInst(CastInst &I) {
   const Type *DstTy = I.getType();
   const Type *SrcTy = I.getOperand(0)->getType();
   Out << '(';
-  printCast(I.getOpcode(), SrcTy, DstTy);
-  if (I.getOpcode() == Instruction::SExt && SrcTy == Type::BoolTy) {
-// Make sure we really get a sext from bool by subtracing the bool from 0
-Out << "0-";
-  }
-  writeOperand(I.getOperand(0));
-  if (DstTy == Type::BoolTy && 
-  (I.getOpcode() == Instruction::Trunc ||
-   I.getOpcode() == Instruction::FPToUI ||
-   I.getOpcode() == Instruction::FPToSI ||
-   I.getOpcode() == Instruction::PtrToInt)) {
-// Make sure we really get a trunc to bool by anding the operand with 1 
-Out << "&1u";
+  if (isa(I) &&
+  ((I.getType()->isFloatingPoint() && 
+I.getOperand(0)->getType()->isInteger()) ||
+   (I.getType()->isInteger() && 
+I.getOperand(0)->getType()->isFloatingPoint( {
+// These int<->float and long<->double casts need to be handled specially
+Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY." 
+<< getFloatBitCastField(I.getOperand(0)->getType()) << " = ";
+writeOperand(I.getOperand(0));
+Out << ", " << Mang->getValueName(&I) << "__BITCAST_TEMPORARY."
+<< getFloatBitCastField(I.getType());
+  } else {
+printCast(I.getOpcode(), SrcTy, DstTy);
+if (I.getOpcode() == Instruction::SExt && SrcTy == Type::BoolTy) {
+  // Make sure we really get a sext from bool by subtracing the bool from 0
+  Out << "0-";
+}
+writeOperand(I.getOperand(0));
+if (DstTy == Type::BoolTy && 
+(I.getOpcode() == Instruction::Trunc ||
+ I.getOpcode() == Instruction::FPToUI ||
+ I.getOpcode() == Instruction::FPToSI ||
+ I.getOpcode() == Instruction::PtrToInt)) {
+  // Make sure we really get a trunc to bool by anding the operand with 1 
+  Out << "&1u";
+}
   }
   Out << ')';
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-11 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.296 -> 1.297
---
Log message:

Fix the BitCastUnion type for 32-bit targets.


---
Diffs of the changes:  (+6 -6)

 Writer.cpp |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.296 
llvm/lib/Target/CBackend/Writer.cpp:1.297
--- llvm/lib/Target/CBackend/Writer.cpp:1.296   Mon Dec 11 14:39:15 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Dec 11 18:11:08 2006
@@ -1510,12 +1510,12 @@
 void CWriter::printModuleTypes(const SymbolTable &ST) {
   Out << "/* Helper union for bitcasts */\n";
   Out << "typedef union {\n";
-  Out << "  unsigned int  UInt;\n";
-  Out << "signed int  SInt;\n";
-  Out << "  unsigned long ULong;\n";
-  Out << "signed long SLong;\n";
-  Out << "  float Float;\n";
-  Out << " double Double;\n";
+  Out << "  unsigned int UInt;\n";
+  Out << "  signed int SInt;\n";
+  Out << "  unsigned long long ULong;\n";
+  Out << "  signed long long SLong;\n";
+  Out << "  float Float;\n";
+  Out << "  double Double;\n";
   Out << "} llvmBitCastUnion;\n";
 
   // We are only interested in the type plane of the symbol table.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-11 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.297 -> 1.298
---
Log message:

Change inferred getCast into specific getCast. Passes all tests.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.297 
llvm/lib/Target/CBackend/Writer.cpp:1.298
--- llvm/lib/Target/CBackend/Writer.cpp:1.297   Mon Dec 11 18:11:08 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Dec 11 23:04:59 2006
@@ -296,7 +296,7 @@
   if (!X.second) {
 // Found a conflict, replace this global with the previous one.
 GlobalValue *OldGV = X.first->second;
-GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
 GV->eraseFromParent();
 Changed = true;
   }
@@ -312,7 +312,7 @@
   if (!X.second) {
 // Found a conflict, replace this global with the previous one.
 GlobalValue *OldGV = X.first->second;
-GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
 GV->eraseFromParent();
 Changed = true;
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-17 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.298 -> 1.299
---
Log message:

Fix PR1058: http://llvm.org/PR1058 :
Generate the BITCAST_TEMPORARY regardless of the uses or inlinability of
the instruction. This temporary is needed to perform the instruction, not
provide storage for its results.


---
Diffs of the changes:  (+13 -8)

 Writer.cpp |   21 +
 1 files changed, 13 insertions(+), 8 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.298 
llvm/lib/Target/CBackend/Writer.cpp:1.299
--- llvm/lib/Target/CBackend/Writer.cpp:1.298   Mon Dec 11 23:04:59 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Dec 17 12:50:51 2006
@@ -1696,7 +1696,7 @@
   bool PrintedVar = false;
   
   // print local variable information for the function
-  for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I)
+  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));
@@ -1714,16 +1714,20 @@
 Out << ";\n";
   }
   PrintedVar = true;
-} else if (isa(*I) && 
-   ((I->getType()->isFloatingPoint() && 
- I->getOperand(0)->getType()->isInteger()) ||
-(I->getType()->isInteger() && 
- I->getOperand(0)->getType()->isFloatingPoint( {
-  // We need a temporary for the BitCast to use so it can pluck a 
-  // value out of a union to do the BitCast.
+}
+// We need a temporary for the BitCast to use so it can pluck a value out
+// of a uniont to do the BitCast. This is separate from the need for a
+// variable to hold the result of the BitCast. 
+if (isa(*I) && 
+((I->getType()->isFloatingPoint() && 
+  I->getOperand(0)->getType()->isInteger()) ||
+ (I->getType()->isInteger() && 
+  I->getOperand(0)->getType()->isFloatingPoint( {
   Out << "  llvmBitCastUnion " << Mang->getValueName(&*I)
   << "__BITCAST_TEMPORARY;\n";
+  PrintedVar = true;
 }
+  }
 
   if (PrintedVar)
 Out << '\n';
@@ -2026,6 +2030,7 @@
 I.getOperand(0)->getType()->isInteger()) ||
(I.getType()->isInteger() && 
 I.getOperand(0)->getType()->isFloatingPoint( {
+
 // These int<->float and long<->double casts need to be handled specially
 Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY." 
 << getFloatBitCastField(I.getOperand(0)->getType()) << " = ";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-17 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.299 -> 1.300
---
Log message:

Use a predicate function to identify bitcast of fp and integer instead of 
repeating the logic in two different parts of the code.


---
Diffs of the changes:  (+11 -11)

 Writer.cpp |   22 +++---
 1 files changed, 11 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.299 
llvm/lib/Target/CBackend/Writer.cpp:1.300
--- llvm/lib/Target/CBackend/Writer.cpp:1.299   Sun Dec 17 12:50:51 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Dec 17 14:24:50 2006
@@ -1676,6 +1676,15 @@
   printType(Out, RetTy, FunctionInnards.str());
 }
 
+static inline bool isFPIntBitCast(const Instruction &I) {
+  if (!isa(I))
+return false;
+  const Type *SrcTy = I.getOperand(0)->getType();
+  const Type *DstTy = I.getType();
+  return (SrcTy->isFloatingPoint() && DstTy->isInteger()) ||
+ (DstTy->isFloatingPoint() && SrcTy->isInteger());
+}
+
 void CWriter::printFunction(Function &F) {
   printFunctionSignature(&F, false);
   Out << " {\n";
@@ -1718,11 +1727,7 @@
 // We need a temporary for the BitCast to use so it can pluck a value out
 // of a uniont to do the BitCast. This is separate from the need for a
 // variable to hold the result of the BitCast. 
-if (isa(*I) && 
-((I->getType()->isFloatingPoint() && 
-  I->getOperand(0)->getType()->isInteger()) ||
- (I->getType()->isInteger() && 
-  I->getOperand(0)->getType()->isFloatingPoint( {
+if (isFPIntBitCast(*I)) {
   Out << "  llvmBitCastUnion " << Mang->getValueName(&*I)
   << "__BITCAST_TEMPORARY;\n";
   PrintedVar = true;
@@ -2025,12 +2030,7 @@
   const Type *DstTy = I.getType();
   const Type *SrcTy = I.getOperand(0)->getType();
   Out << '(';
-  if (isa(I) &&
-  ((I.getType()->isFloatingPoint() && 
-I.getOperand(0)->getType()->isInteger()) ||
-   (I.getType()->isInteger() && 
-I.getOperand(0)->getType()->isFloatingPoint( {
-
+  if (isFPIntBitCast(I)) {
 // These int<->float and long<->double casts need to be handled specially
 Out << Mang->getValueName(&I) << "__BITCAST_TEMPORARY." 
 << getFloatBitCastField(I.getOperand(0)->getType()) << " = ";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-30 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.301 -> 1.302
---
Log message:

For PR950: http://llvm.org/PR950 :
Three changes:
1. Convert signed integer types to signless versions.
2. Implement the @sext and @zext parameter attributes. Previously the
   type of an function parameter was used to determine whether it should
   be sign extended or zero extended before the call. This information is
   now communicated via the function type's parameter attributes. 
3. The interface to LowerCallTo had to be changed in order to accommodate
   the parameter attribute information. Although it would have been
   convenient to pass in the FunctionType itself, there isn't always one
   present in the caller. Consequently, a signedness indication for the
   result type and for each parameter was provided for in the interface
   to this method. All implementations were changed to make the adjustment
   necessary.


---
Diffs of the changes:  (+16 -56)

 Writer.cpp |   72 +
 1 files changed, 16 insertions(+), 56 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.301 
llvm/lib/Target/CBackend/Writer.cpp:1.302
--- llvm/lib/Target/CBackend/Writer.cpp:1.301   Sat Dec 23 00:05:41 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sat Dec 30 23:55:36 2006
@@ -365,17 +365,13 @@
   switch (Ty->getTypeID()) {
   case Type::VoidTyID:   return Out << "void "   << NameSoFar;
   case Type::BoolTyID:   return Out << "bool "   << NameSoFar;
-  case Type::UByteTyID:  
-  case Type::SByteTyID:
+  case Type::Int8TyID:
 return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar;
-  case Type::UShortTyID: 
-  case Type::ShortTyID:  
+  case Type::Int16TyID:  
 return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar;
-  case Type::UIntTyID:   
-  case Type::IntTyID:
+  case Type::Int32TyID:
 return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar;
-  case Type::ULongTyID:  
-  case Type::LongTyID:   
+  case Type::Int64TyID:   
 return Out << (isSigned?"signed":"unsigned") << " long long " << NameSoFar;
   case Type::FloatTyID:  return Out << "float "  << NameSoFar;
   case Type::DoubleTyID: return Out << "double " << NameSoFar;
@@ -488,7 +484,7 @@
   // ubytes or an array of sbytes with positive values.
   //
   const Type *ETy = CPA->getType()->getElementType();
-  bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
+  bool isString = (ETy == Type::Int8Ty || ETy == Type::Int8Ty);
 
   // Make sure the last character is a null char, as automatically added by C
   if (isString && (CPA->getNumOperands() == 0 ||
@@ -810,50 +806,19 @@
   case Type::BoolTyID:
 Out << (cast(CPV)->getValue() ? '1' : '0');
 break;
-  case Type::SByteTyID:
-  case Type::UByteTyID:
+  case Type::Int8TyID:
 Out << "((char)" << cast(CPV)->getSExtValue() << ")";
 break;
-  case Type::ShortTyID:
-  case Type::UShortTyID:
+  case Type::Int16TyID:
 Out << "((short)" << cast(CPV)->getSExtValue() << ")";
 break;
-  case Type::IntTyID:
-  case Type::UIntTyID:
+  case Type::Int32TyID:
 Out << "((int)" << cast(CPV)->getSExtValue() << ")";
 break;
-  case Type::LongTyID:
-  case Type::ULongTyID:
+  case Type::Int64TyID:
 Out << "((long long)" << cast(CPV)->getSExtValue() << "ll)";
 break;
 
-#if 0
-  case Type::IntTyID:
-if ((int)cast(CPV)->getSExtValue() == (int)0x8000)
-  Out << "((int)0x8000U)";   // Handle MININT specially to avoid 
warning
-else
-  Out << cast(CPV)->getSExtValue();
-break;
-
-  case Type::LongTyID:
-if (cast(CPV)->isMinValue(true))
-  Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
-else
-  Out << cast(CPV)->getSExtValue() << "ll";
-break;
-
-  case Type::UByteTyID:
-  case Type::UShortTyID:
-Out << cast(CPV)->getZExtValue();
-break;
-  case Type::UIntTyID:
-Out << cast(CPV)->getZExtValue() << 'u';
-break;
-  case Type::ULongTyID:
-Out << cast(CPV)->getZExtValue() << "ull";
-break;
-#endif
-
   case Type::FloatTyID:
   case Type::DoubleTyID: {
 ConstantFP *FPC = cast(CPV);
@@ -1627,10 +1592,8 @@
 void CWriter::printModuleTypes(const SymbolTable &ST) {
   Out << "/* Helper union for bitcasts */\n";
   Out << "typedef union {\n";
-  Out << "  unsigned int UInt;\n";
-  Out << "  signed int SInt;\n";
-  Out << "  unsigned long long ULong;\n";
-  Out << "  signed long long SLong;\n";
+  Out << "  unsigned int Int32;\n";
+  Out << "  unsigned long long Int64;\n";
   Out << "  float Float;\n";
   Out << "  double Double;\n";
   Out << "} llvmBitCastUnion;\n";
@@ -2060,8 +2023,7 @@
 
   // We must cast the results of binary operations which might be promoted.
   bool needsCast = false;
-  if ((I.getType() == Type::UByteTy) || (I.getType() == Type::SByteTy)
-  || (I.getType() == Type::UShortTy

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-05 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.302 -> 1.303
---
Log message:

For PR411: http://llvm.org/PR411 :
Take an incremental step towards type plane elimination. This change 
separates types from values in the symbol tables by finally making use
of the TypeSymbolTable class. This yields more natural interfaces for
dealing with types and unclutters the SymbolTable class.


---
Diffs of the changes:  (+12 -11)

 Writer.cpp |   23 ---
 1 files changed, 12 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.302 
llvm/lib/Target/CBackend/Writer.cpp:1.303
--- llvm/lib/Target/CBackend/Writer.cpp:1.302   Sat Dec 30 23:55:36 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sat Jan  6 01:24:43 2007
@@ -21,6 +21,7 @@
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/IntrinsicInst.h"
 #include "llvm/InlineAsm.h"
@@ -136,7 +137,7 @@
 void lowerIntrinsics(Function &F);
 
 void printModule(Module *M);
-void printModuleTypes(const SymbolTable &ST);
+void printModuleTypes(const TypeSymbolTable &ST);
 void printContainedStructs(const Type *Ty, std::set &);
 void printFloatingPointConstants(Function &F);
 void printFunctionSignature(const Function *F, bool Prototype);
@@ -263,15 +264,15 @@
   // Loop over the module symbol table, removing types from UT that are
   // already named, and removing names for types that are not used.
   //
-  SymbolTable &MST = M.getSymbolTable();
-  for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
+  TypeSymbolTable &TST = M.getTypeSymbolTable();
+  for (TypeSymbolTable::iterator TI = TST.begin(), TE = TST.end();
TI != TE; ) {
-SymbolTable::type_iterator I = TI++;
+TypeSymbolTable::iterator I = TI++;
 
 // If this is not used, remove it from the symbol table.
 std::set::iterator UTI = UT.find(I->second);
 if (UTI == UT.end())
-  MST.remove(I);
+  TST.remove(I);
 else
   UT.erase(UTI);// Only keep one name for this type.
   }
@@ -1421,7 +1422,7 @@
   //
 
   // Loop over the symbol table, emitting all named constants...
-  printModuleTypes(M.getSymbolTable());
+  printModuleTypes(M.getTypeSymbolTable());
 
   // Global variable declarations...
   if (!M.global_empty()) {
@@ -1589,7 +1590,7 @@
 /// printSymbolTable - Run through symbol table looking for type names.  If a
 /// type name is found, emit its declaration...
 ///
-void CWriter::printModuleTypes(const SymbolTable &ST) {
+void CWriter::printModuleTypes(const TypeSymbolTable &TST) {
   Out << "/* Helper union for bitcasts */\n";
   Out << "typedef union {\n";
   Out << "  unsigned int Int32;\n";
@@ -1599,8 +1600,8 @@
   Out << "} llvmBitCastUnion;\n";
 
   // We are only interested in the type plane of the symbol table.
-  SymbolTable::type_const_iterator I   = ST.type_begin();
-  SymbolTable::type_const_iterator End = ST.type_end();
+  TypeSymbolTable::const_iterator I   = TST.begin();
+  TypeSymbolTable::const_iterator End = TST.end();
 
   // If there are no type names, exit early.
   if (I == End) return;
@@ -1618,7 +1619,7 @@
 
   // Now we can print out typedefs...
   Out << "/* Typedefs */\n";
-  for (I = ST.type_begin(); I != End; ++I) {
+  for (I = TST.begin(); I != End; ++I) {
 const Type *Ty = cast(I->second);
 std::string Name = "l_" + Mang->makeNameProper(I->first);
 Out << "typedef ";
@@ -1635,7 +1636,7 @@
   // printed in the correct order.
   //
   Out << "/* Structure contents */\n";
-  for (I = ST.type_begin(); I != End; ++I)
+  for (I = TST.begin(); I != End; ++I)
 if (const StructType *STy = dyn_cast(I->second))
   // Only print out used types!
   printContainedStructs(STy, StructPrinted);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-06 Thread Reid Spencer


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(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(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(PTy->getElementType()))
   ptrName = "(" + ptrName + ")";
 
-return printType(Out, PTy->getElementType(), ptrName);
+return printType(Out, PTy->getElementType(), true, ptrName);
   }
 
   case Type::ArrayTyID: {
 const ArrayType *ATy = cast(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(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 << ";\

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-07 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.304 -> 1.305
---
Log message:

Fix PR1090: http://llvm.org/PR1090 :
Implemented some llvm_fcmp_{pred} functions at the start of the function bodies 
and use them for fcmp instructions and constant expressions. These help
implement the ordered and unordered comparisons necessary for correct exectuion
of these comparisons.


---
Diffs of the changes:  (+97 -41)

 Writer.cpp |  138 ++---
 1 files changed, 97 insertions(+), 41 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.304 
llvm/lib/Target/CBackend/Writer.cpp:1.305
--- llvm/lib/Target/CBackend/Writer.cpp:1.304   Sat Jan  6 21:24:48 2007
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Jan  8 00:58:32 2007
@@ -732,7 +732,6 @@
 case Instruction::Or:
 case Instruction::Xor:
 case Instruction::ICmp:
-case Instruction::FCmp:
 case Instruction::Shl:
 case Instruction::LShr:
 case Instruction::AShr:
@@ -771,25 +770,6 @@
   default: assert(0 && "Illegal ICmp predicate");
 }
 break;
-  case Instruction::FCmp:
-switch (CE->getPredicate()) {
-  case FCmpInst::FCMP_ORD: 
-  case FCmpInst::FCMP_UEQ: 
-  case FCmpInst::FCMP_OEQ: Out << " == "; break;
-  case FCmpInst::FCMP_UNO: 
-  case FCmpInst::FCMP_UNE: 
-  case FCmpInst::FCMP_ONE: Out << " != "; break;
-  case FCmpInst::FCMP_OLT:
-  case FCmpInst::FCMP_ULT: Out << " < "; break;
-  case FCmpInst::FCMP_OLE:
-  case FCmpInst::FCMP_ULE: Out << " <= "; break;
-  case FCmpInst::FCMP_OGT: 
-  case FCmpInst::FCMP_UGT: Out << " > "; break;
-  case FCmpInst::FCMP_OGE:
-  case FCmpInst::FCMP_UGE: Out << " >= "; break;
-  default: assert(0 && "Illegal FCmp predicate");
-}
-break;
   default: assert(0 && "Illegal opcode here!");
   }
   printConstantWithCast(CE->getOperand(1), CE->getOpcode());
@@ -798,7 +778,42 @@
   Out << ')';
   return;
 }
-
+case Instruction::FCmp: {
+  Out << '('; 
+  bool NeedsClosingParens = printConstExprCast(CE); 
+  if (CE->getPredicate() == FCmpInst::FCMP_FALSE)
+Out << "0";
+  else if (CE->getPredicate() == FCmpInst::FCMP_TRUE)
+Out << "1";
+  else {
+const char* op = 0;
+switch (CE->getPredicate()) {
+default: assert(0 && "Illegal FCmp predicate");
+case FCmpInst::FCMP_ORD: op = "ord"; break;
+case FCmpInst::FCMP_UNO: op = "uno"; break;
+case FCmpInst::FCMP_UEQ: op = "ueq"; break;
+case FCmpInst::FCMP_UNE: op = "une"; break;
+case FCmpInst::FCMP_ULT: op = "ult"; break;
+case FCmpInst::FCMP_ULE: op = "ule"; break;
+case FCmpInst::FCMP_UGT: op = "ugt"; break;
+case FCmpInst::FCMP_UGE: op = "uge"; break;
+case FCmpInst::FCMP_OEQ: op = "oeq"; break;
+case FCmpInst::FCMP_ONE: op = "one"; break;
+case FCmpInst::FCMP_OLT: op = "olt"; break;
+case FCmpInst::FCMP_OLE: op = "ole"; break;
+case FCmpInst::FCMP_OGT: op = "ogt"; break;
+case FCmpInst::FCMP_OGE: op = "oge"; break;
+}
+Out << "llvm_fcmp_" << op << "(";
+printConstantWithCast(CE->getOperand(0), CE->getOpcode());
+Out << ", ";
+printConstantWithCast(CE->getOperand(1), CE->getOpcode());
+Out << ")";
+  }
+  if (NeedsClosingParens)
+Out << "))";
+  Out << ')';
+}
 default:
   cerr << "CWriter Error: Unhandled constant expression: "
<< *CE << "\n";
@@ -1563,6 +1578,37 @@
 
   if (!M.empty())
 Out << "\n\n/* Function Bodies */\n";
+
+  // Emit some helper functions for dealing with FCMP instruction's 
+  // predicates
+  Out << "static inline int llvm_fcmp_ord(double X, double Y) { ";
+  Out << "return X == X && Y == Y; }\n";
+  Out << "static inline int llvm_fcmp_uno(double X, double Y) { ";
+  Out << "return X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_ueq(double X, double Y) { ";
+  Out << "return X == Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_une(double X, double Y) { ";
+  Out << "return X != Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_ult(double X, double Y) { ";
+  Out << "return X <  Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_ugt(double X, double Y) { ";
+  Out << "return X >  Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_ule(double X, double Y) { ";
+  Out << "return X <= Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_uge(double X, double Y) { ";
+  Out << "return X >= Y || X != X || Y != Y; }\n";
+  Out << "static inline int llvm_fcmp_oeq(double X, double Y) { ";
+  Out << "return X == Y && X == X && Y == Y; }\n";
+  Out << "static inline int llvm

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-08 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.305 -> 1.306
---
Log message:

For PR1090: http://llvm.org/PR1090 :
Clean up the definitions of the helper functions per Chris' review 
suggestions so they are easier to read.

For PR1091: http://llvm.org/PR1091 :
Print minimum signed integer values as unsigned so that we get no warnings
from the C compiler about constant ranges and value comparisons.



---
Diffs of the changes:  (+31 -28)

 Writer.cpp |   59 +++
 1 files changed, 31 insertions(+), 28 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.305 
llvm/lib/Target/CBackend/Writer.cpp:1.306
--- llvm/lib/Target/CBackend/Writer.cpp:1.305   Mon Jan  8 00:58:32 2007
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Jan  8 02:00:00 2007
@@ -826,23 +826,26 @@
 return;
   }
 
-  switch (CPV->getType()->getTypeID()) {
-  case Type::BoolTyID:
-Out << (cast(CPV)->getValue() ? '1' : '0');
-break;
-  case Type::Int8TyID:
-Out << "((char)" << cast(CPV)->getSExtValue() << ")";
-break;
-  case Type::Int16TyID:
-Out << "((short)" << cast(CPV)->getSExtValue() << ")";
-break;
-  case Type::Int32TyID:
-Out << "((int)" << cast(CPV)->getSExtValue() << ")";
-break;
-  case Type::Int64TyID:
-Out << "((long long)" << cast(CPV)->getSExtValue() << "ll)";
-break;
+  if (ConstantBool *CB = dyn_cast(CPV)) {
+Out << (CB->getValue() ? '1' : '0') ;
+return;
+  }
 
+  if (ConstantInt *CI = dyn_cast(CPV)) {
+const Type* Ty = CI->getType();
+Out << "((";
+printPrimitiveType(Out, Ty, true) << ')';
+if (CI->isMinValue(true)) 
+  Out << CI->getZExtValue() << 'u';
+else
+  Out << CI->getSExtValue();
+if (Ty->getPrimitiveSizeInBits() > 32)
+  Out << "ll";
+Out << ')';
+return;
+  } 
+
+  switch (CPV->getType()->getTypeID()) {
   case Type::FloatTyID:
   case Type::DoubleTyID: {
 ConstantFP *FPC = cast(CPV);
@@ -1586,29 +1589,29 @@
   Out << "static inline int llvm_fcmp_uno(double X, double Y) { ";
   Out << "return X != X || Y != Y; }\n";
   Out << "static inline int llvm_fcmp_ueq(double X, double Y) { ";
-  Out << "return X == Y || X != X || Y != Y; }\n";
+  Out << "return X == Y || llvm_fcmp_uno(X, Y); }\n";
   Out << "static inline int llvm_fcmp_une(double X, double Y) { ";
-  Out << "return X != Y || X != X || Y != Y; }\n";
+  Out << "return X != Y; }\n";
   Out << "static inline int llvm_fcmp_ult(double X, double Y) { ";
-  Out << "return X <  Y || X != X || Y != Y; }\n";
+  Out << "return X <  Y || llvm_fcmp_uno(X, Y); }\n";
   Out << "static inline int llvm_fcmp_ugt(double X, double Y) { ";
-  Out << "return X >  Y || X != X || Y != Y; }\n";
+  Out << "return X >  Y || llvm_fcmp_uno(X, Y); }\n";
   Out << "static inline int llvm_fcmp_ule(double X, double Y) { ";
-  Out << "return X <= Y || X != X || Y != Y; }\n";
+  Out << "return X <= Y || llvm_fcmp_uno(X, Y); }\n";
   Out << "static inline int llvm_fcmp_uge(double X, double Y) { ";
-  Out << "return X >= Y || X != X || Y != Y; }\n";
+  Out << "return X >= Y || llvm_fcmp_uno(X, Y); }\n";
   Out << "static inline int llvm_fcmp_oeq(double X, double Y) { ";
-  Out << "return X == Y && X == X && Y == Y; }\n";
+  Out << "return X == Y ; }\n";
   Out << "static inline int llvm_fcmp_one(double X, double Y) { ";
-  Out << "return X != Y && X == X && Y == Y; }\n";
+  Out << "return X != Y && llvm_fcmp_ord(X, Y); }\n";
   Out << "static inline int llvm_fcmp_olt(double X, double Y) { ";
-  Out << "return X <  Y && X == X && Y == Y; }\n";
+  Out << "return X <  Y ; }\n";
   Out << "static inline int llvm_fcmp_ogt(double X, double Y) { ";
-  Out << "return X >  Y && X == X && Y == Y; }\n";
+  Out << "return X >  Y ; }\n";
   Out << "static inline int llvm_fcmp_ole(double X, double Y) { ";
-  Out << "return X <= Y && X == X && Y == Y; }\n";
+  Out << "return X <= Y ; }\n";
   Out << "static inline int llvm_fcmp_oge(double X, double Y) { ";
-  Out << "return X >= Y && X == X && Y == Y; }\n";
+  Out << "return X >= Y ; }\n";
   return false;
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-08 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.306 -> 1.307
---
Log message:

For PR1099: http://llvm.org/PR1099 :
Partial fix for this PR. Default function parameters to signed integer, just
like everything else in CBE. The bug was caused by incorrectly introducing
parameter attributes feature by choosing "signed" parameter if the 
SExtAttribute was specified. Howeer, if no attribute is specified, this
causes it to become unsigned which is incorrect. Reversing the logic so
that signedness is detected by "not ZExtAttribute" set fixes the issue. 

This fixes 197.parser but there is more to do. Any comparison and possibly
other operators involving arguments may need to correctly cast the parameter
before its use, depending on the sign of the operator.


---
Diffs of the changes:  (+9 -8)

 Writer.cpp |   17 +
 1 files changed, 9 insertions(+), 8 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.306 
llvm/lib/Target/CBackend/Writer.cpp:1.307
--- llvm/lib/Target/CBackend/Writer.cpp:1.306   Mon Jan  8 02:00:00 2007
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Jan  9 00:38:06 2007
@@ -348,7 +348,7 @@
 if (PrintedType)
   FunctionInnards << ", ";
 printType(FunctionInnards, *I, 
-/*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+/*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
 PrintedType = true;
   }
   if (FTy->isVarArg()) {
@@ -360,7 +360,7 @@
   FunctionInnards << ')';
   std::string tstr = FunctionInnards.str();
   printType(Out, RetTy, 
-  /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+  /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
 }
 
 std::ostream &
@@ -417,7 +417,7 @@
   if (I != FTy->param_begin())
 FunctionInnards << ", ";
   printType(FunctionInnards, *I, 
-  /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), 
"");
+ /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), 
"");
   ++Idx;
 }
 if (FTy->isVarArg()) {
@@ -429,7 +429,7 @@
 FunctionInnards << ')';
 std::string tstr = FunctionInnards.str();
 printType(Out, FTy->getReturnType(), 
-/*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+/*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr);
 return Out;
   }
   case Type::StructTyID: {
@@ -1775,7 +1775,7 @@
 else
   ArgName = "";
 printType(FunctionInnards, I->getType(), 
-/*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), 
+/*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), 
 ArgName);
 PrintedArg = true;
 ++Idx;
@@ -1796,7 +1796,7 @@
 for (; I != E; ++I) {
   if (PrintedArg) FunctionInnards << ", ";
   printType(FunctionInnards, *I,
-   /*isSigned=*/FT->paramHasAttr(Idx, 
FunctionType::SExtAttribute));
+ /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute));
   PrintedArg = true;
   ++Idx;
 }
@@ -1823,7 +1823,8 @@
   }
 
   // Print out the return type and the signature built above.
-  printType(Out, RetTy, FT->paramHasAttr(0, FunctionType::SExtAttribute),
+  printType(Out, RetTy, 
+/*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), 
 FunctionInnards.str());
 }
 
@@ -2516,7 +2517,7 @@
 (*AI)->getType() != FTy->getParamType(ArgNo)) {
   Out << '(';
   printType(Out, FTy->getParamType(ArgNo), 
-  /*isSigned=*/FTy->paramHasAttr(Idx, 
FunctionType::SExtAttribute));
+/*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute));
   Out << ')';
 }
 writeOperand(*AI);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-09 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.307 -> 1.308
---
Log message:

For PR1099: http://llvm.org/PR1099 :
Invert the "isSigned" logic in calls to printType and printPrimitiveType.
We want variables to be declared unsigned by default so that signless
operators like + and - perform the unsigned operation that LLVM expects
by default. Parameters with the sext attribute will be declared signed and
signed instructions will case operand values to signed regardless of the
type of the variable. This passes all tests and fixes PR1099: 
http://llvm.org/PR1099 .


---
Diffs of the changes:  (+33 -33)

 Writer.cpp |   66 ++---
 1 files changed, 33 insertions(+), 33 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.307 
llvm/lib/Target/CBackend/Writer.cpp:1.308
--- llvm/lib/Target/CBackend/Writer.cpp:1.307   Tue Jan  9 00:38:06 2007
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Jan  9 11:09:09 2007
@@ -115,7 +115,7 @@
 }
 
 std::ostream &printType(std::ostream &Out, const Type *Ty, 
-bool isSigned = true,
+bool isSigned = false,
 const std::string &VariableName = "",
 bool IgnoreName = false);
 std::ostream &printPrimitiveType(std::ostream &Out, const Type *Ty, 
@@ -348,7 +348,7 @@
 if (PrintedType)
   FunctionInnards << ", ";
 printType(FunctionInnards, *I, 
-/*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
+/*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
 PrintedType = true;
   }
   if (FTy->isVarArg()) {
@@ -360,7 +360,7 @@
   FunctionInnards << ')';
   std::string tstr = FunctionInnards.str();
   printType(Out, RetTy, 
-  /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+  /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
 }
 
 std::ostream &
@@ -417,7 +417,7 @@
   if (I != FTy->param_begin())
 FunctionInnards << ", ";
   printType(FunctionInnards, *I, 
- /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), 
"");
+ /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
   ++Idx;
 }
 if (FTy->isVarArg()) {
@@ -429,7 +429,7 @@
 FunctionInnards << ')';
 std::string tstr = FunctionInnards.str();
 printType(Out, FTy->getReturnType(), 
-/*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr);
+/*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
 return Out;
   }
   case Type::StructTyID: {
@@ -439,7 +439,7 @@
 for (StructType::element_iterator I = STy->element_begin(),
E = STy->element_end(); I != E; ++I) {
   Out << "  ";
-  printType(Out, *I, true, "field" + utostr(Idx++));
+  printType(Out, *I, false, "field" + utostr(Idx++));
   Out << ";\n";
 }
 return Out << '}';
@@ -453,14 +453,14 @@
 isa(PTy->getElementType()))
   ptrName = "(" + ptrName + ")";
 
-return printType(Out, PTy->getElementType(), true, ptrName);
+return printType(Out, PTy->getElementType(), false, ptrName);
   }
 
   case Type::ArrayTyID: {
 const ArrayType *ATy = cast(Ty);
 unsigned NumElements = ATy->getNumElements();
 if (NumElements == 0) NumElements = 1;
-return printType(Out, ATy->getElementType(), true,
+return printType(Out, ATy->getElementType(), false,
  NameSoFar + "[" + utostr(NumElements) + "]");
   }
 
@@ -468,7 +468,7 @@
 const PackedType *PTy = cast(Ty);
 unsigned NumElements = PTy->getNumElements();
 if (NumElements == 0) NumElements = 1;
-return printType(Out, PTy->getElementType(), true,
+return printType(Out, PTy->getElementType(), false,
  NameSoFar + "[" + utostr(NumElements) + "]");
   }
 
@@ -834,7 +834,7 @@
   if (ConstantInt *CI = dyn_cast(CPV)) {
 const Type* Ty = CI->getType();
 Out << "((";
-printPrimitiveType(Out, Ty, true) << ')';
+printPrimitiveType(Out, Ty, false) << ')';
 if (CI->isMinValue(true)) 
   Out << CI->getZExtValue() << 'u';
 else
@@ -1019,10 +1019,10 @@
   }
   if (NeedsExplicitCast) {
 Out << "((";
-if (Ty->isPrimitiveType())
+if (Ty->isInteger())
   printPrimitiveType(Out, Ty, TypeIsSigned);
 else
-  printType(Out, Ty);
+  printType(Out, Ty); // not integer, sign doesn't matter
 Out << ")(";
   }
   return NeedsExplicitCast;
@@ -1222,10 +1222,10 @@
   // operand.
   if (shouldCast) {
 Out << "((";
-if (OpTy->isPrimitiveType())
+if (OpTy->isInteger())
   printPrimitiveType(Out, OpTy, castIsSigned);
 else
-  printType(Out, OpTy);
+  printType(Out, OpTy); // not integer, sign doesn't matter
 Out << ")";
 writeOperand(Operand);
 Out << ")";
@@ -145

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-09 Thread LLVM


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp (r1.308) removed
---
Log message:

Rename Writer.cpp as CBackend.cpp so it doesn't conflict with Writer.cpp
in the bytecode writer library. This helps with debugging.


---
Diffs of the changes:  (+0 -0)

 0 files changed



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-04-17 Thread Jeff Cohen


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.259 -> 1.260
---
Log message:

Add checks for __OpenBSD__.

---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.259 
llvm/lib/Target/CBackend/Writer.cpp:1.260
--- llvm/lib/Target/CBackend/Writer.cpp:1.259   Thu Mar 23 12:08:29 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Mon Apr 17 12:55:40 2006
@@ -813,7 +813,7 @@
   << "extern void *__builtin_alloca(unsigned int);\n"
   << "#endif\n"
   << "#define alloca(x) __builtin_alloca(x)\n"
-  << "#elif defined(__FreeBSD__)\n"
+  << "#elif defined(__FreeBSD__) || defined(__OpenBSD__)\n"
   << "#define alloca(x) __builtin_alloca(x)\n"
   << "#elif !defined(_MSC_VER)\n"
   << "#include \n"



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-05-23 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.260 -> 1.261
---
Log message:

Print struct return functions and calls as actually returning the hidden
argument struct pointer, enabling ABI compatibility for the CBE with 
platforms with strange struct-return ABIs.  This fixes 252.eon and
CoyoteBench/fftbench on Darwin/X86 among other things.


---
Diffs of the changes:  (+171 -75)

 Writer.cpp |  246 ++---
 1 files changed, 171 insertions(+), 75 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.260 
llvm/lib/Target/CBackend/Writer.cpp:1.261
--- llvm/lib/Target/CBackend/Writer.cpp:1.260   Mon Apr 17 12:55:40 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue May 23 18:39:48 2006
@@ -13,6 +13,7 @@
 
//===--===//
 
 #include "CTargetMachine.h"
+#include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
@@ -115,6 +116,9 @@
 const std::string &VariableName = "",
 bool IgnoreName = false);
 
+void printStructReturnPointerFunctionType(std::ostream &Out,
+  const PointerType *Ty);
+
 void writeOperand(Value *Operand);
 void writeOperandInternal(Value *Operand);
 
@@ -298,6 +302,35 @@
   return Changed;
 }
 
+/// printStructReturnPointerFunctionType - This is like printType for a struct
+/// return type, except, instead of printing the type as void (*)(Struct*, ...)
+/// print it as "Struct (*)(...)", for struct return functions.
+void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
+   const PointerType *TheTy) {
+  const FunctionType *FTy = cast(TheTy->getElementType());
+  std::stringstream FunctionInnards;
+  FunctionInnards << " (*) (";
+  bool PrintedType = false;
+
+  FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end();
+  const Type *RetTy = cast(I->get())->getElementType();
+  for (++I; I != E; ++I) {
+if (PrintedType)
+  FunctionInnards << ", ";
+printType(FunctionInnards, *I, "");
+PrintedType = true;
+  }
+  if (FTy->isVarArg()) {
+if (PrintedType)
+  FunctionInnards << ", ...";
+  } else if (!PrintedType) {
+FunctionInnards << "void";
+  }
+  FunctionInnards << ')';
+  std::string tstr = FunctionInnards.str();
+  printType(Out, RetTy, tstr);
+}
+
 
 // Pass the Type* and the variable name and this prints out the variable
 // declaration.
@@ -332,24 +365,24 @@
 
   switch (Ty->getTypeID()) {
   case Type::FunctionTyID: {
-const FunctionType *MTy = cast(Ty);
+const FunctionType *FTy = cast(Ty);
 std::stringstream FunctionInnards;
 FunctionInnards << " (" << NameSoFar << ") (";
-for (FunctionType::param_iterator I = MTy->param_begin(),
-   E = MTy->param_end(); I != E; ++I) {
-  if (I != MTy->param_begin())
+for (FunctionType::param_iterator I = FTy->param_begin(),
+   E = FTy->param_end(); I != E; ++I) {
+  if (I != FTy->param_begin())
 FunctionInnards << ", ";
   printType(FunctionInnards, *I, "");
 }
-if (MTy->isVarArg()) {
-  if (MTy->getNumParams())
+if (FTy->isVarArg()) {
+  if (FTy->getNumParams())
 FunctionInnards << ", ...";
-} else if (!MTy->getNumParams()) {
+} else if (!FTy->getNumParams()) {
   FunctionInnards << "void";
 }
 FunctionInnards << ')';
 std::string tstr = FunctionInnards.str();
-printType(Out, MTy->getReturnType(), tstr);
+printType(Out, FTy->getReturnType(), tstr);
 return Out;
   }
   case Type::StructTyID: {
@@ -1223,6 +1256,9 @@
 }
 
 void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
+  /// isCStructReturn - Should this function actually return a struct by-value?
+  bool isCStructReturn = F->getCallingConv() == CallingConv::CSRet;
+  
   if (F->hasInternalLinkage()) Out << "static ";
 
   // Loop over the arguments, printing them...
@@ -1233,55 +1269,97 @@
   // Print out the name...
   FunctionInnards << Mang->getValueName(F) << '(';
 
+  bool PrintedArg = false;
   if (!F->isExternal()) {
 if (!F->arg_empty()) {
+  Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
+  
+  // If this is a struct-return function, don't print the hidden
+  // struct-return argument.
+  if (isCStructReturn) {
+assert(I != E && "Invalid struct return function!");
+++I;
+  }
+  
   std::string ArgName;
-  if (F->arg_begin()->hasName() || !Prototype)
-ArgName = Mang->getValueName(F->arg_begin());
-  printType(FunctionInnards, F->arg_begin()->getType(), ArgName);
-  for (Function::const_arg_iterator I = ++F->arg_begin(), E = F->arg_end();
-   I != E; ++I) {
-FunctionInnar

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-05-24 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.261 -> 1.262
---
Log message:

For PR786: http://llvm.cs.uiuc.edu/PR786 :
Minor tweaks in public headers and a few .cpp files so that LLVM can build
successfully with -pedantic and projects using LLVM with -pedantic don't 
get warnings from LLVM. There's still more -pedantic warnings to fix.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.261 
llvm/lib/Target/CBackend/Writer.cpp:1.262
--- llvm/lib/Target/CBackend/Writer.cpp:1.261   Tue May 23 18:39:48 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed May 24 14:21:12 2006
@@ -685,7 +685,7 @@
 char Buffer[100];
 
 uint64_t ll = DoubleToBits(FPC->getValue());
-sprintf(Buffer, "0x%llx", (unsigned long long)ll);
+sprintf(Buffer, "0x%llx", uint64_t(ll));
 
 std::string Num(&Buffer[0], &Buffer[6]);
 unsigned long Val = strtoul(Num.c_str(), 0, 16);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-05-31 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.262 -> 1.263
---
Log message:

Fix casting so there's no warning on Alpha.


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.262 
llvm/lib/Target/CBackend/Writer.cpp:1.263
--- llvm/lib/Target/CBackend/Writer.cpp:1.262   Wed May 24 14:21:12 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Wed May 31 17:26:11 2006
@@ -685,7 +685,7 @@
 char Buffer[100];
 
 uint64_t ll = DoubleToBits(FPC->getValue());
-sprintf(Buffer, "0x%llx", uint64_t(ll));
+sprintf(Buffer, "0x%llx", static_cast(ll));
 
 std::string Num(&Buffer[0], &Buffer[6]);
 unsigned long Val = strtoul(Num.c_str(), 0, 16);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-06-02 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.263 -> 1.264
---
Log message:

Add mingw support, patch contributed by Anton


---
Diffs of the changes:  (+1 -1)

 Writer.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.263 
llvm/lib/Target/CBackend/Writer.cpp:1.264
--- llvm/lib/Target/CBackend/Writer.cpp:1.263   Wed May 31 17:26:11 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Fri Jun  2 13:54:01 2006
@@ -833,7 +833,7 @@
 static void generateCompilerSpecificCode(std::ostream& Out) {
   // Alloca is hard to get, and we don't want to include stdlib.h here.
   Out << "/* get a declaration for alloca */\n"
-  << "#if defined(__CYGWIN__)\n"
+  << "#if defined(__CYGWIN__) || defined(__MINGW32__)\n"
   << "extern void *_alloca(unsigned long);\n"
   << "#define alloca(x) _alloca(x)\n"
   << "#elif defined(__APPLE__)\n"



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-06-06 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.264 -> 1.265
---
Log message:

Now that PR633: http://llvm.cs.uiuc.edu/PR633  is implemented, the CBE can know 
to emit _setjmp/_longjmp
when available.  This speeds up hexxagon from 18.61s to 16.61s with the CBE on
PPC Mac OS (for reference, LLC is 15.48s and GCC is 23.35s).


---
Diffs of the changes:  (+6 -0)

 Writer.cpp |6 ++
 1 files changed, 6 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.264 
llvm/lib/Target/CBackend/Writer.cpp:1.265
--- llvm/lib/Target/CBackend/Writer.cpp:1.264   Fri Jun  2 13:54:01 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Jun  6 16:45:47 2006
@@ -1779,11 +1779,17 @@
 Out << ')';
 return;
   case Intrinsic::setjmp:
+#if defined(HAVE__SETJMP) && defined(HAVE__LONGJMP)
+Out << "_";  // Use _setjmp on systems that support it!
+#endif
 Out << "setjmp(*(jmp_buf*)";
 writeOperand(I.getOperand(1));
 Out << ')';
 return;
   case Intrinsic::longjmp:
+#if defined(HAVE__SETJMP) && defined(HAVE__LONGJMP)
+Out << "_";  // Use _longjmp on systems that support it!
+#endif
 Out << "longjmp(*(jmp_buf*)";
 writeOperand(I.getOperand(1));
 Out << ", ";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-06-20 Thread Evan Cheng


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.265 -> 1.266
---
Log message:

__i386__, __i386, etc. are not defined for x86-64. Use __x86_64__.

---
Diffs of the changes:  (+2 -1)

 Writer.cpp |3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.265 
llvm/lib/Target/CBackend/Writer.cpp:1.266
--- llvm/lib/Target/CBackend/Writer.cpp:1.265   Tue Jun  6 16:45:47 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Jun 20 17:11:12 2006
@@ -937,7 +937,8 @@
   Out << "#define CODE_FOR_MAIN() /* Any target-specific code for main()*/\n";
   // On X86, set the FP control word to 64-bits of precision instead of 80 
bits.
   Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
-  << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
+  << "#if defined(i386) || defined(__i386__) || defined(__i386) || "
+  << "defined(__x86_64__)\n"
   << "#undef CODE_FOR_MAIN\n"
   << "#define CODE_FOR_MAIN() \\\n"
   << "  {short F;__asm__ (\"fnstcw %0\" : \"=m\" (*&F)); \\\n"



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-07-28 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.266 -> 1.267
---
Log message:

Make functions with an "asm" name propagate that asm name into the cbe.c file.
This fixes link errors on programs with these on targets with prefixes.


---
Diffs of the changes:  (+6 -0)

 Writer.cpp |6 ++
 1 files changed, 6 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.266 
llvm/lib/Target/CBackend/Writer.cpp:1.267
--- llvm/lib/Target/CBackend/Writer.cpp:1.266   Tue Jun 20 17:11:12 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Fri Jul 28 15:58:47 2006
@@ -921,6 +921,7 @@
   "__builtin_prefetch(addr,rw,locality)\n"
   << "#define __ATTRIBUTE_CTOR__ __attribute__((constructor))\n"
   << "#define __ATTRIBUTE_DTOR__ __attribute__((destructor))\n"
+  << "#define LLVM_ASM   __asm__\n"
   << "#else\n"
   << "#define LLVM_NAN(NanStr)   ((double)0.0)   /* Double */\n"
   << "#define LLVM_NANF(NanStr)  0.0F/* Float */\n"
@@ -931,6 +932,7 @@
   << "#define LLVM_PREFETCH(addr,rw,locality)/* PREFETCH */\n"
   << "#define __ATTRIBUTE_CTOR__\n"
   << "#define __ATTRIBUTE_DTOR__\n"
+  << "#define LLVM_ASM(X)\n"
   << "#endif\n\n";
 
   // Output target-specific code that should be inserted into main.
@@ -1072,6 +1074,10 @@
 Out << " __ATTRIBUTE_CTOR__";
   if (StaticDtors.count(I))
 Out << " __ATTRIBUTE_DTOR__";
+  
+  if (I->hasName() && I->getName()[0] == 1)
+Out << " LLVM_ASM(\"" << I->getName().c_str()+1 << "\")";
+  
   Out << ";\n";
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-09-08 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.268 -> 1.269
---
Log message:

Add cbe support for powi


---
Diffs of the changes:  (+10 -0)

 Writer.cpp |   10 ++
 1 files changed, 10 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.268 
llvm/lib/Target/CBackend/Writer.cpp:1.269
--- llvm/lib/Target/CBackend/Writer.cpp:1.268   Sun Sep  3 23:14:57 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sat Sep  9 01:17:12 2006
@@ -1693,6 +1693,8 @@
   case Intrinsic::longjmp:
   case Intrinsic::prefetch:
   case Intrinsic::dbg_stoppoint:
+  case Intrinsic::powi_f32:
+  case Intrinsic::powi_f64:
 // We directly implement these intrinsics
 break;
   default:
@@ -1785,6 +1787,14 @@
 writeOperand(I.getOperand(1));
 Out << ')';
 return;
+  case Intrinsic::powi_f32:
+  case Intrinsic::powi_f64:
+Out << "__builtin_powi(";
+writeOperand(I.getOperand(1));
+Out << ", ";
+writeOperand(I.getOperand(2));
+Out << ')';
+return;
   case Intrinsic::setjmp:
 #if defined(HAVE__SETJMP) && defined(HAVE__LONGJMP)
 Out << "_";  // Use _setjmp on systems that support it!



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-09-14 Thread Anton Korobeynikov


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.269 -> 1.270
---
Log message:

Adding dllimport, dllexport and external weak linkage types.
DLL* linkages got full (I hope) codegeneration support in C & both x86 
assembler backends.
External weak linkage added for future use, we don't provide any 
codegeneration, etc. support for it.


---
Diffs of the changes:  (+12 -1)

 Writer.cpp |   13 -
 1 files changed, 12 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.269 
llvm/lib/Target/CBackend/Writer.cpp:1.270
--- llvm/lib/Target/CBackend/Writer.cpp:1.269   Sat Sep  9 01:17:12 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Sep 14 13:23:26 2006
@@ -1054,7 +1054,11 @@
 Out << "extern ";
 printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
 Out << ";\n";
-  }
+  } else if (I->hasDLLImportLinkage()) {
+Out << "__declspec(dllimport) ";
+printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
+Out << ";\n";
+  }  
 }
   }
 
@@ -1118,6 +1122,11 @@
 
 if (I->hasInternalLinkage())
   Out << "static ";
+else if (I->hasDLLImportLinkage())
+  Out << "__declspec(dllimport) ";
+else if (I->hasDLLExportLinkage())
+  Out << "__declspec(dllexport) ";
+
 printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
 if (I->hasLinkOnceLinkage())
   Out << " __attribute__((common))";
@@ -1267,6 +1276,8 @@
   bool isCStructReturn = F->getCallingConv() == CallingConv::CSRet;
   
   if (F->hasInternalLinkage()) Out << "static ";
+  if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
+  if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";  
 
   // Loop over the arguments, printing them...
   const FunctionType *FT = cast(F->getFunctionType());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-09-17 Thread Anton Korobeynikov


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.270 -> 1.271
---
Log message:

Added some eye-candy for Subtarget type checking
Added X86 StdCall & FastCall calling conventions. Codegen will follow.


---
Diffs of the changes:  (+9 -1)

 Writer.cpp |   10 +-
 1 files changed, 9 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.270 
llvm/lib/Target/CBackend/Writer.cpp:1.271
--- llvm/lib/Target/CBackend/Writer.cpp:1.270   Thu Sep 14 13:23:26 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Sep 17 15:25:45 2006
@@ -1278,7 +1278,15 @@
   if (F->hasInternalLinkage()) Out << "static ";
   if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
   if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";  
-
+  switch (F->getCallingConv()) {
+   case CallingConv::X86_StdCall:
+Out << "__stdcall ";
+break;
+   case CallingConv::X86_FastCall:
+Out << "__fastcall ";
+break;
+  }
+  
   // Loop over the arguments, printing them...
   const FunctionType *FT = cast(F->getFunctionType());
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-09-28 Thread Chris Lattner


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.271 -> 1.272
---
Log message:

Simplify some code, reformat break's


---
Diffs of the changes:  (+12 -6)

 Writer.cpp |   18 --
 1 files changed, 12 insertions(+), 6 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.271 
llvm/lib/Target/CBackend/Writer.cpp:1.272
--- llvm/lib/Target/CBackend/Writer.cpp:1.271   Sun Sep 17 15:25:45 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Sep 28 18:19:29 2006
@@ -638,10 +638,12 @@
 
   switch (CPV->getType()->getTypeID()) {
   case Type::BoolTyID:
-Out << (CPV == ConstantBool::False ? '0' : '1'); break;
+Out << (cast(CPV)->getValue() ? '1' : '0');
+break;
   case Type::SByteTyID:
   case Type::ShortTyID:
-Out << cast(CPV)->getValue(); break;
+Out << cast(CPV)->getValue();
+break;
   case Type::IntTyID:
 if ((int)cast(CPV)->getValue() == (int)0x8000)
   Out << "((int)0x8000U)";   // Handle MININT specially to avoid 
warning
@@ -653,15 +655,19 @@
 if (cast(CPV)->isMinValue())
   Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
 else
-  Out << cast(CPV)->getValue() << "ll"; break;
+  Out << cast(CPV)->getValue() << "ll";
+break;
 
   case Type::UByteTyID:
   case Type::UShortTyID:
-Out << cast(CPV)->getValue(); break;
+Out << cast(CPV)->getValue();
+break;
   case Type::UIntTyID:
-Out << cast(CPV)->getValue() << 'u'; break;
+Out << cast(CPV)->getValue() << 'u';
+break;
   case Type::ULongTyID:
-Out << cast(CPV)->getValue() << "ull"; break;
+Out << cast(CPV)->getValue() << "ull";
+break;
 
   case Type::FloatTyID:
   case Type::DoubleTyID: {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-10-20 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.272 -> 1.273
---
Log message:

For PR950: http://llvm.org/PR950 :
This patch implements the first increment for the Signless Types feature.
All changes pertain to removing the ConstantSInt and ConstantUInt classes
in favor of just using ConstantInt.


---
Diffs of the changes:  (+11 -11)

 Writer.cpp |   22 +++---
 1 files changed, 11 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.272 
llvm/lib/Target/CBackend/Writer.cpp:1.273
--- llvm/lib/Target/CBackend/Writer.cpp:1.272   Thu Sep 28 18:19:29 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Fri Oct 20 02:07:24 2006
@@ -460,7 +460,7 @@
 
 // Do not include the last character, which we know is null
 for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {
-  unsigned char C = cast(CPA->getOperand(i))->getRawValue();
+  unsigned char C = cast(CPA->getOperand(i))->getZExtValue();
 
   // Print it out literally if it is a printable character.  The only thing
   // to be careful about is when the last letter output was a hex escape
@@ -642,31 +642,31 @@
 break;
   case Type::SByteTyID:
   case Type::ShortTyID:
-Out << cast(CPV)->getValue();
+Out << cast(CPV)->getSExtValue();
 break;
   case Type::IntTyID:
-if ((int)cast(CPV)->getValue() == (int)0x8000)
+if ((int)cast(CPV)->getSExtValue() == (int)0x8000)
   Out << "((int)0x8000U)";   // Handle MININT specially to avoid 
warning
 else
-  Out << cast(CPV)->getValue();
+  Out << cast(CPV)->getSExtValue();
 break;
 
   case Type::LongTyID:
-if (cast(CPV)->isMinValue())
+if (cast(CPV)->isMinValue())
   Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
 else
-  Out << cast(CPV)->getValue() << "ll";
+  Out << cast(CPV)->getSExtValue() << "ll";
 break;
 
   case Type::UByteTyID:
   case Type::UShortTyID:
-Out << cast(CPV)->getValue();
+Out << cast(CPV)->getZExtValue();
 break;
   case Type::UIntTyID:
-Out << cast(CPV)->getValue() << 'u';
+Out << cast(CPV)->getZExtValue() << 'u';
 break;
   case Type::ULongTyID:
-Out << cast(CPV)->getValue() << "ull";
+Out << cast(CPV)->getZExtValue() << "ull";
 break;
 
   case Type::FloatTyID:
@@ -2002,14 +2002,14 @@
 // Print out the -> operator if possible...
 if (TmpI != E && isa(*TmpI)) {
   Out << (HasImplicitAddress ? "." : "->");
-  Out << "field" << cast(TmpI.getOperand())->getValue();
+  Out << "field" << cast(TmpI.getOperand())->getZExtValue();
   I = ++TmpI;
 }
   }
 
   for (; I != E; ++I)
 if (isa(*I)) {
-  Out << ".field" << cast(I.getOperand())->getValue();
+  Out << ".field" << cast(I.getOperand())->getZExtValue();
 } else {
   Out << '[';
   writeOperand(I.getOperand());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-10-22 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.273 -> 1.274
---
Log message:

Don't generate a prototype for _setjmp. At least on Linux, this function
has a different prototype than the one #included from . This
patch fixes siod and a number of other test cases on Linux that were
failing the CBE because of this _setjmp issue.


---
Diffs of the changes:  (+2 -2)

 Writer.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.273 
llvm/lib/Target/CBackend/Writer.cpp:1.274
--- llvm/lib/Target/CBackend/Writer.cpp:1.273   Fri Oct 20 02:07:24 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Sun Oct 22 04:58:21 2006
@@ -1075,8 +1075,8 @@
   
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
 // Don't print declarations for intrinsic functions.
-if (!I->getIntrinsicID() &&
-I->getName() != "setjmp" && I->getName() != "longjmp") {
+if (!I->getIntrinsicID() && I->getName() != "setjmp" && 
+I->getName() != "longjmp" && I->getName() != "_setjmp") {
   printFunctionSignature(I, true);
   if (I->hasWeakLinkage() || I->hasLinkOnceLinkage()) 
 Out << " __ATTRIBUTE_WEAK__";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-10-25 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.274 -> 1.275
---
Log message:

For PR950: http://llvm.org/PR950 :
Make necessary changes to support DIV -> [SUF]Div. This changes llvm to
have three division instructions: signed, unsigned, floating point. The
bytecode and assembler are bacwards compatible, however.


---
Diffs of the changes:  (+161 -7)

 Writer.cpp |  168 ++---
 1 files changed, 161 insertions(+), 7 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.274 
llvm/lib/Target/CBackend/Writer.cpp:1.275
--- llvm/lib/Target/CBackend/Writer.cpp:1.274   Sun Oct 22 04:58:21 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Oct 26 01:15:43 2006
@@ -121,6 +121,8 @@
 
 void writeOperand(Value *Operand);
 void writeOperandInternal(Value *Operand);
+void writeOperandWithCast(Value* Operand, unsigned Opcode);
+bool writeInstructionCast(const Instruction &I);
 
   private :
 void lowerIntrinsics(Function &F);
@@ -136,6 +138,8 @@
 void printLoop(Loop *L);
 
 void printConstant(Constant *CPV);
+void printConstantWithCast(Constant *CPV, unsigned Opcode);
+bool printConstExprCast(const ConstantExpr *CE);
 void printConstantArray(ConstantArray *CPA);
 void printConstantPacked(ConstantPacked *CP);
 
@@ -586,7 +590,9 @@
 case Instruction::Add:
 case Instruction::Sub:
 case Instruction::Mul:
-case Instruction::Div:
+case Instruction::SDiv:
+case Instruction::UDiv:
+case Instruction::FDiv:
 case Instruction::Rem:
 case Instruction::And:
 case Instruction::Or:
@@ -600,12 +606,15 @@
 case Instruction::Shl:
 case Instruction::Shr:
   Out << '(';
-  printConstant(CE->getOperand(0));
+  bool NeedsClosingParens = printConstExprCast(CE); 
+  printConstantWithCast(CE->getOperand(0), CE->getOpcode());
   switch (CE->getOpcode()) {
   case Instruction::Add: Out << " + "; break;
   case Instruction::Sub: Out << " - "; break;
   case Instruction::Mul: Out << " * "; break;
-  case Instruction::Div: Out << " / "; break;
+  case Instruction::UDiv: 
+  case Instruction::SDiv: 
+  case Instruction::FDiv: Out << " / "; break;
   case Instruction::Rem: Out << " % "; break;
   case Instruction::And: Out << " & "; break;
   case Instruction::Or:  Out << " | "; break;
@@ -620,7 +629,9 @@
   case Instruction::Shr: Out << " >> "; break;
   default: assert(0 && "Illegal opcode here!");
   }
-  printConstant(CE->getOperand(1));
+  printConstantWithCast(CE->getOperand(1), CE->getOpcode());
+  if (NeedsClosingParens)
+Out << "))";
   Out << ')';
   return;
 
@@ -805,6 +816,71 @@
   }
 }
 
+// Some constant expressions need to be casted back to the original types
+// because their operands were casted to the expected type. This function takes
+// care of detecting that case and printing the cast for the ConstantExpr.
+bool CWriter::printConstExprCast(const ConstantExpr* CE) {
+  bool Result = false;
+  const Type* Ty = CE->getOperand(0)->getType();
+  switch (CE->getOpcode()) {
+  case Instruction::UDiv: Result = Ty->isSigned(); break;
+  case Instruction::SDiv: Result = Ty->isUnsigned(); break;
+  default: break;
+  }
+  if (Result) {
+Out << "((";
+printType(Out, Ty);
+Out << ")(";
+  }
+  return Result;
+}
+
+//  Print a constant assuming that it is the operand for a given Opcode. The
+//  opcodes that care about sign need to cast their operands to the expected
+//  type before the operation proceeds. This function does the casting.
+void CWriter::printConstantWithCast(Constant* CPV, unsigned Opcode) {
+
+  // Extract the operand's type, we'll need it.
+  const Type* OpTy = CPV->getType();
+
+  // Indicate whether to do the cast or not.
+  bool shouldCast = false;
+
+  // Based on the Opcode for which this Constant is being written, determine
+  // the new type to which the operand should be casted by setting the value
+  // of OpTy. If we change OpTy, also set shouldCast to true.
+  switch (Opcode) {
+default:
+  // for most instructions, it doesn't matter
+  break; 
+case Instruction::UDiv:
+  // For UDiv to have unsigned operands
+  if (OpTy->isSigned()) {
+OpTy = OpTy->getUnsignedVersion();
+shouldCast = true;
+  }
+  break;
+case Instruction::SDiv:
+  if (OpTy->isUnsigned()) {
+OpTy = OpTy->getSignedVersion();
+shouldCast = true;
+  }
+  break;
+  }
+
+  // Write out the casted constnat if we should, otherwise just write the
+  // operand.
+  if (shouldCast) {
+Out << "((";
+printType(Out, OpTy);
+Out << ")";
+printConstant(CPV);
+Out << ")";
+  } else 
+writeOperand(CPV);
+
+}
+
 void CWriter::writeOperandInternal(Value *Operand) {
   if (Instruction *I = dyn_cast(Operand))
 if (isInlinableInst(*I)

[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-10-25 Thread Reid Spencer


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.275 -> 1.276
---
Log message:

Enclose a case in { and } so that the pickier compilers don't complain.


---
Diffs of the changes:  (+2 -0)

 Writer.cpp |2 ++
 1 files changed, 2 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.275 
llvm/lib/Target/CBackend/Writer.cpp:1.276
--- llvm/lib/Target/CBackend/Writer.cpp:1.275   Thu Oct 26 01:15:43 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Thu Oct 26 01:17:40 2006
@@ -605,6 +605,7 @@
 case Instruction::SetGE:
 case Instruction::Shl:
 case Instruction::Shr:
+{
   Out << '(';
   bool NeedsClosingParens = printConstExprCast(CE); 
   printConstantWithCast(CE->getOperand(0), CE->getOpcode());
@@ -634,6 +635,7 @@
 Out << "))";
   Out << ')';
   return;
+}
 
 default:
   std::cerr << "CWriter Error: Unhandled constant expression: "



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-06 Thread Chris Lattner

On Dec 6,lib/Target/CBackend/Writer.cpp
> diff -u llvm/lib/Target/CBackend/Writer.cpp:1.290 llvm/lib/Target/ 
> CBackend/Writer.cpp:1.291
> --- llvm/lib/Target/CBackend/Writer.cpp:1.290 Thu Nov 30 18:25:12 2006
> +++ llvm/lib/Target/CBackend/Writer.cpp   Wed Dec  6 14:45:15 2006
> @@ -753,7 +753,7 @@
>  break;
>
>case Type::LongTyID:
> -if (cast(CPV)->isMinValue())
> +if (cast(CPV)->isMinValue(CPV->getType()->isSigned 
> ()))
>Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
>  else
>Out << cast(CPV)->getSExtValue() << "ll";

This should always pass true.

-Chris

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-06 Thread Reid Spencer
On Wed, 2006-12-06 at 13:20 -0800, Chris Lattner wrote:
> On Dec 6,lib/Target/CBackend/Writer.cpp
> > diff -u llvm/lib/Target/CBackend/Writer.cpp:1.290 llvm/lib/Target/ 
> > CBackend/Writer.cpp:1.291
> > --- llvm/lib/Target/CBackend/Writer.cpp:1.290   Thu Nov 30 18:25:12 2006
> > +++ llvm/lib/Target/CBackend/Writer.cpp Wed Dec  6 14:45:15 2006
> > @@ -753,7 +753,7 @@
> >  break;
> >
> >case Type::LongTyID:
> > -if (cast(CPV)->isMinValue())
> > +if (cast(CPV)->isMinValue(CPV->getType()->isSigned 
> > ()))
> >Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
> >  else
> >Out << cast(CPV)->getSExtValue() << "ll";
> 
> This should always pass true.

Right.
> 
> -Chris
> 


signature.asc
Description: This is a digitally signed message part
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2006-12-11 Thread Chris Lattner
> Implement correct bitcast of int<->float and long<->double by using a
> union to perform the bitcast.
> @@ -1508,6 +1508,16 @@
>  /// type name is found, emit its declaration...
>  ///
>  void CWriter::printModuleTypes(const SymbolTable &ST) {
> +  Out << "/* Helper union for bitcasts */\n";
> +  Out << "typedef union {\n";
> +  Out << "  unsigned int  UInt;\n";
> +  Out << "signed int  SInt;\n";
> +  Out << "  unsigned long ULong;\n";
> +  Out << "signed long SLong;\n";
> +  Out << "  float Float;\n";
> +  Out << " double Double;\n";
> +  Out << "} llvmBitCastUnion;\n"

This is wrong for 32-bit targets.  ULong should be 'unsigned long  
long'.  SLong should be 'signed long long'.

Thanks Reid,

-Chris

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-01-07 Thread Chris Lattner
> +  // Emit some helper functions for dealing with FCMP instruction's
> +  // predicates
> +  Out << "static inline int llvm_fcmp_ord(double X, double Y) { ";
> +  Out << "return X == X && Y == Y; }\n";
> +  Out << "static inline int llvm_fcmp_uno(double X, double Y) { ";
> +  Out << "return X != X || Y != Y; }\n";
> +  Out << "static inline int llvm_fcmp_ueq(double X, double Y) { ";
> +  Out << "return X == Y || X != X || Y != Y; }\n";

These would be more obvious if written as:

   return X == Y || llvm_fcmp_uno(X, Y)

> +  Out << "static inline int llvm_fcmp_ult(double X, double Y) { ";
> +  Out << "return X <  Y || X != X || Y != Y; }\n";
> +  Out << "static inline int llvm_fcmp_ugt(double X, double Y) { ";
> +  Out << "return X >  Y || X != X || Y != Y; }\n";
> +  Out << "static inline int llvm_fcmp_ule(double X, double Y) { ";
> +  Out << "return X <= Y || X != X || Y != Y; }\n";
> +  Out << "static inline int llvm_fcmp_uge(double X, double Y) { ";
> +  Out << "return X >= Y || X != X || Y != Y; }\n";



> +  Out << "static inline int llvm_fcmp_une(double X, double Y) { ";
> +  Out << "return X != Y || X != X || Y != Y; }\n";
> +  Out << "static inline int llvm_fcmp_oeq(double X, double Y) { ";
> +  Out << "return X == Y && X == X && Y == Y; }\n";
> +  Out << "static inline int llvm_fcmp_olt(double X, double Y) { ";
> +  Out << "return X <  Y && X == X && Y == Y; }\n";
> +  Out << "static inline int llvm_fcmp_ogt(double X, double Y) { ";
> +  Out << "return X >  Y && X == X && Y == Y; }\n";
> +  Out << "static inline int llvm_fcmp_ole(double X, double Y) { ";
> +  Out << "return X <= Y && X == X && Y == Y; }\n";
> +  Out << "static inline int llvm_fcmp_oge(double X, double Y) { ";
> +  Out << "return X >= Y && X == X && Y == Y; }\n";

You can drop the 2nd and 3rd term of each of thse.

> +  Out << "static inline int llvm_fcmp_one(double X, double Y) { ";
> +  Out << "return X != Y && X == X && Y == Y; }\n";

This one is needed though.

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits