[llvm-commits] CVS: llvm/lib/Transforms/LevelRaise.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Apr 27 20:26:00 PDT 2003


Changes in directory llvm/lib/Transforms:

LevelRaise.cpp updated: 1.78 -> 1.79

---
Log message:

Create constant expression casts instead of constant instructions if possible


---
Diffs of the changes:

Index: llvm/lib/Transforms/LevelRaise.cpp
diff -u llvm/lib/Transforms/LevelRaise.cpp:1.78 llvm/lib/Transforms/LevelRaise.cpp:1.79
--- llvm/lib/Transforms/LevelRaise.cpp:1.78	Sun Apr 27 17:55:56 2003
+++ llvm/lib/Transforms/LevelRaise.cpp	Sun Apr 27 20:25:38 2003
@@ -504,8 +504,18 @@
       PointerType *NewPFunTy = PointerType::get(NewFT);
 
       // Create a new cast, inserting it right before the function call...
-      CastInst *NewCast = new CastInst(CI->getCalledValue(), NewPFunTy,
-                                       CI->getCalledValue()->getName()+"_c",CI);
+      Value *NewCast;
+      Constant *ConstantCallSrc = 0;
+      if (Constant *CS = dyn_cast<Constant>(CI->getCalledValue()))
+        ConstantCallSrc = CS;
+      else if (GlobalValue *GV = dyn_cast<GlobalValue>(CI->getCalledValue()))
+        ConstantCallSrc = ConstantPointerRef::get(GV);
+
+      if (ConstantCallSrc)
+        NewCast = ConstantExpr::getCast(ConstantCallSrc, NewPFunTy);
+      else
+        NewCast = new CastInst(CI->getCalledValue(), NewPFunTy,
+                               CI->getCalledValue()->getName()+"_c",CI);
 
       // Create a new call instruction...
       CallInst *NewCall = new CallInst(NewCast,





More information about the llvm-commits mailing list