@@ -813,14 +813,6 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
813
813
LLVM_DEBUG (dbgs () << " inputs: " << inputs.size () << " \n " );
814
814
LLVM_DEBUG (dbgs () << " outputs: " << outputs.size () << " \n " );
815
815
816
- // This function returns unsigned, outputs will go back by reference.
817
- switch (NumExitBlocks) {
818
- case 0 :
819
- case 1 : RetTy = Type::getVoidTy (header->getContext ()); break ;
820
- case 2 : RetTy = Type::getInt1Ty (header->getContext ()); break ;
821
- default : RetTy = Type::getInt16Ty (header->getContext ()); break ;
822
- }
823
-
824
816
std::vector<Type *> ParamTy;
825
817
std::vector<Type *> AggParamTy;
826
818
std::vector<std::tuple<unsigned , Value *>> NumberedInputs;
@@ -870,6 +862,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
870
862
StructTy, ArgsInZeroAddressSpace ? 0 : DL.getAllocaAddrSpace ()));
871
863
}
872
864
865
+ Type *RetTy = getSwitchType ();
873
866
LLVM_DEBUG ({
874
867
dbgs () << " Function type: " << *RetTy << " f(" ;
875
868
for (Type *i : ParamTy)
@@ -1080,6 +1073,22 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
1080
1073
return newFunction;
1081
1074
}
1082
1075
1076
+ Type *CodeExtractor::getSwitchType () {
1077
+ LLVMContext &Context = Blocks.front ()->getContext ();
1078
+
1079
+ assert (NumExitBlocks < 0xffff && " too many exit blocks for switch" );
1080
+ switch (NumExitBlocks) {
1081
+ case 0 :
1082
+ case 1 :
1083
+ return Type::getVoidTy (Context);
1084
+ case 2 :
1085
+ // Conditional branch, return a bool
1086
+ return Type::getInt1Ty (Context);
1087
+ default :
1088
+ return Type::getInt16Ty (Context);
1089
+ }
1090
+ }
1091
+
1083
1092
// / Erase lifetime.start markers which reference inputs to the extraction
1084
1093
// / region, and insert the referenced memory into \p LifetimesStart.
1085
1094
// /
0 commit comments