blob: 56896466c931eee0ee652bcaa70d0d879dd44653 [file] [log] [blame]
Gordon Henriksena8a118b2008-05-08 17:46:35 +00001//===-- StructRetPromotion.cpp - Promote sret arguments ------------------===//
Devang Patelca891ec2008-02-29 23:34:08 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Gordon Henriksena8a118b2008-05-08 17:46:35 +000010// This pass finds functions that return a struct (using a pointer to the struct
11// as the first argument of the function, marked with the 'sret' attribute) and
12// replaces them with a new function that simply returns each of the elements of
13// that struct (using multiple return values).
14//
15// This pass works under a number of conditions:
16// 1. The returned struct must not contain other structs
17// 2. The returned struct must only be used to load values from
18// 3. The placeholder struct passed in is the result of an alloca
19//
Devang Patelca891ec2008-02-29 23:34:08 +000020//===----------------------------------------------------------------------===//
21
22#define DEBUG_TYPE "sretpromotion"
23#include "llvm/Transforms/IPO.h"
24#include "llvm/Constants.h"
25#include "llvm/DerivedTypes.h"
Owen Anderson14ce9ef2009-07-06 01:34:54 +000026#include "llvm/LLVMContext.h"
Devang Patelca891ec2008-02-29 23:34:08 +000027#include "llvm/Module.h"
28#include "llvm/CallGraphSCCPass.h"
29#include "llvm/Instructions.h"
30#include "llvm/Analysis/CallGraph.h"
31#include "llvm/Support/CallSite.h"
32#include "llvm/Support/CFG.h"
33#include "llvm/Support/Debug.h"
34#include "llvm/ADT/Statistic.h"
35#include "llvm/ADT/SmallVector.h"
Devang Patel98a6e062008-03-04 17:44:37 +000036#include "llvm/ADT/Statistic.h"
Daniel Dunbar460f6562009-07-26 09:48:23 +000037#include "llvm/Support/raw_ostream.h"
Devang Patelca891ec2008-02-29 23:34:08 +000038using namespace llvm;
39
Devang Patel98a6e062008-03-04 17:44:37 +000040STATISTIC(NumRejectedSRETUses , "Number of sret rejected due to unexpected uses");
41STATISTIC(NumSRET , "Number of sret promoted");
Devang Patelca891ec2008-02-29 23:34:08 +000042namespace {
43 /// SRETPromotion - This pass removes sret parameter and updates
44 /// function to use multiple return value.
45 ///
Nick Lewycky6726b6d2009-10-25 06:33:48 +000046 struct SRETPromotion : public CallGraphSCCPass {
Devang Patelca891ec2008-02-29 23:34:08 +000047 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
48 CallGraphSCCPass::getAnalysisUsage(AU);
49 }
50
Chris Lattner2decb222010-04-16 22:42:17 +000051 virtual bool runOnSCC(CallGraphSCC &SCC);
Devang Patelca891ec2008-02-29 23:34:08 +000052 static char ID; // Pass identification, replacement for typeid
Owen Anderson1f745902010-08-06 00:23:35 +000053 SRETPromotion() : CallGraphSCCPass(&ID) {}
Devang Patelca891ec2008-02-29 23:34:08 +000054
55 private:
Chris Lattner5095e3d2009-08-31 00:19:58 +000056 CallGraphNode *PromoteReturn(CallGraphNode *CGN);
Devang Patelca891ec2008-02-29 23:34:08 +000057 bool isSafeToUpdateAllCallers(Function *F);
58 Function *cloneFunctionBody(Function *F, const StructType *STy);
Chris Lattner5095e3d2009-08-31 00:19:58 +000059 CallGraphNode *updateCallSites(Function *F, Function *NF);
Devang Patela9fe8bb2008-03-04 21:32:09 +000060 bool nestedStructType(const StructType *STy);
Devang Patelca891ec2008-02-29 23:34:08 +000061 };
Devang Patelca891ec2008-02-29 23:34:08 +000062}
63
Dan Gohman844731a2008-05-13 00:00:25 +000064char SRETPromotion::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +000065INITIALIZE_PASS(SRETPromotion, "sretpromotion",
66 "Promote sret arguments to multiple ret values", false, false);
Dan Gohman844731a2008-05-13 00:00:25 +000067
Devang Patelca891ec2008-02-29 23:34:08 +000068Pass *llvm::createStructRetPromotionPass() {
69 return new SRETPromotion();
70}
71
Chris Lattner2decb222010-04-16 22:42:17 +000072bool SRETPromotion::runOnSCC(CallGraphSCC &SCC) {
Devang Patelca891ec2008-02-29 23:34:08 +000073 bool Changed = false;
74
Chris Lattner2decb222010-04-16 22:42:17 +000075 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I)
76 if (CallGraphNode *NewNode = PromoteReturn(*I)) {
77 SCC.ReplaceNode(*I, NewNode);
Chris Lattner5095e3d2009-08-31 00:19:58 +000078 Changed = true;
79 }
Devang Patelca891ec2008-02-29 23:34:08 +000080
81 return Changed;
82}
83
84/// PromoteReturn - This method promotes function that uses StructRet paramater
Chris Lattner5095e3d2009-08-31 00:19:58 +000085/// into a function that uses multiple return values.
86CallGraphNode *SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
Devang Patelca891ec2008-02-29 23:34:08 +000087 Function *F = CGN->getFunction();
88
Rafael Espindolabb46f522009-01-15 20:18:42 +000089 if (!F || F->isDeclaration() || !F->hasLocalLinkage())
Chris Lattner5095e3d2009-08-31 00:19:58 +000090 return 0;
Devang Patelca891ec2008-02-29 23:34:08 +000091
92 // Make sure that function returns struct.
Devang Patel41e23972008-03-03 21:46:28 +000093 if (F->arg_size() == 0 || !F->hasStructRetAttr() || F->doesNotReturn())
Chris Lattner5095e3d2009-08-31 00:19:58 +000094 return 0;
Devang Patelca891ec2008-02-29 23:34:08 +000095
David Greene09d70db2010-01-05 01:27:54 +000096 DEBUG(dbgs() << "SretPromotion: Looking at sret function "
Daniel Dunbar460f6562009-07-26 09:48:23 +000097 << F->getName() << "\n");
Matthijs Kooijman81ec2482008-08-07 15:14:04 +000098
Benjamin Kramerf0127052010-01-05 13:12:22 +000099 assert(F->getReturnType()->isVoidTy() && "Invalid function return type");
Devang Patelca891ec2008-02-29 23:34:08 +0000100 Function::arg_iterator AI = F->arg_begin();
101 const llvm::PointerType *FArgType = dyn_cast<PointerType>(AI->getType());
Chris Lattner5095e3d2009-08-31 00:19:58 +0000102 assert(FArgType && "Invalid sret parameter type");
Devang Patelca891ec2008-02-29 23:34:08 +0000103 const llvm::StructType *STy =
104 dyn_cast<StructType>(FArgType->getElementType());
Chris Lattner5095e3d2009-08-31 00:19:58 +0000105 assert(STy && "Invalid sret parameter element type");
Devang Patelca891ec2008-02-29 23:34:08 +0000106
107 // Check if it is ok to perform this promotion.
Devang Patel98a6e062008-03-04 17:44:37 +0000108 if (isSafeToUpdateAllCallers(F) == false) {
David Greene09d70db2010-01-05 01:27:54 +0000109 DEBUG(dbgs() << "SretPromotion: Not all callers can be updated\n");
Dan Gohmanfe601042010-06-22 15:08:57 +0000110 ++NumRejectedSRETUses;
Chris Lattner5095e3d2009-08-31 00:19:58 +0000111 return 0;
Devang Patel98a6e062008-03-04 17:44:37 +0000112 }
Devang Patelca891ec2008-02-29 23:34:08 +0000113
David Greene09d70db2010-01-05 01:27:54 +0000114 DEBUG(dbgs() << "SretPromotion: sret argument will be promoted\n");
Dan Gohmanfe601042010-06-22 15:08:57 +0000115 ++NumSRET;
Devang Patelca891ec2008-02-29 23:34:08 +0000116 // [1] Replace use of sret parameter
Owen Anderson50dead02009-07-15 23:53:25 +0000117 AllocaInst *TheAlloca = new AllocaInst(STy, NULL, "mrv",
118 F->getEntryBlock().begin());
Devang Patelca891ec2008-02-29 23:34:08 +0000119 Value *NFirstArg = F->arg_begin();
120 NFirstArg->replaceAllUsesWith(TheAlloca);
121
Devang Patel98a6e062008-03-04 17:44:37 +0000122 // [2] Find and replace ret instructions
Devang Patelca891ec2008-02-29 23:34:08 +0000123 for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
124 for(BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ) {
125 Instruction *I = BI;
126 ++BI;
127 if (isa<ReturnInst>(I)) {
Dan Gohmanfc74abf2008-07-23 00:34:11 +0000128 Value *NV = new LoadInst(TheAlloca, "mrv.ld", I);
Owen Anderson1d0be152009-08-13 21:58:54 +0000129 ReturnInst *NR = ReturnInst::Create(F->getContext(), NV, I);
Devang Patelca891ec2008-02-29 23:34:08 +0000130 I->replaceAllUsesWith(NR);
131 I->eraseFromParent();
132 }
133 }
134
Devang Patel98a6e062008-03-04 17:44:37 +0000135 // [3] Create the new function body and insert it into the module.
Devang Patelca891ec2008-02-29 23:34:08 +0000136 Function *NF = cloneFunctionBody(F, STy);
137
Devang Patel98a6e062008-03-04 17:44:37 +0000138 // [4] Update all call sites to use new function
Chris Lattner5095e3d2009-08-31 00:19:58 +0000139 CallGraphNode *NF_CFN = updateCallSites(F, NF);
Devang Patelca891ec2008-02-29 23:34:08 +0000140
Chris Lattner5095e3d2009-08-31 00:19:58 +0000141 CallGraph &CG = getAnalysis<CallGraph>();
142 NF_CFN->stealCalledFunctionsFrom(CG[F]);
143
144 delete CG.removeFunctionFromModule(F);
145 return NF_CFN;
Devang Patelca891ec2008-02-29 23:34:08 +0000146}
147
Duncan Sands33af59d2008-05-09 12:20:10 +0000148// Check if it is ok to perform this promotion.
Devang Patelca891ec2008-02-29 23:34:08 +0000149bool SRETPromotion::isSafeToUpdateAllCallers(Function *F) {
150
151 if (F->use_empty())
152 // No users. OK to modify signature.
153 return true;
154
155 for (Value::use_iterator FnUseI = F->use_begin(), FnUseE = F->use_end();
156 FnUseI != FnUseE; ++FnUseI) {
Matthijs Kooijman257da0a2008-06-05 08:48:32 +0000157 // The function is passed in as an argument to (possibly) another function,
158 // we can't change it!
Gabor Greif7d3056b2010-07-28 22:50:26 +0000159 CallSite CS(*FnUseI);
Devang Patelca891ec2008-02-29 23:34:08 +0000160 Instruction *Call = CS.getInstruction();
Matthijs Kooijman47c6fd72008-06-05 08:57:20 +0000161 // The function is used by something else than a call or invoke instruction,
162 // we can't change it!
Gabor Greifedc4d692009-01-22 21:35:57 +0000163 if (!Call || !CS.isCallee(FnUseI))
Matthijs Kooijman47c6fd72008-06-05 08:57:20 +0000164 return false;
Devang Patelca891ec2008-02-29 23:34:08 +0000165 CallSite::arg_iterator AI = CS.arg_begin();
166 Value *FirstArg = *AI;
167
168 if (!isa<AllocaInst>(FirstArg))
169 return false;
170
171 // Check FirstArg's users.
172 for (Value::use_iterator ArgI = FirstArg->use_begin(),
173 ArgE = FirstArg->use_end(); ArgI != ArgE; ++ArgI) {
Gabor Greiffc41f902010-07-12 11:19:24 +0000174 User *U = *ArgI;
Devang Patelca891ec2008-02-29 23:34:08 +0000175 // If FirstArg user is a CallInst that does not correspond to current
176 // call site then this function F is not suitable for sret promotion.
Gabor Greiffc41f902010-07-12 11:19:24 +0000177 if (CallInst *CI = dyn_cast<CallInst>(U)) {
Devang Patelca891ec2008-02-29 23:34:08 +0000178 if (CI != Call)
179 return false;
180 }
181 // If FirstArg user is a GEP whose all users are not LoadInst then
182 // this function F is not suitable for sret promotion.
Gabor Greiffc41f902010-07-12 11:19:24 +0000183 else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
Devang Patele0a6a3f2008-03-05 23:39:23 +0000184 // TODO : Use dom info and insert PHINodes to collect get results
185 // from multiple call sites for this GEP.
186 if (GEP->getParent() != Call->getParent())
187 return false;
Devang Patelca891ec2008-02-29 23:34:08 +0000188 for (Value::use_iterator GEPI = GEP->use_begin(), GEPE = GEP->use_end();
189 GEPI != GEPE; ++GEPI)
Gabor Greif96f1d8e2010-07-22 13:36:47 +0000190 if (!isa<LoadInst>(*GEPI))
Devang Patelca891ec2008-02-29 23:34:08 +0000191 return false;
192 }
193 // Any other FirstArg users make this function unsuitable for sret
194 // promotion.
195 else
196 return false;
197 }
198 }
199
200 return true;
201}
202
203/// cloneFunctionBody - Create a new function based on F and
204/// insert it into module. Remove first argument. Use STy as
205/// the return type for new function.
206Function *SRETPromotion::cloneFunctionBody(Function *F,
207 const StructType *STy) {
208
Devang Patelca891ec2008-02-29 23:34:08 +0000209 const FunctionType *FTy = F->getFunctionType();
210 std::vector<const Type*> Params;
211
Devang Patel05988662008-09-25 21:00:45 +0000212 // Attributes - Keep track of the parameter attributes for the arguments.
213 SmallVector<AttributeWithIndex, 8> AttributesVec;
214 const AttrListPtr &PAL = F->getAttributes();
Devang Patel2a4821b2008-03-03 18:36:03 +0000215
216 // Add any return attributes.
Devang Patel19c87462008-09-26 22:53:05 +0000217 if (Attributes attrs = PAL.getRetAttributes())
Devang Patel05988662008-09-25 21:00:45 +0000218 AttributesVec.push_back(AttributeWithIndex::get(0, attrs));
Devang Patel2a4821b2008-03-03 18:36:03 +0000219
Devang Patelca891ec2008-02-29 23:34:08 +0000220 // Skip first argument.
221 Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
222 ++I;
Devang Patel8f9b5512008-03-12 00:07:03 +0000223 // 0th parameter attribute is reserved for return type.
224 // 1th parameter attribute is for first 1st sret argument.
225 unsigned ParamIndex = 2;
Devang Patelca891ec2008-02-29 23:34:08 +0000226 while (I != E) {
227 Params.push_back(I->getType());
Devang Patel19c87462008-09-26 22:53:05 +0000228 if (Attributes Attrs = PAL.getParamAttributes(ParamIndex))
Devang Patel05988662008-09-25 21:00:45 +0000229 AttributesVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs));
Devang Patelca891ec2008-02-29 23:34:08 +0000230 ++I;
Devang Patel2a4821b2008-03-03 18:36:03 +0000231 ++ParamIndex;
Devang Patelca891ec2008-02-29 23:34:08 +0000232 }
233
Devang Patel19c87462008-09-26 22:53:05 +0000234 // Add any fn attributes.
235 if (Attributes attrs = PAL.getFnAttributes())
236 AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
237
238
Owen Andersondebcb012009-07-29 22:17:13 +0000239 FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
Matthijs Kooijman7d942002008-08-07 16:01:23 +0000240 Function *NF = Function::Create(NFTy, F->getLinkage());
241 NF->takeName(F);
Duncan Sands28c3cff2008-05-26 19:58:59 +0000242 NF->copyAttributesFrom(F);
Devang Patel05988662008-09-25 21:00:45 +0000243 NF->setAttributes(AttrListPtr::get(AttributesVec.begin(), AttributesVec.end()));
Devang Patelca891ec2008-02-29 23:34:08 +0000244 F->getParent()->getFunctionList().insert(F, NF);
245 NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
246
247 // Replace arguments
248 I = F->arg_begin();
249 E = F->arg_end();
250 Function::arg_iterator NI = NF->arg_begin();
251 ++I;
252 while (I != E) {
Chris Lattner5095e3d2009-08-31 00:19:58 +0000253 I->replaceAllUsesWith(NI);
254 NI->takeName(I);
255 ++I;
256 ++NI;
Devang Patelca891ec2008-02-29 23:34:08 +0000257 }
258
259 return NF;
260}
261
262/// updateCallSites - Update all sites that call F to use NF.
Chris Lattner5095e3d2009-08-31 00:19:58 +0000263CallGraphNode *SRETPromotion::updateCallSites(Function *F, Function *NF) {
Duncan Sandsa9c32512008-09-08 11:08:09 +0000264 CallGraph &CG = getAnalysis<CallGraph>();
Devang Patelca891ec2008-02-29 23:34:08 +0000265 SmallVector<Value*, 16> Args;
266
Devang Patel05988662008-09-25 21:00:45 +0000267 // Attributes - Keep track of the parameter attributes for the arguments.
268 SmallVector<AttributeWithIndex, 8> ArgAttrsVec;
Devang Patel2a4821b2008-03-03 18:36:03 +0000269
Chris Lattner5095e3d2009-08-31 00:19:58 +0000270 // Get a new callgraph node for NF.
271 CallGraphNode *NF_CGN = CG.getOrInsertFunction(NF);
272
Matthijs Kooijmanc1f1d462008-08-14 15:03:05 +0000273 while (!F->use_empty()) {
Gabor Greif7d3056b2010-07-28 22:50:26 +0000274 CallSite CS(*F->use_begin());
Devang Patelca891ec2008-02-29 23:34:08 +0000275 Instruction *Call = CS.getInstruction();
276
Devang Patel05988662008-09-25 21:00:45 +0000277 const AttrListPtr &PAL = F->getAttributes();
Devang Patel2a4821b2008-03-03 18:36:03 +0000278 // Add any return attributes.
Devang Patel19c87462008-09-26 22:53:05 +0000279 if (Attributes attrs = PAL.getRetAttributes())
Devang Patel05988662008-09-25 21:00:45 +0000280 ArgAttrsVec.push_back(AttributeWithIndex::get(0, attrs));
Devang Patel2a4821b2008-03-03 18:36:03 +0000281
Devang Patelca891ec2008-02-29 23:34:08 +0000282 // Copy arguments, however skip first one.
283 CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
284 Value *FirstCArg = *AI;
285 ++AI;
Devang Patel8f9b5512008-03-12 00:07:03 +0000286 // 0th parameter attribute is reserved for return type.
287 // 1th parameter attribute is for first 1st sret argument.
288 unsigned ParamIndex = 2;
Devang Patelca891ec2008-02-29 23:34:08 +0000289 while (AI != AE) {
290 Args.push_back(*AI);
Devang Patel19c87462008-09-26 22:53:05 +0000291 if (Attributes Attrs = PAL.getParamAttributes(ParamIndex))
Devang Patel05988662008-09-25 21:00:45 +0000292 ArgAttrsVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs));
Devang Patel2a4821b2008-03-03 18:36:03 +0000293 ++ParamIndex;
Devang Patelca891ec2008-02-29 23:34:08 +0000294 ++AI;
295 }
296
Devang Patel19c87462008-09-26 22:53:05 +0000297 // Add any function attributes.
298 if (Attributes attrs = PAL.getFnAttributes())
299 ArgAttrsVec.push_back(AttributeWithIndex::get(~0, attrs));
Chris Lattner58d74912008-03-12 17:45:29 +0000300
Devang Patel05988662008-09-25 21:00:45 +0000301 AttrListPtr NewPAL = AttrListPtr::get(ArgAttrsVec.begin(), ArgAttrsVec.end());
Chris Lattner58d74912008-03-12 17:45:29 +0000302
Devang Patelca891ec2008-02-29 23:34:08 +0000303 // Build new call instruction.
304 Instruction *New;
305 if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
Gabor Greif051a9502008-04-06 20:25:17 +0000306 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
307 Args.begin(), Args.end(), "", Call);
Devang Patelca891ec2008-02-29 23:34:08 +0000308 cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
Devang Patel05988662008-09-25 21:00:45 +0000309 cast<InvokeInst>(New)->setAttributes(NewPAL);
Devang Patelca891ec2008-02-29 23:34:08 +0000310 } else {
Gabor Greif051a9502008-04-06 20:25:17 +0000311 New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call);
Devang Patelca891ec2008-02-29 23:34:08 +0000312 cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
Devang Patel05988662008-09-25 21:00:45 +0000313 cast<CallInst>(New)->setAttributes(NewPAL);
Devang Patelca891ec2008-02-29 23:34:08 +0000314 if (cast<CallInst>(Call)->isTailCall())
315 cast<CallInst>(New)->setTailCall();
316 }
317 Args.clear();
Devang Patel544b92b2008-03-04 19:12:58 +0000318 ArgAttrsVec.clear();
Devang Patelca891ec2008-02-29 23:34:08 +0000319 New->takeName(Call);
320
Duncan Sandsa9c32512008-09-08 11:08:09 +0000321 // Update the callgraph to know that the callsite has been transformed.
Chris Lattnerda230cb2009-09-01 18:52:39 +0000322 CallGraphNode *CalleeNode = CG[Call->getParent()->getParent()];
323 CalleeNode->removeCallEdgeFor(Call);
324 CalleeNode->addCalledFunction(New, NF_CGN);
Chris Lattner7c8c1ba2009-09-01 18:50:55 +0000325
Dan Gohmanfc74abf2008-07-23 00:34:11 +0000326 // Update all users of sret parameter to extract value using extractvalue.
Devang Patelca891ec2008-02-29 23:34:08 +0000327 for (Value::use_iterator UI = FirstCArg->use_begin(),
328 UE = FirstCArg->use_end(); UI != UE; ) {
329 User *U2 = *UI++;
330 CallInst *C2 = dyn_cast<CallInst>(U2);
331 if (C2 && (C2 == Call))
332 continue;
Chris Lattner5095e3d2009-08-31 00:19:58 +0000333
Chris Lattner7c8c1ba2009-09-01 18:50:55 +0000334 GetElementPtrInst *UGEP = cast<GetElementPtrInst>(U2);
335 ConstantInt *Idx = cast<ConstantInt>(UGEP->getOperand(2));
336 Value *GR = ExtractValueInst::Create(New, Idx->getZExtValue(),
337 "evi", UGEP);
338 while(!UGEP->use_empty()) {
339 // isSafeToUpdateAllCallers has checked that all GEP uses are
340 // LoadInsts
341 LoadInst *L = cast<LoadInst>(*UGEP->use_begin());
342 L->replaceAllUsesWith(GR);
343 L->eraseFromParent();
Devang Patelca891ec2008-02-29 23:34:08 +0000344 }
Chris Lattner7c8c1ba2009-09-01 18:50:55 +0000345 UGEP->eraseFromParent();
346 continue;
Devang Patelca891ec2008-02-29 23:34:08 +0000347 }
348 Call->eraseFromParent();
349 }
Chris Lattner5095e3d2009-08-31 00:19:58 +0000350
351 return NF_CGN;
Devang Patelca891ec2008-02-29 23:34:08 +0000352}
Devang Patela9fe8bb2008-03-04 21:32:09 +0000353
354/// nestedStructType - Return true if STy includes any
355/// other aggregate types
356bool SRETPromotion::nestedStructType(const StructType *STy) {
357 unsigned Num = STy->getNumElements();
358 for (unsigned i = 0; i < Num; i++) {
359 const Type *Ty = STy->getElementType(i);
Benjamin Kramerf0127052010-01-05 13:12:22 +0000360 if (!Ty->isSingleValueType() && !Ty->isVoidTy())
Devang Patela9fe8bb2008-03-04 21:32:09 +0000361 return true;
362 }
363 return false;
364}