| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "IRGenerator.h" | ||
| 4 | |||
| 5 | #include <ast/ASTNodes.h> | ||
| 6 | #include <driver/Driver.h> | ||
| 7 | #include <irgenerator/NameMangling.h> | ||
| 8 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 9 | |||
| 10 | #include <llvm/IR/Module.h> | ||
| 11 | |||
| 12 | namespace spice::compiler { | ||
| 13 | |||
| 14 | 18648 | std::any IRGenerator::visitValue(const ValueNode *node) { | |
| 15 | 18648 | diGenerator.setSourceLocation(node); | |
| 16 | |||
| 17 | // Function call | ||
| 18 |
2/2✓ Branch 3 → 4 taken 16688 times.
✓ Branch 3 → 5 taken 1960 times.
|
18648 | if (node->fctCall) |
| 19 | 16688 | return visit(node->fctCall); | |
| 20 | |||
| 21 | // Array initialization | ||
| 22 |
2/2✓ Branch 5 → 6 taken 59 times.
✓ Branch 5 → 7 taken 1901 times.
|
1960 | if (node->arrayInitialization) |
| 23 | 59 | return visit(node->arrayInitialization); | |
| 24 | |||
| 25 | // Struct instantiation | ||
| 26 |
2/2✓ Branch 7 → 8 taken 281 times.
✓ Branch 7 → 9 taken 1620 times.
|
1901 | if (node->structInstantiation) |
| 27 | 281 | return visit(node->structInstantiation); | |
| 28 | |||
| 29 | // Lambda function | ||
| 30 |
2/2✓ Branch 9 → 10 taken 12 times.
✓ Branch 9 → 11 taken 1608 times.
|
1620 | if (node->lambdaFunc) |
| 31 | 12 | return visit(node->lambdaFunc); | |
| 32 | |||
| 33 | // Lambda procedure | ||
| 34 |
2/2✓ Branch 11 → 12 taken 30 times.
✓ Branch 11 → 13 taken 1578 times.
|
1608 | if (node->lambdaProc) |
| 35 | 30 | return visit(node->lambdaProc); | |
| 36 | |||
| 37 | // Lambda expression | ||
| 38 |
2/2✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 1577 times.
|
1578 | if (node->lambdaExpr) |
| 39 | 1 | return visit(node->lambdaExpr); | |
| 40 | |||
| 41 |
1/2✓ Branch 15 → 16 taken 1577 times.
✗ Branch 15 → 23 not taken.
|
1577 | if (node->isNil) { |
| 42 | // Retrieve type of the nil constant | ||
| 43 |
2/4✓ Branch 16 → 17 taken 1577 times.
✗ Branch 16 → 34 not taken.
✓ Branch 17 → 18 taken 1577 times.
✗ Branch 17 → 32 not taken.
|
1577 | const auto nilType = any_cast<llvm::Type *>(visit(node->nilType)); |
| 44 | // Create constant nil value | ||
| 45 | 1577 | llvm::Constant *nilValue = llvm::Constant::getNullValue(nilType); | |
| 46 | // Return it | ||
| 47 |
1/2✓ Branch 20 → 21 taken 1577 times.
✗ Branch 20 → 35 not taken.
|
3154 | return LLVMExprResult{.constant = nilValue}; |
| 48 | } | ||
| 49 | |||
| 50 | − | throw CompilerError(UNHANDLED_BRANCH, "Value fall-through"); // GCOV_EXCL_LINE | |
| 51 | } | ||
| 52 | |||
| 53 | 18016 | std::any IRGenerator::visitConstant(const ConstantNode *node) { | |
| 54 |
3/6✓ Branch 2 → 3 taken 18016 times.
✗ Branch 2 → 10 not taken.
✓ Branch 4 → 5 taken 18016 times.
✗ Branch 4 → 9 not taken.
✓ Branch 5 → 6 taken 18016 times.
✗ Branch 5 → 9 not taken.
|
18016 | return getConst(node->getCompileTimeValue(), node->getEvaluatedSymbolType(manIdx), node); |
| 55 | } | ||
| 56 | |||
| 57 | 16688 | std::any IRGenerator::visitFctCall(const FctCallNode *node) { | |
| 58 |
1/2✓ Branch 2 → 3 taken 16688 times.
✗ Branch 2 → 526 not taken.
|
16688 | diGenerator.setSourceLocation(node); |
| 59 | |||
| 60 |
1/2✓ Branch 3 → 4 taken 16688 times.
✗ Branch 3 → 526 not taken.
|
16688 | const FctCallNode::FctCallData &data = node->data.at(manIdx); |
| 61 | |||
| 62 | 16688 | Function *spiceFunc = data.callee; | |
| 63 |
3/4✓ Branch 5 → 6 taken 16643 times.
✓ Branch 5 → 8 taken 45 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 16643 times.
|
16688 | assert(data.isFctPtrCall() || spiceFunc != nullptr); // If not a function pointer call, we must have a function |
| 64 | 16688 | std::string mangledName; | |
| 65 |
2/2✓ Branch 10 → 11 taken 16643 times.
✓ Branch 10 → 15 taken 45 times.
|
16688 | if (!data.isFctPtrCall()) |
| 66 |
1/2✓ Branch 11 → 12 taken 16643 times.
✗ Branch 11 → 383 not taken.
|
16643 | mangledName = spiceFunc->getMangledName(); |
| 67 | |||
| 68 | // Get entry of the first fragment | ||
| 69 | 16688 | SymbolTableEntry *firstFragEntry = currentScope->lookup(node->functionNameFragments.front()); | |
| 70 | |||
| 71 | // Get this type | ||
| 72 | 16688 | std::vector<llvm::Value *> argValues; | |
| 73 | 16688 | llvm::Value *thisPtr = nullptr; | |
| 74 |
2/2✓ Branch 20 → 21 taken 6090 times.
✓ Branch 20 → 68 taken 10598 times.
|
16688 | if (data.isMethodCall()) { |
| 75 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 6090 times.
|
6090 | assert(!data.isCtorCall()); |
| 76 | |||
| 77 | // Retrieve entry of the first fragment | ||
| 78 |
2/4✓ Branch 24 → 25 taken 6090 times.
✗ Branch 24 → 398 not taken.
✓ Branch 25 → 26 taken 6090 times.
✗ Branch 25 → 398 not taken.
|
6090 | const QualType baseType = firstFragEntry->getQualType().getBase(); |
| 79 |
3/6✓ Branch 26 → 27 taken 6090 times.
✗ Branch 26 → 30 not taken.
✓ Branch 27 → 28 taken 6090 times.
✗ Branch 27 → 384 not taken.
✓ Branch 28 → 29 taken 6090 times.
✗ Branch 28 → 30 not taken.
|
6090 | assert(firstFragEntry != nullptr && baseType.isOneOf({TY_STRUCT, TY_INTERFACE})); |
| 80 |
1/2✓ Branch 31 → 32 taken 6090 times.
✗ Branch 31 → 398 not taken.
|
6090 | Scope *structScope = baseType.getBodyScope(); |
| 81 | |||
| 82 | // Get address of the referenced variable / struct instance | ||
| 83 |
1/2✓ Branch 32 → 33 taken 6090 times.
✗ Branch 32 → 398 not taken.
|
6090 | thisPtr = firstFragEntry->getAddress(); |
| 84 | |||
| 85 | // Auto de-reference 'this' pointer | ||
| 86 |
1/2✓ Branch 33 → 34 taken 6090 times.
✗ Branch 33 → 398 not taken.
|
6090 | QualType firstFragmentType = firstFragEntry->getQualType(); |
| 87 |
1/2✓ Branch 34 → 35 taken 6090 times.
✗ Branch 34 → 398 not taken.
|
6090 | autoDeReferencePtr(thisPtr, firstFragmentType); |
| 88 |
1/2✓ Branch 35 → 36 taken 6090 times.
✗ Branch 35 → 398 not taken.
|
6090 | llvm::Type *structTy = baseType.toLLVMType(sourceFile); |
| 89 | |||
| 90 | // Traverse through structs - the first fragment is already looked up and the last one is the function name | ||
| 91 |
2/2✓ Branch 65 → 37 taken 850 times.
✓ Branch 65 → 66 taken 6090 times.
|
6940 | for (size_t i = 1; i < node->functionNameFragments.size() - 1; i++) { |
| 92 |
2/4✓ Branch 37 → 38 taken 850 times.
✗ Branch 37 → 397 not taken.
✓ Branch 38 → 39 taken 850 times.
✗ Branch 38 → 397 not taken.
|
850 | const std::string identifier = node->functionNameFragments.at(i); |
| 93 | // Retrieve field entry | ||
| 94 | 850 | SymbolTableEntry *fieldEntry = structScope->lookupStrict(identifier); | |
| 95 |
1/2✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 850 times.
|
850 | assert(fieldEntry != nullptr); |
| 96 |
1/2✓ Branch 44 → 45 taken 850 times.
✗ Branch 44 → 395 not taken.
|
850 | QualType fieldEntryType = fieldEntry->getQualType(); |
| 97 |
3/6✓ Branch 45 → 46 taken 850 times.
✗ Branch 45 → 386 not taken.
✓ Branch 46 → 47 taken 850 times.
✗ Branch 46 → 385 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 850 times.
|
850 | assert(fieldEntryType.getBase().isOneOf({TY_STRUCT, TY_INTERFACE})); |
| 98 | // Get struct type and scope | ||
| 99 |
2/4✓ Branch 49 → 50 taken 850 times.
✗ Branch 49 → 387 not taken.
✓ Branch 50 → 51 taken 850 times.
✗ Branch 50 → 387 not taken.
|
850 | structScope = fieldEntryType.getBase().getBodyScope(); |
| 100 |
1/2✗ Branch 51 → 52 not taken.
✓ Branch 51 → 53 taken 850 times.
|
850 | assert(structScope != nullptr); |
| 101 | // Get address of field | ||
| 102 |
1/2✓ Branch 56 → 57 taken 850 times.
✗ Branch 56 → 388 not taken.
|
850 | thisPtr = insertStructGEP(structTy, thisPtr, fieldEntry->orderIndex); |
| 103 | // Auto de-reference pointer and get new struct type | ||
| 104 |
1/2✓ Branch 59 → 60 taken 850 times.
✗ Branch 59 → 395 not taken.
|
850 | autoDeReferencePtr(thisPtr, fieldEntryType); |
| 105 |
2/4✓ Branch 60 → 61 taken 850 times.
✗ Branch 60 → 394 not taken.
✓ Branch 61 → 62 taken 850 times.
✗ Branch 61 → 394 not taken.
|
850 | structTy = fieldEntryType.getBase().toLLVMType(sourceFile); |
| 106 | 850 | } | |
| 107 | |||
| 108 | // Add 'this' pointer to the front of the argument list | ||
| 109 |
1/2✓ Branch 66 → 67 taken 6090 times.
✗ Branch 66 → 398 not taken.
|
6090 | argValues.push_back(thisPtr); |
| 110 | } | ||
| 111 | |||
| 112 |
2/2✓ Branch 69 → 70 taken 2334 times.
✓ Branch 69 → 81 taken 14354 times.
|
16688 | if (data.isCtorCall()) { |
| 113 |
1/2✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 2334 times.
|
2334 | assert(!data.isMethodCall()); |
| 114 | |||
| 115 |
1/2✓ Branch 73 → 74 taken 2334 times.
✗ Branch 73 → 522 not taken.
|
2334 | llvm::Type *thisType = spiceFunc->thisType.toLLVMType(sourceFile); |
| 116 |
1/2✓ Branch 77 → 78 taken 2334 times.
✗ Branch 77 → 399 not taken.
|
2334 | thisPtr = insertAlloca(thisType); |
| 117 | |||
| 118 | // Add 'this' pointer to the front of the argument list | ||
| 119 |
1/2✓ Branch 80 → 81 taken 2334 times.
✗ Branch 80 → 522 not taken.
|
2334 | argValues.push_back(thisPtr); |
| 120 | } | ||
| 121 | |||
| 122 | // If we have a lambda call that takes captures, add them to the argument list | ||
| 123 | 16688 | llvm::Value *fctPtr = nullptr; | |
| 124 |
2/2✓ Branch 82 → 83 taken 45 times.
✓ Branch 82 → 112 taken 16643 times.
|
16688 | if (data.isFctPtrCall()) { |
| 125 |
1/2✓ Branch 83 → 84 taken 45 times.
✗ Branch 83 → 522 not taken.
|
45 | llvm::Value *fatPtr = firstFragEntry->getAddress(); |
| 126 | // Load fctPtr | ||
| 127 |
3/6✓ Branch 84 → 85 taken 45 times.
✗ Branch 84 → 405 not taken.
✓ Branch 85 → 86 taken 45 times.
✗ Branch 85 → 405 not taken.
✓ Branch 87 → 88 taken 45 times.
✗ Branch 87 → 405 not taken.
|
45 | llvm::StructType *fatStructType = llvm::StructType::get(context, {builder.getPtrTy(), builder.getPtrTy()}); |
| 128 |
1/2✓ Branch 91 → 92 taken 45 times.
✗ Branch 91 → 407 not taken.
|
45 | fctPtr = insertStructGEP(fatStructType, fatPtr, 0); |
| 129 |
4/6✓ Branch 94 → 95 taken 45 times.
✗ Branch 94 → 522 not taken.
✓ Branch 95 → 96 taken 45 times.
✗ Branch 95 → 522 not taken.
✓ Branch 96 → 97 taken 16 times.
✓ Branch 96 → 112 taken 29 times.
|
45 | if (firstFragEntry->getQualType().hasLambdaCaptures()) { |
| 130 | // Load captures struct | ||
| 131 |
1/2✓ Branch 100 → 101 taken 16 times.
✗ Branch 100 → 413 not taken.
|
16 | llvm::Value *capturesPtrPtr = insertStructGEP(fatStructType, fatPtr, 1); |
| 132 |
3/6✓ Branch 105 → 106 taken 16 times.
✗ Branch 105 → 421 not taken.
✓ Branch 106 → 107 taken 16 times.
✗ Branch 106 → 419 not taken.
✓ Branch 107 → 108 taken 16 times.
✗ Branch 107 → 419 not taken.
|
16 | llvm::Value *capturesPtr = insertLoad(builder.getPtrTy(), capturesPtrPtr, false, CAPTURES_PARAM_NAME); |
| 133 | // Add captures to argument list | ||
| 134 |
1/2✓ Branch 110 → 111 taken 16 times.
✗ Branch 110 → 425 not taken.
|
16 | argValues.push_back(capturesPtr); |
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | // Get arg values | ||
| 139 |
2/2✓ Branch 112 → 113 taken 13116 times.
✓ Branch 112 → 201 taken 3572 times.
|
16688 | if (node->hasArgs) { |
| 140 |
1/2✓ Branch 113 → 114 taken 13116 times.
✗ Branch 113 → 459 not taken.
|
13116 | const std::vector<AssignExprNode *> args = node->argLst->args; |
| 141 |
1/2✓ Branch 115 → 116 taken 13116 times.
✗ Branch 115 → 457 not taken.
|
13116 | argValues.reserve(args.size()); |
| 142 | const QualTypeList paramSTypes = | ||
| 143 |
6/10✓ Branch 117 → 118 taken 22 times.
✓ Branch 117 → 121 taken 13094 times.
✓ Branch 118 → 119 taken 22 times.
✗ Branch 118 → 426 not taken.
✓ Branch 119 → 120 taken 22 times.
✗ Branch 119 → 426 not taken.
✓ Branch 120 → 122 taken 22 times.
✗ Branch 120 → 426 not taken.
✓ Branch 121 → 122 taken 13094 times.
✗ Branch 121 → 426 not taken.
|
13116 | data.isFctPtrCall() ? firstFragEntry->getQualType().getBase().getFunctionParamTypes() : spiceFunc->getParamTypes(); |
| 144 |
1/2✗ Branch 124 → 125 not taken.
✓ Branch 124 → 126 taken 13116 times.
|
13116 | assert(paramSTypes.size() == args.size()); |
| 145 |
2/2✓ Branch 197 → 127 taken 23054 times.
✓ Branch 197 → 198 taken 13116 times.
|
36170 | for (size_t i = 0; i < args.size(); i++) { |
| 146 |
1/2✓ Branch 127 → 128 taken 23054 times.
✗ Branch 127 → 454 not taken.
|
23054 | AssignExprNode *argNode = args.at(i); |
| 147 |
1/2✓ Branch 128 → 129 taken 23054 times.
✗ Branch 128 → 454 not taken.
|
23054 | const auto &[copyCtor] = node->argLst->argInfos.at(i); |
| 148 | |||
| 149 |
1/2✓ Branch 129 → 130 taken 23054 times.
✗ Branch 129 → 454 not taken.
|
23054 | const QualType &expectedSTy = paramSTypes.at(i); |
| 150 |
1/2✓ Branch 130 → 131 taken 23054 times.
✗ Branch 130 → 454 not taken.
|
23054 | const QualType &actualSTy = argNode->getEvaluatedSymbolType(manIdx); |
| 151 | |||
| 152 | 24181 | const auto matchFct = [](const QualType &lhsTy, const QualType &rhsTy) { | |
| 153 |
4/4✓ Branch 3 → 4 taken 1142 times.
✓ Branch 3 → 6 taken 23039 times.
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 7 taken 1140 times.
|
24181 | return lhsTy.matches(rhsTy, false, true, true) || lhsTy.matchesInterfaceImplementedByStruct(rhsTy); |
| 154 | }; | ||
| 155 | |||
| 156 |
3/4✓ Branch 131 → 132 taken 23054 times.
✗ Branch 131 → 454 not taken.
✓ Branch 132 → 133 taken 21914 times.
✓ Branch 132 → 169 taken 1140 times.
|
23054 | if (matchFct(expectedSTy, actualSTy)) { |
| 157 | // Resolve address if actual type is reference, otherwise value | ||
| 158 |
3/4✓ Branch 133 → 134 taken 21914 times.
✗ Branch 133 → 454 not taken.
✓ Branch 134 → 135 taken 498 times.
✓ Branch 134 → 138 taken 21416 times.
|
21914 | if (actualSTy.isRef()) { |
| 159 |
2/4✓ Branch 135 → 136 taken 498 times.
✗ Branch 135 → 427 not taken.
✓ Branch 136 → 137 taken 498 times.
✗ Branch 136 → 427 not taken.
|
498 | argValues.push_back(resolveAddress(argNode)); |
| 160 | } else { | ||
| 161 |
2/2✓ Branch 138 → 139 taken 14 times.
✓ Branch 138 → 166 taken 21402 times.
|
21416 | if (copyCtor) { |
| 162 |
2/4✓ Branch 139 → 140 taken 14 times.
✗ Branch 139 → 447 not taken.
✗ Branch 140 → 141 not taken.
✓ Branch 140 → 142 taken 14 times.
|
14 | assert(!actualSTy.isTriviallyCopyable(node)); |
| 163 |
1/2✓ Branch 142 → 143 taken 14 times.
✗ Branch 142 → 447 not taken.
|
14 | llvm::Value *originalPtr = resolveAddress(argNode); |
| 164 | |||
| 165 | // Generate copy ctor call | ||
| 166 |
1/2✓ Branch 143 → 144 taken 14 times.
✗ Branch 143 → 447 not taken.
|
14 | llvm::Type *valueType = actualSTy.toLLVMType(sourceFile); |
| 167 |
2/4✓ Branch 146 → 147 taken 14 times.
✗ Branch 146 → 430 not taken.
✓ Branch 147 → 148 taken 14 times.
✗ Branch 147 → 428 not taken.
|
14 | llvm::Value *valueCopyPtr = insertAlloca(valueType, "arg.copy"); |
| 168 |
2/4✓ Branch 152 → 153 taken 14 times.
✗ Branch 152 → 436 not taken.
✓ Branch 153 → 154 taken 14 times.
✗ Branch 153 → 434 not taken.
|
42 | generateCtorOrDtorCall(valueCopyPtr, copyCtor, {originalPtr}); |
| 169 |
2/4✓ Branch 158 → 159 taken 14 times.
✗ Branch 158 → 443 not taken.
✓ Branch 159 → 160 taken 14 times.
✗ Branch 159 → 441 not taken.
|
14 | llvm::Value *newValue = insertLoad(valueType, valueCopyPtr); |
| 170 | |||
| 171 | // Attach address of copy to anonymous symbol | ||
| 172 |
1/2✓ Branch 162 → 163 taken 14 times.
✗ Branch 162 → 447 not taken.
|
14 | SymbolTableEntry *anonymousSymbol = currentScope->symbolTable.lookupAnonymous(argNode->codeLoc, SIZE_MAX); |
| 173 |
1/2✓ Branch 163 → 164 taken 14 times.
✗ Branch 163 → 447 not taken.
|
14 | anonymousSymbol->updateAddress(valueCopyPtr); |
| 174 | |||
| 175 |
1/2✓ Branch 164 → 165 taken 14 times.
✗ Branch 164 → 447 not taken.
|
14 | argValues.push_back(newValue); |
| 176 | } else { | ||
| 177 |
2/4✓ Branch 166 → 167 taken 21402 times.
✗ Branch 166 → 448 not taken.
✓ Branch 167 → 168 taken 21402 times.
✗ Branch 167 → 448 not taken.
|
21402 | argValues.push_back(resolveValue(argNode)); |
| 178 | } | ||
| 179 | } | ||
| 180 |
8/12✓ Branch 169 → 170 taken 1140 times.
✗ Branch 169 → 449 not taken.
✓ Branch 170 → 171 taken 980 times.
✓ Branch 170 → 175 taken 160 times.
✓ Branch 171 → 172 taken 980 times.
✗ Branch 171 → 449 not taken.
✓ Branch 172 → 173 taken 980 times.
✗ Branch 172 → 449 not taken.
✓ Branch 173 → 174 taken 980 times.
✗ Branch 173 → 175 not taken.
✓ Branch 176 → 177 taken 980 times.
✓ Branch 176 → 180 taken 160 times.
|
1140 | } else if (expectedSTy.isRef() && matchFct(expectedSTy.getContained(), actualSTy)) { // Matches with ref |
| 181 |
1/2✓ Branch 177 → 178 taken 980 times.
✗ Branch 177 → 450 not taken.
|
980 | llvm::Value *argAddress = resolveAddress(argNode); |
| 182 |
1/2✓ Branch 178 → 179 taken 980 times.
✗ Branch 178 → 450 not taken.
|
980 | argValues.push_back(argAddress); |
| 183 |
8/12✓ Branch 180 → 181 taken 160 times.
✗ Branch 180 → 451 not taken.
✓ Branch 181 → 182 taken 147 times.
✓ Branch 181 → 186 taken 13 times.
✓ Branch 182 → 183 taken 147 times.
✗ Branch 182 → 451 not taken.
✓ Branch 183 → 184 taken 147 times.
✗ Branch 183 → 451 not taken.
✓ Branch 184 → 185 taken 147 times.
✗ Branch 184 → 186 not taken.
✓ Branch 187 → 188 taken 147 times.
✓ Branch 187 → 191 taken 13 times.
|
160 | } else if (actualSTy.isRef() && matchFct(expectedSTy, actualSTy.getContained())) { // Matches with ref |
| 184 |
1/2✓ Branch 188 → 189 taken 147 times.
✗ Branch 188 → 452 not taken.
|
147 | llvm::Value *argAddress = resolveValue(argNode); |
| 185 |
1/2✓ Branch 189 → 190 taken 147 times.
✗ Branch 189 → 452 not taken.
|
147 | argValues.push_back(argAddress); |
| 186 | } else { // Need implicit cast | ||
| 187 |
1/2✓ Branch 191 → 192 taken 13 times.
✗ Branch 191 → 454 not taken.
|
13 | llvm::Value *argAddress = resolveAddress(argNode); |
| 188 |
2/4✓ Branch 192 → 193 taken 13 times.
✗ Branch 192 → 453 not taken.
✓ Branch 193 → 194 taken 13 times.
✗ Branch 193 → 453 not taken.
|
13 | argValues.push_back(doImplicitCast(argAddress, expectedSTy, actualSTy)); |
| 189 | } | ||
| 190 | } | ||
| 191 | 13116 | } | |
| 192 | |||
| 193 | // Retrieve return and param types | ||
| 194 |
1/2✓ Branch 201 → 202 taken 16688 times.
✗ Branch 201 → 522 not taken.
|
16688 | QualType returnSType(TY_DYN); |
| 195 | 16688 | QualTypeList paramSTypes; | |
| 196 |
2/2✓ Branch 203 → 204 taken 45 times.
✓ Branch 203 → 217 taken 16643 times.
|
16688 | if (data.isFctPtrCall()) { |
| 197 |
4/6✓ Branch 204 → 205 taken 45 times.
✗ Branch 204 → 520 not taken.
✓ Branch 205 → 206 taken 45 times.
✗ Branch 205 → 520 not taken.
✓ Branch 206 → 207 taken 19 times.
✓ Branch 206 → 211 taken 26 times.
|
45 | if (firstFragEntry->getQualType().isBase(TY_FUNCTION)) |
| 198 |
3/6✓ Branch 207 → 208 taken 19 times.
✗ Branch 207 → 460 not taken.
✓ Branch 208 → 209 taken 19 times.
✗ Branch 208 → 460 not taken.
✓ Branch 209 → 210 taken 19 times.
✗ Branch 209 → 460 not taken.
|
19 | returnSType = firstFragEntry->getQualType().getBase().getFunctionReturnType(); |
| 199 |
3/6✓ Branch 211 → 212 taken 45 times.
✗ Branch 211 → 461 not taken.
✓ Branch 212 → 213 taken 45 times.
✗ Branch 212 → 461 not taken.
✓ Branch 213 → 214 taken 45 times.
✗ Branch 213 → 461 not taken.
|
45 | paramSTypes = firstFragEntry->getQualType().getBase().getFunctionParamTypes(); |
| 200 | } else { | ||
| 201 | 16643 | returnSType = spiceFunc->returnType; | |
| 202 |
1/2✓ Branch 217 → 218 taken 16643 times.
✗ Branch 217 → 463 not taken.
|
16643 | paramSTypes = spiceFunc->getParamTypes(); |
| 203 | } | ||
| 204 | |||
| 205 | // Function is not defined in the current module -> declare it | ||
| 206 | llvm::FunctionType *fctType; | ||
| 207 |
3/4✓ Branch 222 → 223 taken 16688 times.
✗ Branch 222 → 464 not taken.
✓ Branch 223 → 224 taken 13842 times.
✓ Branch 223 → 226 taken 2846 times.
|
16688 | if (llvm::Function *fct = module->getFunction(mangledName)) { |
| 208 |
1/2✓ Branch 224 → 225 taken 13842 times.
✗ Branch 224 → 520 not taken.
|
13842 | fctType = fct->getFunctionType(); |
| 209 | } else { | ||
| 210 | // Get returnType | ||
| 211 |
1/2✓ Branch 226 → 227 taken 2846 times.
✗ Branch 226 → 473 not taken.
|
2846 | llvm::Type *returnType = builder.getVoidTy(); |
| 212 |
3/4✓ Branch 227 → 228 taken 2846 times.
✗ Branch 227 → 473 not taken.
✓ Branch 228 → 229 taken 1734 times.
✓ Branch 228 → 231 taken 1112 times.
|
2846 | if (!returnSType.is(TY_DYN)) |
| 213 |
1/2✓ Branch 229 → 230 taken 1734 times.
✗ Branch 229 → 473 not taken.
|
1734 | returnType = returnSType.toLLVMType(sourceFile); |
| 214 | |||
| 215 | // Get arg types | ||
| 216 | 2846 | std::vector<llvm::Type *> argTypes; | |
| 217 |
6/6✓ Branch 232 → 233 taken 1574 times.
✓ Branch 232 → 235 taken 1272 times.
✓ Branch 234 → 235 taken 508 times.
✓ Branch 234 → 236 taken 1066 times.
✓ Branch 237 → 238 taken 1780 times.
✓ Branch 237 → 241 taken 1066 times.
|
2846 | if (data.isMethodCall() || data.isCtorCall()) |
| 218 |
2/4✓ Branch 238 → 239 taken 1780 times.
✗ Branch 238 → 465 not taken.
✓ Branch 239 → 240 taken 1780 times.
✗ Branch 239 → 465 not taken.
|
1780 | argTypes.push_back(builder.getPtrTy()); // This pointer |
| 219 |
8/10✓ Branch 242 → 243 taken 45 times.
✓ Branch 242 → 247 taken 2801 times.
✓ Branch 243 → 244 taken 45 times.
✗ Branch 243 → 471 not taken.
✓ Branch 244 → 245 taken 45 times.
✗ Branch 244 → 471 not taken.
✓ Branch 245 → 246 taken 16 times.
✓ Branch 245 → 247 taken 29 times.
✓ Branch 248 → 249 taken 16 times.
✓ Branch 248 → 252 taken 2830 times.
|
2846 | if (data.isFctPtrCall() && firstFragEntry->getQualType().hasLambdaCaptures()) |
| 220 |
2/4✓ Branch 249 → 250 taken 16 times.
✗ Branch 249 → 466 not taken.
✓ Branch 250 → 251 taken 16 times.
✗ Branch 250 → 466 not taken.
|
16 | argTypes.push_back(builder.getPtrTy()); // Capture pointer |
| 221 |
2/2✓ Branch 259 → 254 taken 2711 times.
✓ Branch 259 → 260 taken 2846 times.
|
5557 | for (const QualType ¶mType : paramSTypes) |
| 222 |
2/4✓ Branch 255 → 256 taken 2711 times.
✗ Branch 255 → 467 not taken.
✓ Branch 256 → 257 taken 2711 times.
✗ Branch 256 → 467 not taken.
|
2711 | argTypes.push_back(paramType.toLLVMType(sourceFile)); |
| 223 | |||
| 224 |
1/2✓ Branch 261 → 262 taken 2846 times.
✗ Branch 261 → 469 not taken.
|
2846 | fctType = llvm::FunctionType::get(returnType, argTypes, false); |
| 225 |
7/8✓ Branch 263 → 264 taken 2801 times.
✓ Branch 263 → 267 taken 45 times.
✓ Branch 264 → 265 taken 2801 times.
✗ Branch 264 → 471 not taken.
✓ Branch 265 → 266 taken 2784 times.
✓ Branch 265 → 267 taken 17 times.
✓ Branch 268 → 269 taken 2784 times.
✓ Branch 268 → 272 taken 62 times.
|
2846 | if (!data.isFctPtrCall() && !data.isVirtualMethodCall()) |
| 226 |
1/2✓ Branch 270 → 271 taken 2784 times.
✗ Branch 270 → 470 not taken.
|
2784 | module->getOrInsertFunction(mangledName, fctType); |
| 227 | 2846 | } | |
| 228 |
1/2✗ Branch 274 → 275 not taken.
✓ Branch 274 → 276 taken 16688 times.
|
16688 | assert(fctType != nullptr); |
| 229 | |||
| 230 | llvm::CallInst *callInst; | ||
| 231 |
3/4✓ Branch 276 → 277 taken 16688 times.
✗ Branch 276 → 520 not taken.
✓ Branch 277 → 278 taken 17 times.
✓ Branch 277 → 310 taken 16671 times.
|
16688 | if (data.isVirtualMethodCall()) { |
| 232 |
1/2✗ Branch 278 → 279 not taken.
✓ Branch 278 → 280 taken 17 times.
|
17 | assert(data.callee->isVirtual); |
| 233 |
1/2✗ Branch 280 → 281 not taken.
✓ Branch 280 → 282 taken 17 times.
|
17 | assert(thisPtr != nullptr); |
| 234 | // Load VTable | ||
| 235 |
3/6✓ Branch 284 → 285 taken 17 times.
✗ Branch 284 → 476 not taken.
✓ Branch 285 → 286 taken 17 times.
✗ Branch 285 → 474 not taken.
✓ Branch 286 → 287 taken 17 times.
✗ Branch 286 → 474 not taken.
|
17 | llvm::Value *vtablePtr = insertLoad(builder.getPtrTy(), thisPtr, false, "vtable.addr"); |
| 236 | 17 | const size_t vtableIndex = data.callee->vtableIndex; | |
| 237 | // Lookup function pointer in VTable | ||
| 238 |
4/8✓ Branch 291 → 292 taken 17 times.
✗ Branch 291 → 484 not taken.
✓ Branch 292 → 293 taken 17 times.
✗ Branch 292 → 480 not taken.
✓ Branch 294 → 295 taken 17 times.
✗ Branch 294 → 480 not taken.
✓ Branch 295 → 296 taken 17 times.
✗ Branch 295 → 480 not taken.
|
34 | fctPtr = insertInBoundsGEP(builder.getPtrTy(), vtablePtr, builder.getInt64(vtableIndex), "vfct.addr"); |
| 239 |
3/6✓ Branch 300 → 301 taken 17 times.
✗ Branch 300 → 490 not taken.
✓ Branch 301 → 302 taken 17 times.
✗ Branch 301 → 488 not taken.
✓ Branch 302 → 303 taken 17 times.
✗ Branch 302 → 488 not taken.
|
17 | llvm::Value *fct = insertLoad(builder.getPtrTy(), fctPtr, false, "fct"); |
| 240 | |||
| 241 | // Generate function call | ||
| 242 |
2/4✓ Branch 305 → 306 taken 17 times.
✗ Branch 305 → 496 not taken.
✓ Branch 308 → 309 taken 17 times.
✗ Branch 308 → 494 not taken.
|
17 | callInst = builder.CreateCall({fctType, fct}, argValues); |
| 243 |
2/2✓ Branch 311 → 312 taken 45 times.
✓ Branch 311 → 331 taken 16626 times.
|
16671 | } else if (data.isFctPtrCall()) { |
| 244 |
1/2✗ Branch 312 → 313 not taken.
✓ Branch 312 → 314 taken 45 times.
|
45 | assert(firstFragEntry != nullptr); |
| 245 |
1/2✓ Branch 314 → 315 taken 45 times.
✗ Branch 314 → 506 not taken.
|
45 | QualType firstFragType = firstFragEntry->getQualType(); |
| 246 |
1/2✗ Branch 315 → 316 not taken.
✓ Branch 315 → 318 taken 45 times.
|
45 | if (!fctPtr) |
| 247 | ✗ | fctPtr = firstFragEntry->getAddress(); | |
| 248 |
1/2✓ Branch 318 → 319 taken 45 times.
✗ Branch 318 → 506 not taken.
|
45 | autoDeReferencePtr(fctPtr, firstFragType); |
| 249 |
3/6✓ Branch 321 → 322 taken 45 times.
✗ Branch 321 → 499 not taken.
✓ Branch 322 → 323 taken 45 times.
✗ Branch 322 → 497 not taken.
✓ Branch 323 → 324 taken 45 times.
✗ Branch 323 → 497 not taken.
|
45 | llvm::Value *fct = insertLoad(builder.getPtrTy(), fctPtr, false, "fct"); |
| 250 | |||
| 251 | // Generate function call | ||
| 252 |
2/4✓ Branch 326 → 327 taken 45 times.
✗ Branch 326 → 505 not taken.
✓ Branch 329 → 330 taken 45 times.
✗ Branch 329 → 503 not taken.
|
45 | callInst = builder.CreateCall({fctType, fct}, argValues); |
| 253 | } else { | ||
| 254 | // Get callee function | ||
| 255 |
1/2✓ Branch 332 → 333 taken 16626 times.
✗ Branch 332 → 507 not taken.
|
16626 | llvm::Function *callee = module->getFunction(mangledName); |
| 256 |
1/2✗ Branch 333 → 334 not taken.
✓ Branch 333 → 335 taken 16626 times.
|
16626 | assert(callee != nullptr); |
| 257 | |||
| 258 | // Generate function call | ||
| 259 |
3/6✓ Branch 335 → 336 taken 16626 times.
✗ Branch 335 → 510 not taken.
✓ Branch 337 → 338 taken 16626 times.
✗ Branch 337 → 508 not taken.
✓ Branch 338 → 339 taken 16626 times.
✗ Branch 338 → 508 not taken.
|
16626 | callInst = builder.CreateCall(callee, argValues); |
| 260 | } | ||
| 261 | |||
| 262 | // Set argument and return value attributes | ||
| 263 |
2/2✓ Branch 341 → 342 taken 16643 times.
✓ Branch 341 → 344 taken 45 times.
|
16688 | if (!data.isFctPtrCall()) { |
| 264 |
1/2✓ Branch 342 → 343 taken 16643 times.
✗ Branch 342 → 520 not taken.
|
16643 | setCallArgAttrs(callInst, spiceFunc, paramSTypes); |
| 265 |
1/2✓ Branch 343 → 344 taken 16643 times.
✗ Branch 343 → 520 not taken.
|
16643 | setCallReturnValAttrs(callInst, returnSType); |
| 266 | } | ||
| 267 | |||
| 268 | // Attach address to anonymous symbol to keep track of de-allocation | ||
| 269 | 16688 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 270 | 16688 | llvm::Value *resultPtr = nullptr; | |
| 271 |
7/8✓ Branch 344 → 345 taken 16688 times.
✗ Branch 344 → 520 not taken.
✓ Branch 345 → 346 taken 15745 times.
✓ Branch 345 → 348 taken 943 times.
✓ Branch 347 → 348 taken 2334 times.
✓ Branch 347 → 349 taken 13411 times.
✓ Branch 350 → 351 taken 3277 times.
✓ Branch 350 → 365 taken 13411 times.
|
16688 | if (returnSType.is(TY_STRUCT) || data.isCtorCall()) { |
| 272 |
1/2✓ Branch 351 → 352 taken 3277 times.
✗ Branch 351 → 520 not taken.
|
3277 | anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node->codeLoc); |
| 273 |
2/2✓ Branch 352 → 353 taken 261 times.
✓ Branch 352 → 365 taken 3016 times.
|
3277 | if (anonymousSymbol != nullptr) { |
| 274 |
2/2✓ Branch 354 → 355 taken 179 times.
✓ Branch 354 → 356 taken 82 times.
|
261 | if (data.isCtorCall()) { |
| 275 |
1/2✓ Branch 355 → 365 taken 179 times.
✗ Branch 355 → 520 not taken.
|
179 | anonymousSymbol->updateAddress(thisPtr); |
| 276 | } else { | ||
| 277 |
1/2✓ Branch 360 → 361 taken 82 times.
✗ Branch 360 → 511 not taken.
|
82 | resultPtr = insertAlloca(callInst->getType()); |
| 278 |
1/2✓ Branch 363 → 364 taken 82 times.
✗ Branch 363 → 520 not taken.
|
82 | insertStore(callInst, resultPtr); |
| 279 |
1/2✓ Branch 364 → 365 taken 82 times.
✗ Branch 364 → 520 not taken.
|
82 | anonymousSymbol->updateAddress(resultPtr); |
| 280 | } | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | // In case this is a constructor call, return the thisPtr as pointer | ||
| 285 |
2/2✓ Branch 366 → 367 taken 2334 times.
✓ Branch 366 → 370 taken 14354 times.
|
16688 | if (data.isCtorCall()) |
| 286 |
1/2✓ Branch 367 → 368 taken 2334 times.
✗ Branch 367 → 517 not taken.
|
4668 | return LLVMExprResult{.ptr = thisPtr, .refPtr = resultPtr, .entry = anonymousSymbol}; |
| 287 | |||
| 288 | // In case this is a callee, returning a reference, return the address | ||
| 289 |
3/4✓ Branch 370 → 371 taken 14354 times.
✗ Branch 370 → 520 not taken.
✓ Branch 371 → 372 taken 696 times.
✓ Branch 371 → 375 taken 13658 times.
|
14354 | if (returnSType.isRef()) |
| 290 |
1/2✓ Branch 372 → 373 taken 696 times.
✗ Branch 372 → 518 not taken.
|
1392 | return LLVMExprResult{.ptr = callInst, .refPtr = resultPtr, .entry = anonymousSymbol}; |
| 291 | |||
| 292 | // Otherwise return the value | ||
| 293 |
1/2✓ Branch 375 → 376 taken 13658 times.
✗ Branch 375 → 519 not taken.
|
27316 | return LLVMExprResult{.value = callInst, .ptr = resultPtr, .entry = anonymousSymbol}; |
| 294 | 16688 | } | |
| 295 | |||
| 296 | 16643 | void IRGenerator::setCallArgAttrs(llvm::CallInst *callInst, const Function *spiceFunc, const QualTypeList ¶mSTypes) const { | |
| 297 | 16643 | const bool isFctPtr = spiceFunc == nullptr; | |
| 298 |
3/4✓ Branch 2 → 3 taken 16643 times.
✗ Branch 2 → 6 not taken.
✓ Branch 4 → 5 taken 8424 times.
✓ Branch 4 → 6 taken 8219 times.
|
16643 | const bool isMethod = !isFctPtr && !spiceFunc->thisType.is(TY_DYN); |
| 299 |
3/4✓ Branch 7 → 8 taken 8219 times.
✓ Branch 7 → 9 taken 8424 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 8219 times.
|
16643 | const size_t expectedParamCount = isMethod || isFctPtr ? paramSTypes.size() + 1 : paramSTypes.size(); |
| 300 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 16643 times.
|
16643 | assert(callInst->arg_size() == expectedParamCount); |
| 301 |
2/2✓ Branch 48 → 16 taken 31451 times.
✓ Branch 48 → 49 taken 16643 times.
|
48094 | for (size_t i = 0; i < expectedParamCount; i++) { |
| 302 |
8/10✓ Branch 16 → 17 taken 16465 times.
✓ Branch 16 → 20 taken 14986 times.
✓ Branch 17 → 18 taken 8424 times.
✓ Branch 17 → 20 taken 8041 times.
✓ Branch 18 → 19 taken 8424 times.
✗ Branch 18 → 52 not taken.
✓ Branch 20 → 21 taken 6712 times.
✓ Branch 20 → 22 taken 16315 times.
✓ Branch 23 → 24 taken 23027 times.
✗ Branch 23 → 52 not taken.
|
31451 | const QualType ¶mType = i == 0 && isMethod ? spiceFunc->thisType.toPtr(nullptr) : paramSTypes.at(isMethod ? i - 1 : i); |
| 303 | |||
| 304 | // NoUndef attribute | ||
| 305 |
1/2✓ Branch 25 → 26 taken 31451 times.
✗ Branch 25 → 52 not taken.
|
31451 | callInst->addParamAttr(i, llvm::Attribute::NoUndef); |
| 306 | |||
| 307 |
3/4✓ Branch 26 → 27 taken 31451 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 11368 times.
✓ Branch 27 → 44 taken 20083 times.
|
31451 | if (paramType.isPtr()) { |
| 308 | // NonNull attribute | ||
| 309 |
4/4✓ Branch 28 → 29 taken 10031 times.
✓ Branch 28 → 31 taken 1337 times.
✓ Branch 29 → 30 taken 8424 times.
✓ Branch 29 → 31 taken 1607 times.
|
11368 | if (i == 0 && isMethod) |
| 310 |
1/2✓ Branch 30 → 31 taken 8424 times.
✗ Branch 30 → 52 not taken.
|
8424 | callInst->addParamAttr(i, llvm::Attribute::NonNull); |
| 311 | // Dereferenceable attribute | ||
| 312 |
2/4✓ Branch 31 → 32 taken 11368 times.
✗ Branch 31 → 50 not taken.
✓ Branch 32 → 33 taken 11368 times.
✗ Branch 32 → 50 not taken.
|
11368 | llvm::Type *pointeeType = paramType.getContained().toLLVMType(sourceFile); |
| 313 |
1/2✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 11368 times.
|
11368 | assert(pointeeType != nullptr); |
| 314 |
4/8✓ Branch 35 → 36 taken 11368 times.
✗ Branch 35 → 51 not taken.
✓ Branch 37 → 38 taken 11368 times.
✗ Branch 37 → 51 not taken.
✓ Branch 38 → 39 taken 11368 times.
✗ Branch 38 → 51 not taken.
✓ Branch 39 → 40 taken 11368 times.
✗ Branch 39 → 51 not taken.
|
11368 | callInst->addDereferenceableParamAttr(i, callInst->getModule()->getDataLayout().getTypeStoreSize(pointeeType)); |
| 315 | // Alignment attribute | ||
| 316 |
3/6✓ Branch 41 → 42 taken 11368 times.
✗ Branch 41 → 52 not taken.
✓ Branch 42 → 43 taken 11368 times.
✗ Branch 42 → 52 not taken.
✓ Branch 43 → 44 taken 11368 times.
✗ Branch 43 → 52 not taken.
|
11368 | callInst->addParamAttr(i, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(pointeeType))); |
| 317 | } | ||
| 318 | |||
| 319 | // ZExt or SExt attribute | ||
| 320 |
3/4✓ Branch 44 → 45 taken 31451 times.
✗ Branch 44 → 52 not taken.
✓ Branch 45 → 46 taken 5881 times.
✓ Branch 45 → 47 taken 25570 times.
|
31451 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(paramType); extAttrKind != llvm::Attribute::None) |
| 321 |
1/2✓ Branch 46 → 47 taken 5881 times.
✗ Branch 46 → 52 not taken.
|
5881 | callInst->addParamAttr(i, extAttrKind); |
| 322 | } | ||
| 323 | 16643 | } | |
| 324 | |||
| 325 | 16643 | void IRGenerator::setCallReturnValAttrs(llvm::CallInst *callInst, const QualType &returnType) const { | |
| 326 |
2/2✓ Branch 3 → 4 taken 6684 times.
✓ Branch 3 → 5 taken 9959 times.
|
16643 | if (returnType.is(TY_DYN)) |
| 327 | 6684 | return; | |
| 328 | |||
| 329 | // NoUndef attribute | ||
| 330 | 9959 | callInst->addRetAttr(llvm::Attribute::NoUndef); | |
| 331 | // ZExt or SExt attribute | ||
| 332 |
2/2✓ Branch 7 → 8 taken 2808 times.
✓ Branch 7 → 9 taken 7151 times.
|
9959 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(returnType); extAttrKind != llvm::Attribute::None) |
| 333 | 2808 | callInst->addRetAttr(extAttrKind); | |
| 334 | } | ||
| 335 | |||
| 336 | 59 | std::any IRGenerator::visitArrayInitialization(const ArrayInitializationNode *node) { | |
| 337 | // Return immediately if the initialization is empty | ||
| 338 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 59 times.
|
59 | if (node->actualSize == 0) |
| 339 | ✗ | return LLVMExprResult{.node = node}; | |
| 340 | |||
| 341 | // Visit array items | ||
| 342 | 59 | bool canBeConstant = true; | |
| 343 | 59 | std::vector<LLVMExprResult> itemResults; | |
| 344 |
1/2✓ Branch 6 → 7 taken 59 times.
✗ Branch 6 → 132 not taken.
|
59 | itemResults.reserve(node->actualSize); |
| 345 |
2/2✓ Branch 16 → 9 taken 373 times.
✓ Branch 16 → 17 taken 59 times.
|
432 | for (const AssignExprNode *itemNode : node->itemLst->args) { |
| 346 |
2/4✓ Branch 10 → 11 taken 373 times.
✗ Branch 10 → 94 not taken.
✓ Branch 11 → 12 taken 373 times.
✗ Branch 11 → 92 not taken.
|
373 | auto item = std::any_cast<LLVMExprResult>(visit(itemNode)); |
| 347 | 373 | canBeConstant &= item.constant != nullptr; | |
| 348 | 373 | item.node = itemNode; | |
| 349 |
1/2✓ Branch 13 → 14 taken 373 times.
✗ Branch 13 → 95 not taken.
|
373 | itemResults.push_back(item); |
| 350 | } | ||
| 351 | |||
| 352 | // Get LLVM type of item and array | ||
| 353 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 59 times.
|
59 | assert(!itemResults.empty()); |
| 354 |
1/2✓ Branch 21 → 22 taken 59 times.
✗ Branch 21 → 132 not taken.
|
59 | const QualType &firstItemSTy = node->itemLst->args.front()->getEvaluatedSymbolType(manIdx); |
| 355 |
1/2✓ Branch 22 → 23 taken 59 times.
✗ Branch 22 → 132 not taken.
|
59 | llvm::Type *itemType = firstItemSTy.toLLVMType(sourceFile); |
| 356 |
1/2✓ Branch 23 → 24 taken 59 times.
✗ Branch 23 → 132 not taken.
|
59 | llvm::ArrayType *arrayType = llvm::ArrayType::get(itemType, node->actualSize); |
| 357 | |||
| 358 |
2/2✓ Branch 24 → 25 taken 57 times.
✓ Branch 24 → 50 taken 2 times.
|
59 | if (canBeConstant) { // All items are constants, so we can create a global constant array |
| 359 | // Collect constants | ||
| 360 | 57 | std::vector<llvm::Constant *> constants; | |
| 361 |
2/2✓ Branch 37 → 27 taken 368 times.
✓ Branch 37 → 38 taken 57 times.
|
425 | for (const LLVMExprResult &exprResult : itemResults) { |
| 362 | // Delete potential constant globals, that were already created a layer below | ||
| 363 |
2/2✓ Branch 30 → 31 taken 22 times.
✓ Branch 30 → 34 taken 346 times.
|
368 | if (exprResult.constant->getType()->isArrayTy()) |
| 364 |
3/6✓ Branch 31 → 32 taken 22 times.
✗ Branch 31 → 97 not taken.
✓ Branch 32 → 33 taken 22 times.
✗ Branch 32 → 97 not taken.
✓ Branch 33 → 34 taken 22 times.
✗ Branch 33 → 97 not taken.
|
22 | module->getNamedGlobal(exprResult.ptr->getName())->eraseFromParent(); |
| 365 |
1/2✓ Branch 34 → 35 taken 368 times.
✗ Branch 34 → 97 not taken.
|
368 | constants.push_back(exprResult.constant); |
| 366 | } | ||
| 367 | |||
| 368 | // Create global array | ||
| 369 |
1/2✓ Branch 39 → 40 taken 57 times.
✗ Branch 39 → 98 not taken.
|
57 | llvm::Constant *constantArray = llvm::ConstantArray::get(arrayType, constants); |
| 370 |
2/4✓ Branch 42 → 43 taken 57 times.
✗ Branch 42 → 101 not taken.
✓ Branch 43 → 44 taken 57 times.
✗ Branch 43 → 99 not taken.
|
57 | llvm::Value *arrayAddr = createGlobalConst(ANON_GLOBAL_ARRAY_NAME, constantArray); |
| 371 | |||
| 372 |
1/2✓ Branch 46 → 47 taken 57 times.
✗ Branch 46 → 105 not taken.
|
57 | return LLVMExprResult{.constant = constantArray, .ptr = arrayAddr}; |
| 373 | 57 | } else { // We have non-immediate values as items, so we need to take normal arrays as fallback | |
| 374 |
1/2✓ Branch 53 → 54 taken 2 times.
✗ Branch 53 → 109 not taken.
|
2 | llvm::Value *arrayAddr = insertAlloca(arrayType); |
| 375 | |||
| 376 | // Retrieve address of first item | ||
| 377 |
2/4✓ Branch 59 → 60 taken 2 times.
✗ Branch 59 → 115 not taken.
✓ Branch 61 → 62 taken 2 times.
✗ Branch 61 → 115 not taken.
|
2 | llvm::Value *firstItemAddress = insertInBoundsGEP(arrayType, arrayAddr, builder.getInt64(0)); |
| 378 | |||
| 379 | // Store all array items at their corresponding offsets | ||
| 380 | 2 | llvm::Value *currentItemAddress = firstItemAddress; | |
| 381 |
2/2✓ Branch 84 → 65 taken 5 times.
✓ Branch 84 → 85 taken 2 times.
|
7 | for (size_t i = 0; i < itemResults.size(); i++) { |
| 382 | 5 | LLVMExprResult &exprResult = itemResults[i]; | |
| 383 |
1/2✓ Branch 66 → 67 taken 5 times.
✗ Branch 66 → 132 not taken.
|
5 | llvm::Value *itemValue = resolveValue(exprResult.node, exprResult); |
| 384 | // Retrieve current item address | ||
| 385 |
2/2✓ Branch 67 → 68 taken 3 times.
✓ Branch 67 → 77 taken 2 times.
|
5 | if (i >= 1) |
| 386 |
2/4✓ Branch 71 → 72 taken 3 times.
✗ Branch 71 → 123 not taken.
✓ Branch 73 → 74 taken 3 times.
✗ Branch 73 → 123 not taken.
|
3 | currentItemAddress = insertInBoundsGEP(itemType, currentItemAddress, builder.getInt64(1)); |
| 387 | // Store the item value | ||
| 388 |
3/4✓ Branch 77 → 78 taken 3 times.
✓ Branch 77 → 80 taken 2 times.
✗ Branch 78 → 79 not taken.
✓ Branch 78 → 80 taken 3 times.
|
5 | const bool storeVolatile = exprResult.entry != nullptr && exprResult.entry->isVolatile; |
| 389 |
1/2✓ Branch 81 → 82 taken 5 times.
✗ Branch 81 → 132 not taken.
|
5 | insertStore(itemValue, currentItemAddress, storeVolatile); |
| 390 | } | ||
| 391 | |||
| 392 |
1/2✓ Branch 85 → 86 taken 2 times.
✗ Branch 85 → 131 not taken.
|
4 | return LLVMExprResult{.ptr = arrayAddr}; |
| 393 | } | ||
| 394 | 59 | } | |
| 395 | |||
| 396 | 281 | std::any IRGenerator::visitStructInstantiation(const StructInstantiationNode *node) { | |
| 397 | // Get struct object | ||
| 398 |
1/2✓ Branch 2 → 3 taken 281 times.
✗ Branch 2 → 138 not taken.
|
281 | const Struct *spiceStruct = node->instantiatedStructs.at(manIdx); |
| 399 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 281 times.
|
281 | assert(spiceStruct != nullptr); |
| 400 | 281 | const QualTypeList &fieldTypes = spiceStruct->fieldTypes; | |
| 401 | |||
| 402 | // Can only be constant if none of the fields is of type reference | ||
| 403 |
1/2✓ Branch 5 → 6 taken 281 times.
✗ Branch 5 → 138 not taken.
|
281 | bool canBeConstant = !spiceStruct->hasReferenceFields(); |
| 404 | |||
| 405 | // Get struct type | ||
| 406 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 281 times.
|
281 | assert(spiceStruct->entry != nullptr); |
| 407 |
2/4✓ Branch 8 → 9 taken 281 times.
✗ Branch 8 → 138 not taken.
✓ Branch 9 → 10 taken 281 times.
✗ Branch 9 → 138 not taken.
|
281 | const auto structType = reinterpret_cast<llvm::StructType *>(spiceStruct->entry->getQualType().toLLVMType(sourceFile)); |
| 408 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 281 times.
|
281 | assert(structType != nullptr); |
| 409 | |||
| 410 |
2/2✓ Branch 12 → 13 taken 10 times.
✓ Branch 12 → 18 taken 271 times.
|
281 | if (!node->fieldLst) { |
| 411 |
2/4✓ Branch 13 → 14 taken 10 times.
✗ Branch 13 → 138 not taken.
✓ Branch 14 → 15 taken 10 times.
✗ Branch 14 → 138 not taken.
|
10 | llvm::Constant *constantStruct = getDefaultValueForSymbolType(spiceStruct->entry->getQualType()); |
| 412 |
1/2✓ Branch 15 → 16 taken 10 times.
✗ Branch 15 → 103 not taken.
|
20 | return LLVMExprResult{.constant = constantStruct}; |
| 413 | } | ||
| 414 | |||
| 415 | // Visit struct field values | ||
| 416 | 271 | std::vector<LLVMExprResult> fieldValueResults; | |
| 417 |
1/2✓ Branch 19 → 20 taken 271 times.
✗ Branch 19 → 136 not taken.
|
271 | fieldValueResults.reserve(spiceStruct->fieldTypes.size()); |
| 418 |
2/2✓ Branch 29 → 22 taken 399 times.
✓ Branch 29 → 30 taken 271 times.
|
670 | for (const AssignExprNode *fieldValueNode : node->fieldLst->args) { |
| 419 |
2/4✓ Branch 23 → 24 taken 399 times.
✗ Branch 23 → 106 not taken.
✓ Branch 24 → 25 taken 399 times.
✗ Branch 24 → 104 not taken.
|
399 | auto fieldValue = std::any_cast<LLVMExprResult>(visit(fieldValueNode)); |
| 420 | 399 | fieldValue.node = fieldValueNode; | |
| 421 |
1/2✓ Branch 26 → 27 taken 399 times.
✗ Branch 26 → 107 not taken.
|
399 | fieldValueResults.push_back(fieldValue); |
| 422 | 399 | canBeConstant &= fieldValue.constant != nullptr; | |
| 423 | } | ||
| 424 | |||
| 425 |
2/2✓ Branch 30 → 31 taken 25 times.
✓ Branch 30 → 52 taken 246 times.
|
271 | if (canBeConstant) { // All field values are constants, so we can create a global constant struct instantiation |
| 426 | // Collect constants | ||
| 427 | 25 | std::vector<llvm::Constant *> constants; | |
| 428 | // For each interface a nullptr | ||
| 429 |
1/2✗ Branch 38 → 33 not taken.
✓ Branch 38 → 39 taken 25 times.
|
25 | for (const QualType &interfaceType : spiceStruct->interfaceTypes) |
| 430 | ✗ | constants.push_back(getDefaultValueForSymbolType(interfaceType)); | |
| 431 | // Constant value for each field | ||
| 432 |
2/2✓ Branch 45 → 41 taken 80 times.
✓ Branch 45 → 46 taken 25 times.
|
105 | for (const LLVMExprResult &exprResult : fieldValueResults) |
| 433 |
1/2✓ Branch 42 → 43 taken 80 times.
✗ Branch 42 → 111 not taken.
|
80 | constants.push_back(exprResult.constant); |
| 434 | |||
| 435 | // Create global constant struct | ||
| 436 |
1/2✓ Branch 47 → 48 taken 25 times.
✗ Branch 47 → 112 not taken.
|
25 | llvm::Constant *constantStruct = llvm::ConstantStruct::get(structType, constants); |
| 437 | |||
| 438 |
1/2✓ Branch 48 → 49 taken 25 times.
✗ Branch 48 → 113 not taken.
|
25 | return LLVMExprResult{.constant = constantStruct}; |
| 439 | 25 | } else { // We have at least one non-immediate value, so we need to take normal struct instantiation as fallback | |
| 440 |
1/2✓ Branch 55 → 56 taken 246 times.
✗ Branch 55 → 117 not taken.
|
246 | llvm::Value *structAddr = insertAlloca(structType); |
| 441 | 246 | const size_t interfaceCount = spiceStruct->interfaceTypes.size(); | |
| 442 | 246 | const size_t fieldCount = spiceStruct->fieldTypes.size(); | |
| 443 | 246 | size_t i = 0; | |
| 444 | |||
| 445 | // Store interface values at their corresponding offsets | ||
| 446 |
1/2✗ Branch 71 → 61 not taken.
✓ Branch 71 → 72 taken 246 times.
|
246 | for (; i < interfaceCount; i++) { |
| 447 | ✗ | const QualType &interfaceType = spiceStruct->interfaceTypes.at(i); | |
| 448 | // Get field value | ||
| 449 | ✗ | llvm::Value *itemValue = getDefaultValueForSymbolType(interfaceType); | |
| 450 | // Get field address | ||
| 451 | ✗ | llvm::Value *currentFieldAddress = insertStructGEP(structType, structAddr, i); | |
| 452 | // Store the item value | ||
| 453 | ✗ | insertStore(itemValue, currentFieldAddress); | |
| 454 | } | ||
| 455 | |||
| 456 | // Store all field values at their corresponding offsets | ||
| 457 |
2/2✓ Branch 93 → 73 taken 319 times.
✓ Branch 93 → 94 taken 246 times.
|
565 | for (; i < interfaceCount + fieldCount; i++) { |
| 458 |
1/2✓ Branch 73 → 74 taken 319 times.
✗ Branch 73 → 136 not taken.
|
319 | LLVMExprResult &exprResult = fieldValueResults.at(i); |
| 459 | // Get field value | ||
| 460 |
6/10✓ Branch 74 → 75 taken 319 times.
✗ Branch 74 → 136 not taken.
✓ Branch 75 → 76 taken 319 times.
✗ Branch 75 → 136 not taken.
✓ Branch 76 → 77 taken 4 times.
✓ Branch 76 → 79 taken 315 times.
✓ Branch 77 → 78 taken 4 times.
✗ Branch 77 → 136 not taken.
✓ Branch 79 → 80 taken 315 times.
✗ Branch 79 → 136 not taken.
|
319 | llvm::Value *itemValue = fieldTypes.at(i).isRef() ? resolveAddress(exprResult) : resolveValue(exprResult.node, exprResult); |
| 461 | // Get field address | ||
| 462 |
1/2✓ Branch 84 → 85 taken 319 times.
✗ Branch 84 → 129 not taken.
|
319 | llvm::Value *currentFieldAddress = insertStructGEP(structType, structAddr, i); |
| 463 | // Store the item value | ||
| 464 |
3/4✓ Branch 87 → 88 taken 107 times.
✓ Branch 87 → 90 taken 212 times.
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 90 taken 107 times.
|
319 | const bool storeVolatile = exprResult.entry != nullptr && exprResult.entry->isVolatile; |
| 465 |
1/2✓ Branch 91 → 92 taken 319 times.
✗ Branch 91 → 136 not taken.
|
319 | insertStore(itemValue, currentFieldAddress, storeVolatile); |
| 466 | } | ||
| 467 | |||
| 468 | // Attach address to anonymous symbol to keep track of de-allocation | ||
| 469 |
1/2✓ Branch 94 → 95 taken 246 times.
✗ Branch 94 → 136 not taken.
|
246 | SymbolTableEntry *returnSymbol = currentScope->symbolTable.lookupAnonymous(node->codeLoc); |
| 470 |
2/2✓ Branch 95 → 96 taken 8 times.
✓ Branch 95 → 97 taken 238 times.
|
246 | if (returnSymbol != nullptr) |
| 471 |
1/2✓ Branch 96 → 97 taken 8 times.
✗ Branch 96 → 136 not taken.
|
8 | returnSymbol->updateAddress(structAddr); |
| 472 | |||
| 473 |
1/2✓ Branch 97 → 98 taken 246 times.
✗ Branch 97 → 135 not taken.
|
492 | return LLVMExprResult{.ptr = structAddr}; |
| 474 | } | ||
| 475 | 271 | } | |
| 476 | |||
| 477 | 12 | std::any IRGenerator::visitLambdaFunc(const LambdaFuncNode *node) { | |
| 478 |
2/4✓ Branch 2 → 3 taken 12 times.
✗ Branch 2 → 232 not taken.
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 232 not taken.
|
12 | Function spiceFunc = node->manifestations.at(manIdx); |
| 479 | 12 | ParamInfoList paramInfoList; | |
| 480 | 12 | std::vector<llvm::Type *> paramTypes; | |
| 481 | |||
| 482 | // Change scope | ||
| 483 |
2/4✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 166 not taken.
✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 164 not taken.
|
12 | Scope *bodyScope = currentScope = currentScope->getChildScope(node->getScopeId()); |
| 484 | |||
| 485 | // If there are captures, we pass them in a struct as the first function argument | ||
| 486 | 12 | const CaptureMap &captures = bodyScope->symbolTable.captures; | |
| 487 | 12 | const bool hasCaptures = !captures.empty(); | |
| 488 | 12 | llvm::Type *capturesStructType = nullptr; | |
| 489 |
2/2✓ Branch 8 → 9 taken 4 times.
✓ Branch 8 → 14 taken 8 times.
|
12 | if (hasCaptures) { |
| 490 | // Create captures struct type | ||
| 491 |
1/2✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 226 not taken.
|
4 | capturesStructType = buildCapturesContainerType(captures); |
| 492 | // Add the captures struct as first parameter | ||
| 493 |
1/2✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 167 not taken.
|
4 | paramInfoList.emplace_back(CAPTURES_PARAM_NAME, nullptr); |
| 494 |
2/4✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 168 not taken.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 168 not taken.
|
4 | paramTypes.push_back(builder.getPtrTy()); // The capture struct is always passed as pointer |
| 495 | } | ||
| 496 | |||
| 497 | // Visit parameters | ||
| 498 | 12 | size_t argIdx = 0; | |
| 499 |
2/2✓ Branch 14 → 15 taken 8 times.
✓ Branch 14 → 33 taken 4 times.
|
12 | if (node->hasParams) { |
| 500 | 8 | const size_t numOfParams = spiceFunc.paramList.size(); | |
| 501 |
1/2✓ Branch 16 → 17 taken 8 times.
✗ Branch 16 → 226 not taken.
|
8 | paramInfoList.reserve(numOfParams); |
| 502 |
1/2✓ Branch 17 → 18 taken 8 times.
✗ Branch 17 → 226 not taken.
|
8 | paramTypes.reserve(numOfParams); |
| 503 |
2/2✓ Branch 32 → 19 taken 14 times.
✓ Branch 32 → 33 taken 8 times.
|
22 | for (; argIdx < numOfParams; argIdx++) { |
| 504 |
1/2✓ Branch 19 → 20 taken 14 times.
✗ Branch 19 → 172 not taken.
|
14 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 505 | // Get symbol table entry of param | ||
| 506 |
1/2✓ Branch 20 → 21 taken 14 times.
✗ Branch 20 → 172 not taken.
|
14 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 507 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 14 times.
|
14 | assert(paramSymbol != nullptr); |
| 508 | // Retrieve type of param | ||
| 509 |
3/6✓ Branch 25 → 26 taken 14 times.
✗ Branch 25 → 171 not taken.
✓ Branch 26 → 27 taken 14 times.
✗ Branch 26 → 169 not taken.
✓ Branch 27 → 28 taken 14 times.
✗ Branch 27 → 169 not taken.
|
14 | llvm::Type *paramType = spiceFunc.getParamTypes().at(argIdx).toLLVMType(sourceFile); |
| 510 | // Add it to the lists | ||
| 511 |
1/2✓ Branch 29 → 30 taken 14 times.
✗ Branch 29 → 172 not taken.
|
14 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 512 |
1/2✓ Branch 30 → 31 taken 14 times.
✗ Branch 30 → 172 not taken.
|
14 | paramTypes.push_back(paramType); |
| 513 | } | ||
| 514 | } | ||
| 515 | |||
| 516 | // Get return type | ||
| 517 |
1/2✓ Branch 33 → 34 taken 12 times.
✗ Branch 33 → 226 not taken.
|
12 | llvm::Type *returnType = spiceFunc.returnType.toLLVMType(sourceFile); |
| 518 | |||
| 519 | // Create function or implement declared function | ||
| 520 |
2/4✓ Branch 34 → 35 taken 12 times.
✗ Branch 34 → 175 not taken.
✓ Branch 35 → 36 taken 12 times.
✗ Branch 35 → 173 not taken.
|
12 | spiceFunc.mangleSuffix = "." + std::to_string(manIdx); |
| 521 |
1/2✓ Branch 39 → 40 taken 12 times.
✗ Branch 39 → 226 not taken.
|
12 | const std::string mangledName = spiceFunc.getMangledName(); |
| 522 |
1/2✓ Branch 41 → 42 taken 12 times.
✗ Branch 41 → 177 not taken.
|
12 | llvm::FunctionType *funcType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 523 |
1/2✓ Branch 43 → 44 taken 12 times.
✗ Branch 43 → 178 not taken.
|
12 | module->getOrInsertFunction(mangledName, funcType); |
| 524 |
1/2✓ Branch 45 → 46 taken 12 times.
✗ Branch 45 → 179 not taken.
|
12 | llvm::Function *lambda = module->getFunction(mangledName); |
| 525 | |||
| 526 | // Set attributes to function | ||
| 527 | 12 | lambda->setDSOLocal(true); | |
| 528 |
1/2✓ Branch 47 → 48 taken 12 times.
✗ Branch 47 → 224 not taken.
|
12 | lambda->setLinkage(llvm::Function::PrivateLinkage); |
| 529 |
1/2✓ Branch 48 → 49 taken 12 times.
✗ Branch 48 → 224 not taken.
|
12 | enableFunctionInstrumentation(lambda); |
| 530 | |||
| 531 | // In case of captures, add attribute to captures argument | ||
| 532 |
2/2✓ Branch 49 → 50 taken 4 times.
✓ Branch 49 → 55 taken 8 times.
|
12 | if (hasCaptures) { |
| 533 |
1/2✓ Branch 50 → 51 taken 4 times.
✗ Branch 50 → 224 not taken.
|
4 | lambda->addParamAttr(0, llvm::Attribute::NoUndef); |
| 534 |
1/2✓ Branch 51 → 52 taken 4 times.
✗ Branch 51 → 224 not taken.
|
4 | lambda->addParamAttr(0, llvm::Attribute::NonNull); |
| 535 |
2/4✓ Branch 53 → 54 taken 4 times.
✗ Branch 53 → 224 not taken.
✓ Branch 54 → 55 taken 4 times.
✗ Branch 54 → 224 not taken.
|
4 | lambda->addDereferenceableParamAttr(0, module->getDataLayout().getPointerSize()); |
| 536 | } | ||
| 537 | |||
| 538 | // Add debug info | ||
| 539 |
1/2✓ Branch 55 → 56 taken 12 times.
✗ Branch 55 → 224 not taken.
|
12 | diGenerator.generateFunctionDebugInfo(lambda, &spiceFunc, true); |
| 540 |
1/2✓ Branch 56 → 57 taken 12 times.
✗ Branch 56 → 224 not taken.
|
12 | diGenerator.setSourceLocation(node); |
| 541 | |||
| 542 | // Save alloca insert markers | ||
| 543 | 12 | llvm::BasicBlock *allocaInsertBlockOrig = allocaInsertBlock; | |
| 544 | 12 | llvm::AllocaInst *allocaInsertInstOrig = allocaInsertInst; | |
| 545 | 12 | llvm::BasicBlock *bOrig = builder.GetInsertBlock(); | |
| 546 | |||
| 547 | // Create entry block | ||
| 548 |
2/4✓ Branch 60 → 61 taken 12 times.
✗ Branch 60 → 182 not taken.
✓ Branch 61 → 62 taken 12 times.
✗ Branch 61 → 180 not taken.
|
12 | llvm::BasicBlock *bEntry = createBlock(); |
| 549 |
1/2✓ Branch 64 → 65 taken 12 times.
✗ Branch 64 → 224 not taken.
|
12 | switchToBlock(bEntry, lambda); |
| 550 | |||
| 551 | // Reset alloca insert markers to this block | ||
| 552 | 12 | allocaInsertBlock = bEntry; | |
| 553 | 12 | allocaInsertInst = nullptr; | |
| 554 | |||
| 555 | // Declare result variable | ||
| 556 |
1/2✓ Branch 67 → 68 taken 12 times.
✗ Branch 67 → 188 not taken.
|
36 | SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 557 |
1/2✗ Branch 73 → 74 not taken.
✓ Branch 73 → 75 taken 12 times.
|
12 | assert(resultEntry != nullptr); |
| 558 |
2/4✓ Branch 77 → 78 taken 12 times.
✗ Branch 77 → 194 not taken.
✓ Branch 78 → 79 taken 12 times.
✗ Branch 78 → 192 not taken.
|
12 | llvm::Value *resultAddr = insertAlloca(returnType, RETURN_VARIABLE_NAME); |
| 559 |
1/2✓ Branch 81 → 82 taken 12 times.
✗ Branch 81 → 224 not taken.
|
12 | resultEntry->updateAddress(resultAddr); |
| 560 | // Generate debug info | ||
| 561 |
2/4✓ Branch 84 → 85 taken 12 times.
✗ Branch 84 → 200 not taken.
✓ Branch 85 → 86 taken 12 times.
✗ Branch 85 → 198 not taken.
|
24 | diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr); |
| 562 | |||
| 563 | // Store function argument values | ||
| 564 | 12 | llvm::Value *captureStructPtrPtr = nullptr; | |
| 565 |
3/4✓ Branch 88 → 89 taken 12 times.
✗ Branch 88 → 210 not taken.
✓ Branch 112 → 91 taken 18 times.
✓ Branch 112 → 113 taken 12 times.
|
30 | for (auto &arg : lambda->args()) { |
| 566 | // Get parameter info | ||
| 567 | 18 | const size_t argNumber = arg.getArgNo(); | |
| 568 |
2/4✓ Branch 92 → 93 taken 18 times.
✗ Branch 92 → 209 not taken.
✓ Branch 93 → 94 taken 18 times.
✗ Branch 93 → 209 not taken.
|
18 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 569 | // Allocate space for it | ||
| 570 |
1/2✓ Branch 96 → 97 taken 18 times.
✗ Branch 96 → 207 not taken.
|
18 | llvm::Type *paramType = funcType->getParamType(argNumber); |
| 571 |
2/4✓ Branch 97 → 98 taken 18 times.
✗ Branch 97 → 206 not taken.
✓ Branch 98 → 99 taken 18 times.
✗ Branch 98 → 204 not taken.
|
18 | llvm::Value *paramAddress = insertAlloca(paramType, paramName); |
| 572 | // Update the symbol table entry | ||
| 573 |
4/4✓ Branch 100 → 101 taken 6 times.
✓ Branch 100 → 103 taken 12 times.
✓ Branch 101 → 102 taken 4 times.
✓ Branch 101 → 103 taken 2 times.
|
18 | const bool isCapturesStruct = hasCaptures && argNumber == 0; |
| 574 |
2/2✓ Branch 104 → 105 taken 4 times.
✓ Branch 104 → 106 taken 14 times.
|
18 | if (isCapturesStruct) |
| 575 | 4 | captureStructPtrPtr = paramAddress; | |
| 576 | else | ||
| 577 |
1/2✓ Branch 106 → 107 taken 14 times.
✗ Branch 106 → 207 not taken.
|
14 | paramSymbol->updateAddress(paramAddress); |
| 578 | // Store the value at the new address | ||
| 579 |
1/2✓ Branch 107 → 108 taken 18 times.
✗ Branch 107 → 207 not taken.
|
18 | insertStore(&arg, paramAddress); |
| 580 | // Generate debug info | ||
| 581 |
2/2✓ Branch 108 → 109 taken 14 times.
✓ Branch 108 → 110 taken 4 times.
|
18 | if (!isCapturesStruct) |
| 582 |
1/2✓ Branch 109 → 110 taken 14 times.
✗ Branch 109 → 207 not taken.
|
14 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 583 | 18 | } | |
| 584 | |||
| 585 | // Store the default values for optional function args | ||
| 586 |
2/2✓ Branch 113 → 114 taken 8 times.
✓ Branch 113 → 124 taken 4 times.
|
12 | if (node->paramLst) { |
| 587 |
1/2✓ Branch 114 → 115 taken 8 times.
✗ Branch 114 → 214 not taken.
|
8 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 588 |
1/2✗ Branch 121 → 116 not taken.
✓ Branch 121 → 122 taken 8 times.
|
8 | for (; argIdx < params.size(); argIdx++) |
| 589 | ✗ | visit(params.at(argIdx)); | |
| 590 | 8 | } | |
| 591 | |||
| 592 | // Extract captures from captures struct | ||
| 593 |
2/2✓ Branch 124 → 125 taken 4 times.
✓ Branch 124 → 129 taken 8 times.
|
12 | if (hasCaptures) { |
| 594 |
1/2✗ Branch 126 → 127 not taken.
✓ Branch 126 → 128 taken 4 times.
|
4 | assert(!paramInfoList.empty()); |
| 595 |
1/2✓ Branch 128 → 129 taken 4 times.
✗ Branch 128 → 224 not taken.
|
4 | unpackCapturesToLocalVariables(captures, captureStructPtrPtr, capturesStructType); |
| 596 | } | ||
| 597 | |||
| 598 | // Visit body | ||
| 599 |
1/2✓ Branch 129 → 130 taken 12 times.
✗ Branch 129 → 215 not taken.
|
12 | visit(node->body); |
| 600 | |||
| 601 | // Create return statement if the block is not terminated yet | ||
| 602 |
1/2✗ Branch 131 → 132 not taken.
✓ Branch 131 → 140 taken 12 times.
|
12 | if (!blockAlreadyTerminated) { |
| 603 | ✗ | llvm::Value *result = insertLoad(returnType, resultEntry->getAddress()); | |
| 604 | ✗ | builder.CreateRet(result); | |
| 605 | } | ||
| 606 | |||
| 607 | // Pop capture addresses | ||
| 608 |
2/2✓ Branch 140 → 141 taken 4 times.
✓ Branch 140 → 151 taken 8 times.
|
12 | if (hasCaptures) |
| 609 |
5/8✓ Branch 141 → 142 taken 4 times.
✗ Branch 141 → 222 not taken.
✓ Branch 142 → 143 taken 4 times.
✗ Branch 142 → 222 not taken.
✓ Branch 143 → 144 taken 4 times.
✗ Branch 143 → 222 not taken.
✓ Branch 149 → 145 taken 6 times.
✓ Branch 149 → 150 taken 4 times.
|
10 | for (const auto &capture : captures | std::views::values) |
| 610 |
1/2✓ Branch 146 → 147 taken 6 times.
✗ Branch 146 → 222 not taken.
|
6 | capture.capturedSymbol->popAddress(); |
| 611 | |||
| 612 | // Conclude debug info for function | ||
| 613 |
1/2✓ Branch 151 → 152 taken 12 times.
✗ Branch 151 → 224 not taken.
|
12 | diGenerator.concludeFunctionDebugInfo(); |
| 614 |
1/2✓ Branch 152 → 153 taken 12 times.
✗ Branch 152 → 224 not taken.
|
12 | diGenerator.setSourceLocation(node); |
| 615 | |||
| 616 | // Restore alloca insert markers | ||
| 617 |
1/2✓ Branch 153 → 154 taken 12 times.
✗ Branch 153 → 224 not taken.
|
12 | builder.SetInsertPoint(bOrig); |
| 618 | 12 | blockAlreadyTerminated = false; | |
| 619 | 12 | allocaInsertBlock = allocaInsertBlockOrig; | |
| 620 | 12 | allocaInsertInst = allocaInsertInstOrig; | |
| 621 | |||
| 622 | // Change back to original scope | ||
| 623 | 12 | currentScope = currentScope->parent; | |
| 624 | |||
| 625 | // Verify function | ||
| 626 |
1/2✓ Branch 154 → 155 taken 12 times.
✗ Branch 154 → 224 not taken.
|
12 | verifyFunction(lambda, node->codeLoc); |
| 627 | |||
| 628 | // Captures, create a struct { <fct-ptr>, <capture struct ptr> } | ||
| 629 |
1/2✓ Branch 155 → 156 taken 12 times.
✗ Branch 155 → 224 not taken.
|
12 | llvm::Value *result = buildFatFctPtr(bodyScope, capturesStructType, lambda); |
| 630 | |||
| 631 |
1/2✓ Branch 156 → 157 taken 12 times.
✗ Branch 156 → 223 not taken.
|
24 | return LLVMExprResult{.ptr = result, .node = node}; |
| 632 | 12 | } | |
| 633 | |||
| 634 | 30 | std::any IRGenerator::visitLambdaProc(const LambdaProcNode *node) { | |
| 635 |
2/4✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 178 not taken.
✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 178 not taken.
|
30 | Function spiceFunc = node->manifestations.at(manIdx); |
| 636 | 30 | ParamInfoList paramInfoList; | |
| 637 | 30 | std::vector<llvm::Type *> paramTypes; | |
| 638 | |||
| 639 | // Change scope | ||
| 640 |
2/4✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 136 not taken.
✓ Branch 5 → 6 taken 30 times.
✗ Branch 5 → 134 not taken.
|
30 | Scope *bodyScope = currentScope = currentScope->getChildScope(node->getScopeId()); |
| 641 | |||
| 642 | // If there are captures, we pass them in a struct as the first function argument | ||
| 643 | 30 | const CaptureMap &captures = bodyScope->symbolTable.captures; | |
| 644 | 30 | const bool hasCaptures = !captures.empty(); | |
| 645 | 30 | llvm::Type *capturesStructType = nullptr; | |
| 646 |
2/2✓ Branch 8 → 9 taken 11 times.
✓ Branch 8 → 14 taken 19 times.
|
30 | if (hasCaptures) { |
| 647 | // Create captures struct type | ||
| 648 |
1/2✓ Branch 9 → 10 taken 11 times.
✗ Branch 9 → 172 not taken.
|
11 | capturesStructType = buildCapturesContainerType(captures); |
| 649 | // Add the captures struct as first parameter | ||
| 650 |
1/2✓ Branch 10 → 11 taken 11 times.
✗ Branch 10 → 137 not taken.
|
11 | paramInfoList.emplace_back(CAPTURES_PARAM_NAME, nullptr); |
| 651 |
2/4✓ Branch 11 → 12 taken 11 times.
✗ Branch 11 → 138 not taken.
✓ Branch 12 → 13 taken 11 times.
✗ Branch 12 → 138 not taken.
|
11 | paramTypes.push_back(builder.getPtrTy()); // The captures struct is always passed as pointer |
| 652 | } | ||
| 653 | |||
| 654 | // Visit parameters | ||
| 655 | 30 | size_t argIdx = 0; | |
| 656 |
2/2✓ Branch 14 → 15 taken 9 times.
✓ Branch 14 → 33 taken 21 times.
|
30 | if (node->hasParams) { |
| 657 | 9 | const size_t numOfParams = spiceFunc.paramList.size(); | |
| 658 |
1/2✓ Branch 16 → 17 taken 9 times.
✗ Branch 16 → 172 not taken.
|
9 | paramInfoList.reserve(numOfParams); |
| 659 |
1/2✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 172 not taken.
|
9 | paramTypes.reserve(numOfParams); |
| 660 |
2/2✓ Branch 32 → 19 taken 15 times.
✓ Branch 32 → 33 taken 9 times.
|
24 | for (; argIdx < numOfParams; argIdx++) { |
| 661 |
1/2✓ Branch 19 → 20 taken 15 times.
✗ Branch 19 → 142 not taken.
|
15 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 662 | // Get symbol table entry of param | ||
| 663 |
1/2✓ Branch 20 → 21 taken 15 times.
✗ Branch 20 → 142 not taken.
|
15 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 664 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 15 times.
|
15 | assert(paramSymbol != nullptr); |
| 665 | // Retrieve type of param | ||
| 666 |
3/6✓ Branch 25 → 26 taken 15 times.
✗ Branch 25 → 141 not taken.
✓ Branch 26 → 27 taken 15 times.
✗ Branch 26 → 139 not taken.
✓ Branch 27 → 28 taken 15 times.
✗ Branch 27 → 139 not taken.
|
15 | llvm::Type *paramType = spiceFunc.getParamTypes().at(argIdx).toLLVMType(sourceFile); |
| 667 | // Add it to the lists | ||
| 668 |
1/2✓ Branch 29 → 30 taken 15 times.
✗ Branch 29 → 142 not taken.
|
15 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 669 |
1/2✓ Branch 30 → 31 taken 15 times.
✗ Branch 30 → 142 not taken.
|
15 | paramTypes.push_back(paramType); |
| 670 | } | ||
| 671 | } | ||
| 672 | |||
| 673 | // Create function or implement declared function | ||
| 674 |
2/4✓ Branch 33 → 34 taken 30 times.
✗ Branch 33 → 145 not taken.
✓ Branch 34 → 35 taken 30 times.
✗ Branch 34 → 143 not taken.
|
30 | spiceFunc.mangleSuffix = "." + std::to_string(manIdx); |
| 675 |
1/2✓ Branch 38 → 39 taken 30 times.
✗ Branch 38 → 172 not taken.
|
30 | const std::string mangledName = spiceFunc.getMangledName(); |
| 676 |
2/4✓ Branch 40 → 41 taken 30 times.
✗ Branch 40 → 147 not taken.
✓ Branch 41 → 42 taken 30 times.
✗ Branch 41 → 147 not taken.
|
30 | llvm::FunctionType *funcType = llvm::FunctionType::get(builder.getVoidTy(), paramTypes, false); |
| 677 |
1/2✓ Branch 43 → 44 taken 30 times.
✗ Branch 43 → 148 not taken.
|
30 | module->getOrInsertFunction(mangledName, funcType); |
| 678 |
1/2✓ Branch 45 → 46 taken 30 times.
✗ Branch 45 → 149 not taken.
|
30 | llvm::Function *lambda = module->getFunction(mangledName); |
| 679 | |||
| 680 | // Set attributes to function | ||
| 681 | 30 | lambda->setDSOLocal(true); | |
| 682 |
1/2✓ Branch 47 → 48 taken 30 times.
✗ Branch 47 → 170 not taken.
|
30 | lambda->setLinkage(llvm::Function::PrivateLinkage); |
| 683 |
1/2✓ Branch 48 → 49 taken 30 times.
✗ Branch 48 → 170 not taken.
|
30 | enableFunctionInstrumentation(lambda); |
| 684 | |||
| 685 | // In case of captures, add attribute to captures argument | ||
| 686 |
2/2✓ Branch 49 → 50 taken 11 times.
✓ Branch 49 → 55 taken 19 times.
|
30 | if (hasCaptures) { |
| 687 |
1/2✓ Branch 50 → 51 taken 11 times.
✗ Branch 50 → 170 not taken.
|
11 | lambda->addParamAttr(0, llvm::Attribute::NoUndef); |
| 688 |
1/2✓ Branch 51 → 52 taken 11 times.
✗ Branch 51 → 170 not taken.
|
11 | lambda->addParamAttr(0, llvm::Attribute::NonNull); |
| 689 |
2/4✓ Branch 53 → 54 taken 11 times.
✗ Branch 53 → 170 not taken.
✓ Branch 54 → 55 taken 11 times.
✗ Branch 54 → 170 not taken.
|
11 | lambda->addDereferenceableParamAttr(0, module->getDataLayout().getPointerSize()); |
| 690 | } | ||
| 691 | |||
| 692 | // Add debug info | ||
| 693 |
1/2✓ Branch 55 → 56 taken 30 times.
✗ Branch 55 → 170 not taken.
|
30 | diGenerator.generateFunctionDebugInfo(lambda, &spiceFunc, true); |
| 694 |
1/2✓ Branch 56 → 57 taken 30 times.
✗ Branch 56 → 170 not taken.
|
30 | diGenerator.setSourceLocation(node); |
| 695 | |||
| 696 | // Save alloca insert markers | ||
| 697 | 30 | llvm::BasicBlock *allocaInsertBlockOrig = allocaInsertBlock; | |
| 698 | 30 | llvm::AllocaInst *allocaInsertInstOrig = allocaInsertInst; | |
| 699 | 30 | llvm::BasicBlock *bOrig = builder.GetInsertBlock(); | |
| 700 | |||
| 701 | // Create entry block | ||
| 702 |
2/4✓ Branch 60 → 61 taken 30 times.
✗ Branch 60 → 152 not taken.
✓ Branch 61 → 62 taken 30 times.
✗ Branch 61 → 150 not taken.
|
30 | llvm::BasicBlock *bEntry = createBlock(); |
| 703 |
1/2✓ Branch 64 → 65 taken 30 times.
✗ Branch 64 → 170 not taken.
|
30 | switchToBlock(bEntry, lambda); |
| 704 | |||
| 705 | // Reset alloca insert markers to this block | ||
| 706 | 30 | allocaInsertBlock = bEntry; | |
| 707 | 30 | allocaInsertInst = nullptr; | |
| 708 | |||
| 709 | // Save values of parameters to locals | ||
| 710 | 30 | llvm::Value *captureStructPtrPtr = nullptr; | |
| 711 |
3/4✓ Branch 65 → 66 taken 30 times.
✗ Branch 65 → 162 not taken.
✓ Branch 89 → 68 taken 26 times.
✓ Branch 89 → 90 taken 30 times.
|
56 | for (auto &arg : lambda->args()) { |
| 712 | // Get information about the parameter | ||
| 713 | 26 | const size_t argNumber = arg.getArgNo(); | |
| 714 |
2/4✓ Branch 69 → 70 taken 26 times.
✗ Branch 69 → 161 not taken.
✓ Branch 70 → 71 taken 26 times.
✗ Branch 70 → 161 not taken.
|
26 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 715 | // Allocate space for it | ||
| 716 |
1/2✓ Branch 73 → 74 taken 26 times.
✗ Branch 73 → 159 not taken.
|
26 | llvm::Type *paramType = funcType->getParamType(argNumber); |
| 717 |
2/4✓ Branch 74 → 75 taken 26 times.
✗ Branch 74 → 158 not taken.
✓ Branch 75 → 76 taken 26 times.
✗ Branch 75 → 156 not taken.
|
26 | llvm::Value *paramAddress = insertAlloca(paramType, paramName); |
| 718 | // Update the symbol table entry | ||
| 719 |
4/4✓ Branch 77 → 78 taken 13 times.
✓ Branch 77 → 80 taken 13 times.
✓ Branch 78 → 79 taken 11 times.
✓ Branch 78 → 80 taken 2 times.
|
26 | const bool isCapturesStruct = hasCaptures && argNumber == 0; |
| 720 |
2/2✓ Branch 81 → 82 taken 11 times.
✓ Branch 81 → 83 taken 15 times.
|
26 | if (isCapturesStruct) |
| 721 | 11 | captureStructPtrPtr = paramAddress; | |
| 722 | else | ||
| 723 |
1/2✓ Branch 83 → 84 taken 15 times.
✗ Branch 83 → 159 not taken.
|
15 | paramSymbol->updateAddress(paramAddress); |
| 724 | // Store the value at the new address | ||
| 725 |
1/2✓ Branch 84 → 85 taken 26 times.
✗ Branch 84 → 159 not taken.
|
26 | insertStore(&arg, paramAddress); |
| 726 | // Generate debug info | ||
| 727 |
2/2✓ Branch 85 → 86 taken 15 times.
✓ Branch 85 → 87 taken 11 times.
|
26 | if (!isCapturesStruct) |
| 728 |
1/2✓ Branch 86 → 87 taken 15 times.
✗ Branch 86 → 159 not taken.
|
15 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 729 | 26 | } | |
| 730 | |||
| 731 | // Store the default values for optional function args | ||
| 732 |
2/2✓ Branch 90 → 91 taken 9 times.
✓ Branch 90 → 101 taken 21 times.
|
30 | if (node->paramLst) { |
| 733 |
1/2✓ Branch 91 → 92 taken 9 times.
✗ Branch 91 → 166 not taken.
|
9 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 734 |
1/2✗ Branch 98 → 93 not taken.
✓ Branch 98 → 99 taken 9 times.
|
9 | for (; argIdx < params.size(); argIdx++) |
| 735 | ✗ | visit(params.at(argIdx)); | |
| 736 | 9 | } | |
| 737 | |||
| 738 | // Extract captures from captures struct | ||
| 739 |
2/2✓ Branch 101 → 102 taken 11 times.
✓ Branch 101 → 106 taken 19 times.
|
30 | if (hasCaptures) { |
| 740 |
1/2✗ Branch 103 → 104 not taken.
✓ Branch 103 → 105 taken 11 times.
|
11 | assert(!paramInfoList.empty()); |
| 741 |
1/2✓ Branch 105 → 106 taken 11 times.
✗ Branch 105 → 170 not taken.
|
11 | unpackCapturesToLocalVariables(captures, captureStructPtrPtr, capturesStructType); |
| 742 | } | ||
| 743 | |||
| 744 | // Visit body | ||
| 745 |
1/2✓ Branch 106 → 107 taken 30 times.
✗ Branch 106 → 167 not taken.
|
30 | visit(node->body); |
| 746 | |||
| 747 | // Create return statement if the block is not terminated yet | ||
| 748 |
1/2✓ Branch 108 → 109 taken 30 times.
✗ Branch 108 → 110 not taken.
|
30 | if (!blockAlreadyTerminated) |
| 749 |
1/2✓ Branch 109 → 110 taken 30 times.
✗ Branch 109 → 170 not taken.
|
30 | builder.CreateRetVoid(); |
| 750 | |||
| 751 | // Pop capture addresses | ||
| 752 |
2/2✓ Branch 110 → 111 taken 11 times.
✓ Branch 110 → 121 taken 19 times.
|
30 | if (hasCaptures) |
| 753 |
5/8✓ Branch 111 → 112 taken 11 times.
✗ Branch 111 → 168 not taken.
✓ Branch 112 → 113 taken 11 times.
✗ Branch 112 → 168 not taken.
✓ Branch 113 → 114 taken 11 times.
✗ Branch 113 → 168 not taken.
✓ Branch 119 → 115 taken 18 times.
✓ Branch 119 → 120 taken 11 times.
|
29 | for (const auto &capture : captures | std::views::values) |
| 754 |
1/2✓ Branch 116 → 117 taken 18 times.
✗ Branch 116 → 168 not taken.
|
18 | capture.capturedSymbol->popAddress(); |
| 755 | |||
| 756 | // Conclude debug info for function | ||
| 757 |
1/2✓ Branch 121 → 122 taken 30 times.
✗ Branch 121 → 170 not taken.
|
30 | diGenerator.concludeFunctionDebugInfo(); |
| 758 |
1/2✓ Branch 122 → 123 taken 30 times.
✗ Branch 122 → 170 not taken.
|
30 | diGenerator.setSourceLocation(node); |
| 759 | |||
| 760 | // Restore alloca insert markers | ||
| 761 |
1/2✓ Branch 123 → 124 taken 30 times.
✗ Branch 123 → 170 not taken.
|
30 | builder.SetInsertPoint(bOrig); |
| 762 | 30 | blockAlreadyTerminated = false; | |
| 763 | 30 | allocaInsertBlock = allocaInsertBlockOrig; | |
| 764 | 30 | allocaInsertInst = allocaInsertInstOrig; | |
| 765 | |||
| 766 | // Change back to original scope | ||
| 767 | 30 | currentScope = currentScope->parent; | |
| 768 | |||
| 769 | // Verify function | ||
| 770 |
1/2✓ Branch 124 → 125 taken 30 times.
✗ Branch 124 → 170 not taken.
|
30 | verifyFunction(lambda, node->codeLoc); |
| 771 | |||
| 772 | // Create a struct { <fct-ptr>, <capture struct ptr> } | ||
| 773 |
1/2✓ Branch 125 → 126 taken 30 times.
✗ Branch 125 → 170 not taken.
|
30 | llvm::Value *result = buildFatFctPtr(bodyScope, capturesStructType, lambda); |
| 774 | |||
| 775 |
1/2✓ Branch 126 → 127 taken 30 times.
✗ Branch 126 → 169 not taken.
|
60 | return LLVMExprResult{.ptr = result, .node = node}; |
| 776 | 30 | } | |
| 777 | |||
| 778 | 1 | std::any IRGenerator::visitLambdaExpr(const LambdaExprNode *node) { | |
| 779 |
1/2✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 168 not taken.
|
1 | const Function &spiceFunc = node->manifestations.at(manIdx); |
| 780 | 1 | ParamInfoList paramInfoList; | |
| 781 | 1 | std::vector<llvm::Type *> paramTypes; | |
| 782 | |||
| 783 | // Change scope | ||
| 784 |
2/4✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 133 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 131 not taken.
|
1 | Scope *bodyScope = currentScope = currentScope->getChildScope(node->getScopeId()); |
| 785 | |||
| 786 | // If there are captures, we pass them in a struct as the first function argument | ||
| 787 | 1 | const CaptureMap &captures = bodyScope->symbolTable.captures; | |
| 788 | 1 | const bool hasCaptures = !captures.empty(); | |
| 789 | 1 | llvm::Type *capturesStructType = nullptr; | |
| 790 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 13 taken 1 time.
|
1 | if (hasCaptures) { |
| 791 | // Create captures struct type | ||
| 792 | ✗ | capturesStructType = buildCapturesContainerType(captures); | |
| 793 | // Add the captures struct as first parameter | ||
| 794 | ✗ | paramInfoList.emplace_back(CAPTURES_PARAM_NAME, nullptr); | |
| 795 | ✗ | paramTypes.push_back(builder.getPtrTy()); // The capture struct is always passed as pointer | |
| 796 | } | ||
| 797 | |||
| 798 | // Visit parameters | ||
| 799 | 1 | size_t argIdx = 0; | |
| 800 |
1/2✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 32 not taken.
|
1 | if (node->hasParams) { |
| 801 | 1 | const size_t numOfParams = spiceFunc.paramList.size(); | |
| 802 |
1/2✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 164 not taken.
|
1 | paramInfoList.reserve(numOfParams); |
| 803 |
1/2✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 164 not taken.
|
1 | paramTypes.reserve(numOfParams); |
| 804 |
2/2✓ Branch 31 → 18 taken 2 times.
✓ Branch 31 → 32 taken 1 time.
|
3 | for (; argIdx < numOfParams; argIdx++) { |
| 805 |
1/2✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 139 not taken.
|
2 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 806 | // Get symbol table entry of param | ||
| 807 |
1/2✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 139 not taken.
|
2 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 808 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 2 times.
|
2 | assert(paramSymbol != nullptr); |
| 809 | // Retrieve type of param | ||
| 810 |
3/6✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 138 not taken.
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 136 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 136 not taken.
|
2 | llvm::Type *paramType = spiceFunc.getParamTypes().at(argIdx).toLLVMType(sourceFile); |
| 811 | // Add it to the lists | ||
| 812 |
1/2✓ Branch 28 → 29 taken 2 times.
✗ Branch 28 → 139 not taken.
|
2 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 813 |
1/2✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 139 not taken.
|
2 | paramTypes.push_back(paramType); |
| 814 | } | ||
| 815 | } | ||
| 816 | |||
| 817 | // Get return type | ||
| 818 |
2/4✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 164 not taken.
✓ Branch 33 → 34 taken 1 time.
✗ Branch 33 → 164 not taken.
|
1 | llvm::Type *returnType = builder.getVoidTy(); |
| 819 |
1/2✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 39 not taken.
|
1 | if (spiceFunc.isFunction()) |
| 820 |
1/2✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 164 not taken.
|
1 | returnType = spiceFunc.returnType.toLLVMType(sourceFile); |
| 821 | |||
| 822 | // Create function or implement declared function | ||
| 823 |
1/2✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 164 not taken.
|
1 | const std::string mangledName = spiceFunc.getMangledName(); |
| 824 |
1/2✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 140 not taken.
|
1 | llvm::FunctionType *funcType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 825 |
1/2✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 141 not taken.
|
1 | module->getOrInsertFunction(mangledName, funcType); |
| 826 |
1/2✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 142 not taken.
|
1 | llvm::Function *lambda = module->getFunction(mangledName); |
| 827 | |||
| 828 | // Set attributes to function | ||
| 829 | 1 | lambda->setDSOLocal(true); | |
| 830 |
1/2✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 162 not taken.
|
1 | lambda->setLinkage(llvm::Function::PrivateLinkage); |
| 831 |
1/2✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 162 not taken.
|
1 | enableFunctionInstrumentation(lambda); |
| 832 | |||
| 833 | // In case of captures, add attribute to captures argument | ||
| 834 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 55 taken 1 time.
|
1 | if (hasCaptures) { |
| 835 | ✗ | lambda->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 836 | ✗ | lambda->addParamAttr(0, llvm::Attribute::NonNull); | |
| 837 | ✗ | lambda->addDereferenceableParamAttr(0, module->getDataLayout().getPointerSize()); | |
| 838 | } | ||
| 839 | |||
| 840 | // Add debug info | ||
| 841 |
1/2✓ Branch 55 → 56 taken 1 time.
✗ Branch 55 → 162 not taken.
|
1 | diGenerator.generateFunctionDebugInfo(lambda, &spiceFunc, true); |
| 842 |
1/2✓ Branch 56 → 57 taken 1 time.
✗ Branch 56 → 162 not taken.
|
1 | diGenerator.setSourceLocation(node); |
| 843 | |||
| 844 | // Save alloca insert markers | ||
| 845 | 1 | llvm::BasicBlock *allocaInsertBlockOrig = allocaInsertBlock; | |
| 846 | 1 | llvm::AllocaInst *allocaInsertInstOrig = allocaInsertInst; | |
| 847 | 1 | llvm::BasicBlock *bOrig = builder.GetInsertBlock(); | |
| 848 | |||
| 849 | // Create entry block | ||
| 850 |
2/4✓ Branch 60 → 61 taken 1 time.
✗ Branch 60 → 145 not taken.
✓ Branch 61 → 62 taken 1 time.
✗ Branch 61 → 143 not taken.
|
1 | llvm::BasicBlock *bEntry = createBlock(); |
| 851 |
1/2✓ Branch 64 → 65 taken 1 time.
✗ Branch 64 → 162 not taken.
|
1 | switchToBlock(bEntry, lambda); |
| 852 | |||
| 853 | // Reset alloca insert markers to this block | ||
| 854 | 1 | allocaInsertBlock = bEntry; | |
| 855 | 1 | allocaInsertInst = nullptr; | |
| 856 | |||
| 857 | // Save values of parameters to locals | ||
| 858 | 1 | llvm::Value *captureStructPtrPtr = nullptr; | |
| 859 |
3/4✓ Branch 65 → 66 taken 1 time.
✗ Branch 65 → 155 not taken.
✓ Branch 89 → 68 taken 2 times.
✓ Branch 89 → 90 taken 1 time.
|
3 | for (auto &arg : lambda->args()) { |
| 860 | // Get information about the parameter | ||
| 861 | 2 | const size_t argNumber = arg.getArgNo(); | |
| 862 |
2/4✓ Branch 69 → 70 taken 2 times.
✗ Branch 69 → 154 not taken.
✓ Branch 70 → 71 taken 2 times.
✗ Branch 70 → 154 not taken.
|
2 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 863 | // Allocate space for it | ||
| 864 |
1/2✓ Branch 73 → 74 taken 2 times.
✗ Branch 73 → 152 not taken.
|
2 | llvm::Type *paramType = funcType->getParamType(argNumber); |
| 865 |
2/4✓ Branch 74 → 75 taken 2 times.
✗ Branch 74 → 151 not taken.
✓ Branch 75 → 76 taken 2 times.
✗ Branch 75 → 149 not taken.
|
2 | llvm::Value *paramAddress = insertAlloca(paramType, paramName); |
| 866 | // Update the symbol table entry | ||
| 867 |
1/4✗ Branch 77 → 78 not taken.
✓ Branch 77 → 80 taken 2 times.
✗ Branch 78 → 79 not taken.
✗ Branch 78 → 80 not taken.
|
2 | const bool isCapturesStruct = hasCaptures && argNumber == 0; |
| 868 |
1/2✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 2 times.
|
2 | if (isCapturesStruct) |
| 869 | ✗ | captureStructPtrPtr = paramAddress; | |
| 870 | else | ||
| 871 |
1/2✓ Branch 83 → 84 taken 2 times.
✗ Branch 83 → 152 not taken.
|
2 | paramSymbol->updateAddress(paramAddress); |
| 872 | // Store the value at the new address | ||
| 873 |
1/2✓ Branch 84 → 85 taken 2 times.
✗ Branch 84 → 152 not taken.
|
2 | insertStore(&arg, paramAddress); |
| 874 | // Generate debug info | ||
| 875 |
1/2✓ Branch 85 → 86 taken 2 times.
✗ Branch 85 → 87 not taken.
|
2 | if (!isCapturesStruct) |
| 876 |
1/2✓ Branch 86 → 87 taken 2 times.
✗ Branch 86 → 152 not taken.
|
2 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 877 | 2 | } | |
| 878 | |||
| 879 | // Store the default values for optional function args | ||
| 880 |
1/2✓ Branch 90 → 91 taken 1 time.
✗ Branch 90 → 101 not taken.
|
1 | if (node->paramLst) { |
| 881 |
1/2✓ Branch 91 → 92 taken 1 time.
✗ Branch 91 → 159 not taken.
|
1 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 882 |
1/2✗ Branch 98 → 93 not taken.
✓ Branch 98 → 99 taken 1 time.
|
1 | for (; argIdx < params.size(); argIdx++) |
| 883 | ✗ | visit(params.at(argIdx)); | |
| 884 | 1 | } | |
| 885 | |||
| 886 | // Extract captures from captures struct | ||
| 887 |
1/2✗ Branch 101 → 102 not taken.
✓ Branch 101 → 106 taken 1 time.
|
1 | if (hasCaptures) { |
| 888 | ✗ | assert(!paramInfoList.empty()); | |
| 889 | ✗ | unpackCapturesToLocalVariables(captures, captureStructPtrPtr, capturesStructType); | |
| 890 | } | ||
| 891 | |||
| 892 | // Visit lambda expression | ||
| 893 |
1/2✓ Branch 106 → 107 taken 1 time.
✗ Branch 106 → 162 not taken.
|
1 | llvm::Value *exprResult = resolveValue(node->lambdaExpr); |
| 894 |
1/2✓ Branch 107 → 108 taken 1 time.
✗ Branch 107 → 162 not taken.
|
1 | builder.CreateRet(exprResult); |
| 895 | |||
| 896 | // Pop capture addresses | ||
| 897 |
1/2✗ Branch 108 → 109 not taken.
✓ Branch 108 → 119 taken 1 time.
|
1 | if (hasCaptures) |
| 898 | ✗ | for (const auto &val : captures | std::views::values) | |
| 899 | ✗ | val.capturedSymbol->popAddress(); | |
| 900 | |||
| 901 | // Conclude debug info for function | ||
| 902 |
1/2✓ Branch 119 → 120 taken 1 time.
✗ Branch 119 → 162 not taken.
|
1 | diGenerator.concludeFunctionDebugInfo(); |
| 903 |
1/2✓ Branch 120 → 121 taken 1 time.
✗ Branch 120 → 162 not taken.
|
1 | diGenerator.setSourceLocation(node); |
| 904 | |||
| 905 | // Restore alloca insert markers | ||
| 906 |
1/2✓ Branch 121 → 122 taken 1 time.
✗ Branch 121 → 162 not taken.
|
1 | builder.SetInsertPoint(bOrig); |
| 907 | 1 | blockAlreadyTerminated = false; | |
| 908 | 1 | allocaInsertBlock = allocaInsertBlockOrig; | |
| 909 | 1 | allocaInsertInst = allocaInsertInstOrig; | |
| 910 | |||
| 911 | // Change back to original scope | ||
| 912 | 1 | currentScope = currentScope->parent; | |
| 913 | |||
| 914 | // Verify function | ||
| 915 |
1/2✓ Branch 122 → 123 taken 1 time.
✗ Branch 122 → 162 not taken.
|
1 | verifyFunction(lambda, node->codeLoc); |
| 916 | // Create a struct { <fct-ptr>, <capture struct ptr> } | ||
| 917 |
1/2✓ Branch 123 → 124 taken 1 time.
✗ Branch 123 → 162 not taken.
|
1 | llvm::Value *result = buildFatFctPtr(bodyScope, capturesStructType, lambda); |
| 918 | |||
| 919 |
1/2✓ Branch 124 → 125 taken 1 time.
✗ Branch 124 → 161 not taken.
|
2 | return LLVMExprResult{.ptr = result, .node = node}; |
| 920 | 1 | } | |
| 921 | |||
| 922 | 2885 | std::any IRGenerator::visitDataType(const DataTypeNode *node) { | |
| 923 | // Only set the source location if this is not the root scope | ||
| 924 |
6/8✓ Branch 2 → 3 taken 1720 times.
✓ Branch 2 → 7 taken 1165 times.
✓ Branch 3 → 4 taken 1712 times.
✓ Branch 3 → 7 taken 8 times.
✓ Branch 4 → 5 taken 1712 times.
✗ Branch 4 → 7 not taken.
✓ Branch 5 → 6 taken 1712 times.
✗ Branch 5 → 7 not taken.
|
2885 | if (currentScope != rootScope && !node->isParamType && !node->isReturnType && !node->isFieldType) |
| 925 |
1/2✓ Branch 6 → 7 taken 1712 times.
✗ Branch 6 → 17 not taken.
|
1712 | diGenerator.setSourceLocation(node); |
| 926 | // Retrieve symbol type | ||
| 927 |
1/2✓ Branch 7 → 8 taken 2885 times.
✗ Branch 7 → 17 not taken.
|
2885 | const QualType symbolType = node->getEvaluatedSymbolType(manIdx); |
| 928 |
2/4✓ Branch 8 → 9 taken 2885 times.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 2885 times.
|
2885 | assert(!symbolType.is(TY_DYN)); // Symbol type should not be dyn anymore at this point |
| 929 |
2/4✓ Branch 11 → 12 taken 2885 times.
✗ Branch 11 → 16 not taken.
✓ Branch 12 → 13 taken 2885 times.
✗ Branch 12 → 16 not taken.
|
2885 | return symbolType.toLLVMType(sourceFile); |
| 930 | } | ||
| 931 | |||
| 932 | 51 | llvm::Value *IRGenerator::buildFatFctPtr(Scope *bodyScope, llvm::Type *capturesStructType, llvm::Value *lambda) { | |
| 933 | // Create capture struct if required | ||
| 934 | 51 | llvm::Value *capturesPtr = nullptr; | |
| 935 |
2/2✓ Branch 2 → 3 taken 15 times.
✓ Branch 2 → 62 taken 36 times.
|
51 | if (capturesStructType != nullptr) { |
| 936 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 15 times.
|
15 | assert(bodyScope != nullptr); |
| 937 | // If we have a single capture of ptr type, we can directly store it into the fat ptr. Otherwise, we need a stack allocated | ||
| 938 | // struct to store the captures in a memory-efficient manner and store a pointer to that struct to the fat ptr. | ||
| 939 |
2/2✓ Branch 6 → 7 taken 6 times.
✓ Branch 6 → 26 taken 9 times.
|
15 | if (capturesStructType->isPointerTy()) { |
| 940 | 6 | const CaptureMap &captures = bodyScope->symbolTable.captures; | |
| 941 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 6 times.
|
6 | assert(captures.size() == 1); |
| 942 | 6 | const Capture &capture = captures.begin()->second; | |
| 943 |
2/2✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 24 taken 5 times.
|
6 | if (capture.getMode() == BY_VALUE) { |
| 944 | 1 | llvm::Type *varType = capture.capturedSymbol->getQualType().toLLVMType(sourceFile); | |
| 945 |
3/6✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 97 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 95 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 95 not taken.
|
2 | capturesPtr = insertLoad(varType, capture.capturedSymbol->getAddress()); |
| 946 | } else { | ||
| 947 | 5 | capturesPtr = capture.capturedSymbol->getAddress(); | |
| 948 | } | ||
| 949 | } else { | ||
| 950 |
2/4✓ Branch 28 → 29 taken 9 times.
✗ Branch 28 → 103 not taken.
✓ Branch 29 → 30 taken 9 times.
✗ Branch 29 → 101 not taken.
|
9 | capturesPtr = insertAlloca(capturesStructType, CAPTURES_PARAM_NAME); |
| 951 | 9 | size_t captureIdx = 0; | |
| 952 |
5/8✓ Branch 32 → 33 taken 9 times.
✗ Branch 32 → 119 not taken.
✓ Branch 33 → 34 taken 9 times.
✗ Branch 33 → 119 not taken.
✓ Branch 34 → 35 taken 9 times.
✗ Branch 34 → 119 not taken.
✓ Branch 60 → 36 taken 18 times.
✓ Branch 60 → 61 taken 9 times.
|
27 | for (const auto &capture : bodyScope->symbolTable.captures | std::views::values) { |
| 953 | 18 | const SymbolTableEntry *capturedEntry = capture.capturedSymbol; | |
| 954 | // Get address or value of captured variable, depending on the capturing mode | ||
| 955 |
1/2✓ Branch 37 → 38 taken 18 times.
✗ Branch 37 → 119 not taken.
|
18 | llvm::Value *capturedValue = capturedEntry->getAddress(); |
| 956 |
1/2✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 18 times.
|
18 | assert(capturedValue != nullptr); |
| 957 |
3/4✓ Branch 40 → 41 taken 18 times.
✗ Branch 40 → 119 not taken.
✓ Branch 41 → 42 taken 15 times.
✓ Branch 41 → 51 taken 3 times.
|
18 | if (capture.getMode() == BY_VALUE) { |
| 958 |
2/4✓ Branch 42 → 43 taken 15 times.
✗ Branch 42 → 119 not taken.
✓ Branch 43 → 44 taken 15 times.
✗ Branch 43 → 119 not taken.
|
15 | llvm::Type *captureType = capturedEntry->getQualType().toLLVMType(sourceFile); |
| 959 |
2/4✓ Branch 46 → 47 taken 15 times.
✗ Branch 46 → 109 not taken.
✓ Branch 47 → 48 taken 15 times.
✗ Branch 47 → 107 not taken.
|
30 | capturedValue = insertLoad(captureType, capturedValue); |
| 960 | } | ||
| 961 | // Store it in the capture struct | ||
| 962 |
1/2✓ Branch 54 → 55 taken 18 times.
✗ Branch 54 → 113 not taken.
|
18 | llvm::Value *captureAddress = insertStructGEP(capturesStructType, capturesPtr, captureIdx); |
| 963 |
1/2✓ Branch 57 → 58 taken 18 times.
✗ Branch 57 → 119 not taken.
|
18 | insertStore(capturedValue, captureAddress); |
| 964 | 18 | captureIdx++; | |
| 965 | } | ||
| 966 | } | ||
| 967 | } | ||
| 968 | |||
| 969 | // Create fat ptr struct type if not exists yet | ||
| 970 |
2/2✓ Branch 62 → 63 taken 20 times.
✓ Branch 62 → 68 taken 31 times.
|
51 | if (!llvmTypes.fatPtrType) |
| 971 |
3/6✓ Branch 63 → 64 taken 20 times.
✗ Branch 63 → 120 not taken.
✓ Branch 64 → 65 taken 20 times.
✗ Branch 64 → 120 not taken.
✓ Branch 66 → 67 taken 20 times.
✗ Branch 66 → 120 not taken.
|
20 | llvmTypes.fatPtrType = llvm::StructType::get(context, {builder.getPtrTy(), builder.getPtrTy()}); |
| 972 | |||
| 973 | // Create fat pointer | ||
| 974 |
2/4✓ Branch 70 → 71 taken 51 times.
✗ Branch 70 → 124 not taken.
✓ Branch 71 → 72 taken 51 times.
✗ Branch 71 → 122 not taken.
|
102 | llvm::Value *fatFctPtr = insertAlloca(llvmTypes.fatPtrType, "fat.ptr"); |
| 975 |
1/2✓ Branch 77 → 78 taken 51 times.
✗ Branch 77 → 128 not taken.
|
51 | llvm::Value *fctPtr = insertStructGEP(llvmTypes.fatPtrType, fatFctPtr, 0); |
| 976 | 51 | insertStore(lambda, fctPtr); | |
| 977 |
1/2✓ Branch 84 → 85 taken 51 times.
✗ Branch 84 → 134 not taken.
|
51 | llvm::Value *capturePtr = insertStructGEP(llvmTypes.fatPtrType, fatFctPtr, 1); |
| 978 |
2/2✓ Branch 87 → 88 taken 36 times.
✓ Branch 87 → 91 taken 15 times.
|
51 | insertStore(capturesPtr != nullptr ? capturesPtr : llvm::PoisonValue::get(builder.getPtrTy()), capturePtr); |
| 979 | |||
| 980 | 51 | return fatFctPtr; | |
| 981 | } | ||
| 982 | |||
| 983 | 15 | llvm::Type *IRGenerator::buildCapturesContainerType(const CaptureMap &captures) const { | |
| 984 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 15 times.
|
15 | assert(!captures.empty()); |
| 985 | |||
| 986 | // If we have only one capture that is a ptr, we can just use that ptr type | ||
| 987 | 15 | const Capture &capture = captures.begin()->second; | |
| 988 |
10/14✓ Branch 8 → 9 taken 6 times.
✓ Branch 8 → 15 taken 9 times.
✓ Branch 9 → 10 taken 6 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 6 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 14 taken 2 times.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 48 not taken.
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 19 taken 9 times.
|
15 | if (captures.size() == 1 && (capture.capturedSymbol->getQualType().isPtr() || capture.getMode() == BY_REFERENCE)) |
| 989 |
1/2✓ Branch 17 → 18 taken 6 times.
✗ Branch 17 → 48 not taken.
|
6 | return builder.getPtrTy(); |
| 990 | |||
| 991 | // Create captures struct type | ||
| 992 | 9 | std::vector<llvm::Type *> captureTypes; | |
| 993 |
5/8✓ Branch 19 → 20 taken 9 times.
✗ Branch 19 → 44 not taken.
✓ Branch 20 → 21 taken 9 times.
✗ Branch 20 → 44 not taken.
✓ Branch 21 → 22 taken 9 times.
✗ Branch 21 → 44 not taken.
✓ Branch 35 → 23 taken 18 times.
✓ Branch 35 → 36 taken 9 times.
|
27 | for (const auto &c : captures | std::views::values) { |
| 994 |
3/4✓ Branch 24 → 25 taken 18 times.
✗ Branch 24 → 44 not taken.
✓ Branch 25 → 26 taken 15 times.
✓ Branch 25 → 30 taken 3 times.
|
18 | if (c.getMode() == BY_VALUE) |
| 995 |
3/6✓ Branch 26 → 27 taken 15 times.
✗ Branch 26 → 42 not taken.
✓ Branch 27 → 28 taken 15 times.
✗ Branch 27 → 42 not taken.
✓ Branch 28 → 29 taken 15 times.
✗ Branch 28 → 42 not taken.
|
15 | captureTypes.push_back(c.capturedSymbol->getQualType().toLLVMType(sourceFile)); |
| 996 | else | ||
| 997 |
2/4✓ Branch 30 → 31 taken 3 times.
✗ Branch 30 → 43 not taken.
✓ Branch 31 → 32 taken 3 times.
✗ Branch 31 → 43 not taken.
|
3 | captureTypes.push_back(builder.getPtrTy()); |
| 998 | } | ||
| 999 |
1/2✓ Branch 37 → 38 taken 9 times.
✗ Branch 37 → 45 not taken.
|
9 | return llvm::StructType::get(context, captureTypes); |
| 1000 | 9 | } | |
| 1001 | |||
| 1002 | 15 | void IRGenerator::unpackCapturesToLocalVariables(const CaptureMap &captures, llvm::Value *val, llvm::Type *structType) { | |
| 1003 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 15 times.
|
15 | assert(!captures.empty()); |
| 1004 | // If we have only one capture that is a ptr, we can just load the ptr | ||
| 1005 | 15 | const Capture &firstCapture = captures.begin()->second; | |
| 1006 |
7/8✓ Branch 8 → 9 taken 6 times.
✓ Branch 8 → 15 taken 9 times.
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 14 taken 2 times.
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 16 → 22 taken 9 times.
|
15 | if (captures.size() == 1 && (firstCapture.capturedSymbol->getQualType().isPtr() || firstCapture.getMode() == BY_REFERENCE)) { |
| 1007 | // Interpret capturesPtr as ptr to the first and only capture | ||
| 1008 | 6 | llvm::Value *captureAddress = val; | |
| 1009 | 6 | firstCapture.capturedSymbol->pushAddress(captureAddress); | |
| 1010 | // Generate debug info | ||
| 1011 |
2/4✓ Branch 18 → 19 taken 6 times.
✗ Branch 18 → 53 not taken.
✓ Branch 19 → 20 taken 6 times.
✗ Branch 19 → 51 not taken.
|
6 | diGenerator.generateLocalVarDebugInfo(firstCapture.getName(), captureAddress); |
| 1012 | } else { | ||
| 1013 | // Interpret capturesPtr as ptr to the captures struct | ||
| 1014 |
3/6✓ Branch 24 → 25 taken 9 times.
✗ Branch 24 → 56 not taken.
✓ Branch 25 → 26 taken 9 times.
✗ Branch 25 → 54 not taken.
✓ Branch 26 → 27 taken 9 times.
✗ Branch 26 → 54 not taken.
|
9 | llvm::Value *capturesPtr = insertLoad(builder.getPtrTy(), val); |
| 1015 | |||
| 1016 | 9 | size_t captureIdx = 0; | |
| 1017 |
2/2✓ Branch 48 → 31 taken 18 times.
✓ Branch 48 → 49 taken 9 times.
|
27 | for (const auto &[name, capture] : captures) { |
| 1018 |
5/8✓ Branch 34 → 35 taken 18 times.
✗ Branch 34 → 68 not taken.
✓ Branch 35 → 36 taken 3 times.
✓ Branch 35 → 37 taken 15 times.
✓ Branch 36 → 38 taken 3 times.
✗ Branch 36 → 68 not taken.
✓ Branch 37 → 38 taken 15 times.
✗ Branch 37 → 68 not taken.
|
18 | const std::string valueName = capture.getMode() == BY_REFERENCE ? name + ".addr" : name; |
| 1019 |
2/4✓ Branch 38 → 39 taken 18 times.
✗ Branch 38 → 62 not taken.
✓ Branch 39 → 40 taken 18 times.
✗ Branch 39 → 60 not taken.
|
18 | llvm::Value *captureAddress = insertStructGEP(structType, capturesPtr, captureIdx, valueName); |
| 1020 |
1/2✓ Branch 41 → 42 taken 18 times.
✗ Branch 41 → 66 not taken.
|
18 | capture.capturedSymbol->pushAddress(captureAddress); |
| 1021 | // Generate debug info | ||
| 1022 |
2/4✓ Branch 42 → 43 taken 18 times.
✗ Branch 42 → 65 not taken.
✓ Branch 43 → 44 taken 18 times.
✗ Branch 43 → 63 not taken.
|
18 | diGenerator.generateLocalVarDebugInfo(capture.getName(), captureAddress); |
| 1023 | 18 | captureIdx++; | |
| 1024 | 18 | } | |
| 1025 | } | ||
| 1026 | 15 | } | |
| 1027 | |||
| 1028 | } // namespace spice::compiler | ||
| 1029 |