[llvm-commits] [llvm] r47847 - /llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp

Devang Patel dpatel at apple.com
Mon Mar 3 10:36:03 PST 2008


Author: dpatel
Date: Mon Mar  3 12:36:03 2008
New Revision: 47847

URL: http://llvm.org/viewvc/llvm-project?rev=47847&view=rev
Log:
Preserve paramater attributes.

Modified:
    llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp

Modified: llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp?rev=47847&r1=47846&r2=47847&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp Mon Mar  3 12:36:03 2008
@@ -17,6 +17,7 @@
 #include "llvm/Module.h"
 #include "llvm/CallGraphSCCPass.h"
 #include "llvm/Instructions.h"
+#include "llvm/ParamAttrsList.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
@@ -181,21 +182,34 @@
 Function *SRETPromotion::cloneFunctionBody(Function *F, 
                                            const StructType *STy) {
 
-  // FIXME : Do not drop param attributes on the floor.
   const FunctionType *FTy = F->getFunctionType();
   std::vector<const Type*> Params;
 
+  // ParamAttrs - Keep track of the parameter attributes for the arguments.
+  ParamAttrsVector ParamAttrsVec;
+  const ParamAttrsList *PAL = F->getParamAttrs();
+
+  // Add any return attributes.
+  if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None)
+    ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
+
   // Skip first argument.
   Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
   ++I;
+  unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
   while (I != E) {
     Params.push_back(I->getType());
+    if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(ParamIndex) : 
+        ParamAttr::None)
+      ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), attrs));
     ++I;
+    ++ParamIndex;
   }
 
   FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
   Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
   NF->setCallingConv(F->getCallingConv());
+  NF->setParamAttrs(ParamAttrsList::get(ParamAttrsVec));
   F->getParent()->getFunctionList().insert(F, NF);
   NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
 
@@ -217,20 +231,32 @@
 /// updateCallSites - Update all sites that call F to use NF.
 void SRETPromotion::updateCallSites(Function *F, Function *NF) {
 
-  // FIXME : Handle parameter attributes
   SmallVector<Value*, 16> Args;
 
+  // ParamAttrs - Keep track of the parameter attributes for the arguments.
+  ParamAttrsVector ParamAttrsVec;
+
   for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); FUI != FUE;) {
     CallSite CS = CallSite::get(*FUI);
     ++FUI;
     Instruction *Call = CS.getInstruction();
 
+    const ParamAttrsList *PAL = F->getParamAttrs();
+    // Add any return attributes.
+    if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None)
+      ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
+
     // Copy arguments, however skip first one.
     CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
     Value *FirstCArg = *AI;
     ++AI;
+    unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
     while (AI != AE) {
       Args.push_back(*AI); 
+      if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ParamIndex) :
+          ParamAttr::None)
+        ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
+      ++ParamIndex;
       ++AI;
     }
 
@@ -240,13 +266,16 @@
       New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
                            Args.begin(), Args.end(), "", Call);
       cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
+      cast<InvokeInst>(New)->setParamAttrs(ParamAttrsList::get(ParamAttrsVec));
     } else {
       New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
       cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
+      cast<CallInst>(New)->setParamAttrs(ParamAttrsList::get(ParamAttrsVec));
       if (cast<CallInst>(Call)->isTailCall())
         cast<CallInst>(New)->setTailCall();
     }
     Args.clear();
+    ParamAttrsVec.clear();
     New->takeName(Call);
 
     // Update all users of sret parameter to extract value using getresult.





More information about the llvm-commits mailing list