[llvm-commits] CVS: llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp

Reid Spencer reid at x10sys.com
Tue Dec 12 16:48:13 PST 2006



Changes in directory llvm/projects/Stacker/lib/compiler:

StackerCompiler.cpp updated: 1.25 -> 1.26
---
Log message:

Change createInferredCast calls to more accurate cast creation calls.


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

 StackerCompiler.cpp |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)


Index: llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp
diff -u llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.25 llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.26
--- llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp:1.25	Wed Dec  6 13:00:27 2006
+++ llvm/projects/Stacker/lib/compiler/StackerCompiler.cpp	Tue Dec 12 18:47:58 2006
@@ -367,7 +367,7 @@
 
     // Increment the loaded index value
     if ( ival == 0 ) ival = One;
-    CastInst* caster = CastInst::createInferredCast( ival, Type::LongTy );
+    CastInst* caster = CastInst::createSExtOrBitCast( ival, Type::LongTy );
     bb->getInstList().push_back( caster );
     BinaryOperator* addop = BinaryOperator::create( Instruction::Add,
             loadop, caster);
@@ -388,7 +388,7 @@
 
     // Decrement the loaded index value
     if ( ival == 0 ) ival = One;
-    CastInst* caster = CastInst::createInferredCast( ival, Type::LongTy );
+    CastInst* caster = CastInst::createSExtOrBitCast( ival, Type::LongTy );
     bb->getInstList().push_back( caster );
     BinaryOperator* subop = BinaryOperator::create( Instruction::Sub,
             loadop, caster);
@@ -422,7 +422,7 @@
     }
     else
     {
-        CastInst* caster = CastInst::createInferredCast( index, Type::LongTy );
+        CastInst* caster = CastInst::createSExtOrBitCast( index, Type::LongTy );
         bb->getInstList().push_back( caster );
         BinaryOperator* subop = BinaryOperator::create(
             Instruction::Sub, loadop, caster );
@@ -448,7 +448,11 @@
             get_stack_pointer( bb ) );
 
     // Cast the value to a long .. hopefully it works
-    CastInst* cast_inst = CastInst::createInferredCast( val, Type::LongTy );
+    Instruction::CastOps opcode = 
+       (isa<PointerType>(val->getType()) ? Instruction::PtrToInt :
+        (val->getType()->getPrimitiveSizeInBits() < 64 ? Instruction::SExt :
+         Instruction::BitCast));
+    CastInst* cast_inst = CastInst::create(opcode, val, Type::LongTy );
     bb->getInstList().push_back( cast_inst );
 
     // Store the value
@@ -523,7 +527,7 @@
 
     // Cast the integer to a sbyte*
     CastInst* caster = 
-      CastInst::createInferredCast( loader, PointerType::get(Type::SByteTy) );
+      new IntToPtrInst(loader, PointerType::get(Type::SByteTy));
     bb->getInstList().push_back( caster );
 
     // Decrement stack index
@@ -576,7 +580,7 @@
 
     // Cast the integer to a sbyte*
     CastInst* caster = 
-      CastInst::createInferredCast( loader, PointerType::get(Type::SByteTy) );
+      new IntToPtrInst(loader, PointerType::get(Type::SByteTy) );
     bb->getInstList().push_back( caster );
 
     // Return the value
@@ -1245,7 +1249,7 @@
         if (echo) bb->setName("SHL");
         LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
         LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
-        CastInst* castop = CastInst::createInferredCast( op1, Type::UByteTy );
+        CastInst* castop = new TruncInst( op1, Type::UByteTy );
         bb->getInstList().push_back( castop );
         ShiftInst* shlop = new ShiftInst( Instruction::Shl, op2, castop );
         bb->getInstList().push_back( shlop );
@@ -1257,7 +1261,7 @@
         if (echo) bb->setName("SHR");
         LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
         LoadInst* op2 = cast<LoadInst>(pop_integer(bb));
-        CastInst* castop = CastInst::createInferredCast( op1, Type::UByteTy );
+        CastInst* castop = new TruncInst( op1, Type::UByteTy );
         bb->getInstList().push_back( castop );
         ShiftInst* shrop = new ShiftInst( Instruction::AShr, op2, castop );
         bb->getInstList().push_back( shrop );
@@ -1479,7 +1483,7 @@
         LoadInst* op1 = cast<LoadInst>( pop_integer(bb) );
 
         // Make sure its a UIntTy
-        CastInst* caster = CastInst::createInferredCast( op1, Type::UIntTy );
+        CastInst* caster = CastInst::createTruncOrBitCast( op1, Type::UIntTy );
         bb->getInstList().push_back( caster );
 
         // Allocate the bytes
@@ -1507,7 +1511,7 @@
         if (echo) bb->setName("GET");
         // Get the character index
         LoadInst* op1 = cast<LoadInst>( stack_top(bb) );
-        CastInst* chr_idx = CastInst::createInferredCast( op1, Type::LongTy );
+        CastInst* chr_idx = CastInst::createSExtOrBitCast( op1, Type::LongTy );
         bb->getInstList().push_back( chr_idx );
 
         // Get the String pointer
@@ -1522,7 +1526,7 @@
         // Get the value and push it
         LoadInst* loader = new LoadInst( gep );
         bb->getInstList().push_back( loader );
-        CastInst* caster = CastInst::createInferredCast( loader, Type::IntTy );
+        CastInst* caster = CastInst::createTruncOrBitCast(loader, Type::IntTy);
         bb->getInstList().push_back( caster );
 
         // Push the result back on stack
@@ -1539,7 +1543,7 @@
 
         // Get the character index
         LoadInst* w2 = cast<LoadInst>( pop_integer(bb) );
-        CastInst* chr_idx = CastInst::createInferredCast( w2, Type::LongTy );
+        CastInst* chr_idx = CastInst::createSExtOrBitCast( w2, Type::LongTy );
         bb->getInstList().push_back( chr_idx );
 
         // Get the String pointer
@@ -1552,7 +1556,7 @@
         bb->getInstList().push_back( gep );
 
         // Cast the value and put it
-        CastInst* caster = CastInst::createInferredCast( w1, Type::SByteTy );
+        CastInst* caster = new TruncInst( w1, Type::SByteTy );
         bb->getInstList().push_back( caster );
         StoreInst* storer = new StoreInst( caster, gep );
         bb->getInstList().push_back( storer );
@@ -1580,7 +1584,7 @@
         LoadInst* op1 = cast<LoadInst>(pop_integer(bb));
 
         // Cast down to an integer
-        CastInst* caster = CastInst::createInferredCast( op1, Type::IntTy );
+        CastInst* caster = new TruncInst( op1, Type::IntTy );
         bb->getInstList().push_back( caster );
 
         // Call exit(3)






More information about the llvm-commits mailing list