@@ -87,28 +87,14 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
8787 return NewBB;
8888}
8989
90- // Clone OldFunc into NewFunc, transforming the old arguments into references to
91- // VMap values.
92- //
93- void llvm::CloneFunctionInto (Function *NewFunc, const Function *OldFunc,
94- ValueToValueMapTy &VMap,
95- CloneFunctionChangeType Changes,
96- SmallVectorImpl<ReturnInst *> &Returns,
97- const char *NameSuffix, ClonedCodeInfo *CodeInfo,
98- ValueMapTypeRemapper *TypeMapper,
99- ValueMaterializer *Materializer) {
100- NewFunc->setIsNewDbgInfoFormat (OldFunc->IsNewDbgInfoFormat );
101- assert (NameSuffix && " NameSuffix cannot be null!" );
102-
103- #ifndef NDEBUG
104- for (const Argument &I : OldFunc->args ())
105- assert (VMap.count (&I) && " No mapping from source argument specified!" );
106- #endif
107-
108- bool ModuleLevelChanges = Changes > CloneFunctionChangeType::LocalChangesOnly;
109-
110- // Copy all attributes other than those stored in the AttributeList. We need
111- // to remap the parameter indices of the AttributeList.
90+ void llvm::CloneFunctionAttributesInto (Function *NewFunc,
91+ const Function *OldFunc,
92+ ValueToValueMapTy &VMap,
93+ bool ModuleLevelChanges,
94+ ValueMapTypeRemapper *TypeMapper,
95+ ValueMaterializer *Materializer) {
96+ // Copy all attributes other than those stored in Function's AttributeList
97+ // which holds e.g. parameters and return value attributes.
11298 AttributeList NewAttrs = NewFunc->getAttributes ();
11399 NewFunc->copyAttributesFrom (OldFunc);
114100 NewFunc->setAttributes (NewAttrs);
@@ -140,6 +126,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
140126 // Clone any argument attributes that are present in the VMap.
141127 for (const Argument &OldArg : OldFunc->args ()) {
142128 if (Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) {
129+ // Remap the parameter indices.
143130 NewArgAttrs[NewArg->getArgNo ()] =
144131 OldAttrs.getParamAttrs (OldArg.getArgNo ());
145132 }
@@ -148,6 +135,29 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
148135 NewFunc->setAttributes (
149136 AttributeList::get (NewFunc->getContext (), OldAttrs.getFnAttrs (),
150137 OldAttrs.getRetAttrs (), NewArgAttrs));
138+ }
139+
140+ // Clone OldFunc into NewFunc, transforming the old arguments into references to
141+ // VMap values.
142+ void llvm::CloneFunctionInto (Function *NewFunc, const Function *OldFunc,
143+ ValueToValueMapTy &VMap,
144+ CloneFunctionChangeType Changes,
145+ SmallVectorImpl<ReturnInst *> &Returns,
146+ const char *NameSuffix, ClonedCodeInfo *CodeInfo,
147+ ValueMapTypeRemapper *TypeMapper,
148+ ValueMaterializer *Materializer) {
149+ NewFunc->setIsNewDbgInfoFormat (OldFunc->IsNewDbgInfoFormat );
150+ assert (NameSuffix && " NameSuffix cannot be null!" );
151+
152+ #ifndef NDEBUG
153+ for (const Argument &I : OldFunc->args ())
154+ assert (VMap.count (&I) && " No mapping from source argument specified!" );
155+ #endif
156+
157+ bool ModuleLevelChanges = Changes > CloneFunctionChangeType::LocalChangesOnly;
158+
159+ CloneFunctionAttributesInto (NewFunc, OldFunc, VMap, ModuleLevelChanges,
160+ TypeMapper, Materializer);
151161
152162 // Everything else beyond this point deals with function instructions,
153163 // so if we are dealing with a function declaration, we're done.
0 commit comments