@@ -535,15 +535,41 @@ void CodeExtractor::findAllocas(ValueSet &SinkCands, ValueSet &HoistCands,
535
535
}
536
536
}
537
537
538
+ bool CodeExtractor::isEligible () const {
539
+ if (Blocks.empty ())
540
+ return false ;
541
+ BasicBlock *Header = *Blocks.begin ();
542
+ Function *F = Header->getParent ();
543
+
544
+ // For functions with varargs, check that varargs handling is only done in the
545
+ // outlined function, i.e vastart and vaend are only used in outlined blocks.
546
+ if (AllowVarArgs && F->getFunctionType ()->isVarArg ()) {
547
+ auto containsVarArgIntrinsic = [](const Instruction &I) {
548
+ if (const CallInst *CI = dyn_cast<CallInst>(&I))
549
+ if (const Function *Callee = CI->getCalledFunction ())
550
+ return Callee->getIntrinsicID () == Intrinsic::vastart ||
551
+ Callee->getIntrinsicID () == Intrinsic::vaend;
552
+ return false ;
553
+ };
554
+
555
+ for (auto &BB : *F) {
556
+ if (Blocks.count (&BB))
557
+ continue ;
558
+ if (llvm::any_of (BB, containsVarArgIntrinsic))
559
+ return false ;
560
+ }
561
+ }
562
+ return true ;
563
+ }
564
+
538
565
void CodeExtractor::findInputsOutputs (ValueSet &Inputs, ValueSet &Outputs,
539
566
const ValueSet &SinkCands) const {
540
567
for (BasicBlock *BB : Blocks) {
541
568
// If a used value is defined outside the region, it's an input. If an
542
569
// instruction is used outside the region, it's an output.
543
570
for (Instruction &II : *BB) {
544
- for (User::op_iterator OI = II.op_begin (), OE = II.op_end (); OI != OE;
545
- ++OI) {
546
- Value *V = *OI;
571
+ for (auto &OI : II.operands ()) {
572
+ Value *V = OI;
547
573
if (!SinkCands.count (V) && definedInCaller (Blocks, V))
548
574
Inputs.insert (V);
549
575
}
@@ -1339,27 +1365,6 @@ Function *CodeExtractor::extractCodeRegion() {
1339
1365
BasicBlock *header = *Blocks.begin ();
1340
1366
Function *oldFunction = header->getParent ();
1341
1367
1342
- // For functions with varargs, check that varargs handling is only done in the
1343
- // outlined function, i.e vastart and vaend are only used in outlined blocks.
1344
- if (AllowVarArgs && oldFunction->getFunctionType ()->isVarArg ()) {
1345
- auto containsVarArgIntrinsic = [](Instruction &I) {
1346
- if (const CallInst *CI = dyn_cast<CallInst>(&I))
1347
- if (const Function *F = CI->getCalledFunction ())
1348
- return F->getIntrinsicID () == Intrinsic::vastart ||
1349
- F->getIntrinsicID () == Intrinsic::vaend;
1350
- return false ;
1351
- };
1352
-
1353
- for (auto &BB : *oldFunction) {
1354
- if (Blocks.count (&BB))
1355
- continue ;
1356
- if (llvm::any_of (BB, containsVarArgIntrinsic))
1357
- return nullptr ;
1358
- }
1359
- }
1360
- ValueSet inputs, outputs, SinkingCands, HoistingCands;
1361
- BasicBlock *CommonExit = nullptr ;
1362
-
1363
1368
// Calculate the entry frequency of the new function before we change the root
1364
1369
// block.
1365
1370
BlockFrequency EntryFreq;
@@ -1426,6 +1431,8 @@ Function *CodeExtractor::extractCodeRegion() {
1426
1431
}
1427
1432
newFuncRoot->getInstList ().push_back (BranchI);
1428
1433
1434
+ ValueSet inputs, outputs, SinkingCands, HoistingCands;
1435
+ BasicBlock *CommonExit = nullptr ;
1429
1436
findAllocas (SinkingCands, HoistingCands, CommonExit);
1430
1437
assert (HoistingCands.empty () || CommonExit);
1431
1438
0 commit comments