llvm.org GIT mirror llvm / 39472f2
[CodeExtractor] NFC: Refactor sanity checks into isEligible Reviewers: fhahn Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68331 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373479 91177308-0d34-0410-b5e6-96231b3b80d8 Aditya Kumar 1 year, 2 months ago
2 changed file(s) with 35 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
109109 ///
110110 /// Based on the blocks used when constructing the code extractor,
111111 /// determine whether it is eligible for extraction.
112 bool isEligible() const { return !Blocks.empty(); }
112 ///
113 /// Checks that varargs handling (with vastart and vaend) is only done in
114 /// the outlined blocks.
115 bool isEligible() const;
113116
114117 /// Compute the set of input values and output values for the code.
115118 ///
534534 }
535535 }
536536
537 bool CodeExtractor::isEligible() const {
538 if (Blocks.empty())
539 return false;
540 BasicBlock *Header = *Blocks.begin();
541 Function *F = Header->getParent();
542
543 // For functions with varargs, check that varargs handling is only done in the
544 // outlined function, i.e vastart and vaend are only used in outlined blocks.
545 if (AllowVarArgs && F->getFunctionType()->isVarArg()) {
546 auto containsVarArgIntrinsic = [](const Instruction &I) {
547 if (const CallInst *CI = dyn_cast(&I))
548 if (const Function *Callee = CI->getCalledFunction())
549 return Callee->getIntrinsicID() == Intrinsic::vastart ||
550 Callee->getIntrinsicID() == Intrinsic::vaend;
551 return false;
552 };
553
554 for (auto &BB : *F) {
555 if (Blocks.count(&BB))
556 continue;
557 if (llvm::any_of(BB, containsVarArgIntrinsic))
558 return false;
559 }
560 }
561 return true;
562 }
563
537564 void CodeExtractor::findInputsOutputs(ValueSet &Inputs, ValueSet &Outputs,
538565 const ValueSet &SinkCands) const {
539566 for (BasicBlock *BB : Blocks) {
540567 // If a used value is defined outside the region, it's an input. If an
541568 // instruction is used outside the region, it's an output.
542569 for (Instruction &II : *BB) {
543 for (User::op_iterator OI = II.op_begin(), OE = II.op_end(); OI != OE;
544 ++OI) {
545 Value *V = *OI;
570 for (auto &OI : II.operands()) {
571 Value *V = OI;
546572 if (!SinkCands.count(V) && definedInCaller(Blocks, V))
547573 Inputs.insert(V);
548574 }
13381364 BasicBlock *header = *Blocks.begin();
13391365 Function *oldFunction = header->getParent();
13401366
1341 // For functions with varargs, check that varargs handling is only done in the
1342 // outlined function, i.e vastart and vaend are only used in outlined blocks.
1343 if (AllowVarArgs && oldFunction->getFunctionType()->isVarArg()) {
1344 auto containsVarArgIntrinsic = [](Instruction &I) {
1345 if (const CallInst *CI = dyn_cast(&I))
1346 if (const Function *F = CI->getCalledFunction())
1347 return F->getIntrinsicID() == Intrinsic::vastart ||
1348 F->getIntrinsicID() == Intrinsic::vaend;
1349 return false;
1350 };
1351
1352 for (auto &BB : *oldFunction) {
1353 if (Blocks.count(&BB))
1354 continue;
1355 if (llvm::any_of(BB, containsVarArgIntrinsic))
1356 return nullptr;
1357 }
1358 }
1359 ValueSet inputs, outputs, SinkingCands, HoistingCands;
1360 BasicBlock *CommonExit = nullptr;
1361
13621367 // Calculate the entry frequency of the new function before we change the root
13631368 // block.
13641369 BlockFrequency EntryFreq;
14251430 }
14261431 newFuncRoot->getInstList().push_back(BranchI);
14271432
1433 ValueSet inputs, outputs, SinkingCands, HoistingCands;
1434 BasicBlock *CommonExit = nullptr;
14281435 findAllocas(SinkingCands, HoistingCands, CommonExit);
14291436 assert(HoistingCands.empty() || CommonExit);
14301437