@@ -26,50 +26,52 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
26
26
// will (maybe) happen later.
27
27
bool HasBody = FuncDecl->hasBody (FuncDecl);
28
28
29
- // Set up argument indices.
30
- unsigned ParamOffset = 0 ;
31
- SmallVector<PrimType, 8 > ParamTypes;
32
- llvm::DenseMap<unsigned , Function::ParamDescriptor> ParamDescriptors;
33
-
34
- // If the return is not a primitive, a pointer to the storage where the value
35
- // is initialized in is passed as the first argument.
36
- // See 'RVO' elsewhere in the code.
37
- QualType Ty = FuncDecl->getReturnType ();
38
- bool HasRVO = false ;
39
- if (!Ty->isVoidType () && !Ctx.classify (Ty)) {
40
- HasRVO = true ;
41
- ParamTypes.push_back (PT_Ptr);
42
- ParamOffset += align (primSize (PT_Ptr));
43
- }
29
+ // Create a handle over the emitted code.
30
+ Function *Func = P.getFunction (FuncDecl);
31
+ if (!Func) {
32
+ // Set up argument indices.
33
+ unsigned ParamOffset = 0 ;
34
+ SmallVector<PrimType, 8 > ParamTypes;
35
+ llvm::DenseMap<unsigned , Function::ParamDescriptor> ParamDescriptors;
36
+
37
+ // If the return is not a primitive, a pointer to the storage where the
38
+ // value is initialized in is passed as the first argument. See 'RVO'
39
+ // elsewhere in the code.
40
+ QualType Ty = FuncDecl->getReturnType ();
41
+ bool HasRVO = false ;
42
+ if (!Ty->isVoidType () && !Ctx.classify (Ty)) {
43
+ HasRVO = true ;
44
+ ParamTypes.push_back (PT_Ptr);
45
+ ParamOffset += align (primSize (PT_Ptr));
46
+ }
44
47
45
- // If the function decl is a member decl, the next parameter is
46
- // the 'this' pointer. This parameter is pop()ed from the
47
- // InterpStack when calling the function.
48
- bool HasThisPointer = false ;
49
- if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl);
50
- MD && MD->isInstance ()) {
51
- HasThisPointer = true ;
52
- ParamTypes.push_back (PT_Ptr);
53
- ParamOffset += align (primSize (PT_Ptr));
54
- }
48
+ // If the function decl is a member decl, the next parameter is
49
+ // the 'this' pointer. This parameter is pop()ed from the
50
+ // InterpStack when calling the function.
51
+ bool HasThisPointer = false ;
52
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl);
53
+ MD && MD->isInstance ()) {
54
+ HasThisPointer = true ;
55
+ ParamTypes.push_back (PT_Ptr);
56
+ ParamOffset += align (primSize (PT_Ptr));
57
+ }
55
58
56
- // Assign descriptors to all parameters.
57
- // Composite objects are lowered to pointers.
58
- for (const ParmVarDecl *PD : FuncDecl->parameters ()) {
59
- PrimType Ty = Ctx.classify (PD->getType ()).value_or (PT_Ptr);
60
- Descriptor *Desc = P.createDescriptor (PD, Ty);
61
- ParamDescriptors.insert ({ParamOffset, {Ty, Desc}});
62
- Params.insert ({PD, ParamOffset});
63
- ParamOffset += align (primSize (Ty));
64
- ParamTypes.push_back (Ty);
65
- }
59
+ // Assign descriptors to all parameters.
60
+ // Composite objects are lowered to pointers.
61
+ for (const ParmVarDecl *PD : FuncDecl->parameters ()) {
62
+ PrimType Ty = Ctx.classify (PD->getType ()).value_or (PT_Ptr);
63
+ Descriptor *Desc = P.createDescriptor (PD, Ty);
64
+ ParamDescriptors.insert ({ParamOffset, {Ty, Desc}});
65
+ Params.insert ({PD, ParamOffset});
66
+ ParamOffset += align (primSize (Ty));
67
+ ParamTypes.push_back (Ty);
68
+ }
66
69
67
- // Create a handle over the emitted code.
68
- Function *Func = P.getFunction (FuncDecl);
69
- if (!Func)
70
70
Func =
71
71
P.createFunction (FuncDecl, ParamOffset, std::move (ParamTypes),
72
72
std::move (ParamDescriptors), HasThisPointer, HasRVO);
73
+ }
74
+
73
75
assert (Func);
74
76
if (!HasBody)
75
77
return Func;
0 commit comments