[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Function.cpp Instructions.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri May 6 13:26:57 PDT 2005



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.177 -> 1.178
Function.cpp updated: 1.94 -> 1.95
Instructions.cpp updated: 1.18 -> 1.19
---
Log message:

add support for explicit calling conventions


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

 AsmWriter.cpp    |   29 +++++++++++++++++++++++++++--
 Function.cpp     |    1 +
 Instructions.cpp |   17 ++++++++++++++++-
 3 files changed, 44 insertions(+), 3 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.177 llvm/lib/VMCore/AsmWriter.cpp:1.178
--- llvm/lib/VMCore/AsmWriter.cpp:1.177	Fri May  6 00:50:54 2005
+++ llvm/lib/VMCore/AsmWriter.cpp	Fri May  6 15:26:43 2005
@@ -18,6 +18,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Assembly/AsmAnnotationWriter.h"
+#include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instruction.h"
@@ -915,6 +916,14 @@
       abort();
     }
 
+  // Print the calling convention.
+  switch (F->getCallingConv()) {
+  case CallingConv::C: break;   // default
+  case CallingConv::Fast: Out << "fastcc "; break;
+  case CallingConv::Cold: Out << "coldcc "; break;
+  default: Out << "cc" << F->getCallingConv() << " "; break;
+  }
+
   printType(F->getReturnType()) << ' ';
   if (!F->getName().empty())
     Out << getLLVMName(F->getName());
@@ -1090,7 +1099,15 @@
     }
   } else if (isa<ReturnInst>(I) && !Operand) {
     Out << " void";
-  } else if (isa<CallInst>(I)) {
+  } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
+    // Print the calling convention being used.
+    switch (CI->getCallingConv()) {
+    case CallingConv::C: break;   // default
+    case CallingConv::Fast: Out << " fastcc"; break;
+    case CallingConv::Cold: Out << " coldcc"; break;
+    default: Out << " cc" << CI->getCallingConv(); break;
+    }
+
     const PointerType  *PTy = cast<PointerType>(Operand->getType());
     const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
     const Type       *RetTy = FTy->getReturnType();
@@ -1108,7 +1125,7 @@
       writeOperand(Operand, true);
     }
     Out << '(';
-    if (I.getNumOperands() > 1) writeOperand(I.getOperand(1), true);
+    if (CI->getNumOperands() > 1) writeOperand(CI->getOperand(1), true);
     for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; ++op) {
       Out << ',';
       writeOperand(I.getOperand(op), true);
@@ -1120,6 +1137,14 @@
     const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
     const Type       *RetTy = FTy->getReturnType();
 
+    // Print the calling convention being used.
+    switch (II->getCallingConv()) {
+    case CallingConv::C: break;   // default
+    case CallingConv::Fast: Out << " fastcc"; break;
+    case CallingConv::Cold: Out << " coldcc"; break;
+    default: Out << " cc" << II->getCallingConv(); break;
+    }
+
     // If possible, print out the short form of the invoke instruction. We can
     // only do this if the first argument is a pointer to a nonvararg function,
     // and if the return type is not a pointer to a function.


Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.94 llvm/lib/VMCore/Function.cpp:1.95
--- llvm/lib/VMCore/Function.cpp:1.94	Tue May  3 12:19:30 2005
+++ llvm/lib/VMCore/Function.cpp	Fri May  6 15:26:43 2005
@@ -77,6 +77,7 @@
 Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
                    const std::string &name, Module *ParentModule)
   : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name) {
+  CallingConvention = 0;
   BasicBlocks.setItemParent(this);
   BasicBlocks.setParent(this);
   ArgumentList.setItemParent(this);


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.18 llvm/lib/VMCore/Instructions.cpp:1.19
--- llvm/lib/VMCore/Instructions.cpp:1.18	Fri May  6 00:50:54 2005
+++ llvm/lib/VMCore/Instructions.cpp	Fri May  6 15:26:43 2005
@@ -20,6 +20,20 @@
 #include "llvm/Support/CallSite.h"
 using namespace llvm;
 
+unsigned CallSite::getCallingConv() const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->getCallingConv();
+  else
+    return cast<InvokeInst>(I)->getCallingConv();
+}
+void CallSite::setCallingConv(unsigned CC) {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    CI->setCallingConv(CC);
+  else
+    cast<InvokeInst>(I)->setCallingConv(CC);
+}
+
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
@@ -249,7 +263,7 @@
 CallInst::CallInst(const CallInst &CI)
   : Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()],
                 CI.getNumOperands()) {
-  setTailCall(CI.isTailCall());
+  SubclassData = CI.SubclassData;
   Use *OL = OperandList;
   Use *InOL = CI.OperandList;
   for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
@@ -306,6 +320,7 @@
 InvokeInst::InvokeInst(const InvokeInst &II)
   : TerminatorInst(II.getType(), Instruction::Invoke,
                    new Use[II.getNumOperands()], II.getNumOperands()) {
+  SubclassData = II.SubclassData;
   Use *OL = OperandList, *InOL = II.OperandList;
   for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
     OL[i].init(InOL[i], this);






More information about the llvm-commits mailing list