diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..067b805b5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,192 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index fcc2f2305..7057db4d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,9 +65,9 @@ add_subdirectory(rtlib) add_subdirectory(scripts) -add_subdirectory(test/unit_tests) +#add_subdirectory(test/unit_tests) -add_subdirectory(benchmark) +#add_subdirectory(benchmark) ##### DEPRECATED ##### # save build configuration to build/build_config.txt diff --git a/DiscoPoP/CMakeLists.txt b/DiscoPoP/CMakeLists.txt index 2528e09d8..7519d5bb9 100644 --- a/DiscoPoP/CMakeLists.txt +++ b/DiscoPoP/CMakeLists.txt @@ -16,3 +16,13 @@ add_llvm_library(LLVMDiscoPoP MODULE InstructionDG.cpp ../share/lib/DPUtils.cpp ) + +# forward compiler flags +if(DEFINED DP_HYBRID_PROFILING) + message("Defined DP_HYBRID_PROFILING=" ${DP_HYBRID_PROFILING}) + target_compile_definitions(LLVMDiscoPoP PUBLIC DP_HYBRID_PROFILING=${DP_HYBRID_PROFILING}) +else() + target_compile_definitions(LLVMDiscoPoP PUBLIC DP_HYBRID_PROFILING=1) + message("Default defined DP_HYBRID_PROFILING=1") +endif() +# end of compiler flags \ No newline at end of file diff --git a/DiscoPoP/DiscoPoP.cpp b/DiscoPoP/DiscoPoP.cpp index ca6c6931f..8bf8ea695 100644 --- a/DiscoPoP/DiscoPoP.cpp +++ b/DiscoPoP/DiscoPoP.cpp @@ -19,9 +19,7 @@ #define DP_DEBUG false #define DP_VERBOSE false // prints warning messages #define DP_hybrid_DEBUG false -#define DP_hybrid_SKIP \ - true // todo add parameter to disable hybrid dependence analysis on demand. -#define DP_BRANCH_TRACKING \ +#define DP_BRANCH_TRACKING \ true // toggles the creation of instrumentation calls for tracking taken // branches. Required by the graph pruning step of the DiscoPoP // optimizer. @@ -35,10 +33,8 @@ StringRef DiscoPoP::getPassName() const { return "DiscoPoP"; } // Initializations void DiscoPoP::setupDataTypes() { Void = const_cast(Type::getVoidTy(*ThisModuleContext)); - Int32 = - const_cast(IntegerType::getInt32Ty(*ThisModuleContext)); - Int64 = - const_cast(IntegerType::getInt64Ty(*ThisModuleContext)); + Int32 = const_cast(IntegerType::getInt32Ty(*ThisModuleContext)); + Int64 = const_cast(IntegerType::getInt64Ty(*ThisModuleContext)); CharPtr = const_cast(Type::getInt8PtrTy(*ThisModuleContext)); } @@ -48,8 +44,7 @@ void DiscoPoP::setupCallbacks() { * arg types * NULL */ - DpInit = - ThisModule->getOrInsertFunction("__dp_init", Void, Int32, Int32, Int32); + DpInit = ThisModule->getOrInsertFunction("__dp_init", Void, Int32, Int32, Int32); DpFinalize = ThisModule->getOrInsertFunction("__dp_finalize", Void, Int32); @@ -71,30 +66,24 @@ void DiscoPoP::setupCallbacks() { DpAlloca = ThisModule->getOrInsertFunction("__dp_alloca", Void, - Int32, CharPtr, Int64, Int64, - Int64, Int64); + Int32, CharPtr, Int64, Int64, Int64, Int64); - DpNew = ThisModule->getOrInsertFunction("__dp_new", Void, Int32, Int64, Int64, - Int64); + DpNew = ThisModule->getOrInsertFunction("__dp_new", Void, Int32, Int64, Int64, Int64); DpDelete = ThisModule->getOrInsertFunction("__dp_delete", Void, Int32, Int64); DpCallOrInvoke = ThisModule->getOrInsertFunction("__dp_call", Void, Int32); - DpFuncEntry = - ThisModule->getOrInsertFunction("__dp_func_entry", Void, Int32, Int32); + DpFuncEntry = ThisModule->getOrInsertFunction("__dp_func_entry", Void, Int32, Int32); - DpFuncExit = - ThisModule->getOrInsertFunction("__dp_func_exit", Void, Int32, Int32); + DpFuncExit = ThisModule->getOrInsertFunction("__dp_func_exit", Void, Int32, Int32); - DpLoopEntry = - ThisModule->getOrInsertFunction("__dp_loop_entry", Void, Int32, Int32); + DpLoopEntry = ThisModule->getOrInsertFunction("__dp_loop_entry", Void, Int32, Int32); - DpLoopExit = - ThisModule->getOrInsertFunction("__dp_loop_exit", Void, Int32, Int32); + DpLoopExit = ThisModule->getOrInsertFunction("__dp_loop_exit", Void, Int32, Int32); - DpTakenBranchCounterIncr = ThisModule->getOrInsertFunction( - "__dp_incr_taken_branch_counter", Void, CharPtr, Int32, Int32); + DpTakenBranchCounterIncr = + ThisModule->getOrInsertFunction("__dp_incr_taken_branch_counter", Void, CharPtr, Int32, Int32); } bool DiscoPoP::doInitialization(Module &M) { @@ -127,10 +116,14 @@ bool DiscoPoP::doInitialization(Module &M) { if (tmp2 == NULL) { // DP_PROJECT_ROOT_DIR needs to be initialized std::cerr << "\nWARNING: No value for DP_PROJECT_ROOT_DIR found. \n"; - std::cerr << " As a result, library functions might be instrumented which can lead to\n"; + std::cerr << " As a result, library functions might be " + "instrumented which can lead to\n"; std::cerr << " increased profiling times and unexpected behavior.\n"; - std::cerr << " Please consider to specify the environment variable and rebuild.\n"; - std::cerr << " https://discopop-project.github.io/discopop/setup/environment_variables/\n\n"; + std::cerr << " Please consider to specify the environment variable " + "and rebuild.\n"; + std::cerr << " " + "https://discopop-project.github.io/discopop/setup/" + "environment_variables/\n\n"; // define fallback setenv("DP_PROJECT_ROOT_DIR", "/", 1); } @@ -144,8 +137,7 @@ bool DiscoPoP::doInitialization(Module &M) { initializeCUIDCounter(); - for (Module::global_iterator I = ThisModule->global_begin(); - I != ThisModule->global_end(); I++) { + for (Module::global_iterator I = ThisModule->global_begin(); I != ThisModule->global_end(); I++) { Value *globalVariable = dyn_cast(I); string glo = string(globalVariable->getName()); if (glo.find(".") == glo.npos) { @@ -162,8 +154,7 @@ bool DiscoPoP::doInitialization(Module &M) { ThisModule = &M; ThisModuleContext = &(M.getContext()); - for (set::iterator it = GlobalVars.begin(); - it != GlobalVars.end(); ++it) { + for (set::iterator it = GlobalVars.begin(); it != GlobalVars.end(); ++it) { GlobalVars.erase(it); } @@ -194,8 +185,7 @@ bool DiscoPoP::doInitialization(Module &M) { initializeBBDepCounter(); ReportBB = M.getOrInsertFunction("__dp_report_bb", Void, Int32); - ReportBBPair = - M.getOrInsertFunction("__dp_report_bb_pair", Void, Int32, Int32); + ReportBBPair = M.getOrInsertFunction("__dp_report_bb_pair", Void, Int32, Int32); VNF = new dputil::VariableNameFinder(M); int nextFreeStaticMemoryRegionID = 0; } @@ -229,11 +219,8 @@ bool DiscoPoP::doFinalization(Module &M) { if (Function *Fun = call_inst->getCalledFunction()) { if (Fun->getName() == "__dp_finalize") { IRBuilder<> builder(call_inst); - Value *V = builder.CreateGlobalStringPtr(StringRef(bbDepString), - ".dp_bb_deps"); - CallInst::Create(F.getParent()->getOrInsertFunction( - "__dp_add_bb_deps", Void, CharPtr), - V, "", call_inst); + Value *V = builder.CreateGlobalStringPtr(StringRef(bbDepString), ".dp_bb_deps"); + CallInst::Create(F.getParent()->getOrInsertFunction("__dp_add_bb_deps", Void, CharPtr), V, "", call_inst); } } } @@ -277,10 +264,8 @@ void DiscoPoP::getAnalysisUsage(AnalysisUsage &AU) const { void DiscoPoP::getFunctionReturnLines(Region *TopRegion, Node *root) { int lid = 0; - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { if (isa(instruction)) { lid = getLID(&*instruction, fileID); if (lid > 0) @@ -296,9 +281,7 @@ string DiscoPoP::determineVariableDefLine(Instruction *I) { bool isGlobal = false; string varName = determineVariableName_static(&*I, isGlobal, true); // varName = refineVarName(varName); - varName = (varName.find(".addr") == varName.npos) - ? varName - : varName.erase(varName.find(".addr"), 5); + varName = (varName.find(".addr") == varName.npos) ? varName : varName.erase(varName.find(".addr"), 5); // varName.erase(varName.find(".addr"), 5); // size_t pos = varName.find(".addr"); // if (pos != varName.npos) @@ -309,18 +292,14 @@ string DiscoPoP::determineVariableDefLine(Instruction *I) { if (programGlobalVariablesSet.count(varName)) { varDefLine = "GlobalVar"; // Find definition line of global variables - GlobalVariable *globalVariable = - I->getParent()->getParent()->getParent()->getGlobalVariable( - StringRef(varName)); + GlobalVariable *globalVariable = I->getParent()->getParent()->getParent()->getGlobalVariable(StringRef(varName)); if (globalVariable) { MDNode *metadata = globalVariable->getMetadata("dbg"); if (metadata) { if (isa(metadata)) { - varDefLine = to_string(fileID) + ":" + - to_string(cast( - globalVariable->getMetadata("dbg")) - ->getVariable() - ->getLine()); + varDefLine = + to_string(fileID) + ":" + + to_string(cast(globalVariable->getMetadata("dbg"))->getVariable()->getLine()); } } } @@ -335,8 +314,7 @@ string DiscoPoP::determineVariableDefLine(Instruction *I) { if (auto *N = dyn_cast(DI->getVariable())) { if (auto *DV = dyn_cast(N)) { - if (varType.find("ARRAY") != string::npos || - varType.find("STRUCT") != string::npos) { + if (varType.find("ARRAY") != string::npos || varType.find("STRUCT") != string::npos) { if (DV->getName() == varName) { varDefLine = to_string(fileID) + ":" + to_string(DV->getLine()); break; @@ -356,8 +334,7 @@ string DiscoPoP::determineVariableDefLine(Instruction *I) { } } if (vn == varName || vn == varName + ".addr") { - varDefLine = - to_string(fileID) + ":" + to_string(DV->getLine()); + varDefLine = to_string(fileID) + ":" + to_string(DV->getLine()); break; } } @@ -412,21 +389,16 @@ string DiscoPoP::determineVariableType(Instruction *I) { // recieves the region and outputs all variables and variables crossing basic // block boundaries in the region. -void DiscoPoP::populateGlobalVariablesSet(Region *TopRegion, - set &globalVariablesSet) { +void DiscoPoP::populateGlobalVariablesSet(Region *TopRegion, set &globalVariablesSet) { map variableToBBMap; bool isGlobalVariable; - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { - if (isa(instruction) || isa(instruction) || - isa(instruction)) { + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { + if (isa(instruction) || isa(instruction) || isa(instruction)) { // NOTE: changed 'instruction' to '&*instruction' - string varName = determineVariableName_static(&*instruction, - isGlobalVariable, false); + string varName = determineVariableName_static(&*instruction, isGlobalVariable, false); if (isGlobalVariable) // add it if it is a global variable in the // program @@ -449,13 +421,10 @@ void DiscoPoP::populateGlobalVariablesSet(Region *TopRegion, } } -void DiscoPoP::createTakenBranchInstrumentation( - Region *TopRegion, map> &BBIDToCUIDsMap) { +void DiscoPoP::createTakenBranchInstrumentation(Region *TopRegion, map> &BBIDToCUIDsMap) { /* Create calls to count taken branches inbetween CUs during execution */ - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { if (isa(instruction)) { BranchInst *branchInst = cast(instruction); // check for conditional branches, as unconditional ones can be ignored @@ -469,19 +438,16 @@ void DiscoPoP::createTakenBranchInstrumentation( for (auto source_cu : BBIDToCUIDsMap[source_BBID]) { // get BBIds of all targets for (int i = 0; i < branchInst->getNumSuccessors(); i++) { - string successor_BBID = - branchInst->getSuccessor(i)->getName().str(); + string successor_BBID = branchInst->getSuccessor(i)->getName().str(); // get CUs of all targets for (auto target_cu : BBIDToCUIDsMap[successor_BBID]) { // add instrumentation prior to the branch instruction vector args; string source_and_target = source_cu->ID + ";" + target_cu->ID; - args.push_back( - getOrInsertVarName_dynamic(source_and_target, IRB)); + args.push_back(getOrInsertVarName_dynamic(source_and_target, IRB)); args.push_back(branchInst->getCondition()); bool counter_active_on_cmp_value = (i == 0 ? 1 : 0); - args.push_back( - ConstantInt::get(Int32, counter_active_on_cmp_value)); + args.push_back(ConstantInt::get(Int32, counter_active_on_cmp_value)); IRB.CreateCall(DpTakenBranchCounterIncr, args); } } @@ -492,12 +458,9 @@ void DiscoPoP::createTakenBranchInstrumentation( } } -void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, - vector &CUVector, - map> &BBIDToCUIDsMap, Node *root, - LoopInfo &LI) { - const DataLayout *DL = - &ThisModule->getDataLayout(); // used to get data size of variables, +void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, vector &CUVector, + map> &BBIDToCUIDsMap, Node *root, LoopInfo &LI) { + const DataLayout *DL = &ThisModule->getDataLayout(); // used to get data size of variables, // pointers, structs etc. Node *currentNode = root; CU *cu; @@ -510,8 +473,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, map loopToNodeMap; - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { // Get the closest loop where bb lives in. // (loop == NULL) if bb is not in any loop. @@ -536,14 +498,11 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, } else { // end of loops. go to the parent of the loop. may have to jump several // nodes in case of nested loops - for (map::iterator it = loopToNodeMap.begin(); - it != loopToNodeMap.end(); it++) - if (it->second == - currentNode) // current node found in loop map jump to its parent. + for (map::iterator it = loopToNodeMap.begin(); it != loopToNodeMap.end(); it++) + if (it->second == currentNode) // current node found in loop map jump to its parent. { currentNode = currentNode->parentNode; - it = loopToNodeMap - .begin(); // search the whole map again for current node + it = loopToNodeMap.begin(); // search the whole map again for current node if (it->second == currentNode) // due to it++ we need to check first // element of map ourself currentNode = currentNode->parentNode; @@ -560,12 +519,10 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, currentNode->childrenNodes.push_back(cu); vector basicBlockCUVector; basicBlockCUVector.push_back(cu); - BBIDToCUIDsMap.insert( - pair>(bb->getName(), basicBlockCUVector)); + BBIDToCUIDsMap.insert(pair>(bb->getName(), basicBlockCUVector)); DILocalScope *scopeBuffer = NULL; - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { // NOTE: 'instruction' --> '&*instruction' lid = getLID(&*instruction, fileID); basicBlockName = bb->getName().str(); @@ -578,9 +535,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, int scopeIsParentOfBuffer = 0; if (scopeBuffer) { - scopeIsParentOfBuffer = - (&*instruction)->getDebugLoc()->getScope() == - scopeBuffer->getScope(); + scopeIsParentOfBuffer = (&*instruction)->getDebugLoc()->getScope() == scopeBuffer->getScope(); } if (scopeIsParentOfBuffer) { @@ -591,8 +546,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, // different scopes in the source code. // create new CU if the old one contains any instruction - if ((!cu->readPhaseLineNumbers.empty()) || - (!cu->writePhaseLineNumbers.empty()) || + if ((!cu->readPhaseLineNumbers.empty()) || (!cu->writePhaseLineNumbers.empty()) || (!cu->returnInstructions.empty())) { cu->startLine = *(cu->instructionsLineNumbers.begin()); cu->endLine = *(cu->instructionsLineNumbers.rbegin()); @@ -600,8 +554,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, cu->basicBlockName = basicBlockName; CUVector.push_back(cu); suspiciousVariables.clear(); - CU *temp = - cu; // keep current CU to make a reference to the successor CU + CU *temp = cu; // keep current CU to make a reference to the successor CU cu = new CU; cu->BBID = bb->getName().str(); @@ -628,10 +581,9 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, else if (isa(instruction)) { if ((cast(instruction))->isUnconditional()) { if ((cast(instruction))->getNumSuccessors() == 1) { - BasicBlock *successorBB = - (cast(instruction))->getSuccessor(0); - for (BasicBlock::iterator innerInstruction = successorBB->begin(); - innerInstruction != successorBB->end(); ++innerInstruction) { + BasicBlock *successorBB = (cast(instruction))->getSuccessor(0); + for (BasicBlock::iterator innerInstruction = successorBB->begin(); innerInstruction != successorBB->end(); + ++innerInstruction) { if (isa(innerInstruction)) { cu->returnInstructions.insert(lid); break; @@ -646,8 +598,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, Type *Ty = operand->getType(); unsigned u = DL->getTypeSizeInBits(Ty); cu->writeDataSize += u; - varName = - determineVariableName_static(&*instruction, isGlobalVar, false); + varName = determineVariableName_static(&*instruction, isGlobalVar, false); varType = determineVariableType(&*instruction); suspiciousVariables.insert(varName); if (lid > 0) @@ -657,8 +608,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, Type *Ty = instruction->getType(); unsigned u = DL->getTypeSizeInBits(Ty); cu->readDataSize += u; - varName = - determineVariableName_static(&*instruction, isGlobalVar, false); + varName = determineVariableName_static(&*instruction, isGlobalVar, false); if (suspiciousVariables.count(varName)) { // VIOLATION OF CAUTIOUS PROPERTY // it is a load instruction which read the value of a global @@ -680,8 +630,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, cu->basicBlockName = basicBlockName; CUVector.push_back(cu); suspiciousVariables.clear(); - CU *temp = - cu; // keep current CU to make a reference to the successor CU + CU *temp = cu; // keep current CU to make a reference to the successor CU cu = new CU; cu->BBID = bb->getName().str(); @@ -695,8 +644,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, cu->instructionsLineNumbers.insert(lid); } } else { - if (globalVariablesSet.count(varName) || - programGlobalVariablesSet.count(varName)) { + if (globalVariablesSet.count(varName) || programGlobalVariablesSet.count(varName)) { if (lid > 0) cu->readPhaseLineNumbers.insert(lid); } @@ -706,37 +654,25 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, // is called CallInst *ci = cast(instruction); set IOFunctions{ - "fopen", "fopen_s", "freopen", "freopen_s", - "fclose", "fflush", "setbuf", "setvbuf", - "fwide", "fread", "fwrite", "fgetc", - "getc", "fgets", "fputc", "putc", - "fputs", "getchar", "gets", "gets_s", - "putchar", "puts", "ungetc", "fgetwc", - "getwc", "fgetws", "fputwc", "putwc", - "fputws", "getwchar", "putwchar", "ungetwc", - "scanf", "fscanf", "sscanf", "scanf_s", - "fscanf_s", "sscanf_s", "vscanf", "vfscanf", - "vsscanf", "vscanf_s", "vfscanf_s", "vsscanf_s", - "printf", "fprintf", "sprintf", "snprintf", - "printf_s", "fprintf_s", "sprintf_s", "snprintf_s", - "vprintf", "vfprintf", "vsprintf", "vsnprintf", - "vprintf_s", "vfprintf_s", "vsprintf_s", "vsnprintf_s", - "wscanf", "fwscanf", "swscanf", "wscanf_s", - "fwscanf_s", "swscanf_s", "vwscanf", "vfwscanf", - "vswscanf", "vwscanf_s", "vfwscanf_s", "vswscanf_s", - "wprintf", "fwprintf", "swprintf", "wprintf_s", - "wprintf_s", "swprintf_s", "snwprintf_s", "vwprintf", - "vfwprintf", "vswprintf", "vwprintf_s", "vfwprintf_s", - "vswprintf_s", "vsnwprintf_s", "ftell", "fgetpos", - "fseek", "fsetpos", "rewind", "clearerr", - "feof", "ferror", "perror", "remove", - "rename", "tmpfile", "tmpfile_s", "tmpnam", - "tmpnam_s", "__isoc99_fscanf"}; + "fopen", "fopen_s", "freopen", "freopen_s", "fclose", "fflush", "setbuf", + "setvbuf", "fwide", "fread", "fwrite", "fgetc", "getc", "fgets", + "fputc", "putc", "fputs", "getchar", "gets", "gets_s", "putchar", + "puts", "ungetc", "fgetwc", "getwc", "fgetws", "fputwc", "putwc", + "fputws", "getwchar", "putwchar", "ungetwc", "scanf", "fscanf", "sscanf", + "scanf_s", "fscanf_s", "sscanf_s", "vscanf", "vfscanf", "vsscanf", "vscanf_s", + "vfscanf_s", "vsscanf_s", "printf", "fprintf", "sprintf", "snprintf", "printf_s", + "fprintf_s", "sprintf_s", "snprintf_s", "vprintf", "vfprintf", "vsprintf", "vsnprintf", + "vprintf_s", "vfprintf_s", "vsprintf_s", "vsnprintf_s", "wscanf", "fwscanf", "swscanf", + "wscanf_s", "fwscanf_s", "swscanf_s", "vwscanf", "vfwscanf", "vswscanf", "vwscanf_s", + "vfwscanf_s", "vswscanf_s", "wprintf", "fwprintf", "swprintf", "wprintf_s", "wprintf_s", + "swprintf_s", "snwprintf_s", "vwprintf", "vfwprintf", "vswprintf", "vwprintf_s", "vfwprintf_s", + "vswprintf_s", "vsnwprintf_s", "ftell", "fgetpos", "fseek", "fsetpos", "rewind", + "clearerr", "feof", "ferror", "perror", "remove", "rename", "tmpfile", + "tmpfile_s", "tmpnam", "tmpnam_s", "__isoc99_fscanf"}; if (ci) { if (ci->getCalledFunction()) { if (ci->getCalledFunction()->hasName()) { - if (find(IOFunctions.begin(), IOFunctions.end(), - ci->getCalledFunction()->getName().str()) != + if (find(IOFunctions.begin(), IOFunctions.end(), ci->getCalledFunction()->getName().str()) != IOFunctions.end()) { // Called function performs FileIO cu->performsFileIO = true; @@ -761,8 +697,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, suspiciousVariables.clear(); // check for call instructions in current basic block - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { // Note: Don't create nodes for library functions (c++/llvm). LID lid = getLID(&*instruction, fileID); if (lid > 0) { @@ -775,16 +710,14 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, if (f) { Function::iterator FI = f->begin(); bool externalFunction = true; - for (Function::iterator FI = f->begin(), FE = f->end(); FI != FE; - ++FI) { + for (Function::iterator FI = f->begin(), FE = f->end(); FI != FE; ++FI) { externalFunction = false; auto tempBI = FI->begin(); if (DebugLoc dl = tempBI->getDebugLoc()) { lid = to_string(dl->getLine()); } else { if (tempBI->getFunction()->getSubprogram()) - lid = to_string( - tempBI->getFunction()->getSubprogram()->getLine()); + lid = to_string(tempBI->getFunction()->getSubprogram()->getLine()); else { lid = "LineNotFound"; } @@ -813,8 +746,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, // have checked if f is not null here. Anyway, I (Mohammad) had to // bring the for loop inside to avoid the segmentation fault. If you // think it is not appropriate, find a solution for it. 14.2.2016 - for (Function::arg_iterator it = f->arg_begin(); it != f->arg_end(); - it++) { + for (Function::arg_iterator it = f->arg_begin(); it != f->arg_end(); it++) { string type_str; raw_string_ostream rso(type_str); (it->getType())->print(rso); @@ -837,8 +769,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, CallGraphWrapperPass *CGWP = &(getAnalysis()); if (isRecursive(*f, CGWP->getCallGraph())) { int lid = getLID(&*instruction, fileID); - n->recursiveFunctionCall = - n->name + " " + dputil::decodeLID(lid) + ","; + n->recursiveFunctionCall = n->name + " " + dputil::decodeLID(lid) + ","; } vector BBCUsVector = BBIDToCUIDsMap[bb->getName().str()]; @@ -858,9 +789,7 @@ void DiscoPoP::createCUs(Region *TopRegion, set &globalVariablesSet, } } -void DiscoPoP::fillCUVariables(Region *TopRegion, - set &globalVariablesSet, - vector &CUVector, +void DiscoPoP::fillCUVariables(Region *TopRegion, set &globalVariablesSet, vector &CUVector, map> &BBIDToCUIDsMap) { int lid; string varName, varType, varDefLine; @@ -869,10 +798,8 @@ void DiscoPoP::fillCUVariables(Region *TopRegion, const Instruction *TInst; string successorBB; - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { - CU *lastCU = BBIDToCUIDsMap[bb->getName().str()] - .back(); // get the last CU in the basic block + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { + CU *lastCU = BBIDToCUIDsMap[bb->getName().str()].back(); // get the last CU in the basic block // get all successor basic blocks for bb TInst = bb->getTerminator(); for (unsigned i = 0, nSucc = TInst->getNumSuccessors(); i < nSucc; ++i) { @@ -884,16 +811,14 @@ void DiscoPoP::fillCUVariables(Region *TopRegion, } auto bbCU = BBIDToCUIDsMap[bb->getName().str()].begin(); - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { if (isa(instruction) || isa(instruction)) { // NOTE: changed 'instruction' to '&*instruction' lid = getLID(&*instruction, fileID); if (lid == 0) continue; // NOTE: changed 'instruction' to '&*instruction', next 2 lines - varName = - determineVariableName_static(&*instruction, isGlobalVar, false); + varName = determineVariableName_static(&*instruction, isGlobalVar, false); varType = determineVariableType(&*instruction); int index = isa(&*instruction) ? 1 : 0; @@ -902,22 +827,19 @@ void DiscoPoP::fillCUVariables(Region *TopRegion, variableType = variableType->getPointerElementType(); } - string varSizeInBytes = - to_string(variableType->getScalarSizeInBits() / 8); + string varSizeInBytes = to_string(variableType->getScalarSizeInBits() / 8); varDefLine = determineVariableDefLine(&*instruction); bool readAccess = isa(instruction); bool writeAccess = isa(instruction); - Variable v(varName, varType, varDefLine, readAccess, writeAccess, - varSizeInBytes); + Variable v(varName, varType, varDefLine, readAccess, writeAccess, varSizeInBytes); if (lid > (*bbCU)->endLine) { bbCU = next(bbCU, 1); } - if (globalVariablesSet.count(varName) || - programGlobalVariablesSet.count(varName)) { + if (globalVariablesSet.count(varName) || programGlobalVariablesSet.count(varName)) { (*bbCU)->globalVariableNames.insert(v); } else { (*bbCU)->localVariableNames.insert(v); @@ -1008,14 +930,12 @@ bool DiscoPoP::isRecursive(Function &F, CallGraph &CG) { // iterates over all functions in the module and calls 'instrument_function' // on suitable ones -void DiscoPoP::instrument_module( - llvm::Module *module, map *trueVarNamesFromMetadataMap) { - for (llvm::Module::iterator func_it = module->begin(); - func_it != module->end(); ++func_it) { +void DiscoPoP::instrument_module(llvm::Module *module, map *trueVarNamesFromMetadataMap) { + for (llvm::Module::iterator func_it = module->begin(); func_it != module->end(); ++func_it) { llvm::Function *func = &(*func_it); std::string fn_name = func->getName().str(); - if (func->isDeclaration() || (strcmp(fn_name.c_str(), "NULL") == 0) || - fn_name.find("llvm") != std::string::npos || inlinedFunction(func)) { + if (func->isDeclaration() || (strcmp(fn_name.c_str(), "NULL") == 0) || fn_name.find("llvm") != std::string::npos || + inlinedFunction(func)) { continue; } instrument_function(func, trueVarNamesFromMetadataMap); @@ -1036,9 +956,7 @@ bool DiscoPoP::inlinedFunction(Function *F) { // iterates over all loops in a function and calls 'instrument_loop' for each // one -void DiscoPoP::instrument_function( - llvm::Function *function, - map *trueVarNamesFromMetadataMap) { +void DiscoPoP::instrument_function(llvm::Function *function, map *trueVarNamesFromMetadataMap) { // get the corresponding file id int32_t tmp_file_id; @@ -1047,13 +965,10 @@ void DiscoPoP::instrument_function( return; } - llvm::LoopInfo &loop_info = - getAnalysis(*function).getLoopInfo(); + llvm::LoopInfo &loop_info = getAnalysis(*function).getLoopInfo(); - for (auto loop_it = loop_info.begin(); loop_it != loop_info.end(); - ++loop_it) { - instrument_loop(*function, tmp_file_id, *loop_it, loop_info, - trueVarNamesFromMetadataMap); + for (auto loop_it = loop_info.begin(); loop_it != loop_info.end(); ++loop_it) { + instrument_loop(*function, tmp_file_id, *loop_it, loop_info, trueVarNamesFromMetadataMap); } } @@ -1061,9 +976,8 @@ void DiscoPoP::instrument_function( // suitable for reduction. // An entry is added to the 'loops_' vector and for each suitable instruction, // an entry is added to the 'instructions_' vector. -void DiscoPoP::instrument_loop( - Function &F, int file_id, llvm::Loop *loop, LoopInfo &LI, - map *trueVarNamesFromMetadataMap) { +void DiscoPoP::instrument_loop(Function &F, int file_id, llvm::Loop *loop, LoopInfo &LI, + map *trueVarNamesFromMetadataMap) { auto loc = loop->getStartLoc(); if (!dp_reduction_loc_exists(loc)) { @@ -1087,8 +1001,7 @@ void DiscoPoP::instrument_loop( // call 'instrument_loop' on all its subloops auto const sub_loops = loop->getSubLoops(); - for (auto loop_it = sub_loops.begin(); loop_it != sub_loops.end(); - ++loop_it) { + for (auto loop_it = sub_loops.begin(); loop_it != sub_loops.end(); ++loop_it) { instrument_loop(F, file_id, *loop_it, LI, trueVarNamesFromMetadataMap); } // The key corresponds to the variable that is loaded / stored. @@ -1102,8 +1015,7 @@ void DiscoPoP::instrument_loop( llvm::BasicBlock *const bb = basic_blocks[i]; std::string bb_name = bb->getName().str(); - if ((std::strncmp("for.inc", bb_name.c_str(), 7) == 0) || - (std::strncmp("for.cond", bb_name.c_str(), 8) == 0)) { + if ((std::strncmp("for.inc", bb_name.c_str(), 7) == 0) || (std::strncmp("for.cond", bb_name.c_str(), 8) == 0)) { continue; } @@ -1111,8 +1023,7 @@ void DiscoPoP::instrument_loop( llvm::Instruction *instr = &(*instr_it); auto opcode = instr->getOpcode(); - if (opcode != llvm::Instruction::Store && - opcode != llvm::Instruction::Load) { + if (opcode != llvm::Instruction::Store && opcode != llvm::Instruction::Load) { continue; } @@ -1122,15 +1033,13 @@ void DiscoPoP::instrument_loop( llvm::Value *operand = dp_reduction_get_var(instr); if (operand) { std::map *map_ptr = - (opcode == llvm::Instruction::Store) ? &store_instructions - : &load_instructions; + (opcode == llvm::Instruction::Store) ? &store_instructions : &load_instructions; if (!map_ptr->insert(std::make_pair(operand, instr)).second) { if ((*map_ptr)[operand]) { llvm::DebugLoc new_loc = instr->getDebugLoc(); llvm::DebugLoc old_loc = (*map_ptr)[operand]->getDebugLoc(); - if (!dp_reduction_loc_exists(new_loc) || - !dp_reduction_loc_exists(old_loc)) { + if (!dp_reduction_loc_exists(new_loc) || !dp_reduction_loc_exists(old_loc)) { (*map_ptr)[operand] = nullptr; } else if (new_loc.getLine() != old_loc.getLine()) { (*map_ptr)[operand] = nullptr; @@ -1146,8 +1055,7 @@ void DiscoPoP::instrument_loop( // - a variable must not be read or written more than once // - the store instruction comes after the load instruction std::vector candidates; - for (auto it = load_instructions.begin(); it != load_instructions.end(); - ++it) { + for (auto it = load_instructions.begin(); it != load_instructions.end(); ++it) { if (!it->second) continue; @@ -1155,18 +1063,15 @@ void DiscoPoP::instrument_loop( if (it2 != store_instructions.end() && it2->second) { llvm::DebugLoc load_loc = it->second->getDebugLoc(); llvm::DebugLoc store_loc = it2->second->getDebugLoc(); - if (!dp_reduction_loc_exists(load_loc) || - !dp_reduction_loc_exists(store_loc)) + if (!dp_reduction_loc_exists(load_loc) || !dp_reduction_loc_exists(store_loc)) continue; if (load_loc.getLine() > store_loc.getLine()) continue; - if (load_loc.getLine() == loop_info.line_nr_ || - store_loc.getLine() == loop_info.line_nr_) + if (load_loc.getLine() == loop_info.line_nr_ || store_loc.getLine() == loop_info.line_nr_) continue; if (loop_info.end_line == "LOOPENDNOTFOUND") { - errs() << "WARNING: Loop end not found! File: " << file_id - << " Function: " << F.getName() + errs() << "WARNING: Loop end not found! File: " << file_id << " Function: " << F.getName() << " Start line: " << loop_info.start_line << "\n"; continue; } @@ -1174,17 +1079,14 @@ void DiscoPoP::instrument_loop( continue; // Check if both load and store insts belong to the loop - if (load_loc.getLine() < loop_info.line_nr_ || - load_loc.getLine() > std::stoul(loop_info.end_line)) + if (load_loc.getLine() < loop_info.line_nr_ || load_loc.getLine() > std::stoul(loop_info.end_line)) continue; - if (store_loc.getLine() < loop_info.line_nr_ || - store_loc.getLine() > std::stoul(loop_info.end_line)) + if (store_loc.getLine() < loop_info.line_nr_ || store_loc.getLine() > std::stoul(loop_info.end_line)) continue; if (it->first->hasName()) { instr_info_t info; - info.var_name_ = dp_reduction_determineVariableName( - it->second, trueVarNamesFromMetadataMap); + info.var_name_ = dp_reduction_determineVariableName(it->second, trueVarNamesFromMetadataMap); info.loop_line_nr_ = loop_info.line_nr_; info.file_id_ = file_id; info.store_inst_ = llvm::dyn_cast(it2->second); @@ -1202,22 +1104,16 @@ void DiscoPoP::instrument_loop( string varTypeLoad = "SCALAR"; llvm::DebugLoc loc = (candidate.load_inst_)->getDebugLoc(); - varNameLoad = dp_reduction_determineVariableName( - candidate.load_inst_, trueVarNamesFromMetadataMap); + varNameLoad = dp_reduction_determineVariableName(candidate.load_inst_, trueVarNamesFromMetadataMap); varTypeLoad = dp_reduction_determineVariableType(candidate.load_inst_); - if (llvm::isa( - candidate.load_inst_->getOperand(index))) { - if (varTypeLoad.find("ARRAY,") == std::string::npos || - varNameLoad.find(".addr") == std::string::npos || + if (llvm::isa(candidate.load_inst_->getOperand(index))) { + if (varTypeLoad.find("ARRAY,") == std::string::npos || varNameLoad.find(".addr") == std::string::npos || varTypeLoad.find("**") != std::string::npos) { continue; - } else if (varTypeLoad.find("ARRAY,") != std::string::npos || - varNameLoad.find(".addr") != std::string::npos || - varTypeLoad.find("STRUCT,") != std::string::npos || - varTypeLoad.find("**") != std::string::npos) { + } else if (varTypeLoad.find("ARRAY,") != std::string::npos || varNameLoad.find(".addr") != std::string::npos || + varTypeLoad.find("STRUCT,") != std::string::npos || varTypeLoad.find("**") != std::string::npos) { llvm::Instruction *load_instr = nullptr; - llvm::Instruction *instr = dp_reduction_get_reduction_instr( - candidate.store_inst_, &load_instr); + llvm::Instruction *instr = dp_reduction_get_reduction_instr(candidate.store_inst_, &load_instr); if (instr) { candidate.load_inst_ = llvm::cast(load_instr); candidate.operation_ = dp_reduction_get_char_for_opcode(instr); @@ -1226,13 +1122,10 @@ void DiscoPoP::instrument_loop( } } } else { - if (varTypeLoad.find("ARRAY,") != std::string::npos || - varNameLoad.find(".addr") != std::string::npos || - varTypeLoad.find("STRUCT,") != std::string::npos || - varTypeLoad.find("**") != std::string::npos) { + if (varTypeLoad.find("ARRAY,") != std::string::npos || varNameLoad.find(".addr") != std::string::npos || + varTypeLoad.find("STRUCT,") != std::string::npos || varTypeLoad.find("**") != std::string::npos) { llvm::Instruction *load_instr = nullptr; - llvm::Instruction *instr = dp_reduction_get_reduction_instr( - candidate.store_inst_, &load_instr); + llvm::Instruction *instr = dp_reduction_get_reduction_instr(candidate.store_inst_, &load_instr); if (instr) { candidate.load_inst_ = llvm::cast(load_instr); candidate.operation_ = dp_reduction_get_char_for_opcode(instr); @@ -1243,8 +1136,7 @@ void DiscoPoP::instrument_loop( } } else { llvm::Instruction *load_instr = nullptr; - llvm::Instruction *instr = dp_reduction_get_reduction_instr( - candidate.store_inst_, &load_instr); + llvm::Instruction *instr = dp_reduction_get_reduction_instr(candidate.store_inst_, &load_instr); if (instr) { candidate.load_inst_ = llvm::cast(load_instr); candidate.operation_ = dp_reduction_get_char_for_opcode(instr); @@ -1257,16 +1149,14 @@ void DiscoPoP::instrument_loop( string bbName = BB->getName().str(); // Ignore loops. Only look for conditional blocks - if (bbName.find("if") != std::string::npos || - bbName.find("for") != std::string::npos) { + if (bbName.find("if") != std::string::npos || bbName.find("for") != std::string::npos) { // e.g. in lulesh.cc: "if (domain.vdov(indx) != Real_t(0.)) { if ( // dtf < dtcourant_tmp ) { dtcourant_tmp = dtf ; courant_elem = // indx ; }}" // check if loaded value is used in the store instruction to prevent // "false positives" - if (check_value_usage(candidate.store_inst_->getValueOperand(), - cast(candidate.load_inst_))) { + if (check_value_usage(candidate.store_inst_->getValueOperand(), cast(candidate.load_inst_))) { candidate.operation_ = '>'; } else { continue; @@ -1281,8 +1171,7 @@ void DiscoPoP::instrument_loop( } } -bool DiscoPoP::check_value_usage(llvm::Value *parentValue, - llvm::Value *searchedValue) { +bool DiscoPoP::check_value_usage(llvm::Value *parentValue, llvm::Value *searchedValue) { // Return true, if searchedValue is used within the computation of parentValue if (parentValue == searchedValue) { return true; @@ -1351,8 +1240,7 @@ unsigned DiscoPoP::dp_reduction_get_file_id(llvm::Function *func) { llvm::StringRef filename = di_loc->getFilename(); llvm::StringRef directory = di_loc->getDirectory(); - char *success = - realpath((directory.str() + "/" + filename.str()).c_str(), abs_path); + char *success = realpath((directory.str() + "/" + filename.str()).c_str(), abs_path); if (!success) { realpath(filename.str().c_str(), abs_path); } @@ -1375,8 +1263,7 @@ unsigned DiscoPoP::dp_reduction_get_file_id(llvm::Function *func) { } // finds the previous use of 'val' -llvm::Instruction *DiscoPoP::dp_reduction_get_prev_use(llvm::Instruction *instr, - llvm::Value *val) { +llvm::Instruction *DiscoPoP::dp_reduction_get_prev_use(llvm::Instruction *instr, llvm::Value *val) { if (!instr) return nullptr; @@ -1402,19 +1289,16 @@ llvm::Value *DiscoPoP::dp_reduction_get_var_rec(llvm::Value *val) { if (!val) return nullptr; - if (llvm::isa(val) || - llvm::isa(val)) { + if (llvm::isa(val) || llvm::isa(val)) { return val; } if (llvm::isa(val)) { - llvm::GetElementPtrInst *elem_ptr_instr = - llvm::cast(val); + llvm::GetElementPtrInst *elem_ptr_instr = llvm::cast(val); // struct member reductions are not supported by OpenMP llvm::Value *points_to = dp_reduction_points_to_var(elem_ptr_instr); llvm::AllocaInst *a_instr = llvm::dyn_cast(points_to); - llvm::Type *type = - (a_instr) ? a_instr->getAllocatedType() : points_to->getType(); + llvm::Type *type = (a_instr) ? a_instr->getAllocatedType() : points_to->getType(); if (type->isStructTy()) { return nullptr; } @@ -1439,12 +1323,10 @@ llvm::Value *DiscoPoP::dp_reduction_get_var(llvm::Instruction *instr) { // 'store_instr' (if such a reduction operation exists). // The parameter 'load_instr' will point to the load instruction that actually // loads the value (if such a load instruction exists). -llvm::Instruction * -DiscoPoP::dp_reduction_get_reduction_instr(llvm::Instruction *store_instr, - llvm::Instruction **load_instr) { +llvm::Instruction *DiscoPoP::dp_reduction_get_reduction_instr(llvm::Instruction *store_instr, + llvm::Instruction **load_instr) { // find the reduction operation for the source operand of the 'store_instr' - llvm::Instruction *reduction_instr = - dp_reduction_find_reduction_instr(store_instr->getOperand(0)); + llvm::Instruction *reduction_instr = dp_reduction_find_reduction_instr(store_instr->getOperand(0)); if (!reduction_instr) { return nullptr; } @@ -1454,8 +1336,7 @@ DiscoPoP::dp_reduction_get_reduction_instr(llvm::Instruction *store_instr, llvm::Value *store_dst = dp_reduction_get_var_rec(store_instr->getOperand(1)); if (store_dst) { std::vector reduction_operations; - *load_instr = dp_reduction_get_load_instr(store_dst, reduction_instr, - reduction_operations); + *load_instr = dp_reduction_get_load_instr(store_dst, reduction_instr, reduction_operations); // { *, / } > { +, - } > { & } > { ^ } > { | } if (reduction_operations.size() > 1) { int order = dp_reduction_get_op_order(reduction_operations[0]); @@ -1500,8 +1381,7 @@ Type *DiscoPoP::dp_reduction_pointsToStruct(PointerType *PTy) { return structType->getTypeID() == Type::StructTyID ? structType : NULL; } -string DiscoPoP::findStructMemberName_static(MDNode *structNode, unsigned idx, - IRBuilder<> &builder) { +string DiscoPoP::findStructMemberName_static(MDNode *structNode, unsigned idx, IRBuilder<> &builder) { assert(structNode); assert(structNode->getOperand(10)); MDNode *memberListNodes = cast(structNode->getOperand(10)); @@ -1509,9 +1389,7 @@ string DiscoPoP::findStructMemberName_static(MDNode *structNode, unsigned idx, assert(memberListNodes->getOperand(idx)); MDNode *member = cast(memberListNodes->getOperand(idx)); if (member->getOperand(3)) { - getOrInsertVarName_static( - dyn_cast(member->getOperand(3))->getString().str(), - builder); + getOrInsertVarName_static(dyn_cast(member->getOperand(3))->getString().str(), builder); return dyn_cast(member->getOperand(3))->getString().str(); } } @@ -1519,8 +1397,7 @@ string DiscoPoP::findStructMemberName_static(MDNode *structNode, unsigned idx, } // returns the value that the GetElementPtrInst ultimately points to -llvm::Value * -DiscoPoP::dp_reduction_points_to_var(llvm::GetElementPtrInst *instr) { +llvm::Value *DiscoPoP::dp_reduction_points_to_var(llvm::GetElementPtrInst *instr) { llvm::Value *points_to = nullptr; while (instr) { points_to = instr->getPointerOperand(); @@ -1531,10 +1408,8 @@ DiscoPoP::dp_reduction_points_to_var(llvm::GetElementPtrInst *instr) { // Finds the load instruction that actually loads the value from the address // 'load_val'. -llvm::Instruction * -DiscoPoP::dp_reduction_get_load_instr(llvm::Value *load_val, - llvm::Instruction *cur_instr, - std::vector &reduction_operations) { +llvm::Instruction *DiscoPoP::dp_reduction_get_load_instr(llvm::Value *load_val, llvm::Instruction *cur_instr, + std::vector &reduction_operations) { if (!load_val || !cur_instr) return nullptr; if (llvm::isa(cur_instr)) { @@ -1550,23 +1425,19 @@ DiscoPoP::dp_reduction_get_load_instr(llvm::Value *load_val, llvm::Instruction *prev_use = dp_reduction_get_prev_use(cur_instr, val); if (prev_use) { if (llvm::isa(prev_use)) { - return dp_reduction_get_load_instr(load_val, prev_use, - reduction_operations); + return dp_reduction_get_load_instr(load_val, prev_use, reduction_operations); } else if (llvm::isa(prev_use)) { - llvm::GetElementPtrInst *ptr_instr = - llvm::cast(prev_use); + llvm::GetElementPtrInst *ptr_instr = llvm::cast(prev_use); llvm::Value *points_to = dp_reduction_points_to_var(ptr_instr); if (points_to == load_val) { return cur_instr; } else { bool found = static_cast(dp_reduction_get_load_instr( - load_val, llvm::dyn_cast(points_to), - reduction_operations)); + load_val, llvm::dyn_cast(points_to), reduction_operations)); return (found) ? cur_instr : nullptr; } } else { - bool found = static_cast(dp_reduction_get_load_instr( - load_val, prev_use, reduction_operations)); + bool found = static_cast(dp_reduction_get_load_instr(load_val, prev_use, reduction_operations)); return (found) ? cur_instr : nullptr; } } else { @@ -1587,9 +1458,7 @@ DiscoPoP::dp_reduction_get_load_instr(llvm::Value *load_val, for (unsigned int i = 0; i != cur_instr->getNumOperands(); ++i) { llvm::Value *operand = cur_instr->getOperand(i); if (llvm::isa(operand)) { - result = dp_reduction_get_load_instr( - load_val, llvm::cast(operand), - reduction_operations); + result = dp_reduction_get_load_instr(load_val, llvm::cast(operand), reduction_operations); if (result) { break; } @@ -1605,8 +1474,7 @@ DiscoPoP::dp_reduction_get_load_instr(llvm::Value *load_val, // returns the reduction instruction where 'val' is the operand if it can find // such an operation -llvm::Instruction * -DiscoPoP::dp_reduction_find_reduction_instr(llvm::Value *val) { +llvm::Instruction *DiscoPoP::dp_reduction_find_reduction_instr(llvm::Value *val) { if (!val || !llvm::isa(val)) { return nullptr; } @@ -1616,8 +1484,7 @@ DiscoPoP::dp_reduction_find_reduction_instr(llvm::Value *val) { if (c != ' ') { return instr; } else if (opcode == llvm::Instruction::Load) { - llvm::Instruction *prev_use = - dp_reduction_get_prev_use(instr, instr->getOperand(0)); + llvm::Instruction *prev_use = dp_reduction_get_prev_use(instr, instr->getOperand(0)); return dp_reduction_find_reduction_instr(prev_use); } else if (opcode == llvm::Instruction::Store) { return dp_reduction_find_reduction_instr(instr->getOperand(0)); @@ -1632,8 +1499,7 @@ DiscoPoP::dp_reduction_find_reduction_instr(llvm::Value *val) { return nullptr; } -string DiscoPoP::dp_reduction_determineVariableName( - Instruction *I, map *trueVarNamesFromMetadataMap) { +string DiscoPoP::dp_reduction_determineVariableName(Instruction *I, map *trueVarNamesFromMetadataMap) { assert(I && "Instruction cannot be NULL \n"); int index = isa(I) ? 1 : 0; @@ -1643,8 +1509,7 @@ string DiscoPoP::dp_reduction_determineVariableName( if (operand == NULL) { string retVal = getOrInsertVarName_static("", builder); - if (trueVarNamesFromMetadataMap->find(retVal) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(retVal) == trueVarNamesFromMetadataMap->end()) { return retVal; // not found } else { return (*trueVarNamesFromMetadataMap)[retVal]; // found @@ -1655,8 +1520,7 @@ string DiscoPoP::dp_reduction_determineVariableName( //// we've found a global variable if (isa(*operand)) { string retVal = string(operand->getName()); - if (trueVarNamesFromMetadataMap->find(retVal) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(retVal) == trueVarNamesFromMetadataMap->end()) { return retVal; // not found } else { return (*trueVarNamesFromMetadataMap)[retVal]; // found @@ -1678,20 +1542,17 @@ string DiscoPoP::dp_reduction_determineVariableName( string strName(structType->getStructName().data()); map::iterator it = Structs.find(strName); if (it != Structs.end()) { - std::string ret = - findStructMemberName_static(it->second, memberIdx, builder); + std::string ret = findStructMemberName_static(it->second, memberIdx, builder); if (ret.size() > 0) { string retVal = ret; - if (trueVarNamesFromMetadataMap->find(retVal) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(retVal) == trueVarNamesFromMetadataMap->end()) { return retVal; // not found } else { return (*trueVarNamesFromMetadataMap)[retVal]; // found } } else { string retVal = getOrInsertVarName_static("", builder); - if (trueVarNamesFromMetadataMap->find(retVal) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(retVal) == trueVarNamesFromMetadataMap->end()) { return retVal; // not found } else { return (*trueVarNamesFromMetadataMap)[retVal]; // found @@ -1703,17 +1564,13 @@ string DiscoPoP::dp_reduction_determineVariableName( } // we've found an array - if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && - isa(*ptrOperand)) { - return dp_reduction_determineVariableName((Instruction *)ptrOperand, - trueVarNamesFromMetadataMap); + if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && isa(*ptrOperand)) { + return dp_reduction_determineVariableName((Instruction *)ptrOperand, trueVarNamesFromMetadataMap); } - return dp_reduction_determineVariableName((Instruction *)gep, - trueVarNamesFromMetadataMap); + return dp_reduction_determineVariableName((Instruction *)gep, trueVarNamesFromMetadataMap); } string retVal = string(operand->getName().data()); - if (trueVarNamesFromMetadataMap->find(retVal) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(retVal) == trueVarNamesFromMetadataMap->end()) { return retVal; // not found } else { return (*trueVarNamesFromMetadataMap)[retVal]; // found @@ -1721,8 +1578,7 @@ string DiscoPoP::dp_reduction_determineVariableName( } if (isa(*operand) || isa(*operand)) { - return dp_reduction_determineVariableName((Instruction *)(operand), - trueVarNamesFromMetadataMap); + return dp_reduction_determineVariableName((Instruction *)(operand), trueVarNamesFromMetadataMap); } // if we cannot determine the name, then return * return "*"; @@ -1767,8 +1623,7 @@ string DiscoPoP::dp_reduction_determineVariableType(Instruction *I) { return s; } -std::string DiscoPoP::dp_reduction_CFA(Function &F, llvm::Loop *L, - int file_id) { +std::string DiscoPoP::dp_reduction_CFA(Function &F, llvm::Loop *L, int file_id) { std::string lid = "LOOPENDNOTFOUND"; SmallVector ExitBlocks; for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB) { @@ -1801,14 +1656,10 @@ std::string DiscoPoP::dp_reduction_CFA(Function &F, llvm::Loop *L, // successors of the break statement(s). SmallVector RealExitBlocks; - for (SmallVectorImpl::iterator EI = ExitBlocks.begin(), - END = ExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = ExitBlocks.begin(), END = ExitBlocks.end(); EI != END; ++EI) { StringRef exitType = (*EI)->getName().split('.').first; - if (exitType.equals(loopType) && - ((*EI)->getName().find("end") != string::npos) && - (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), *EI) == - RealExitBlocks.end())) { + if (exitType.equals(loopType) && ((*EI)->getName().find("end") != string::npos) && + (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), *EI) == RealExitBlocks.end())) { RealExitBlocks.push_back(*EI); } else { // Changed TerminatorInst to Instruction @@ -1818,10 +1669,8 @@ std::string DiscoPoP::dp_reduction_CFA(Function &F, llvm::Loop *L, for (unsigned int i = 0; i < numSucc; ++i) { BasicBlock *succ = TI->getSuccessor(i); exitType = succ->getName().split('.').first; - if (exitType.equals(loopType) && - (succ->getName().find("end") != string::npos) && - (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), - succ) == RealExitBlocks.end())) { + if (exitType.equals(loopType) && (succ->getName().find("end") != string::npos) && + (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), succ) == RealExitBlocks.end())) { RealExitBlocks.push_back(succ); } } @@ -1834,26 +1683,21 @@ std::string DiscoPoP::dp_reduction_CFA(Function &F, llvm::Loop *L, // Check if entry block and exit block(s) have valid LID. bool hasValidExit = false; - for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), - END = RealExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), END = RealExitBlocks.end(); EI != END; + ++EI) { hasValidExit = dp_reduction_sanityCheck(*EI, file_id); if (hasValidExit == true) break; } if (hasValidExit) { - for (SmallVectorImpl::iterator - EI = RealExitBlocks.begin(), - END = RealExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), END = RealExitBlocks.end(); EI != END; + ++EI) { BasicBlock *currentBB = *EI; vector args; LID lid = 0; - for (BasicBlock::iterator BI = currentBB->begin(), - EI = currentBB->end(); - BI != EI; ++BI) { + for (BasicBlock::iterator BI = currentBB->begin(), EI = currentBB->end(); BI != EI; ++BI) { lid = dp_reduction_getLID(&*BI, file_id); uint64_t ulid = (uint64_t)lid; if (ulid != 0) { @@ -1931,8 +1775,7 @@ char DiscoPoP::dp_reduction_get_char_for_opcode(llvm::Instruction *instr) { if (instr->getNumOperands() >= 1) { Value *rhs_value = instr->getOperand(1); if (isa(rhs_value)) { - operand_is_negative_constant = - cast(rhs_value)->isNegative(); + operand_is_negative_constant = cast(rhs_value)->isNegative(); } } @@ -1946,8 +1789,7 @@ char DiscoPoP::dp_reduction_get_char_for_opcode(llvm::Instruction *instr) { if (instr->getNumOperands() >= 1) { Value *rhs_value = instr->getOperand(1); if (isa(rhs_value)) { - operand_is_negative_constant = - cast(rhs_value)->isNegative(); + operand_is_negative_constant = cast(rhs_value)->isNegative(); } } @@ -1968,8 +1810,7 @@ char DiscoPoP::dp_reduction_get_char_for_opcode(llvm::Instruction *instr) { } // return true if 'operand' is an operand of the instruction 'instr' -bool DiscoPoP::dp_reduction_is_operand(llvm::Instruction *instr, - llvm::Value *operand) { +bool DiscoPoP::dp_reduction_is_operand(llvm::Instruction *instr, llvm::Value *operand) { unsigned num_operands = instr->getNumOperands(); for (unsigned i = 0; i < num_operands; ++i) { if (instr->getOperand(i) == operand) @@ -2001,17 +1842,14 @@ void DiscoPoP::dp_reduction_insert_functions() { int loop_id = 1; llvm::Type *loop_incr_fn_arg_type = llvm::Type::getInt32Ty(*ctx_); llvm::ArrayRef loop_incr_fn_args(loop_incr_fn_arg_type); - llvm::FunctionType *loop_incr_fn_type = llvm::FunctionType::get( - llvm::Type::getVoidTy(*ctx_), loop_incr_fn_args, false); - FunctionCallee incr_loop_counter_callee = - module_->getOrInsertFunction("__dp_loop_incr", loop_incr_fn_type); + llvm::FunctionType *loop_incr_fn_type = + llvm::FunctionType::get(llvm::Type::getVoidTy(*ctx_), loop_incr_fn_args, false); + FunctionCallee incr_loop_counter_callee = module_->getOrInsertFunction("__dp_loop_incr", loop_incr_fn_type); for (auto const &loop_info : loops_) { - llvm::Value *val = - llvm::ConstantInt::get(llvm::Type::getInt32Ty(*ctx_), loop_id); + llvm::Value *val = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*ctx_), loop_id); llvm::ArrayRef args(val); - llvm::CallInst::Create(incr_loop_counter_callee, args, "", - loop_info.first_body_instr_); + llvm::CallInst::Create(incr_loop_counter_callee, args, "", loop_info.first_body_instr_); loop_metadata_file << loop_info.file_id_ << " "; loop_metadata_file << loop_id++ << " "; loop_metadata_file << loop_info.line_nr_ << "\n"; @@ -2020,17 +1858,13 @@ void DiscoPoP::dp_reduction_insert_functions() { // add a function to output the final data // dp_loop_output - llvm::FunctionType *output_fn_type = - llvm::FunctionType::get(llvm::Type::getVoidTy(*ctx_), false); - FunctionCallee loop_counter_output_callee = - module_->getOrInsertFunction("__dp_loop_output", output_fn_type); + llvm::FunctionType *output_fn_type = llvm::FunctionType::get(llvm::Type::getVoidTy(*ctx_), false); + FunctionCallee loop_counter_output_callee = module_->getOrInsertFunction("__dp_loop_output", output_fn_type); FunctionCallee cu_taken_branch_counter_output_callee = - module_->getOrInsertFunction("__dp_taken_branch_counter_output", - output_fn_type); + module_->getOrInsertFunction("__dp_taken_branch_counter_output", output_fn_type); llvm::Function *main_fn = module_->getFunction("main"); if (main_fn) { - for (auto it = llvm::inst_begin(main_fn); it != llvm::inst_end(main_fn); - ++it) { + for (auto it = llvm::inst_begin(main_fn); it != llvm::inst_end(main_fn); ++it) { if (llvm::isa(&(*it))) { llvm::IRBuilder<> ir_builder(&(*it)); ir_builder.CreateCall(loop_counter_output_callee); @@ -2049,8 +1883,7 @@ void DiscoPoP::dp_reduction_insert_functions() { // Helper functions bool DiscoPoP::isaCallOrInvoke(Instruction *BI) { - return (BI != NULL) && ((isa(BI) && (!isa(BI))) || - isa(BI)); + return (BI != NULL) && ((isa(BI) && (!isa(BI))) || isa(BI)); } bool DiscoPoP::sanityCheck(BasicBlock *BB) { @@ -2083,8 +1916,7 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { if (L != NULL && LI.isLoopHeader(tmpBB)) { StringRef loopType = tmpBB->getName().split('.').first; if (DP_DEBUG) { - errs() << "loop [" << loopType << "] header: " << tmpBB->getName() - << "\n"; + errs() << "loop [" << loopType << "] header: " << tmpBB->getName() << "\n"; } // If tmpBB is the header block, get the exit blocks of the loop. @@ -2097,8 +1929,7 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { } if (ExitBlocks.size() == 0) { - errs() << "WARNING: loop at " << tmpBB - << " is ignored: exit BB not found.\n"; + errs() << "WARNING: loop at " << tmpBB << " is ignored: exit BB not found.\n"; continue; } @@ -2110,14 +1941,10 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { if (DP_DEBUG) { errs() << "loop exits:"; } - for (SmallVectorImpl::iterator EI = ExitBlocks.begin(), - END = ExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = ExitBlocks.begin(), END = ExitBlocks.end(); EI != END; ++EI) { StringRef exitType = (*EI)->getName().split('.').first; - if (exitType.equals(loopType) && - ((*EI)->getName().find("end") != string::npos) && - (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), *EI) == - RealExitBlocks.end())) { + if (exitType.equals(loopType) && ((*EI)->getName().find("end") != string::npos) && + (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), *EI) == RealExitBlocks.end())) { RealExitBlocks.push_back(*EI); if (DP_DEBUG) { errs() << " " << (*EI)->getName(); @@ -2130,10 +1957,8 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { for (unsigned int i = 0; i < numSucc; ++i) { BasicBlock *succ = TI->getSuccessor(i); exitType = succ->getName().split('.').first; - if (exitType.equals(loopType) && - (succ->getName().find("end") != string::npos) && - (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), - succ) == RealExitBlocks.end())) { + if (exitType.equals(loopType) && (succ->getName().find("end") != string::npos) && + (std::find(RealExitBlocks.begin(), RealExitBlocks.end(), succ) == RealExitBlocks.end())) { RealExitBlocks.push_back(succ); if (DP_DEBUG) { errs() << " " << succ->getName(); @@ -2150,8 +1975,7 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { // exit block!"); if (RealExitBlocks.size() == 0) { if (DP_VERBOSE) { - errs() << "WARNING: loop at " << tmpBB - << " is ignored: exit blocks are not well formed.\n"; + errs() << "WARNING: loop at " << tmpBB << " is ignored: exit blocks are not well formed.\n"; } continue; } @@ -2159,9 +1983,8 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { // Check if entry block and exit block(s) have valid LID. bool hasValidEntry = sanityCheck(tmpBB); bool hasValidExit = false; - for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), - END = RealExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), END = RealExitBlocks.end(); EI != END; + ++EI) { hasValidExit = sanityCheck(*EI); if (hasValidExit == true) break; @@ -2172,10 +1995,8 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { instrumentLoopEntry(tmpBB, loopID); // Instrument loop exit block(s). - for (SmallVectorImpl::iterator - EI = RealExitBlocks.begin(), - END = RealExitBlocks.end(); - EI != END; ++EI) { + for (SmallVectorImpl::iterator EI = RealExitBlocks.begin(), END = RealExitBlocks.end(); EI != END; + ++EI) { instrumentLoopExit(*EI, loopID); } ++loopID; @@ -2186,7 +2007,7 @@ void DiscoPoP::CFA(Function &F, LoopInfo &LI) { // pass get invoked here bool DiscoPoP::runOnModule(Module &M) { - //cout << "MODULE " << M.getName().str() << "\n"; + // cout << "MODULE " << M.getName().str() << "\n"; long counter = 0; // cout << "\tFUNCTION:\n"; @@ -2242,11 +2063,11 @@ bool DiscoPoP::runOnModule(Module &M) { bool DiscoPoP::runOnFunction(Function &F) { if (DP_DEBUG) { - errs() << "pass DiscoPoP: run pass on function " << F.getName().str() - << "\n"; + errs() << "pass DiscoPoP: run pass on function " << F.getName().str() << "\n"; } - // avoid instrumenting functions which are defined outside the scope of the project + // avoid instrumenting functions which are defined outside the scope of the + // project std::string dp_project_dir(getenv("DP_PROJECT_ROOT_DIR")); SmallVector, 4> MDs; F.getAllMetadata(MDs); @@ -2255,7 +2076,7 @@ bool DiscoPoP::runOnFunction(Function &F) { if (MDNode *N = MD.second) { if (auto *subProgram = dyn_cast(N)) { std::string fullFileName = ""; - if(subProgram->getDirectory().str().length() > 0){ + if (subProgram->getDirectory().str().length() > 0) { fullFileName += subProgram->getDirectory().str(); fullFileName += "/"; } @@ -2267,7 +2088,7 @@ bool DiscoPoP::runOnFunction(Function &F) { } } } - if (!funcDefinedInProject){ + if (!funcDefinedInProject) { return false; } @@ -2296,7 +2117,7 @@ bool DiscoPoP::runOnFunction(Function &F) { if (funcName.find("pthread_") != string::npos) { return false; } - + vector CUVector; set globalVariablesSet; // list of variables which appear in more than // one basic block @@ -2334,8 +2155,7 @@ bool DiscoPoP::runOnFunction(Function &F) { while (variableType->isPointerTy()) { variableType = variableType->getPointerElementType(); } - Variable v(it->getName().str(), rso.str(), to_string(fileID) + ":" + lid, - true, true, + Variable v(it->getName().str(), rso.str(), to_string(fileID) + ":" + lid, true, true, to_string(variableType->getScalarSizeInBits() / 8)); root->argumentsList.push_back(v); } @@ -2354,8 +2174,7 @@ bool DiscoPoP::runOnFunction(Function &F) { populateGlobalVariablesSet(TopRegion, globalVariablesSet); - createCUs(TopRegion, globalVariablesSet, CUVector, BBIDToCUIDsMap, root, - LI); + createCUs(TopRegion, globalVariablesSet, CUVector, BBIDToCUIDsMap, root, LI); if (DP_BRANCH_TRACKING) { createTakenBranchInstrumentation(TopRegion, BBIDToCUIDsMap); @@ -2407,12 +2226,19 @@ bool DiscoPoP::runOnFunction(Function &F) { { if (F.getInstructionCount() == 0) return false; - if (DP_hybrid_SKIP) { - return true; - } + +// Enable / Disable hybrid profiling +#ifndef DP_HYBRID_PROFILING +#define DP_HYBRID_PROFILING 1 +#endif + +#if DP_HYBRID_PROFILING == 0 + return true; +#endif + ///// + if (DP_hybrid_DEBUG) - errs() << "\n---------- Omission Analysis on " << F.getName() - << " ----------\n"; + errs() << "\n---------- Omission Analysis on " << F.getName() << " ----------\n"; DebugLoc dl; Value *V; @@ -2432,15 +2258,12 @@ bool DiscoPoP::runOnFunction(Function &F) { // other functions (by ref/ptr) if (CallInst *call_inst = dyn_cast(&I)) { if (Function *Fun = call_inst->getCalledFunction()) { - if (Fun->getName() == "__dp_write" || - Fun->getName() == "__dp_read" || - Fun->getName() == "__dp_alloca") { + if (Fun->getName() == "__dp_write" || Fun->getName() == "__dp_read" || Fun->getName() == "__dp_alloca") { ++totalInstrumentations; } for (uint i = 0; i < call_inst->getNumOperands() - 1; ++i) { V = call_inst->getArgOperand(i); - std::set::iterator it = - staticallyPredictableValues.find(V); + std::set::iterator it = staticallyPredictableValues.find(V); if (it != staticallyPredictableValues.end()) { staticallyPredictableValues.erase(V); if (DP_hybrid_DEBUG) @@ -2463,9 +2286,8 @@ bool DiscoPoP::runOnFunction(Function &F) { // assign static memory region IDs to statically predictable values and thus // dependencies - unordered_map> - staticValueNameToMemRegIDMap; // : (original variable - // name, statically assigned MemReg ID) + unordered_map> staticValueNameToMemRegIDMap; // : (original variable + // name, statically assigned MemReg ID) bool tmpIsGlobal; long next_id; string llvmIRVarName; @@ -2485,8 +2307,7 @@ bool DiscoPoP::runOnFunction(Function &F) { originalVarName = llvmIRVarName; } staticMemoryRegionID = "S" + to_string(next_id); - staticValueNameToMemRegIDMap[llvmIRVarName] = - pair(originalVarName, staticMemoryRegionID); + staticValueNameToMemRegIDMap[llvmIRVarName] = pair(originalVarName, staticMemoryRegionID); } if (DP_hybrid_DEBUG) { @@ -2514,8 +2335,7 @@ bool DiscoPoP::runOnFunction(Function &F) { if (isa(Dst)) V = dyn_cast(Dst); - if (staticallyPredictableValues.find(V) == - staticallyPredictableValues.end()) + if (staticallyPredictableValues.find(V) == staticallyPredictableValues.end()) continue; if (Src != Dst && DT.dominates(Dst, Src)) { @@ -2523,15 +2343,13 @@ bool DiscoPoP::runOnFunction(Function &F) { set tmp; conditionalBBDepMap[Src->getParent()] = tmp; } - conditionalBBDepMap[Src->getParent()].insert( - DG.edgeToDPDep(edge, staticValueNameToMemRegIDMap)); + conditionalBBDepMap[Src->getParent()].insert(DG.edgeToDPDep(edge, staticValueNameToMemRegIDMap)); } else { if (!conditionalBBPairDepMap.count(Dst->getParent())) { map> tmp; conditionalBBPairDepMap[Dst->getParent()] = tmp; } - if (!conditionalBBPairDepMap[Dst->getParent()].count( - Src->getParent())) { + if (!conditionalBBPairDepMap[Dst->getParent()].count(Src->getParent())) { set tmp; conditionalBBPairDepMap[Dst->getParent()][Src->getParent()] = tmp; } @@ -2548,8 +2366,7 @@ bool DiscoPoP::runOnFunction(Function &F) { continue; V = node->getItem()->getOperand(isa(node->getItem()) ? 1 : 0); if (!DG.getInEdges(node).size() && !DG.getOutEdges(node).size() && - staticallyPredictableValues.find(V) != - staticallyPredictableValues.end()) + staticallyPredictableValues.find(V) != staticallyPredictableValues.end()) omittableInstructions.insert(node->getItem()); } @@ -2560,8 +2377,7 @@ bool DiscoPoP::runOnFunction(Function &F) { if (isa(pair.first->getTerminator())) { insertionPoint = insertionPoint->getPrevNonDebugInstruction(); } - auto CI = CallInst::Create(ReportBB, ConstantInt::get(Int32, bbDepCount), - "", insertionPoint); + auto CI = CallInst::Create(ReportBB, ConstantInt::get(Int32, bbDepCount), "", insertionPoint); // ---- Insert deps into string ---- if (bbDepCount) @@ -2581,11 +2397,8 @@ bool DiscoPoP::runOnFunction(Function &F) { // Add observation of in-order execution of pairs of basic blocks for (auto pair1 : conditionalBBPairDepMap) { // Alloca and init semaphore var for BB - auto AI = new AllocaInst( - Int32, 0, "__dp_bb", - F.getEntryBlock().getFirstNonPHI()->getNextNonDebugInstruction()); - new StoreInst(ConstantInt::get(Int32, 0), AI, false, - AI->getNextNonDebugInstruction()); + auto AI = new AllocaInst(Int32, 0, "__dp_bb", F.getEntryBlock().getFirstNonPHI()->getNextNonDebugInstruction()); + new StoreInst(ConstantInt::get(Int32, 0), AI, false, AI->getNextNonDebugInstruction()); for (auto pair2 : pair1.second) { // Insert check for semaphore @@ -2613,8 +2426,7 @@ bool DiscoPoP::runOnFunction(Function &F) { ++bbDepCount; } // Insert semaphore update to true - new StoreInst(ConstantInt::get(Int32, 1), AI, false, - pair1.first->getTerminator()); + new StoreInst(ConstantInt::get(Int32, 1), AI, false, pair1.first->getTerminator()); } if (DumpToDot) { @@ -2648,11 +2460,7 @@ bool DiscoPoP::runOnFunction(Function &F) { for (Instruction &I : BB) { if (!isa(I) && !isa(I) && !isa(I)) continue; - errs() << "\t" - << (isa(I) - ? "Write " - : (isa(I) ? "Alloca " : "Read ")) - << " | "; + errs() << "\t" << (isa(I) ? "Write " : (isa(I) ? "Alloca " : "Read ")) << " | "; if (dl = I.getDebugLoc()) { errs() << dl.getLine() << "," << dl.getCol(); } else { @@ -2734,16 +2542,14 @@ void DiscoPoP::collectDebugInfo() { DIGlobalVariable *DiscoPoP::findDbgGlobalDeclare(GlobalVariable *v) { assert(v && "Global variable cannot be null"); - for (set::iterator it = GlobalVars.begin(); - it != GlobalVars.end(); ++it) { + for (set::iterator it = GlobalVars.begin(); it != GlobalVars.end(); ++it) { if ((*it)->getDisplayName() == v->getName()) return *it; } return NULL; } -string DiscoPoP::getOrInsertVarName_static(string varName, - IRBuilder<> &builder) { +string DiscoPoP::getOrInsertVarName_static(string varName, IRBuilder<> &builder) { Value *valName = NULL; std::string vName = varName; map::iterator pair = VarNames.find(varName); @@ -2758,12 +2564,10 @@ string DiscoPoP::getOrInsertVarName_static(string varName, return vName; } -Value *DiscoPoP::getOrInsertVarName_dynamic(string varName, - IRBuilder<> &builder) { +Value *DiscoPoP::getOrInsertVarName_dynamic(string varName, IRBuilder<> &builder) { // 26.08.2022 Lukas // update varName with original varName from Metadata - if (trueVarNamesFromMetadataMap.find(varName) == - trueVarNamesFromMetadataMap.end()) { + if (trueVarNamesFromMetadataMap.find(varName) == trueVarNamesFromMetadataMap.end()) { // not found, do nothing } else { // found, update varName @@ -2781,8 +2585,7 @@ Value *DiscoPoP::getOrInsertVarName_dynamic(string varName, return vName; } -Value *DiscoPoP::findStructMemberName(MDNode *structNode, unsigned idx, - IRBuilder<> &builder) { +Value *DiscoPoP::findStructMemberName(MDNode *structNode, unsigned idx, IRBuilder<> &builder) { assert(structNode); assert(structNode->getOperand(10)); MDNode *memberListNodes = cast(structNode->getOperand(10)); @@ -2790,9 +2593,7 @@ Value *DiscoPoP::findStructMemberName(MDNode *structNode, unsigned idx, assert(memberListNodes->getOperand(idx)); MDNode *member = cast(memberListNodes->getOperand(idx)); if (member->getOperand(3)) { - return getOrInsertVarName_dynamic( - dyn_cast(member->getOperand(3))->getString().str(), - builder); + return getOrInsertVarName_dynamic(dyn_cast(member->getOperand(3))->getString().str(), builder); } } return NULL; @@ -2809,9 +2610,8 @@ Type *DiscoPoP::pointsToStruct(PointerType *PTy) { return structType->getTypeID() == Type::StructTyID ? structType : NULL; } -string DiscoPoP::determineVariableName_static( - Instruction *I, bool &isGlobalVariable /*=defaultIsGlobalVariableValue*/, - bool disable_MetadataMap) { +string DiscoPoP::determineVariableName_static(Instruction *I, bool &isGlobalVariable /*=defaultIsGlobalVariableValue*/, + bool disable_MetadataMap) { assert(I && "Instruction cannot be NULL \n"); int index = isa(I) ? 1 : 0; @@ -2821,9 +2621,7 @@ string DiscoPoP::determineVariableName_static( if (operand == NULL) { string retVal = getOrInsertVarName_static("", builder); - if (trueVarNamesFromMetadataMap.find(retVal) == - trueVarNamesFromMetadataMap.end() || - disable_MetadataMap) { + if (trueVarNamesFromMetadataMap.find(retVal) == trueVarNamesFromMetadataMap.end() || disable_MetadataMap) { return retVal; // not found } else { return trueVarNamesFromMetadataMap[retVal]; // found @@ -2836,9 +2634,7 @@ string DiscoPoP::determineVariableName_static( // MOHAMMAD ADDED THIS FOR CHECKING isGlobalVariable = true; string retVal = string(operand->getName()); - if (trueVarNamesFromMetadataMap.find(retVal) == - trueVarNamesFromMetadataMap.end() || - disable_MetadataMap) { + if (trueVarNamesFromMetadataMap.find(retVal) == trueVarNamesFromMetadataMap.end() || disable_MetadataMap) { return retVal; // not found } else { return trueVarNamesFromMetadataMap[retVal]; // found @@ -2860,12 +2656,10 @@ string DiscoPoP::determineVariableName_static( string strName(structType->getStructName().data()); map::iterator it = Structs.find(strName); if (it != Structs.end()) { - std::string ret = - findStructMemberName_static(it->second, memberIdx, builder); + std::string ret = findStructMemberName_static(it->second, memberIdx, builder); if (ret.size() > 0) { string retVal = ret; - if (trueVarNamesFromMetadataMap.find(retVal) == - trueVarNamesFromMetadataMap.end() || + if (trueVarNamesFromMetadataMap.find(retVal) == trueVarNamesFromMetadataMap.end() || disable_MetadataMap) { return retVal; // not found } else { @@ -2873,8 +2667,7 @@ string DiscoPoP::determineVariableName_static( } } else { string retVal = getOrInsertVarName_static("", builder); - if (trueVarNamesFromMetadataMap.find(retVal) == - trueVarNamesFromMetadataMap.end() || + if (trueVarNamesFromMetadataMap.find(retVal) == trueVarNamesFromMetadataMap.end() || disable_MetadataMap) { return retVal; // not found } else { @@ -2888,18 +2681,13 @@ string DiscoPoP::determineVariableName_static( } // we've found an array - if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && - isa(*ptrOperand)) { - return determineVariableName_static((Instruction *)ptrOperand, - isGlobalVariable, false); + if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && isa(*ptrOperand)) { + return determineVariableName_static((Instruction *)ptrOperand, isGlobalVariable, false); } - return determineVariableName_static((Instruction *)gep, isGlobalVariable, - false); + return determineVariableName_static((Instruction *)gep, isGlobalVariable, false); } string retVal = string(operand->getName().data()); - if (trueVarNamesFromMetadataMap.find(retVal) == - trueVarNamesFromMetadataMap.end() || - disable_MetadataMap) { + if (trueVarNamesFromMetadataMap.find(retVal) == trueVarNamesFromMetadataMap.end() || disable_MetadataMap) { return retVal; // not found } else { return trueVarNamesFromMetadataMap[retVal]; // found @@ -2908,8 +2696,7 @@ string DiscoPoP::determineVariableName_static( } if (isa(*operand) || isa(*operand)) { - return determineVariableName_static((Instruction *)(operand), - isGlobalVariable, false); + return determineVariableName_static((Instruction *)(operand), isGlobalVariable, false); } // if we cannot determine the name, then return * return ""; // getOrInsertVarName("*", builder); @@ -2929,11 +2716,9 @@ Value *DiscoPoP::determineVariableName_dynamic(Instruction *const I) { if (operand->hasName()) { // we've found a global variable if (isa(*operand)) { - DIGlobalVariable *gv = - findDbgGlobalDeclare(cast(operand)); + DIGlobalVariable *gv = findDbgGlobalDeclare(cast(operand)); if (gv != NULL) { - return getOrInsertVarName_dynamic(string(gv->getDisplayName().data()), - builder); + return getOrInsertVarName_dynamic(string(gv->getDisplayName().data()), builder); } } if (isa(*operand)) { @@ -2963,14 +2748,12 @@ Value *DiscoPoP::determineVariableName_dynamic(Instruction *const I) { } // we've found an array - if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && - isa(*ptrOperand)) { + if (PTy->getPointerElementType()->getTypeID() == Type::ArrayTyID && isa(*ptrOperand)) { return determineVariableName_dynamic((Instruction *)ptrOperand); } return determineVariableName_dynamic((Instruction *)gep); } - return getOrInsertVarName_dynamic(string(operand->getName().data()), - builder); + return getOrInsertVarName_dynamic(string(operand->getName().data()), builder); } if (isa(*operand) || isa(*operand)) { @@ -2983,21 +2766,17 @@ Value *DiscoPoP::determineVariableName_dynamic(Instruction *const I) { return getOrInsertVarName_dynamic("*", builder); } -void DiscoPoP::getTrueVarNamesFromMetadata( - Region *TopRegion, Node *root, - std::map *trueVarNamesFromMetadataMap) { +void DiscoPoP::getTrueVarNamesFromMetadata(Region *TopRegion, Node *root, + std::map *trueVarNamesFromMetadataMap) { int lid = 0; - for (Region::block_iterator bb = TopRegion->block_begin(); - bb != TopRegion->block_end(); ++bb) { - for (BasicBlock::iterator instruction = (*bb)->begin(); - instruction != (*bb)->end(); ++instruction) { + for (Region::block_iterator bb = TopRegion->block_begin(); bb != TopRegion->block_end(); ++bb) { + for (BasicBlock::iterator instruction = (*bb)->begin(); instruction != (*bb)->end(); ++instruction) { // search for call instructions to @llvm.dbg.declare if (isa(instruction)) { Function *f = (cast(instruction))->getCalledFunction(); if (f) { StringRef funcName = f->getName(); - if (funcName.find("llvm.dbg.declare") != - string::npos) // llvm debug calls + if (funcName.find("llvm.dbg.declare") != string::npos) // llvm debug calls { CallInst *call = cast(instruction); // check if @llvm.dbg.declare is called @@ -3009,23 +2788,19 @@ void DiscoPoP::getTrueVarNamesFromMetadata( string SRCVarName; string IRVarName; - Metadata *Meta = - cast(call->getOperand(0))->getMetadata(); + Metadata *Meta = cast(call->getOperand(0))->getMetadata(); if (isa(Meta)) { Value *V = cast(Meta)->getValue(); IRVarName = V->getName().str(); } - DIVariable *V = cast( - cast(call->getOperand(1))->getMetadata()); + DIVariable *V = cast(cast(call->getOperand(1))->getMetadata()); SRCVarName = V->getName().str(); // add to trueVarNamesFromMetadataMap // overwrite entry if already existing - if (trueVarNamesFromMetadataMap->find(IRVarName) == - trueVarNamesFromMetadataMap->end()) { + if (trueVarNamesFromMetadataMap->find(IRVarName) == trueVarNamesFromMetadataMap->end()) { // not found - trueVarNamesFromMetadataMap->insert( - std::pair(IRVarName, SRCVarName)); + trueVarNamesFromMetadataMap->insert(std::pair(IRVarName, SRCVarName)); } else { // found (*trueVarNamesFromMetadataMap)[IRVarName] = SRCVarName; @@ -3037,14 +2812,12 @@ void DiscoPoP::getTrueVarNamesFromMetadata( } } -void DiscoPoP::processStructTypes(string const &fullStructName, - MDNode *structNode) { +void DiscoPoP::processStructTypes(string const &fullStructName, MDNode *structNode) { assert(structNode && "structNode cannot be NULL"); DIType *strDes = cast(structNode); assert(strDes->getTag() == dwarf::DW_TAG_structure_type); // sometimes it's impossible to get the list of struct members (e.g badref) - if (structNode->getNumOperands() <= 10 || - structNode->getOperand(10) == NULL) { + if (structNode->getNumOperands() <= 10 || structNode->getOperand(10) == NULL) { errs() << "cannot process member list of this struct: \n"; structNode->dump(); return; @@ -3065,16 +2838,14 @@ void DiscoPoP::processStructTypes(string const &fullStructName, if (memberTypeDes->getTag() == dwarf::DW_TAG_structure_type) { string fullName = ""; // try to get namespace - if (memberType->getNumOperands() > 2 && - structNode->getOperand(2) != NULL) { + if (memberType->getNumOperands() > 2 && structNode->getOperand(2) != NULL) { MDNode *namespaceNode = cast(structNode->getOperand(2)); DINamespace *dins = cast(namespaceNode); // DINameSpace dins(namespaceNode); fullName = "struct." + string(dins->getName().data()) + "::"; } // fullName += string(memberType->getOperand(3)->getName().data()); - fullName += - (dyn_cast(memberType->getOperand(3)))->getString(); + fullName += (dyn_cast(memberType->getOperand(3)))->getString(); if (Structs.find(fullName) == Structs.end()) processStructTypes(fullName, memberType); @@ -3142,15 +2913,14 @@ string DiscoPoP::getLineNumbersString(set LineNumbers) { string DiscoPoP::getChildrenNodesString(Node *root) { string childrenIDs = ""; int i = 0; - std::for_each(root->childrenNodes.begin(), root->childrenNodes.end(), - [&](Node *node) { - if (i == 0) { - childrenIDs = node->ID; - i++; - } else { - childrenIDs += "," + node->ID; - } - }); + std::for_each(root->childrenNodes.begin(), root->childrenNodes.end(), [&](Node *node) { + if (i == 0) { + childrenIDs = node->ID; + i++; + } else { + childrenIDs += "," + node->ID; + } + }); return childrenIDs; } @@ -3167,13 +2937,12 @@ void DiscoPoP::printData(Node *root) { void DiscoPoP::printTree(Node *root, bool isRoot) { printNode(root, isRoot); - std::for_each(root->childrenNodes.begin(), root->childrenNodes.end(), - [&](Node *node) { - if (node->type == nodeTypes::func) { - isRoot = false; - } - printTree(node, isRoot); - }); + std::for_each(root->childrenNodes.begin(), root->childrenNodes.end(), [&](Node *node) { + if (node->type == nodeTypes::func) { + isRoot = false; + } + printTree(node, isRoot); + }); } void DiscoPoP::printNode(Node *root, bool isRoot) { @@ -3191,17 +2960,15 @@ void DiscoPoP::printNode(Node *root, bool isRoot) { << " startsAtLine = \"" << start << "\"" << " endsAtLine = \"" << dputil::decodeLID(root->endLine) << "\"" << ">" << endl; - *outCUs << "\t\t" << getChildrenNodesString(root) - << "" << endl; + *outCUs << "\t\t" << getChildrenNodesString(root) << "" << endl; if (root->type == nodeTypes::func || root->type == nodeTypes::dummy) { *outCUs << "\t\t" << endl; for (auto ai : root->argumentsList) { *outCUs << "\t\t\t" << xmlEscape(ai.name) - << "" << endl; + << " accessMode=\"" << (ai.readAccess ? "R" : "") << (ai.writeAccess ? "W" : "") << "\">" + << xmlEscape(ai.name) << "" << endl; } *outCUs << "\t\t" << endl; @@ -3209,38 +2976,25 @@ void DiscoPoP::printNode(Node *root, bool isRoot) { for (auto rl : root->returnLines) { rlVals += dputil::decodeLID(rl) + ", "; } - *outCUs << "\t\t" << rlVals << "" - << endl; + *outCUs << "\t\t" << rlVals << "" << endl; } if (root->type == nodeTypes::cu) { CU *cu = static_cast(root); *outCUs << "\t\t" << cu->BBID << "" << endl; - *outCUs << "\t\t" << cu->readDataSize << "" - << endl; - *outCUs << "\t\t" << cu->writeDataSize - << "" << endl; - *outCUs << "\t\t" << cu->performsFileIO - << "" << endl; - - *outCUs << "\t\t" << cu->instructionsCount - << "" << endl; - *outCUs << "\t\tinstructionsLineNumbers).size() << "\">" - << getLineNumbersString(cu->instructionsLineNumbers) - << "" << endl; - *outCUs << "\t\treadPhaseLineNumbers).size() << "\">" - << getLineNumbersString(cu->readPhaseLineNumbers) - << "" << endl; - *outCUs << "\t\twritePhaseLineNumbers).size() << "\">" - << getLineNumbersString(cu->writePhaseLineNumbers) - << "" << endl; - *outCUs << "\t\treturnInstructions).size() << "\">" - << getLineNumbersString(cu->returnInstructions) - << "" << endl; + *outCUs << "\t\t" << cu->readDataSize << "" << endl; + *outCUs << "\t\t" << cu->writeDataSize << "" << endl; + *outCUs << "\t\t" << cu->performsFileIO << "" << endl; + + *outCUs << "\t\t" << cu->instructionsCount << "" << endl; + *outCUs << "\t\tinstructionsLineNumbers).size() << "\">" + << getLineNumbersString(cu->instructionsLineNumbers) << "" << endl; + *outCUs << "\t\treadPhaseLineNumbers).size() << "\">" + << getLineNumbersString(cu->readPhaseLineNumbers) << "" << endl; + *outCUs << "\t\twritePhaseLineNumbers).size() << "\">" + << getLineNumbersString(cu->writePhaseLineNumbers) << "" << endl; + *outCUs << "\t\treturnInstructions).size() << "\">" + << getLineNumbersString(cu->returnInstructions) << "" << endl; *outCUs << "\t\t" << endl; for (auto sucCUi : cu->successorCUs) { *outCUs << "\t\t\t" << sucCUi << "" << endl; @@ -3252,9 +3006,8 @@ void DiscoPoP::printNode(Node *root, bool isRoot) { *outCUs << "\t\t\t" << xmlEscape(lvi.name) - << "" << endl; + << " accessMode=\"" << (lvi.readAccess ? "R" : "") << (lvi.writeAccess ? "W" : "") << "\">" + << xmlEscape(lvi.name) << "" << endl; } *outCUs << "\t\t" << endl; @@ -3263,20 +3016,18 @@ void DiscoPoP::printNode(Node *root, bool isRoot) { *outCUs << "\t\t\t" << xmlEscape(gvi.name) - << "" << endl; + << " accessMode=\"" << (gvi.readAccess ? "R" : "") << (gvi.writeAccess ? "W" : "") << "\">" + << xmlEscape(gvi.name) << "" << endl; } *outCUs << "\t\t" << endl; *outCUs << "\t\t" << endl; for (auto i : (cu->callLineTofunctionMap)) { for (auto ii : i.second) { - *outCUs << "\t\t\t" << ii->ID << "" << endl; + *outCUs << "\t\t\t" << ii->ID << "" + << endl; // specifica for recursive fucntions inside loops. (Mo 5.11.2019) - *outCUs << "\t\t\t\t" - << ii->recursiveFunctionCall << "" + *outCUs << "\t\t\t\t" << ii->recursiveFunctionCall << "" << endl; } } @@ -3455,14 +3206,11 @@ void DiscoPoP::runOnBasicBlock(BasicBlock &BB) { // pthread_exit does not return to its caller. // Therefore, we insert DpFuncExit before pthread_exit IRBuilder<> IRBRet(&*BI); - ArrayRef arguments( - {ConstantInt::get(Int32, getLID(&*BI, fileID)), - ConstantInt::get(Int32, 0)}); + ArrayRef arguments({ConstantInt::get(Int32, getLID(&*BI, fileID)), ConstantInt::get(Int32, 0)}); IRBRet.CreateCall(DpFuncExit, arguments); continue; } - if (fn.equals("exit") || - F->doesNotReturn()) // using exit() to terminate program + if (fn.equals("exit") || F->doesNotReturn()) // using exit() to terminate program { // only insert DpFinalize right before the main program exits insertDpFinalize(&*BI); @@ -3539,8 +3287,7 @@ void DiscoPoP::runOnBasicBlock(BasicBlock &BB) { insertDpFinalize(&*BI); } else { IRBuilder<> IRBRet(&*BI); - ArrayRef arguments( - {ConstantInt::get(Int32, lid), ConstantInt::get(Int32, 0)}); + ArrayRef arguments({ConstantInt::get(Int32, lid), ConstantInt::get(Int32, 0)}); IRBRet.CreateCall(DpFuncExit, arguments); } @@ -3572,13 +3319,11 @@ void DiscoPoP::instrumentAlloca(AllocaInst *toInstrument) { args.push_back(startAddr); Value *endAddr = startAddr; - uint64_t elementSizeInBytes = - toInstrument->getAllocatedType()->getScalarSizeInBits() / 8; + uint64_t elementSizeInBytes = toInstrument->getAllocatedType()->getScalarSizeInBits() / 8; Value *numElements = toInstrument->getOperand(0); if (toInstrument->isArrayAllocation()) { // endAddr = startAddr + allocated size - endAddr = - IRB.CreateAdd(startAddr, IRB.CreateIntCast(numElements, Int64, true)); + endAddr = IRB.CreateAdd(startAddr, IRB.CreateIntCast(numElements, Int64, true)); } else if (toInstrument->getAllocatedType()->isArrayTy()) { // unpack potentially multidimensional allocations @@ -3602,13 +3347,12 @@ void DiscoPoP::instrumentAlloca(AllocaInst *toInstrument) { // endAddr = startAddr + allocated size numElements = ConstantInt::get(Int64, tmp_numElements); - endAddr = - IRB.CreateAdd(startAddr, IRB.CreateIntCast(numElements, Int64, true)); + endAddr = IRB.CreateAdd(startAddr, IRB.CreateIntCast(numElements, Int64, true)); } args.push_back(endAddr); - args.push_back(IRB.CreateMul(IRB.CreateIntCast(numElements, Int64, true), - ConstantInt::get(Int64, elementSizeInBytes))); + args.push_back( + IRB.CreateMul(IRB.CreateIntCast(numElements, Int64, true), ConstantInt::get(Int64, elementSizeInBytes))); args.push_back(IRB.CreateIntCast(numElements, Int64, true)); IRB.CreateCall(DpAlloca, args, ""); } @@ -3630,8 +3374,7 @@ void DiscoPoP::instrumentNewOrMalloc(CallBase *toInstrument) { // resumed at a "normal destination" basic block. Set the first instruction // of the normal destination as nextInst in order to add the Instrumentation // at the correct location. - nextInst = - cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); + nextInst = cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); } IRBuilder<> IRB(nextInst); @@ -3639,8 +3382,7 @@ void DiscoPoP::instrumentNewOrMalloc(CallBase *toInstrument) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - Value *startAddr = - PtrToIntInst::CreatePointerCast(toInstrument, Int64, "", nextInst); + Value *startAddr = PtrToIntInst::CreatePointerCast(toInstrument, Int64, "", nextInst); Value *endAddr = startAddr; Value *numBytes = toInstrument->getArgOperand(0); @@ -3668,8 +3410,7 @@ void DiscoPoP::instrumentRealloc(CallBase *toInstrument) { // resumed at a "normal destination" basic block. Set the first instruction // of the normal destination as nextInst in order to add the Instrumentation // at the correct location. - nextInst = - cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); + nextInst = cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); } IRBuilder<> IRB(nextInst); @@ -3677,8 +3418,8 @@ void DiscoPoP::instrumentRealloc(CallBase *toInstrument) { // deallocate args.push_back(ConstantInt::get(Int32, lid)); - Value *startAddr = PtrToIntInst::CreatePointerCast( - toInstrument->getArgOperand(0), Int64, "", toInstrument->getNextNode()); + Value *startAddr = + PtrToIntInst::CreatePointerCast(toInstrument->getArgOperand(0), Int64, "", toInstrument->getNextNode()); args.push_back(startAddr); IRB.CreateCall(DpDelete, args, ""); args.clear(); @@ -3711,8 +3452,7 @@ void DiscoPoP::instrumentCalloc(CallBase *toInstrument) { // resumed at a "normal destination" basic block. Set the first instruction // of the normal destination as nextInst in order to add the Instrumentation // at the correct location. - nextInst = - cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); + nextInst = cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); } IRBuilder<> IRB(nextInst); @@ -3720,11 +3460,9 @@ void DiscoPoP::instrumentCalloc(CallBase *toInstrument) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - Value *startAddr = - PtrToIntInst::CreatePointerCast(toInstrument, Int64, "", nextInst); + Value *startAddr = PtrToIntInst::CreatePointerCast(toInstrument, Int64, "", nextInst); Value *endAddr = startAddr; - Value *numBytes = IRB.CreateMul(toInstrument->getArgOperand(0), - toInstrument->getArgOperand(1)); + Value *numBytes = IRB.CreateMul(toInstrument->getArgOperand(0), toInstrument->getArgOperand(1)); args.push_back(startAddr); args.push_back(endAddr); // currently unused @@ -3750,8 +3488,7 @@ void DiscoPoP::instrumentPosixMemalign(CallBase *toInstrument) { // resumed at a "normal destination" basic block. Set the first instruction // of the normal destination as nextInst in order to add the Instrumentation // at the correct location. - nextInst = - cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); + nextInst = cast(toInstrument)->getNormalDest()->getFirstNonPHIOrDbg(); } IRBuilder<> IRB(nextInst); @@ -3759,8 +3496,7 @@ void DiscoPoP::instrumentPosixMemalign(CallBase *toInstrument) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - Value *startAddr = PtrToIntInst::CreatePointerCast( - toInstrument->getArgOperand(0), Int64, "", nextInst); + Value *startAddr = PtrToIntInst::CreatePointerCast(toInstrument->getArgOperand(0), Int64, "", nextInst); Value *endAddr = startAddr; Value *numBytes = toInstrument->getArgOperand(2); @@ -3781,8 +3517,8 @@ void DiscoPoP::instrumentDeleteOrFree(CallBase *toInstrument) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - Value *startAddr = PtrToIntInst::CreatePointerCast( - toInstrument->getArgOperand(0), Int64, "", toInstrument->getNextNode()); + Value *startAddr = + PtrToIntInst::CreatePointerCast(toInstrument->getArgOperand(0), Int64, "", toInstrument->getNextNode()); args.push_back(startAddr); @@ -3799,8 +3535,7 @@ void DiscoPoP::instrumentLoad(LoadInst *toInstrument) { args.push_back(ConstantInt::get(Int32, lid)); - Value *memAddr = PtrToIntInst::CreatePointerCast( - toInstrument->getPointerOperand(), Int64, "", toInstrument); + Value *memAddr = PtrToIntInst::CreatePointerCast(toInstrument->getPointerOperand(), Int64, "", toInstrument); args.push_back(memAddr); args.push_back(determineVariableName_dynamic(toInstrument)); @@ -3808,22 +3543,18 @@ void DiscoPoP::instrumentLoad(LoadInst *toInstrument) { #ifdef SKIP_DUP_INSTR Twine name = Twine("L").concat(Twine(uniqueNum)); - GlobalVariable *addrTracker = - new GlobalVariable(*this->ThisModule, - Int64, // trackerType - false, GlobalVariable::PrivateLinkage, - Constant::getNullValue(Int64), // trackerType - name); - GlobalVariable *countTracker = new GlobalVariable( - *this->ThisModule, Int64, false, GlobalVariable::PrivateLinkage, - Constant::getNullValue(Int64), name.concat(Twine("count"))); + GlobalVariable *addrTracker = new GlobalVariable(*this->ThisModule, + Int64, // trackerType + false, GlobalVariable::PrivateLinkage, + Constant::getNullValue(Int64), // trackerType + name); + GlobalVariable *countTracker = new GlobalVariable(*this->ThisModule, Int64, false, GlobalVariable::PrivateLinkage, + Constant::getNullValue(Int64), name.concat(Twine("count"))); uniqueNum++; // Load current values before instr - LoadInst *currentAddrTracker = - new LoadInst::LoadInst(addrTracker, Twine(), toInstrument); - LoadInst *currentCount = - new LoadInst::LoadInst(countTracker, Twine(), toInstrument); + LoadInst *currentAddrTracker = new LoadInst::LoadInst(addrTracker, Twine(), toInstrument); + LoadInst *currentCount = new LoadInst::LoadInst(countTracker, Twine(), toInstrument); // add instr before before args.push_back(currentAddrTracker); @@ -3835,8 +3566,8 @@ void DiscoPoP::instrumentLoad(LoadInst *toInstrument) { // Post instrumentation call // Create updates StoreInst *addrUpdate = new StoreInst::StoreInst(memAddr, addrTracker); - BinaryOperator::BinaryOperator *incCount = BinaryOperator::Create( - Instruction::Add, currentCount, ConstantInt::get(Int64, 1)); + BinaryOperator::BinaryOperator *incCount = + BinaryOperator::Create(Instruction::Add, currentCount, ConstantInt::get(Int64, 1)); StoreInst *countUpdate = new StoreInst::StoreInst(incCount, countTracker); // add updates after before @@ -3855,8 +3586,7 @@ void DiscoPoP::instrumentStore(StoreInst *toInstrument) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - Value *memAddr = PtrToIntInst::CreatePointerCast( - toInstrument->getPointerOperand(), Int64, "", toInstrument); + Value *memAddr = PtrToIntInst::CreatePointerCast(toInstrument->getPointerOperand(), Int64, "", toInstrument); args.push_back(memAddr); args.push_back(determineVariableName_dynamic(toInstrument)); @@ -3864,22 +3594,18 @@ void DiscoPoP::instrumentStore(StoreInst *toInstrument) { #ifdef SKIP_DUP_INSTR Twine name = Twine("S").concat(Twine(uniqueNum)); - GlobalVariable *addrTracker = - new GlobalVariable(*this->ThisModule, - Int64, // trackerType - false, GlobalVariable::PrivateLinkage, - Constant::getNullValue(Int64), // trackerType - name); - GlobalVariable *countTracker = new GlobalVariable( - *this->ThisModule, Int64, false, GlobalVariable::PrivateLinkage, - Constant::getNullValue(Int64), name.concat(Twine("count"))); + GlobalVariable *addrTracker = new GlobalVariable(*this->ThisModule, + Int64, // trackerType + false, GlobalVariable::PrivateLinkage, + Constant::getNullValue(Int64), // trackerType + name); + GlobalVariable *countTracker = new GlobalVariable(*this->ThisModule, Int64, false, GlobalVariable::PrivateLinkage, + Constant::getNullValue(Int64), name.concat(Twine("count"))); uniqueNum++; // Load current values before instr - LoadInst *currentAddrTracker = - new LoadInst::LoadInst(addrTracker, Twine(), toInstrument); - LoadInst *currentCount = - new LoadInst::LoadInst(countTracker, Twine(), toInstrument); + LoadInst *currentAddrTracker = new LoadInst::LoadInst(addrTracker, Twine(), toInstrument); + LoadInst *currentCount = new LoadInst::LoadInst(countTracker, Twine(), toInstrument); // add instr before before args.push_back(currentAddrTracker); @@ -3892,8 +3618,8 @@ void DiscoPoP::instrumentStore(StoreInst *toInstrument) { // Post instrumentation call // Create updates StoreInst *addrUpdate = new StoreInst::StoreInst(memAddr, addrTracker); - BinaryOperator::BinaryOperator *incCount = BinaryOperator::Create( - Instruction::Add, currentCount, ConstantInt::get(Int64, 1)); + BinaryOperator::BinaryOperator *incCount = + BinaryOperator::Create(Instruction::Add, currentCount, ConstantInt::get(Int64, 1)); StoreInst *countUpdate = new StoreInst::StoreInst(incCount, countTracker); // add updates after before @@ -3925,8 +3651,7 @@ void DiscoPoP::instrumentFuncEntry(Function &F) { auto tmp_end = F.getParent()->getGlobalList().end(); tmp_end--; // necessary, since the list of Globals is modified when e.g. new // strings are created. - for (auto Global_it = F.getParent()->getGlobalList().begin(); - Global_it != tmp_end; Global_it++) { + for (auto Global_it = F.getParent()->getGlobalList().begin(); Global_it != tmp_end; Global_it++) { // ignore globals which make use of "Appending Linkage", since they are // system internal and do not behave like regular values. An example for // such a value is @llvm.global_ctors @@ -3938,14 +3663,12 @@ void DiscoPoP::instrumentFuncEntry(Function &F) { vector args; args.push_back(ConstantInt::get(Int32, lid)); - args.push_back( - getOrInsertVarName_dynamic(Global_it->getName().str(), IRB)); + args.push_back(getOrInsertVarName_dynamic(Global_it->getName().str(), IRB)); bool isGlobal; // Value *startAddr = PtrToIntInst::CreatePointerCast(toInstrument, Int64, // "", toInstrument->getNextNonDebugInstruction()); - Value *startAddr = - IRB.CreatePtrToInt(cast(&*Global_it), Int64, ""); + Value *startAddr = IRB.CreatePtrToInt(cast(&*Global_it), Int64, ""); args.push_back(startAddr); Value *endAddr = startAddr; @@ -3971,8 +3694,7 @@ void DiscoPoP::instrumentFuncEntry(Function &F) { allocatedSize = elementSizeInBytes * numElements; // endAddr = startAddr + allocated size - endAddr = - IRB.CreateAdd(startAddr, ConstantInt::get(Int64, allocatedSize)); + endAddr = IRB.CreateAdd(startAddr, ConstantInt::get(Int64, allocatedSize)); } args.push_back(endAddr); @@ -3987,14 +3709,12 @@ void DiscoPoP::instrumentFuncEntry(Function &F) { // We always want to insert __dp_func_entry at the beginning // of the basic block, but we need the first valid LID to // get the entry line of the function. - for (BasicBlock::iterator BI = entryBB.begin(), EI = entryBB.end(); BI != EI; - ++BI) { + for (BasicBlock::iterator BI = entryBB.begin(), EI = entryBB.end(); BI != EI; ++BI) { lid = getLID(&*BI, fileID); if (lid > 0 && !isa(BI)) { IRBuilder<> IRB(&*entryBB.begin()); // NOTE: Changed to arrayref - ArrayRef arguments( - {ConstantInt::get(Int32, lid), ConstantInt::get(Int32, isStart)}); + ArrayRef arguments({ConstantInt::get(Int32, lid), ConstantInt::get(Int32, isStart)}); IRB.CreateCall(DpFuncEntry, arguments); if (DP_DEBUG) { errs() << "DiscoPoP: funcEntry instrumented\n"; @@ -4016,8 +3736,7 @@ void DiscoPoP::instrumentLoopEntry(BasicBlock *bb, int32_t id) { // Usually every loop has a .end block as the exit block, thus the // exit of a loop will not be the entry of another loop. The first if // check is just in case the blocks are organized in a abnormal way. - for (BasicBlock::iterator BI = currentBB->begin(), EI = currentBB->end(); - BI != EI; ++BI) { + for (BasicBlock::iterator BI = currentBB->begin(), EI = currentBB->end(); BI != EI; ++BI) { if (isa(BI)) { Function *tmpF = (cast(BI))->getCalledFunction(); StringRef tmpFn = tmpF->getName(); @@ -4041,8 +3760,7 @@ void DiscoPoP::instrumentLoopExit(BasicBlock *bb, int32_t id) { vector args; LID lid = 0; - for (BasicBlock::iterator BI = currentBB->begin(), EI = currentBB->end(); - BI != EI; ++BI) { + for (BasicBlock::iterator BI = currentBB->begin(), EI = currentBB->end(); BI != EI; ++BI) { lid = getLID(&*BI, fileID); if (lid > 0 && !isa(BI)) { args.push_back(ConstantInt::get(Int32, lid)); diff --git a/DiscoPoP/DiscoPoP.hpp b/DiscoPoP/DiscoPoP.hpp index ecb09cdfb..3a39339a0 100644 --- a/DiscoPoP/DiscoPoP.hpp +++ b/DiscoPoP/DiscoPoP.hpp @@ -42,12 +42,11 @@ #include "llvm/PassRegistry.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Instrumentation.h" - #include "DPUtils.hpp" #include "InstructionDG.hpp" @@ -72,14 +71,10 @@ using namespace std; using namespace dputil; // Command line options -static cl::opt ClCheckLoopPar("dp-loop-par", cl::init(true), - cl::desc("Check loop parallelism"), - cl::Hidden); +static cl::opt ClCheckLoopPar("dp-loop-par", cl::init(true), cl::desc("Check loop parallelism"), cl::Hidden); -static cl::opt - DumpToDot("dp-omissions-dump-dot", cl::init(false), - cl::desc("Generate a .dot representation of the CFG and DG"), - cl::Hidden); +static cl::opt DumpToDot("dp-omissions-dump-dot", cl::init(false), + cl::desc("Generate a .dot representation of the CFG and DG"), cl::Hidden); namespace { @@ -103,24 +98,17 @@ typedef struct Variable_struct { string sizeInBytes; Variable_struct(const Variable_struct &other) - : name(other.name), type(other.type), defLine(other.defLine), - readAccess(other.readAccess), writeAccess(other.writeAccess), - sizeInBytes(other.sizeInBytes) {} + : name(other.name), type(other.type), defLine(other.defLine), readAccess(other.readAccess), + writeAccess(other.writeAccess), sizeInBytes(other.sizeInBytes) {} - Variable_struct(string n, string t, string d, bool readAccess, - bool writeAccess, string sizeInBytes) - : name(n), type(t), defLine(d), readAccess(readAccess), - writeAccess(writeAccess), sizeInBytes(sizeInBytes) {} + Variable_struct(string n, string t, string d, bool readAccess, bool writeAccess, string sizeInBytes) + : name(n), type(t), defLine(d), readAccess(readAccess), writeAccess(writeAccess), sizeInBytes(sizeInBytes) {} // We have a set of this struct. The set doesn't know how to order the // elements. - inline bool operator<(const Variable_struct &rhs) const { - return name < rhs.name; - } + inline bool operator<(const Variable_struct &rhs) const { return name < rhs.name; } - inline bool operator>(const Variable_struct &rhs) const { - return name > rhs.name; - } + inline bool operator>(const Variable_struct &rhs) const { return name > rhs.name; } } Variable; @@ -256,20 +244,17 @@ class DiscoPoP : public ModulePass { string getOrInsertVarName_static(string varName, IRBuilder<> &builder); - Value *findStructMemberName(MDNode *structNode, unsigned idx, - IRBuilder<> &builder); + Value *findStructMemberName(MDNode *structNode, unsigned idx, IRBuilder<> &builder); Type *pointsToStruct(PointerType *PTy); Value *determineVariableName_dynamic(Instruction *const I); - string determineVariableName_static( - Instruction *I, bool &isGlobalVariable /*=defaultIsGlobalVariableValue*/, - bool disable_MetadataMap); + string determineVariableName_static(Instruction *I, bool &isGlobalVariable /*=defaultIsGlobalVariableValue*/, + bool disable_MetadataMap); - void getTrueVarNamesFromMetadata( - Region *TopRegion, Node *root, - std::map *trueVarNamesFromMetadataMap); + void getTrueVarNamesFromMetadata(Region *TopRegion, Node *root, + std::map *trueVarNamesFromMetadataMap); // Control flow analysis void CFA(Function &F, LoopInfo &LI); @@ -377,20 +362,14 @@ class DiscoPoP : public ModulePass { bool isRecursive(Function &F, CallGraph &CG); // Populate variable sets global to BB - void populateGlobalVariablesSet(Region *TopRegion, - set &globalVariablesSet); + void populateGlobalVariablesSet(Region *TopRegion, set &globalVariablesSet); - void createCUs(Region *TopRegion, set &globalVariablesSet, - vector &CUVector, - map> &BBIDToCUIDsMap, Node *root, - LoopInfo &LI); + void createCUs(Region *TopRegion, set &globalVariablesSet, vector &CUVector, + map> &BBIDToCUIDsMap, Node *root, LoopInfo &LI); - void - createTakenBranchInstrumentation(Region *TopRegion, - map> &BBIDToCUIDsMap); + void createTakenBranchInstrumentation(Region *TopRegion, map> &BBIDToCUIDsMap); - void fillCUVariables(Region *TopRegion, set &globalVariablesSet, - vector &CUVector, + void fillCUVariables(Region *TopRegion, set &globalVariablesSet, vector &CUVector, map> &BBIDToCUIDsMap); void fillStartEndLineNumbers(Node *root, LoopInfo &LI); @@ -421,41 +400,30 @@ class DiscoPoP : public ModulePass { // DPReduction - void instrument_module(llvm::Module *module, - map *trueVarNamesFromMetadataMap); + void instrument_module(llvm::Module *module, map *trueVarNamesFromMetadataMap); bool inlinedFunction(Function *F); - void instrument_function(llvm::Function *function, - map *trueVarNamesFromMetadataMap); + void instrument_function(llvm::Function *function, map *trueVarNamesFromMetadataMap); void instrument_loop(Function &F, int file_id, llvm::Loop *loop, LoopInfo &LI, map *trueVarNamesFromMetadataMap); std::string dp_reduction_CFA(Function &F, llvm::Loop *loop, int file_id); - string dp_reduction_determineVariableName( - Instruction *I, map *trueVarNamesFromMetadataMap); + string dp_reduction_determineVariableName(Instruction *I, map *trueVarNamesFromMetadataMap); string dp_reduction_determineVariableType(Instruction *I); - llvm::Instruction * - dp_reduction_get_reduction_instr(llvm::Instruction *store_instr, - llvm::Instruction **load_instr); + llvm::Instruction *dp_reduction_get_reduction_instr(llvm::Instruction *store_instr, llvm::Instruction **load_instr); llvm::Instruction *dp_reduction_find_reduction_instr(llvm::Value *val); - llvm::Instruction * - dp_reduction_get_load_instr(llvm::Value *load_val, - llvm::Instruction *cur_instr, - std::vector &reduction_operations); + llvm::Instruction *dp_reduction_get_load_instr(llvm::Value *load_val, llvm::Instruction *cur_instr, + std::vector &reduction_operations); llvm::Value *dp_reduction_points_to_var(llvm::GetElementPtrInst *instr); llvm::Value *dp_reduction_get_var(llvm::Instruction *instr); llvm::Value *dp_reduction_get_var_rec(llvm::Value *val); - llvm::Instruction *dp_reduction_get_prev_use(llvm::Instruction *instr, - llvm::Value *val); - inline bool dp_reduction_loc_exists(llvm::DebugLoc const &loc) { - return static_cast(loc); - } + llvm::Instruction *dp_reduction_get_prev_use(llvm::Instruction *instr, llvm::Value *val); + inline bool dp_reduction_loc_exists(llvm::DebugLoc const &loc) { return static_cast(loc); } unsigned dp_reduction_get_file_id(llvm::Function *func); bool dp_reduction_init_util(std::string fmap_path); char dp_reduction_get_char_for_opcode(llvm::Instruction *instr); bool dp_reduction_is_operand(llvm::Instruction *instr, llvm::Value *operand); int dp_reduction_get_op_order(char c); Type *dp_reduction_pointsToStruct(PointerType *PTy); - string findStructMemberName_static(MDNode *structNode, unsigned idx, - IRBuilder<> &builder); + string findStructMemberName_static(MDNode *structNode, unsigned idx, IRBuilder<> &builder); bool dp_reduction_sanityCheck(BasicBlock *BB, int file_id); LID dp_reduction_getLID(Instruction *BI, int32_t &fileID); void dp_reduction_insert_functions(); @@ -475,19 +443,15 @@ class DiscoPoP : public ModulePass { char DiscoPoP::ID = 0; -static RegisterPass - X("DiscoPoP", "DiscoPoP: finding potential parallelism.", false, false); +static RegisterPass X("DiscoPoP", "DiscoPoP: finding potential parallelism.", false, false); -static void loadPass(const PassManagerBuilder &Builder, - legacy::PassManagerBase &PM) { +static void loadPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { PM.add(new LoopInfoWrapperPass()); PM.add(new DiscoPoP()); } -static RegisterStandardPasses - DiscoPoPLoader_Ox(PassManagerBuilder::EP_OptimizerLast, loadPass); -static RegisterStandardPasses - DiscoPoPLoader_O0(PassManagerBuilder::EP_EnabledOnOptLevel0, loadPass); +static RegisterStandardPasses DiscoPoPLoader_Ox(PassManagerBuilder::EP_OptimizerLast, loadPass); +static RegisterStandardPasses DiscoPoPLoader_O0(PassManagerBuilder::EP_EnabledOnOptLevel0, loadPass); ModulePass *createDiscoPoPPass() { if (DP_DEBUG) { diff --git a/DiscoPoP/Graph.hpp b/DiscoPoP/Graph.hpp index 89d63f712..d67cc92f6 100644 --- a/DiscoPoP/Graph.hpp +++ b/DiscoPoP/Graph.hpp @@ -46,9 +46,7 @@ template class Edge { InstructionNode *dst; public: - Edge(InstructionNode *_src, - InstructionNode *_dst) - : src(_src), dst(_dst){}; + Edge(InstructionNode *_src, InstructionNode *_dst) : src(_src), dst(_dst){}; ~Edge(){}; @@ -63,18 +61,12 @@ template class Graph { unsigned nextIntKey = 0; // This stores a map from object of type T to it's respective pair (Key, // InstructionNode) - std::map *>> - instructionNodes; + std::map *>> instructionNodes; std::list *> edgesList; // This map stores all the outcoming edges from node of type T - std::map *, - std::set *>> - outEdges; + std::map *, std::set *>> outEdges; // This map stores all the incoming edges to node of type T - std::map *, - std::set *>> - inEdges; + std::map *, std::set *>> inEdges; public: Graph(){}; @@ -86,17 +78,13 @@ template class Graph { delete e; } - InstructionNode *operator[](InstructionNodeT item) const { - return getInstructionNode(item); - } + InstructionNode *operator[](InstructionNodeT item) const { return getInstructionNode(item); } InstructionNode *addInstructionNode(InstructionNodeT item) { if (instructionNodes.count(item) == 0) { - InstructionNode *instructionNode = - new InstructionNode(item); + InstructionNode *instructionNode = new InstructionNode(item); instructionNodes[item] = - std::make_pair *>( - nextIntKey, std::move(instructionNode)); + std::make_pair *>(nextIntKey, std::move(instructionNode)); instructionNodesList.push_back(instructionNode); nextIntKey++; return instructionNode; @@ -114,8 +102,7 @@ template class Graph { return instructionNodes.find(item)->second.second; } - InstructionNode * - getInstructionNodeByIndex(const int index) const { + InstructionNode *getInstructionNodeByIndex(const int index) const { for (const auto &pair_ : instructionNodes) { if (pair_.second.first == index) { return pair_.second.second; @@ -130,17 +117,13 @@ template class Graph { return instructionNodes.find(item)->second.first; } - int getInstructionNodeIndex( - InstructionNode *instructionNode) const { + int getInstructionNodeIndex(InstructionNode *instructionNode) const { return getInstructionNodeIndex(instructionNode->getItem()); } - std::list *> getInstructionNodes() const { - return instructionNodesList; - } + std::list *> getInstructionNodes() const { return instructionNodesList; } - Edge *addEdge(InstructionNode *src, - InstructionNode *dst) { + Edge *addEdge(InstructionNode *src, InstructionNode *dst) { for (Edge *ed : outEdges[src]) { if (ed->getDst() == dst) { return nullptr; @@ -166,8 +149,7 @@ template class Graph { return addEdge(src_, dst_); } - std::set *> - getInEdges(InstructionNode *instructionNode) { + std::set *> getInEdges(InstructionNode *instructionNode) { std::set *> inEdges_; if (inEdges.find(instructionNode) != inEdges.end()) inEdges_ = inEdges[instructionNode]; @@ -176,13 +158,11 @@ template class Graph { } std::set *> getInEdges(InstructionNodeT item) { - InstructionNode *instructionNode = - getInstructionNode(item); + InstructionNode *instructionNode = getInstructionNode(item); return getInEdges(instructionNode); } - std::set *> - getOutEdges(InstructionNode *instructionNode) { + std::set *> getOutEdges(InstructionNode *instructionNode) { std::set *> outEdges_; if (outEdges.count(instructionNode) != 0) return outEdges[instructionNode]; diff --git a/DiscoPoP/InstructionCFG.cpp b/DiscoPoP/InstructionCFG.cpp index 19c85e9af..035c2545a 100644 --- a/DiscoPoP/InstructionCFG.cpp +++ b/DiscoPoP/InstructionCFG.cpp @@ -12,8 +12,7 @@ #include "InstructionCFG.hpp" -InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) - : VNF(_VNF) { +InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) : VNF(_VNF) { entry = Graph::addInstructionNode((Instruction *)ENTRY); exit = Graph::addInstructionNode((Instruction *)EXIT); Instruction *previousInstruction; @@ -32,8 +31,7 @@ InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) // Add edges from last instruction in current block to first instruction all // the successor blocks if (previousInstruction != nullptr) - findAndAddFirstRelevantInstructionInSuccessorBlocks(&BB, - previousInstruction); + findAndAddFirstRelevantInstructionInSuccessorBlocks(&BB, previousInstruction); } // Conect entry/exit nodes @@ -48,8 +46,8 @@ InstructionCFG::InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F) } } -void InstructionCFG::findAndAddFirstRelevantInstructionInSuccessorBlocks( - BasicBlock *BB, Instruction *previousInstruction) { +void InstructionCFG::findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBlock *BB, + Instruction *previousInstruction) { bool hasSuccessors = false; for (BasicBlock *S : successors(BB)) { hasSuccessors = true; @@ -65,18 +63,14 @@ void InstructionCFG::findAndAddFirstRelevantInstructionInSuccessorBlocks( } } if (S != BB) - findAndAddFirstRelevantInstructionInSuccessorBlocks(S, - previousInstruction); + findAndAddFirstRelevantInstructionInSuccessorBlocks(S, previousInstruction); next:; } } -set InstructionCFG::findBoundaryInstructions(uint startLine, - uint endLine) {} +set InstructionCFG::findBoundaryInstructions(uint startLine, uint endLine) {} -void InstructionCFG::highlightInstructionNode(Instruction *instr) { - highlightedInstructionNodes.insert(instr); -} +void InstructionCFG::highlightInstructionNode(Instruction *instr) { highlightedInstructionNodes.insert(instr); } void InstructionCFG::dumpToDot(const std::string targetPath) { // Write the graph to a DOT file @@ -96,8 +90,7 @@ void InstructionCFG::dumpToDot(const std::string targetPath) { label = "label=EXIT"; goto printInstructionNode; } - label = "label=\"" + to_string(Graph::getInstructionNodeIndex(instNode)) + - "\\n"; + label = "label=\"" + to_string(Graph::getInstructionNodeIndex(instNode)) + "\\n"; instr = instNode->getItem(); dl = instr->getDebugLoc(); if (isa(instr) || isa(instr)) { @@ -119,8 +112,7 @@ void InstructionCFG::dumpToDot(const std::string targetPath) { label += to_string(instr->getFunction()->getSubprogram()->getLine()); } label += "\""; - if (highlightedInstructionNodes.find(instr) != - highlightedInstructionNodes.end()) { + if (highlightedInstructionNodes.find(instr) != highlightedInstructionNodes.end()) { label += "\",fillcolor=cyan,style=filled"; } } else if (isa(instr)) { @@ -130,15 +122,14 @@ void InstructionCFG::dumpToDot(const std::string targetPath) { label += "?\""; printInstructionNode: - dotStream << "\t\"" << getInstructionNodeIndex(instNode) << "\" [" << label - << "];\n"; + dotStream << "\t\"" << getInstructionNodeIndex(instNode) << "\" [" << label << "];\n"; } dotStream << "\n\n"; // Now print all outgoing edges and their labels for (auto e : getEdges()) { - dotStream << "\t\"" << getInstructionNodeIndex(e->getSrc()) << "\" -> \"" - << getInstructionNodeIndex(e->getDst()) << "\";\n"; + dotStream << "\t\"" << getInstructionNodeIndex(e->getSrc()) << "\" -> \"" << getInstructionNodeIndex(e->getDst()) + << "\";\n"; } dotStream << "}"; dotStream.close(); diff --git a/DiscoPoP/InstructionCFG.hpp b/DiscoPoP/InstructionCFG.hpp index 3fdaaec06..daee2db4e 100644 --- a/DiscoPoP/InstructionCFG.hpp +++ b/DiscoPoP/InstructionCFG.hpp @@ -33,8 +33,7 @@ class InstructionCFG : public Graph { dputil::VariableNameFinder *VNF; set highlightedInstructionNodes; - void findAndAddFirstRelevantInstructionInSuccessorBlocks( - BasicBlock *BB, Instruction *previousInstruction); + void findAndAddFirstRelevantInstructionInSuccessorBlocks(BasicBlock *BB, Instruction *previousInstruction); public: InstructionCFG(dputil::VariableNameFinder *_VNF, Function &F); @@ -46,8 +45,7 @@ class InstructionCFG : public Graph { InstructionNode *getExit() { return exit; } bool isEntryOrExit(Instruction *I) { - return Graph::getInstructionNode(I) == entry || - Graph::getInstructionNode(I) == exit; + return Graph::getInstructionNode(I) == entry || Graph::getInstructionNode(I) == exit; } void highlightInstructionNode(Instruction *instr); diff --git a/DiscoPoP/InstructionDG.cpp b/DiscoPoP/InstructionDG.cpp index 2900098e1..36ebfad3e 100644 --- a/DiscoPoP/InstructionDG.cpp +++ b/DiscoPoP/InstructionDG.cpp @@ -14,8 +14,7 @@ #include "DPUtils.hpp" -InstructionDG::InstructionDG(dputil::VariableNameFinder *_VNF, - InstructionCFG *_CFG, int32_t _fid) +InstructionDG::InstructionDG(dputil::VariableNameFinder *_VNF, InstructionCFG *_CFG, int32_t _fid) : VNF(_VNF), CFG(_CFG), fid(_fid) { for (auto edge : CFG->getInEdges(CFG->getExit())) { // check for nullptr @@ -25,8 +24,7 @@ InstructionDG::InstructionDG(dputil::VariableNameFinder *_VNF, } } -void InstructionDG::recursiveDepChecker(set *checkedInstructions, - Instruction *I, Instruction *C) { +void InstructionDG::recursiveDepChecker(set *checkedInstructions, Instruction *I, Instruction *C) { if (CFG->isEntryOrExit(C)) return; checkedInstructions->insert(C); @@ -46,31 +44,25 @@ void InstructionDG::recursiveDepChecker(set *checkedInstructions, return; } for (auto edge : CFG->getInEdges(C)) - if (checkedInstructions->find(edge->getSrc()->getItem()) == - checkedInstructions->end()) + if (checkedInstructions->find(edge->getSrc()->getItem()) == checkedInstructions->end()) recursiveDepChecker(checkedInstructions, I, edge->getSrc()->getItem()); } -void InstructionDG::recursiveDepFinder(set *checkedInstructions, - Instruction *I) { - if (CFG->isEntryOrExit(I) || - checkedInstructions->find(I) != checkedInstructions->end()) +void InstructionDG::recursiveDepFinder(set *checkedInstructions, Instruction *I) { + if (CFG->isEntryOrExit(I) || checkedInstructions->find(I) != checkedInstructions->end()) return; checkedInstructions->insert(I); if (isa(I) || isa(I)) Graph::addInstructionNode(I); for (auto edge : CFG->getInEdges(I)) { if (isa(I) || isa(I)) { - recursiveDepChecker(new set(), I, - edge->getSrc()->getItem()); + recursiveDepChecker(new set(), I, edge->getSrc()->getItem()); } recursiveDepFinder(checkedInstructions, edge->getSrc()->getItem()); } } -void InstructionDG::highlightInstructionNode(Instruction *instr) { - highlightedInstructionNodes.insert(instr); -} +void InstructionDG::highlightInstructionNode(Instruction *instr) { highlightedInstructionNodes.insert(instr); } string getInstructionLine(Instruction *I) { if (DebugLoc dl = I->getDebugLoc()) { @@ -80,9 +72,8 @@ string getInstructionLine(Instruction *I) { } } -string InstructionDG::edgeToDPDep( - Edge *e, - unordered_map> &staticValueNameToMemRegIDMap) { +string InstructionDG::edgeToDPDep(Edge *e, + unordered_map> &staticValueNameToMemRegIDMap) { // staticValueNameToMemRegIDMap maps: TO (original // variable name, statically assigned MemReg ID) Instruction *I = e->getSrc()->getItem(); @@ -91,30 +82,24 @@ string InstructionDG::edgeToDPDep( string depType; if (isa(J)) { depType = "INIT"; - return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + - depType + " *|" + + return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + depType + " *|" + staticValueNameToMemRegIDMap[VNF->getVarName(I)] .first // use original variable name instead of LLVM IR SSA name - + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + - ")"; + + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + ")"; } else if (DebugLoc dl = J->getDebugLoc()) { - depType = (isa(I) ? string("R") : string("W")) + "A" + - (isa(J) ? string("R") : string("W")); - return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + - depType + " " + to_string(fid) + ":" + getInstructionLine(J) + "|" + + depType = (isa(I) ? string("R") : string("W")) + "A" + (isa(J) ? string("R") : string("W")); + return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + depType + " " + to_string(fid) + ":" + + getInstructionLine(J) + "|" + staticValueNameToMemRegIDMap[VNF->getVarName(I)] .first // use original variable name instead of LLVM IR SSA name - + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + - ")"; + + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + ")"; } else { - depType = (isa(I) ? string("R") : string("W")) + "A" + - (isa(J) ? string("R") : string("W")); - return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + - depType + " " + to_string(fid) + ":" + getInstructionLine(J) + "|" + + depType = (isa(I) ? string("R") : string("W")) + "A" + (isa(J) ? string("R") : string("W")); + return to_string(fid) + ":" + getInstructionLine(I) + " " + "NOM" + " " + depType + " " + to_string(fid) + ":" + + getInstructionLine(J) + "|" + staticValueNameToMemRegIDMap[VNF->getVarName(I)] .first // use original variable name instead of LLVM IR SSA name - + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + - ")"; + + "(" + staticValueNameToMemRegIDMap[VNF->getVarName(I)].second + ")"; } } @@ -126,8 +111,7 @@ void InstructionDG::dumpToDot(const string targetPath) { dotStream << "digraph g {\n"; // Create all nodes in DOT format for (auto instNode : getInstructionNodes()) { - string label = "label=\"" + - to_string(Graph::getInstructionNodeIndex(instNode)) + "\\n"; + string label = "label=\"" + to_string(Graph::getInstructionNodeIndex(instNode)) + "\\n"; Instruction *instr = instNode->getItem(); if (isa(instr)) { if (DebugLoc dl = instr->getDebugLoc()) @@ -149,21 +133,19 @@ void InstructionDG::dumpToDot(const string targetPath) { label += instr->getFunction()->getSubprogram()->getLine() + "\n"; } label += "\""; - if (highlightedInstructionNodes.find(instr) != - highlightedInstructionNodes.end()) { + if (highlightedInstructionNodes.find(instr) != highlightedInstructionNodes.end()) { label += ",fillcolor=cyan,style=filled"; } printInstructionNode: - dotStream << "\t\"" << getInstructionNodeIndex(instNode) << "\" [" << label - << "];\n"; + dotStream << "\t\"" << getInstructionNodeIndex(instNode) << "\" [" << label << "];\n"; } dotStream << "\n\n"; // Now print all outgoing edges and their labels for (auto e : getEdges()) { - dotStream << "\t\"" << getInstructionNodeIndex(e->getSrc()) << "\" -> \"" - << getInstructionNodeIndex(e->getDst()) << "\";\n"; + dotStream << "\t\"" << getInstructionNodeIndex(e->getSrc()) << "\" -> \"" << getInstructionNodeIndex(e->getDst()) + << "\";\n"; } dotStream << "}"; dotStream.close(); diff --git a/DiscoPoP/InstructionDG.hpp b/DiscoPoP/InstructionDG.hpp index 1f43bd92c..785e65443 100644 --- a/DiscoPoP/InstructionDG.hpp +++ b/DiscoPoP/InstructionDG.hpp @@ -25,19 +25,14 @@ class InstructionDG : public Graph { set highlightedInstructionNodes; int32_t fid; - void recursiveDepChecker(set *checkedInstructions, - Instruction *I, Instruction *C); + void recursiveDepChecker(set *checkedInstructions, Instruction *I, Instruction *C); - void recursiveDepFinder(set *checkedInstructions, - Instruction *I); + void recursiveDepFinder(set *checkedInstructions, Instruction *I); public: - InstructionDG(dputil::VariableNameFinder *_VNF, InstructionCFG *_CFG, - int32_t _fid); + InstructionDG(dputil::VariableNameFinder *_VNF, InstructionCFG *_CFG, int32_t _fid); - string edgeToDPDep(Edge *e, - unordered_map> - &staticValueNameToMemRegIDMap); + string edgeToDPDep(Edge *e, unordered_map> &staticValueNameToMemRegIDMap); void highlightInstructionNode(Instruction *instr); diff --git a/benchmark/benchmarks.cpp b/benchmark/benchmarks.cpp index f2372c831..614f56bb0 100644 --- a/benchmark/benchmarks.cpp +++ b/benchmark/benchmarks.cpp @@ -12,14 +12,12 @@ #include -int main(int argc, char** argv) { - ::benchmark::Initialize(&argc, argv); - if (::benchmark::ReportUnrecognizedArguments(argc, argv)) - return 1; - ::benchmark::RunSpecifiedBenchmarks(); - ::benchmark::Shutdown(); - - return 0; -} - +int main(int argc, char **argv) { + ::benchmark::Initialize(&argc, argv); + if (::benchmark::ReportUnrecognizedArguments(argc, argv)) + return 1; + ::benchmark::RunSpecifiedBenchmarks(); + ::benchmark::Shutdown(); + return 0; +} diff --git a/benchmark/memory_region_tree/benchmark_memory_region_tree.cpp b/benchmark/memory_region_tree/benchmark_memory_region_tree.cpp index a1af10505..77303d10e 100644 --- a/benchmark/memory_region_tree/benchmark_memory_region_tree.cpp +++ b/benchmark/memory_region_tree/benchmark_memory_region_tree.cpp @@ -22,156 +22,156 @@ // General functions static std::vector convert_to_address(const std::int64_t number_iterations) { - auto mt = std::mt19937{0}; - auto uid = std::uniform_int_distribution{0, 0x7FFFFFFFFFFFFFFF}; - - auto addresses = std::vector{}; - addresses.resize(number_iterations); - - for (auto i = std::int64_t(0); i < number_iterations; i++) { - addresses[i] = uid(mt); - } + auto mt = std::mt19937{0}; + auto uid = std::uniform_int_distribution{0, 0x7FFFFFFFFFFFFFFF}; + + auto addresses = std::vector{}; + addresses.resize(number_iterations); + + for (auto i = std::int64_t(0); i < number_iterations; i++) { + addresses[i] = uid(mt); + } - std::sort(addresses.begin(), addresses.end()); + std::sort(addresses.begin(), addresses.end()); - return addresses; + return addresses; } // Benchmarks for old version (i.e., establishing a base line) -static void benchmark_mrt_allocate_region(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_allocate_region(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::MemoryRegionTree>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::MemoryRegionTree>{}; - for (auto _ : state) { - state.PauseTiming(); - auto tree = __dp::MemoryRegionTree{}; - state.ResumeTiming(); - - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } + for (auto _ : state) { + state.PauseTiming(); + auto tree = __dp::MemoryRegionTree{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(tree)); - state.ResumeTiming(); + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(tree)); + state.ResumeTiming(); + } } -static void benchmark_mrt_get_memory_region_id(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_get_memory_region_id(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); + } - for (auto _ : state) { - for (auto i = 0; i < number_iterations * 2; i++) { - benchmark::DoNotOptimize(tree.get_memory_region_id(addresses[i])); - } + for (auto _ : state) { + for (auto i = 0; i < number_iterations * 2; i++) { + benchmark::DoNotOptimize(tree.get_memory_region_id(addresses[i])); } + } } -static void benchmark_mrt_get_memory_region_id_string_found(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_get_memory_region_id_string_found(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector{}; - dumping_ground.reserve(number_iterations); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector{}; + dumping_ground.reserve(number_iterations); - for (auto _ : state) { - for (auto i = 0; i < number_iterations * 2; i++) { - dumping_ground.emplace_back(tree.get_memory_region_id_string(addresses[i], "fallback")); - } + for (auto _ : state) { + for (auto i = 0; i < number_iterations * 2; i++) { + dumping_ground.emplace_back(tree.get_memory_region_id_string(addresses[i], "fallback")); } + } } -static void benchmark_mrt_get_memory_region_id_string_fallback(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_get_memory_region_id_string_fallback(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector{}; - dumping_ground.reserve(number_iterations); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector{}; + dumping_ground.reserve(number_iterations); - for (auto _ : state) { - for (auto i = 0; i < number_iterations * 2; i++) { - const auto base_address = addresses[i]; - const auto address = (i % 2 == 0) ? base_address - 1 : base_address + 1; + for (auto _ : state) { + for (auto i = 0; i < number_iterations * 2; i++) { + const auto base_address = addresses[i]; + const auto address = (i % 2 == 0) ? base_address - 1 : base_address + 1; - dumping_ground.emplace_back(tree.get_memory_region_id_string(address, "fallback")); - } + dumping_ground.emplace_back(tree.get_memory_region_id_string(address, "fallback")); } + } } -static void benchmark_mrt_destructor(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_destructor(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - for (auto _ : state) { - state.PauseTiming(); - auto tree = __dp::MemoryRegionTree{}; - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto tree = __dp::MemoryRegionTree{}; + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); } + state.ResumeTiming(); + } } -static void benchmark_mrt_free_region(benchmark::State& state) { - const auto number_iterations = state.range(0); +static void benchmark_mrt_free_region(benchmark::State &state) { + const auto number_iterations = state.range(0); - const auto addresses = convert_to_address(number_iterations * 2); + const auto addresses = convert_to_address(number_iterations * 2); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::MemoryRegionTree>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::MemoryRegionTree>{}; - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; + + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); + } + for (auto _ : state) { + state.PauseTiming(); + auto tree = __dp::MemoryRegionTree{}; for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); + tree.allocate_region(addresses[i], addresses[i + 1], i + 1); } + state.ResumeTiming(); - for (auto _ : state) { - state.PauseTiming(); - auto tree = __dp::MemoryRegionTree{}; - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.allocate_region(addresses[i], addresses[i + 1], i + 1); - } - state.ResumeTiming(); - - for (auto i = 0; i < number_iterations * 2; i += 2) { - tree.free_region(addresses[i]); - } - - state.PauseTiming(); - dumping_ground.emplace_back(std::move(tree)); - state.ResumeTiming(); + for (auto i = 0; i < number_iterations * 2; i += 2) { + tree.free_region(addresses[i]); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(tree)); + state.ResumeTiming(); + } } BENCHMARK(benchmark_mrt_allocate_region)->Unit(benchmark::kMillisecond)->Arg(32)->Iterations(100); @@ -184,7 +184,10 @@ BENCHMARK(benchmark_mrt_get_memory_region_id_string_found)->Unit(benchmark::kMil BENCHMARK(benchmark_mrt_get_memory_region_id_string_found)->Unit(benchmark::kMillisecond)->Arg(1024)->Iterations(100); BENCHMARK(benchmark_mrt_get_memory_region_id_string_fallback)->Unit(benchmark::kMillisecond)->Arg(32)->Iterations(100); -BENCHMARK(benchmark_mrt_get_memory_region_id_string_fallback)->Unit(benchmark::kMillisecond)->Arg(1024)->Iterations(100); +BENCHMARK(benchmark_mrt_get_memory_region_id_string_fallback) + ->Unit(benchmark::kMillisecond) + ->Arg(1024) + ->Iterations(100); BENCHMARK(benchmark_mrt_destructor)->Unit(benchmark::kMillisecond)->Arg(32)->Iterations(100); BENCHMARK(benchmark_mrt_destructor)->Unit(benchmark::kMillisecond)->Arg(1024)->Iterations(100); diff --git a/benchmark/perfect_shadow/benchmark_perfect_shadow.cpp b/benchmark/perfect_shadow/benchmark_perfect_shadow.cpp index 34b7c23dd..c062a5bf3 100644 --- a/benchmark/perfect_shadow/benchmark_perfect_shadow.cpp +++ b/benchmark/perfect_shadow/benchmark_perfect_shadow.cpp @@ -20,386 +20,371 @@ // General functions static std::int64_t convert_to_address(const std::int64_t iteration) { - return ((iteration * 17) + ((iteration + 4) % 5)) % 1024; + return ((iteration * 17) + ((iteration + 4) % 5)) % 1024; } -static bool test_read_address(const std::int64_t address) { - return address & 1; -} +static bool test_read_address(const std::int64_t address) { return address & 1; } -static bool test_write_address(const std::int64_t address) { - return address > 400; -} +static bool test_write_address(const std::int64_t address) { return address > 400; } -static bool insert_read_address(const std::int64_t address) { - return address < 700; -} +static bool insert_read_address(const std::int64_t address) { return address < 700; } -static bool insert_write_address(const std::int64_t address) { - return address & 539; -} +static bool insert_write_address(const std::int64_t address) { return address & 539; } -static bool update_read_address(const std::int64_t address) { - return (address * 13) & 64; -} +static bool update_read_address(const std::int64_t address) { return (address * 13) & 64; } -static bool update_write_address(const std::int64_t address) { - return (address % 19) > 8; -} +static bool update_write_address(const std::int64_t address) { return (address % 19) > 8; } -static bool remove_read_address(const std::int64_t address) { - return address % 512 > 400; -} +static bool remove_read_address(const std::int64_t address) { return address % 512 > 400; } -static bool remove_write_address(const std::int64_t address) { - return (address & 384) < 49; -} +static bool remove_write_address(const std::int64_t address) { return (address & 384) < 49; } // Benchmarks for old version (i.e., establishing a base line) -static void benchmark_perfect_shadow_test(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_perfect_shadow_test(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); - - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow>{}; - for (auto addr : addresses) { - std::ignore = shadow.testInRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + std::ignore = shadow.testInRead(addr); } -} -static void benchmark_perfect_shadow_insert(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_insert(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow>{}; - for (auto addr : addresses) { - std::ignore = shadow.insertToRead(addr, 1); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + std::ignore = shadow.insertToRead(addr, 1); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } } -static void benchmark_perfect_shadow_update(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_perfect_shadow_update(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow>{}; - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow{}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow{}; + state.ResumeTiming(); - for (auto addr : addresses) { - shadow.updateInRead(addr, 1); - } - - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + shadow.updateInRead(addr, 1); } -} -static void benchmark_perfect_shadow_remove(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_remove(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow>{}; - for (auto addr : addresses) { - shadow.removeFromRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + shadow.removeFromRead(addr); } -} -static void benchmark_perfect_shadow(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow>{}; - for (auto addr : addresses) { - if (test_read_address(addr)) { - std::ignore = shadow.testInRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow{}; + state.ResumeTiming(); - if (test_write_address(addr)) { - std::ignore = shadow.testInWrite(addr); - } + for (auto addr : addresses) { + if (test_read_address(addr)) { + std::ignore = shadow.testInRead(addr); + } - if (insert_read_address(addr)) { - std::ignore = shadow.insertToRead(addr, 1); - } + if (test_write_address(addr)) { + std::ignore = shadow.testInWrite(addr); + } - if (insert_write_address(addr)) { - std::ignore = shadow.insertToWrite(addr, 2); - } + if (insert_read_address(addr)) { + std::ignore = shadow.insertToRead(addr, 1); + } - if (update_read_address(addr)) { - shadow.updateInRead(addr, 3); - } + if (insert_write_address(addr)) { + std::ignore = shadow.insertToWrite(addr, 2); + } - if (update_write_address(addr)) { - shadow.updateInWrite(addr, 4); - } + if (update_read_address(addr)) { + shadow.updateInRead(addr, 3); + } - if (remove_read_address(addr)) { - shadow.removeFromRead(addr); - } + if (update_write_address(addr)) { + shadow.updateInWrite(addr, 4); + } - if (remove_write_address(addr)) { - shadow.removeFromWrite(addr); - } - } + if (remove_read_address(addr)) { + shadow.removeFromRead(addr); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + if (remove_write_address(addr)) { + shadow.removeFromWrite(addr); + } } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } } // Benchmarks for new version (i.e., hopefully beating the base line) -static void benchmark_perfect_shadow_2_test(benchmark::State& state) { - const auto number_addresses = state.range(0); - - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_2_test(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow2{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; - for (auto addr : addresses) { - std::ignore = shadow.testInRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow2{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + std::ignore = shadow.testInRead(addr); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } } -static void benchmark_perfect_shadow_2_insert(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_perfect_shadow_2_insert(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow2{}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow2{}; + state.ResumeTiming(); - for (auto addr : addresses) { - std::ignore = shadow.insertToRead(addr, 1); - } - - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + std::ignore = shadow.insertToRead(addr, 1); } -} -static void benchmark_perfect_shadow_2_update(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_2_update(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow2{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; - for (auto addr : addresses) { - shadow.updateInRead(addr, 1); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow2{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + shadow.updateInRead(addr, 1); } -} -static void benchmark_perfect_shadow_2_remove(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_2_remove(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow2{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; - for (auto addr : addresses) { - shadow.removeFromRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow2{}; + state.ResumeTiming(); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + for (auto addr : addresses) { + shadow.removeFromRead(addr); } -} -static void benchmark_perfect_shadow_2(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_perfect_shadow_2(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto shadow = __dp::PerfectShadow2{}; - state.ResumeTiming(); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::PerfectShadow2>{}; - for (auto addr : addresses) { - if (test_read_address(addr)) { - std::ignore = shadow.testInRead(addr); - } + for (auto _ : state) { + state.PauseTiming(); + auto shadow = __dp::PerfectShadow2{}; + state.ResumeTiming(); - if (test_write_address(addr)) { - std::ignore = shadow.testInWrite(addr); - } + for (auto addr : addresses) { + if (test_read_address(addr)) { + std::ignore = shadow.testInRead(addr); + } - if (insert_read_address(addr)) { - std::ignore = shadow.insertToRead(addr, 1); - } + if (test_write_address(addr)) { + std::ignore = shadow.testInWrite(addr); + } - if (insert_write_address(addr)) { - std::ignore = shadow.insertToWrite(addr, 2); - } + if (insert_read_address(addr)) { + std::ignore = shadow.insertToRead(addr, 1); + } - if (update_read_address(addr)) { - shadow.updateInRead(addr, 3); - } + if (insert_write_address(addr)) { + std::ignore = shadow.insertToWrite(addr, 2); + } - if (update_write_address(addr)) { - shadow.updateInWrite(addr, 4); - } + if (update_read_address(addr)) { + shadow.updateInRead(addr, 3); + } - if (remove_read_address(addr)) { - shadow.removeFromRead(addr); - } + if (update_write_address(addr)) { + shadow.updateInWrite(addr, 4); + } - if (remove_write_address(addr)) { - shadow.removeFromWrite(addr); - } - } + if (remove_read_address(addr)) { + shadow.removeFromRead(addr); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(shadow)); - state.ResumeTiming(); + if (remove_write_address(addr)) { + shadow.removeFromWrite(addr); + } } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(shadow)); + state.ResumeTiming(); + } } -// The sorting determines the output order --> put pairs together so a comparison is easier +// The sorting determines the output order --> put pairs together so a +// comparison is easier BENCHMARK(benchmark_perfect_shadow_test)->Unit(benchmark::kMillisecond)->Arg(1024)->Iterations(100); BENCHMARK(benchmark_perfect_shadow_2_test)->Unit(benchmark::kMillisecond)->Arg(1024)->Iterations(100); diff --git a/benchmark/scope/benchmark_scope.cpp b/benchmark/scope/benchmark_scope.cpp index 44ceb3491..0301f0a8a 100644 --- a/benchmark/scope/benchmark_scope.cpp +++ b/benchmark/scope/benchmark_scope.cpp @@ -20,730 +20,727 @@ // General functions static std::int64_t convert_to_address(const std::int64_t iteration) { - return ((iteration * 17) + ((iteration + 4) % 5)) % 1024; + return ((iteration * 17) + ((iteration + 4) % 5)) % 1024; } -static bool read_address(const std::int64_t address) { - return (address * 17) & 11; -} +static bool read_address(const std::int64_t address) { return (address * 17) & 11; } -static bool write_address(const std::int64_t address) { - return address & 2; -} +static bool write_address(const std::int64_t address) { return address & 2; } static bool first_written_address(const std::int64_t address, const std::int64_t iteration) { - return (((iteration * 19) + (address & 23)) % 24) > 7; + return (((iteration * 19) + (address & 23)) % 24) > 7; } // Benchmarks for old version (i.e., establishing a base line) -static void benchmark_scope_read(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_read(benchmark::State &state) { + const auto number_addresses = state.range(0); + + auto addresses = std::vector{}; + addresses.resize(number_addresses); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope>{}; + + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope{1}; + state.ResumeTiming(); + + for (auto addr : addresses) { + scope.registerStackRead(addr, 0, ""); } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope>{}; + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } +} + +static void benchmark_scope_write(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope{1}; - state.ResumeTiming(); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto addr : addresses) { - scope.registerStackRead(addr, 0, ""); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } + + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope>{}; - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope{1}; + state.ResumeTiming(); + + for (auto addr : addresses) { + scope.registerStackWrite(addr, 0, ""); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } } -static void benchmark_scope_write(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope>{}; - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope{1}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope{1}; + state.ResumeTiming(); - for (auto addr : addresses) { - scope.registerStackWrite(addr, 0, ""); - } + for (auto addr : addresses) { + if (read_address(addr)) { + scope.registerStackRead(addr, 1, ""); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + if (write_address(addr)) { + scope.registerStackWrite(addr, 0, ""); + } } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } } -static void benchmark_scope(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_manager_few_accesses(benchmark::State &state) { + const auto number_scopes = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto dumping_ground = std::vector<__dp::ScopeManager>{}; - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager{}; + state.ResumeTiming(); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope>{}; + auto current_number_scopes = 0; - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope{1}; - state.ResumeTiming(); + for (auto i = 0; i < number_scopes; i++) { + manager.enterScope("Enter scope", i); - for (auto addr : addresses) { - if (read_address(addr)) { - scope.registerStackRead(addr, 1, ""); - } + manager.registerStackRead(24, 0, ""); + manager.registerStackWrite(i, 0, ""); + manager.registerStackRead(32, 0, ""); + manager.registerStackRead(64, 1, ""); + manager.registerStackWrite(i + 2, 0, ""); - if (write_address(addr)) { - scope.registerStackWrite(addr, 0, ""); - } - } + current_number_scopes++; + if (current_number_scopes > 10) { + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + + current_number_scopes -= 5; + } + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + for (auto i = 0; i < current_number_scopes; i++) { + manager.leaveScope("Leave scope", i); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } -static void benchmark_scope_manager_few_accesses(benchmark::State& state) { - const auto number_scopes = state.range(0); - - auto dumping_ground = std::vector<__dp::ScopeManager>{}; - - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager{}; - state.ResumeTiming(); - - auto current_number_scopes = 0; - - for (auto i = 0; i < number_scopes; i++) { - manager.enterScope("Enter scope", i); - - manager.registerStackRead(24, 0, ""); - manager.registerStackWrite(i, 0, ""); - manager.registerStackRead(32, 0, ""); - manager.registerStackRead(64, 1, ""); - manager.registerStackWrite(i + 2, 0, ""); - - current_number_scopes++; - if (current_number_scopes > 10) { - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - - current_number_scopes -= 5; - } - } +static void benchmark_scope_manager_many_accesses(benchmark::State &state) { + const auto number_scopes = state.range(0); - for (auto i = 0; i < current_number_scopes; i++) { - manager.leaveScope("Leave scope", i); - } + auto dumping_ground = std::vector<__dp::ScopeManager>{}; - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); - } -} + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager{}; + state.ResumeTiming(); -static void benchmark_scope_manager_many_accesses(benchmark::State& state) { - const auto number_scopes = state.range(0); - - auto dumping_ground = std::vector<__dp::ScopeManager>{}; - - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager{}; - state.ResumeTiming(); - - auto current_number_scopes = 0; - - for (auto i = 0; i < number_scopes; i++) { - manager.enterScope("Enter scope", i); - - for (auto j = 0; j < 1024; j++) { - const auto addr = convert_to_address(j + i); - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } - } - - current_number_scopes++; - if (current_number_scopes > 10) { - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - - current_number_scopes -= 5; - } - } + auto current_number_scopes = 0; - for (auto i = 0; i < current_number_scopes; i++) { - manager.leaveScope("Leave scope", i); + for (auto i = 0; i < number_scopes; i++) { + manager.enterScope("Enter scope", i); + + for (auto j = 0; j < 1024; j++) { + const auto addr = convert_to_address(j + i); + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); } + } + + current_number_scopes++; + if (current_number_scopes > 10) { + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + + current_number_scopes -= 5; + } + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + for (auto i = 0; i < current_number_scopes; i++) { + manager.leaveScope("Leave scope", i); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } -static void benchmark_scope_manager_first_written(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_manager_first_written(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - auto dumping_ground = std::vector<__dp::ScopeManager>{}; + auto dumping_ground = std::vector<__dp::ScopeManager>{}; - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager{}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager{}; + state.ResumeTiming(); - manager.enterScope("First", 1); + manager.enterScope("First", 1); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - if (first_written_address(addr, 1)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (first_written_address(addr, 1)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - manager.enterScope("Second", 2); + manager.enterScope("Second", 2); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - if (first_written_address(addr, 2)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (first_written_address(addr, 2)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - manager.enterScope("Third", 3); + manager.enterScope("Third", 3); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - if (first_written_address(addr, 3)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (first_written_address(addr, 3)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - manager.leaveScope("Third", 3); - manager.leaveScope("Second", 2); + manager.leaveScope("Third", 3); + manager.leaveScope("Second", 2); - manager.enterScope("Forth", 4); + manager.enterScope("Forth", 4); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - if (first_written_address(addr, 4)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } - - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + if (first_written_address(addr, 4)) { + const auto b = manager.isOwnedByScope(addr, true); + } } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } -static void benchmark_scope_manager_positive_change(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_manager_positive_change(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - auto dumping_ground = std::vector<__dp::ScopeManager>{}; + auto dumping_ground = std::vector<__dp::ScopeManager>{}; - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager{}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager{}; + state.ResumeTiming(); - manager.enterScope("First", 1); + manager.enterScope("First", 1); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - manager.enterScope("Second", 2); + manager.enterScope("Second", 2); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } - - manager.enterScope("Third", 3); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Third", 3); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.leaveScope("Third", 3); - manager.leaveScope("Second", 2); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - manager.enterScope("Forth", 4); + manager.leaveScope("Third", 3); + manager.leaveScope("Second", 2); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Forth", 4); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } // Benchmarks for new version (i.e., hopefully beating the base line) -static void benchmark_scope_2_read(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_2_read(benchmark::State &state) { + const auto number_addresses = state.range(0); + + auto addresses = std::vector{}; + addresses.resize(number_addresses); + + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - auto addresses = std::vector{}; - addresses.resize(number_addresses); + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope2>{}; - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope2{1}; + state.ResumeTiming(); + + for (auto addr : addresses) { + scope.registerStackRead(addr, 0, ""); } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope2>{}; + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } +} - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope2{1}; - state.ResumeTiming(); +static void benchmark_scope_2_write(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto addr : addresses) { - scope.registerStackRead(addr, 0, ""); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } + + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope2>{}; + + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope2{1}; + state.ResumeTiming(); + + for (auto addr : addresses) { + scope.registerStackWrite(addr, 0, ""); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } } -static void benchmark_scope_2_write(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_2(benchmark::State &state) { + const auto number_addresses = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto addresses = std::vector{}; + addresses.resize(number_addresses); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope2>{}; + // This exists so that the destructor call does not interfere with the timing + auto dumping_ground = std::vector<__dp::Scope2>{}; - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope2{1}; - state.ResumeTiming(); + for (auto _ : state) { + state.PauseTiming(); + auto scope = __dp::Scope2{1}; + state.ResumeTiming(); - for (auto addr : addresses) { - scope.registerStackWrite(addr, 0, ""); - } + for (auto addr : addresses) { + if (read_address(addr)) { + scope.registerStackRead(addr, 1, ""); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + if (write_address(addr)) { + scope.registerStackWrite(addr, 0, ""); + } } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(scope)); + state.ResumeTiming(); + } } -static void benchmark_scope_2(benchmark::State& state) { - const auto number_addresses = state.range(0); +static void benchmark_scope_manager_2_few_accesses(benchmark::State &state) { + const auto number_scopes = state.range(0); - auto addresses = std::vector{}; - addresses.resize(number_addresses); + auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager2{}; + state.ResumeTiming(); - // This exists so that the destructor call does not interfere with the timing - auto dumping_ground = std::vector<__dp::Scope2>{}; + auto current_number_scopes = 0; - for (auto _ : state) { - state.PauseTiming(); - auto scope = __dp::Scope2{1}; - state.ResumeTiming(); + for (auto i = 0; i < number_scopes; i++) { + manager.enterScope("Enter scope", i); - for (auto addr : addresses) { - if (read_address(addr)) { - scope.registerStackRead(addr, 1, ""); - } + manager.registerStackRead(24, 0, ""); + manager.registerStackWrite(i, 0, ""); + manager.registerStackRead(32, 0, ""); + manager.registerStackRead(64, 1, ""); + manager.registerStackWrite(i + 2, 0, ""); - if (write_address(addr)) { - scope.registerStackWrite(addr, 0, ""); - } - } + current_number_scopes++; + if (current_number_scopes > 10) { + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); - state.PauseTiming(); - dumping_ground.emplace_back(std::move(scope)); - state.ResumeTiming(); + current_number_scopes -= 5; + } } + + for (auto i = 0; i < current_number_scopes; i++) { + manager.leaveScope("Leave scope", i); + } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } -static void benchmark_scope_manager_2_few_accesses(benchmark::State& state) { - const auto number_scopes = state.range(0); - - auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager2{}; - state.ResumeTiming(); - - auto current_number_scopes = 0; - - for (auto i = 0; i < number_scopes; i++) { - manager.enterScope("Enter scope", i); - - manager.registerStackRead(24, 0, ""); - manager.registerStackWrite(i, 0, ""); - manager.registerStackRead(32, 0, ""); - manager.registerStackRead(64, 1, ""); - manager.registerStackWrite(i + 2, 0, ""); - - current_number_scopes++; - if (current_number_scopes > 10) { - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - - current_number_scopes -= 5; - } - } +static void benchmark_scope_manager_2_many_accesses(benchmark::State &state) { + const auto number_scopes = state.range(0); - for (auto i = 0; i < current_number_scopes; i++) { - manager.leaveScope("Leave scope", i); - } + auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); - } -} + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager2{}; + state.ResumeTiming(); -static void benchmark_scope_manager_2_many_accesses(benchmark::State& state) { - const auto number_scopes = state.range(0); - - auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager2{}; - state.ResumeTiming(); - - auto current_number_scopes = 0; - - for (auto i = 0; i < number_scopes; i++) { - manager.enterScope("Enter scope", i); - - for (auto j = 0; j < 1024; j++) { - const auto addr = convert_to_address(j + i); - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } - } - - current_number_scopes++; - if (current_number_scopes > 10) { - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - manager.leaveScope("Leave scope", i); - - current_number_scopes -= 5; - } - } + auto current_number_scopes = 0; + + for (auto i = 0; i < number_scopes; i++) { + manager.enterScope("Enter scope", i); - for (auto i = 0; i < current_number_scopes; i++) { - manager.leaveScope("Leave scope", i); + for (auto j = 0; j < 1024; j++) { + const auto addr = convert_to_address(j + i); + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } + } + + current_number_scopes++; + if (current_number_scopes > 10) { + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + manager.leaveScope("Leave scope", i); + + current_number_scopes -= 5; + } + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + for (auto i = 0; i < current_number_scopes; i++) { + manager.leaveScope("Leave scope", i); } -} -static void benchmark_scope_manager_2_first_written(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_scope_manager_2_first_written(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - auto dumping_ground = std::vector<__dp::ScopeManager2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager2{}; - state.ResumeTiming(); + auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - manager.enterScope("First", 1); + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager2{}; + state.ResumeTiming(); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("First", 1); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (first_written_address(addr, 1)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.enterScope("Second", 2); + if (first_written_address(addr, 1)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Second", 2); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (first_written_address(addr, 2)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.enterScope("Third", 3); + if (first_written_address(addr, 2)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Third", 3); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (first_written_address(addr, 3)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.leaveScope("Third", 3); - manager.leaveScope("Second", 2); + if (first_written_address(addr, 3)) { + const auto b = manager.isOwnedByScope(addr, true); + } + } - manager.enterScope("Forth", 4); + manager.leaveScope("Third", 3); + manager.leaveScope("Second", 2); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Forth", 4); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - if (first_written_address(addr, 4)) { - const auto b = manager.isOwnedByScope(addr, true); - } - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + if (first_written_address(addr, 4)) { + const auto b = manager.isOwnedByScope(addr, true); + } } -} -static void benchmark_scope_manager_2_positive_change(benchmark::State& state) { - const auto number_addresses = state.range(0); + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } +} - auto addresses = std::vector{}; - addresses.resize(number_addresses); +static void benchmark_scope_manager_2_positive_change(benchmark::State &state) { + const auto number_addresses = state.range(0); - for (auto i = std::int64_t(0); i < number_addresses; i++) { - addresses[i] = convert_to_address(i); - } + auto addresses = std::vector{}; + addresses.resize(number_addresses); - auto dumping_ground = std::vector<__dp::ScopeManager2>{}; + for (auto i = std::int64_t(0); i < number_addresses; i++) { + addresses[i] = convert_to_address(i); + } - for (auto _ : state) { - state.PauseTiming(); - auto manager = __dp::ScopeManager2{}; - state.ResumeTiming(); + auto dumping_ground = std::vector<__dp::ScopeManager2>{}; - manager.enterScope("First", 1); + for (auto _ : state) { + state.PauseTiming(); + auto manager = __dp::ScopeManager2{}; + state.ResumeTiming(); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("First", 1); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.enterScope("Second", 2); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Second", 2); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.enterScope("Third", 3); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Third", 3); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - manager.leaveScope("Third", 3); - manager.leaveScope("Second", 2); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - manager.enterScope("Forth", 4); + manager.leaveScope("Third", 3); + manager.leaveScope("Second", 2); - for (const auto addr : addresses) { - if (read_address(addr)) { - manager.registerStackRead(addr, 0, ""); - } + manager.enterScope("Forth", 4); - if (write_address(addr)) { - manager.registerStackWrite(addr, 0, ""); - } + for (const auto addr : addresses) { + if (read_address(addr)) { + manager.registerStackRead(addr, 0, ""); + } - const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + if (write_address(addr)) { + manager.registerStackWrite(addr, 0, ""); + } - state.PauseTiming(); - dumping_ground.emplace_back(std::move(manager)); - state.ResumeTiming(); + const auto b = manager.positiveScopeChangeOccuredSinceLastAccess(addr); } + + state.PauseTiming(); + dumping_ground.emplace_back(std::move(manager)); + state.ResumeTiming(); + } } -// The sorting determines the output order --> put pairs together so a comparison is easier +// The sorting determines the output order --> put pairs together so a +// comparison is easier BENCHMARK(benchmark_scope_read)->Unit(benchmark::kMillisecond)->Arg(32)->Iterations(100); BENCHMARK(benchmark_scope_2_read)->Unit(benchmark::kMillisecond)->Arg(32)->Iterations(100); diff --git a/discopop_explorer/PEGraphX.py b/discopop_explorer/PEGraphX.py index 206a3b7b9..3ee63a790 100644 --- a/discopop_explorer/PEGraphX.py +++ b/discopop_explorer/PEGraphX.py @@ -142,6 +142,10 @@ class Dependency: sink_line: Optional[LineID] = None intra_iteration: bool = False intra_iteration_level: int = -1 + metadata_intra_iteration_dep: Optional[List[LineID]] = None + metadata_inter_iteration_dep: Optional[List[LineID]] = None + metadata_intra_call_dep: Optional[List[LineID]] = None + metadata_inter_call_dep: Optional[List[LineID]] = None def __init__(self, type: EdgeType): self.etype = type @@ -567,6 +571,33 @@ def parse_dependency(dep: DependenceItem) -> Dependency: d.dtype = DepType[dep.type] d.var_name = dep.var_name d.memory_region = dep.memory_region + # parse metadata + if ";" in dep.metadata: + for md in dep.metadata.split(";"): + if len(md) == 0: + continue + md_type = md[: md.index(":")] + md_raw_values = md[md.index(":") + 1 :] + md_values = [tmp for tmp in md_raw_values.split(",") if len(tmp) > 0] + + if md_type == "intra_iteration_dep": + if d.metadata_intra_iteration_dep is None: + d.metadata_intra_iteration_dep = [] + d.metadata_intra_iteration_dep += md_values + elif md_type == "inter_iteration_dep": + if d.metadata_inter_iteration_dep is None: + d.metadata_inter_iteration_dep = [] + d.metadata_inter_iteration_dep += md_values + elif md_type == "intra_call_dep": + if d.metadata_intra_call_dep is None: + d.metadata_intra_call_dep = [] + d.metadata_intra_call_dep += md_values + elif md_type == "inter_call_dep": + if d.metadata_inter_call_dep is None: + d.metadata_inter_call_dep = [] + d.metadata_inter_call_dep += md_values + else: + raise ValueError("Unknown metadata type: ", md_type) return d diff --git a/discopop_explorer/parser.py b/discopop_explorer/parser.py index 5c2aa9f54..ce895e24a 100644 --- a/discopop_explorer/parser.py +++ b/discopop_explorer/parser.py @@ -31,6 +31,7 @@ class DependenceItem(object): type: Any var_name: Any memory_region: Any + metadata: Any # TODO improve typing @@ -154,17 +155,21 @@ def __parse_dep_file(dep_fd, output_path: str) -> Tuple[List[DependenceItem], Li var_str = "" if len(source_fields) == 1 else source_fields[1] var_name = "" aa_var_name = "" + metadata = "" if len(var_str) > 0: if "(" in var_str: split_var_str = var_str.split("(") var_name = split_var_str[0] aa_var_name = split_var_str[1][ - :-1 + : split_var_str[1].index(")") ] # name of the allocated variable which is accessed, i.e. variable name after anti aliasing + metadata_str = split_var_str[1][split_var_str[1].index(")") + 1 :] + if "[" in metadata_str: + metadata = metadata_str[1:-1] else: # compatibility with results created without alias analysis var_name = var_str - dependencies_list.append(DependenceItem(sink, source_fields[0], type, var_name, aa_var_name)) + dependencies_list.append(DependenceItem(sink, source_fields[0], type, var_name, aa_var_name, metadata)) return dependencies_list, loop_data_list diff --git a/discopop_explorer/pattern_detectors/do_all_detector.py b/discopop_explorer/pattern_detectors/do_all_detector.py index 6da0f438e..a0f0a2888 100644 --- a/discopop_explorer/pattern_detectors/do_all_detector.py +++ b/discopop_explorer/pattern_detectors/do_all_detector.py @@ -146,6 +146,12 @@ def __detect_do_all(pet: PEGraphX, root_loop: LoopNode) -> bool: for v in root_children_loops: loop_start_lines.append(v.start_position()) fp, p, lp, s, r = classify_loop_variables(pet, root_loop) + + # get parents of root_loop + parent_loops = __get_parent_loops(pet, root_loop) + parent_function_lineid = pet.get_parent_function(root_loop).start_position() + called_functions_lineids = __get_called_functions(pet, root_loop) + # get variables which are defined inside the loop defined_inside_loop: List[Tuple[Variable, Set[MemoryRegion]]] = [] tmp_loop_variables = pet.get_variables(root_children_cus) @@ -182,6 +188,9 @@ def __detect_do_all(pet: PEGraphX, root_loop: LoopNode) -> bool: p, lp, defined_inside_loop, + parent_loops, + parent_function_lineid, + called_functions_lineids, ): # if pet.depends_ignore_readonly(subnodes[i], subnodes[j], root_loop): return False @@ -204,6 +213,9 @@ def __check_loop_dependencies( privates: List[Variable], last_privates: List[Variable], defined_inside_loop: List[Tuple[Variable, Set[MemoryRegion]]], + parent_loops: List[LineID], + parent_function_lineid: LineID, + called_functions_lineids: List[LineID], ) -> bool: """Returns True, if dependencies between the respective subgraphs chave been found. Returns False otherwise, which results in the potential suggestion of a Do-All pattern.""" @@ -228,6 +240,9 @@ def __check_loop_dependencies( for source, target, dep in deps: + if root_loop.start_position() == "1:153": + pass + # todo: move this calculation to the innermost point possible to reduce computation costs # get metadata for dependency dep_source_nesting_level = __calculate_nesting_level(pet, root_loop, source) @@ -255,7 +270,25 @@ def __check_loop_dependencies( elif dep.dtype == DepType.RAW: # check RAW dependencies # RAW problematic, if it is not an intra-iteration RAW - if not dep.intra_iteration: + if ( + not dep.intra_iteration + and (dep.metadata_intra_iteration_dep is None or len(dep.metadata_intra_iteration_dep) == 0) + and parent_function_lineid + in (dep.metadata_intra_call_dep if dep.metadata_intra_call_dep is not None else []) + ) or ( + ( + False + if dep.metadata_inter_call_dep is None + else (len([cf for cf in called_functions_lineids if cf in dep.metadata_inter_call_dep]) > 0) + ) + and ( + False + if dep.metadata_inter_iteration_dep is None + else (len([t for t in parent_loops if t in dep.metadata_inter_iteration_dep]) > 0) + ) + ): + if root_loop.start_position() == "1:618": + pass return True # if it is an intra iteration dependency, it is problematic if it belongs to a parent loop else: @@ -263,42 +296,60 @@ def __check_loop_dependencies( if pet.node_at(source) in root_children_cus and pet.node_at(target) in root_children_cus: pass else: - return True - - # # dep within the loop. not problematic, if intra_iteration_level == 0 - # if dep.intra_iteration_level == 0: - # pass - # else: - # # might be problematic - # # check if source and target in children loops - # contained_in_nested_loop = False - # for nested_loop in [l for l in root_children_loops if l != root_loop]: - # nested_children = pet.subtree_of_type(nested_loop, (CUNode, LoopNode)) - # nested_children_cus = [cast(CUNode, cu) for cu in nested_children if cu.type == NodeType.CU] - # if pet.node_at(source) in nested_children_cus and pet.node_at(target) in nested_children_cus: - # contained_in_nested_loop = True - # if not contained_in_nested_loop: - # # problematic - # return True - - # else: - # # dep could belong to a parent loop - # if root_loop.get_nesting_level(pet) > 1 and dep.intra_iteration_level > 0: - # # dep belongs to parent loop. Can not be ignored for the inner loop - # return True + # check if metadata exists + if dep.metadata_intra_iteration_dep is not None: + for t in dep.metadata_intra_iteration_dep: + if t in parent_loops: + if root_loop.start_position() == "1:618": + pass + return True + return False + else: + if root_loop.start_position() == "1:618": + pass + return True elif dep.dtype == DepType.WAR: # check WAR dependencies # WAR problematic, if it is not an intra-iteration WAR and the variable is not private or firstprivate - if not dep.intra_iteration: + if ( + not dep.intra_iteration + and (dep.metadata_intra_iteration_dep is None or len(dep.metadata_intra_iteration_dep) == 0) + and parent_function_lineid + in (dep.metadata_intra_call_dep if dep.metadata_intra_call_dep is not None else []) + ) or ( + ( + False + if dep.metadata_inter_call_dep is None + else (len([cf for cf in called_functions_lineids if cf in dep.metadata_inter_call_dep]) > 0) + ) + and ( + False + if dep.metadata_inter_iteration_dep is None + else (len([t for t in parent_loops if t in dep.metadata_inter_iteration_dep]) > 0) + ) + ): if dep.var_name not in [v.name for v in first_privates + privates + last_privates]: # check if variable is defined inside loop if dep.memory_region not in memory_regions_defined_in_loop: + if root_loop.start_position() == "1:618": + pass return True # if it is an intra iteration dependency, it is problematic if it belongs to a parent loop elif dep.intra_iteration_level > root_loop.get_nesting_level(pet): tmp = root_loop.get_nesting_level(pet) - return True + # check if metadata exists + if dep.metadata_intra_iteration_dep is not None: + for t in dep.metadata_intra_iteration_dep: + if t in parent_loops: + if root_loop.start_position() == "1:618": + pass + return True + return False + else: + if root_loop.start_position() == "1:618": + pass + return True elif dep.dtype == DepType.WAW: # check WAW dependencies # handled by variable classification @@ -348,3 +399,48 @@ def __calculate_nesting_level(pet: PEGraphX, root_loop: LoopNode, cu_node_id: st # add new parents to the queue for in_child_edge in pet.in_edges(cast(NodeID, current_node_id), EdgeType.CHILD): potential_parents.append((in_child_edge[0], nesting_level + 1)) + + +def __get_parent_loops(pet: PEGraphX, root_loop: LoopNode): + """duplicates exists: do_all_detector <-> reduction_detector !""" + parents: List[NodeID] = [] + queue = [root_loop.id] + visited: Set[NodeID] = set() + while queue: + current = queue.pop() + visited.add(current) + if type(pet.node_at(current)) == LoopNode: + parents.append(current) + + # process incoming child edges + for s, t, e in pet.in_edges(current, EdgeType.CHILD): + if s not in visited and s not in queue: + queue.append(s) + # process incoming call edges + for s, t, e in pet.in_edges(current, EdgeType.CALLSNODE): + if s not in visited and s not in queue: + queue.append(s) + + parents.remove(root_loop.id) + return [pet.node_at(p).start_position() for p in parents] + + +def __get_called_functions(pet: PEGraphX, root_loop: LoopNode) -> List[LineID]: + """duplicates exists: do_all_detector <-> reduction_detector !""" + # identify children CUs without following function calls + called_functions: Set[NodeID] = set() + queue = [root_loop.id] + visited: Set[NodeID] = set() + while queue: + current = queue.pop() + visited.add(current) + # get called functions + for s, t, e in pet.out_edges(current, EdgeType.CALLSNODE): + called_functions.add(t) + # add children to queue + for s, t, e in pet.out_edges(current, EdgeType.CHILD): + if t not in queue and t not in visited: + queue.append(t) + + # convert node ids of called functions to line ids + return [pet.node_at(n).start_position() for n in called_functions] diff --git a/discopop_explorer/pattern_detectors/reduction_detector.py b/discopop_explorer/pattern_detectors/reduction_detector.py index c17c82c1d..376d2e7ca 100644 --- a/discopop_explorer/pattern_detectors/reduction_detector.py +++ b/discopop_explorer/pattern_detectors/reduction_detector.py @@ -8,7 +8,7 @@ from multiprocessing import Pool -from typing import List, cast +from typing import List, cast, Set from alive_progress import alive_bar # type: ignore @@ -22,6 +22,7 @@ LineID, DepType, EdgeType, + NodeID, ) from ..utils import filter_for_hotspots, is_reduction_var, classify_loop_variables from ..variable import Variable @@ -136,6 +137,11 @@ def __detect_reduction(pet: PEGraphX, root: LoopNode) -> bool: reduction_var_names = [v.name for v in reduction_vars] fp, p, lp, s, r = classify_loop_variables(pet, root) + # get parents of loop + parent_loops = __get_parent_loops(pet, root) + parent_function_lineid = pet.get_parent_function(root).start_position() + called_functions_lineids = __get_called_functions(pet, root) + if __check_loop_dependencies( pet, root, @@ -146,6 +152,9 @@ def __detect_reduction(pet: PEGraphX, root: LoopNode) -> bool: fp, p, lp, + parent_loops, + parent_function_lineid, + called_functions_lineids, ): return False @@ -167,6 +176,9 @@ def __check_loop_dependencies( first_privates: List[Variable], privates: List[Variable], last_privates: List[Variable], + parent_loops: List[LineID], + parent_function_lineid: LineID, + called_functions_lineids: List[LineID], ) -> bool: """Returns True, if dependencies between the respective subgraphs chave been found. Returns False otherwise, which results in the potential suggestion of a Reduction pattern.""" @@ -212,12 +224,44 @@ def __check_loop_dependencies( else: # RAW does not target a reduction variable. # RAW problematic, if it is not an intra-iteration RAW. - if not dep.intra_iteration: + if ( + not dep.intra_iteration + and (dep.metadata_intra_iteration_dep is None or len(dep.metadata_intra_iteration_dep) == 0) + and parent_function_lineid + in (dep.metadata_intra_call_dep if dep.metadata_intra_call_dep is not None else []) + ) or ( + ( + False + if dep.metadata_inter_call_dep is None + else (len([cf for cf in called_functions_lineids if cf in dep.metadata_inter_call_dep]) > 0) + ) + and ( + False + if dep.metadata_inter_iteration_dep is None + else (len([t for t in parent_loops if t in dep.metadata_inter_iteration_dep]) > 0) + ) + ): return True elif dep.dtype == DepType.WAR: # check WAR dependencies # WAR problematic, if it is not an intra-iteration WAR and the variable is not private or firstprivate - if not dep.intra_iteration: + if ( + not dep.intra_iteration + and (dep.metadata_intra_iteration_dep is None or len(dep.metadata_intra_iteration_dep) == 0) + and parent_function_lineid + in (dep.metadata_intra_call_dep if dep.metadata_intra_call_dep is not None else []) + ) or ( + ( + False + if dep.metadata_inter_call_dep is None + else (len([cf for cf in called_functions_lineids if cf in dep.metadata_inter_call_dep]) > 0) + ) + and ( + False + if dep.metadata_inter_iteration_dep is None + else (len([t for t in parent_loops if t in dep.metadata_inter_iteration_dep]) > 0) + ) + ): if dep.var_name not in [v.name for v in first_privates + privates + last_privates]: return True elif dep.dtype == DepType.WAW: @@ -229,3 +273,48 @@ def __check_loop_dependencies( # no problem found. Potentially suggest reduction return False + + +def __get_parent_loops(pet: PEGraphX, root_loop: LoopNode): + """duplicates exists: do_all_detector <-> reduction_detector !""" + parents: List[NodeID] = [] + queue = [root_loop.id] + visited: Set[NodeID] = set() + while queue: + current = queue.pop() + visited.add(current) + if type(pet.node_at(current)) == LoopNode: + parents.append(current) + + # process incoming child edges + for s, t, e in pet.in_edges(current, EdgeType.CHILD): + if s not in visited and s not in queue: + queue.append(s) + # process incoming call edges + for s, t, e in pet.in_edges(current, EdgeType.CALLSNODE): + if s not in visited and s not in queue: + queue.append(s) + + parents.remove(root_loop.id) + return [pet.node_at(p).start_position() for p in parents] + + +def __get_called_functions(pet: PEGraphX, root_loop: LoopNode) -> List[LineID]: + """duplicates exists: do_all_detector <-> reduction_detector !""" + # identify children CUs without following function calls + called_functions: Set[NodeID] = set() + queue = [root_loop.id] + visited: Set[NodeID] = set() + while queue: + current = queue.pop() + visited.add(current) + # get called functions + for s, t, e in pet.out_edges(current, EdgeType.CALLSNODE): + called_functions.add(t) + # add children to queue + for s, t, e in pet.out_edges(current, EdgeType.CHILD): + if t not in queue and t not in visited: + queue.append(t) + + # convert node ids of called functions to line ids + return [pet.node_at(n).start_position() for n in called_functions] diff --git a/docs/setup/discopop.md b/docs/setup/discopop.md index b388087f9..f9bf55ac9 100644 --- a/docs/setup/discopop.md +++ b/docs/setup/discopop.md @@ -1,39 +1,49 @@ ---- -layout: default -title: DiscoPoP -parent: Setup -nav_order: 1 ---- - -# DiscoPoP Setup -## Prerequisites -- LLVM/clang version 11 -- Python version 3.6 or greater - -## Setup -``` -git clone git@github.com:discopop-project/discopop.git -cd discopop -mkdir build -``` - -## Build libraries and install Python modules -``` -cd build -cmake .. -make -cd .. -``` - -where `` can consist of any combination of the following flags and commonly used CMAKE_FLAGS: -- In case you want to use a specific Version of LLVM, it is possible to specify the `-DUSE_LLVM_VERSION=` flag. -- In case you want to use a specific LLVM installation, specify the location via the `-DLLVM_DIST_PATH=` flag. -- In case your application uses PThreads, please specify `-DDP_PTHREAD_COMPATIBILITY_MODE=[0|1]`. Note, however, that this can influence the runtime of the profiling. -- In case you require a more verbose output of the runtime library, specify the `-DDP_RTLIB_VERBOSE=[0|1]` flag. -- In case you want to specify the number of Workers available for the profiling step, specify the `-DDP_NUM_WORKERS=` flag. By default, `3` worker threads are used to analyze the observed memory accesses. `0` might be used to disable the creation of additional threads for the analysis. - -## Testing the installation -To test the installation, it is possible to execute the provided set of unit tests. -``` -python -m unittest -v -``` +--- +layout: default +title: DiscoPoP +parent: Setup +nav_order: 1 +--- + +# DiscoPoP Setup +## Prerequisites +- LLVM/clang version 11 +- Python version 3.6 or greater + +## Setup +``` +git clone git@github.com:discopop-project/discopop.git +cd discopop +mkdir build +``` + +## Build libraries and install Python modules +``` +cd build +cmake .. +make +cd .. +``` + +where `` can consist of any combination of the following flags and commonly used CMAKE_FLAGS: +#### Environment configuration +- `-DUSE_LLVM_VERSION=` – Use a specific Version of LLVM +- `-DLLVM_DIST_PATH=` – Use a specific LLVM installation by specifiying the location +#### Profiling configuration +- `-DDP_PTHREAD_COMPATIBILITY_MODE=[0|1]` – If your application uses PThreads, please specify this flag to serialize the calls to the DiscoPoP runtime functions. Note, however, that this can negatively influence the runtime of the profiling. +- `-DDP_NUM_WORKERS=` – Specify the number of worker threads available for the dependency analysis during profiling. Default: `3` worker threads. `0` can be used to disable the creation of additional threads for the analysis. +- `-DDP_HYBRID_PROFILING=[0|1]` – Enbale hybrid profiling. Default: `1`. +- `-DDP_MEMORY_REGION_DEALIASING=[0|1]`: Enable or disable the generation of dependency de-aliasing information. Reduces potential false positive parallelization suggestions, but increases the profiling overhead. +- `-DDP_STACK_ACCESS_DETECTION=[0|1]`: Enable or disable stack dependency detection. Enabling will reduce false positive dependences, but increase the profiling overhead. This flag only has an effect on the results, if `-DDP_HYBRID_PROFILING=0`. +- `-DDP_CALLSTACK_PROFILING=[0|1]`: Enable or disable callstack profiling. Enabling will allow the detection of parallelization suggestions for more complex code regions, but significantly increase the profiling overhead. + +#### Development and debugging +- `-DDP_RTLIB_VERBOSE=[0|1]` – Enable verbose output during profiling. +- `-DDP_INTERNAL_TIMER=[0|1]`– Enable timing of runtime library functions. + + +## Testing the installation +To test the installation, it is possible to execute the provided set of unit tests. +``` +python -m unittest -v +``` diff --git a/rtlib/CMakeLists.txt b/rtlib/CMakeLists.txt index a3d8b4c49..29770a50d 100644 --- a/rtlib/CMakeLists.txt +++ b/rtlib/CMakeLists.txt @@ -17,6 +17,8 @@ set(DiscoPoP_SOURCES memory/MemoryManager.cpp memory/Signature.cpp + + callstack/CallStack.cpp injected_functions/dp_add_bb_deps.cpp injected_functions/dp_alloca.cpp @@ -64,6 +66,30 @@ if(DEFINED DP_NUM_WORKERS) target_compile_definitions(DiscoPoP_RT PUBLIC DP_NUM_WORKERS=${DP_NUM_WORKERS}) endif() +if(DEFINED DP_INTERNAL_TIMER) + if(NOT ${DP_INTERNAL_TIMER} EQUAL 0) + target_compile_definitions(DiscoPoP_RT PUBLIC DP_INTERNAL_TIMER=${DP_INTERNAL_TIMER}) + endif() +endif() + +if(DEFINED DP_MEMORY_REGION_DEALIASING) + if(NOT ${DP_MEMORY_REGION_DEALIASING} EQUAL 0) + target_compile_definitions(DiscoPoP_RT PUBLIC DP_MEMORY_REGION_DEALIASING=${DP_MEMORY_REGION_DEALIASING}) + endif() +endif() + +if(DEFINED DP_STACK_ACCESS_DETECTION) + if(NOT ${DP_STACK_ACCESS_DETECTION} EQUAL 0) + target_compile_definitions(DiscoPoP_RT PUBLIC DP_STACK_ACCESS_DETECTION=${DP_STACK_ACCESS_DETECTION}) + endif() +endif() + +if(DEFINED DP_CALLSTACK_PROFILING) + if(NOT ${DP_CALLSTACK_PROFILING} EQUAL 0) + target_compile_definitions(DiscoPoP_RT PUBLIC DP_CALLSTACK_PROFILING=${DP_CALLSTACK_PROFILING}) + endif() +endif() + # end of compiler flags install(TARGETS DiscoPoP_RT ARCHIVE DESTINATION lib) diff --git a/rtlib/DPTypes.hpp b/rtlib/DPTypes.hpp index cc01d0c98..702eb34f7 100644 --- a/rtlib/DPTypes.hpp +++ b/rtlib/DPTypes.hpp @@ -15,22 +15,16 @@ #include // Number of bits for holding LID -#define LIDSIZE 14 +#define LIDSIZE 14 // Number of bits for holding LID Metadata (Column + Loop ID + LoopIteration) -#define LIDMETADATASIZE 32 +#define LIDMETADATASIZE 32 // Maximum number of lines in a single file. Has to be 2^LIDSIZE. -#define MAXLNO 16384 +#define MAXLNO 16384 // #define SKIP_DUP_INSTR 1 -// To manually enable/disable internal timing -// #define DP_SKIP_INTERNAL_TIMER -#ifndef DP_SKIP_INTERNAL_TIMER -#define DP_INTERNAL_TIMER -#endif - typedef std::int64_t LID; typedef std::int64_t ADDR; typedef std::int64_t sigElement; @@ -42,19 +36,14 @@ typedef std::int64_t sigElement; #include "../third_party/emhash/hash_set8.hpp" #include "../third_party/emhash/hash_table7.hpp" namespace __dp { -template -using hashmap = emhash7::HashMap; -template -using hashset = emhash8::HashSet; +template using hashmap = emhash7::HashMap; +template using hashset = emhash8::HashSet; } // namespace __dp #else #include #include namespace __dp { -template -using hashmap = std::unordered_map; -template -using hashset = std::unordered_set; +template using hashmap = std::unordered_map; +template using hashset = std::unordered_set; } // namespace __dp #endif - diff --git a/rtlib/DPUtils.hpp b/rtlib/DPUtils.hpp index f76c98c83..a3b8e6441 100644 --- a/rtlib/DPUtils.hpp +++ b/rtlib/DPUtils.hpp @@ -29,12 +29,12 @@ using namespace std; namespace dputil { -inline void decodeLID(std::int64_t lid, std::ostream& out) { +inline void decodeLID(std::int64_t lid, std::ostream &out) { if (lid == 0) { out << '*'; return; } - + // unpack metadata // potentially TODO, currently not necessary diff --git a/rtlib/callstack/CallStack.cpp b/rtlib/callstack/CallStack.cpp new file mode 100644 index 000000000..6e02275fa --- /dev/null +++ b/rtlib/callstack/CallStack.cpp @@ -0,0 +1,132 @@ +/* + * This file is part of the DiscoPoP software + * (http://www.discopop.tu-darmstadt.de) + * + * Copyright (c) 2020, Technische Universitaet Darmstadt, Germany + * + * This software may be modified and distributed under the terms of + * the 3-Clause BSD License. See the LICENSE file in the package base + * directory for details. + * + */ + +#include "CallStack.hpp" + +CallStackEntry *CallStackEntry::getCopy() { + CallStackEntry *copy = new CallStackEntry(type, lid, counter); + return copy; +} + +std::string CallStackEntry::toString() { + if (type == 0) { + return "Function (" + decodeLID(lid) + ") @ callid: " + to_string(counter); + } else if (type == 1) { + return "Loop (" + decodeLID(lid) + ") @ it: " + to_string(counter); + } else { + return "Unknown"; + } +}; + +inline bool CallStackEntry::isLoop() { return type == 1; } + +inline bool CallStackEntry::isFunction() { return type == 0; } + +void CallStack::util_compare_callstacks(CallStack *cs_1, CallStack *cs_2, std::set *intra_iteration_dependencies, + std::set *inter_iteration_dependencies, + std::set *intra_call_dependencies, + std::set *inter_call_dependencies) { + + // if any are nullptr, no information on the dependency type is contained + if ((!cs_1) || (!cs_2)) { + return; + } + + if (DBG) + cout << "compare CallStacks: \n"; + + // iterate along CallStacks (check equal call paths) + bool deviated_before = false; + for (int i = 0; i < min(cs_1->size(), cs_2->size()); i++) { + CallStackEntry *element_1 = cs_1->getElement(i); + CallStackEntry *element_2 = cs_2->getElement(i); + if (DBG) { + cout << "i: " << i << "\n"; + cout << " element_1: " << element_1->toString() << "\n"; + cout << " element_2: " << element_2->toString() << "\n"; + } + + // check for deviations in the CallStack + bool elements_differ = false; + if (!(*element_1 == *element_2)) { + elements_differ = true; + } + + // check for intra iteration dependencies + if (!deviated_before) { + if (!elements_differ) { + if (element_1->isLoop()) { + intra_iteration_dependencies->insert(element_1->lid); + } + } + } + + // check for inter iteration dependencies + if (!deviated_before) { + if (elements_differ) { + if (element_1->isLoop() && element_2->isLoop()) { + if (element_1->lid == element_2->lid) { + if (element_1->counter != element_2->counter) { + inter_iteration_dependencies->insert(element_1->lid); + } + } + } + } + } + + // check for intra call dependencies + if (!deviated_before) { + if (!elements_differ) { + if (element_1->isFunction()) { + intra_call_dependencies->insert(element_1->lid); + } + } + } + + // check for inter call dependencies + if (!deviated_before) { + if (elements_differ) { + if (element_1->isFunction() && element_2->isFunction()) { + if (element_1->lid == element_2->lid) { + if (element_1->counter != element_2->counter) { + inter_call_dependencies->insert(element_1->lid); + } + } + } + } + } + + // register deviation for successive iterations + if (elements_differ) { + deviated_before = true; + } + } + + // check differing call paths + // TODO check all combinations of call stack entrys to support multiple entry + // points and call stacks of variable length + for (CallStackEntry *element_1 : cs_1->stack) { + for (CallStackEntry *element_2 : cs_2->stack) { + + // check for inter call dependencies + if (element_1->isFunction() && element_2->isFunction()) { + if (element_1->lid == element_2->lid) { + if (element_1->counter != element_2->counter) { + inter_call_dependencies->insert(element_1->lid); + } + } + } + } + } + if (DBG) + cout << "\n"; +} \ No newline at end of file diff --git a/rtlib/callstack/CallStack.hpp b/rtlib/callstack/CallStack.hpp new file mode 100644 index 000000000..598b42361 --- /dev/null +++ b/rtlib/callstack/CallStack.hpp @@ -0,0 +1,257 @@ +/* + * This file is part of the DiscoPoP software + * (http://www.discopop.tu-darmstadt.de) + * + * Copyright (c) 2020, Technische Universitaet Darmstadt, Germany + * + * This software may be modified and distributed under the terms of + * the 3-Clause BSD License. See the LICENSE file in the package base + * directory for details. + * + */ + +#pragma once + +#include "../DPUtils.hpp" +#include +#include + +#define DBG 0 + +using namespace dputil; + +struct CallStackEntry { + short type; // 0: function, 1: loop + unsigned long counter = 0; + + LID lid; + + CallStackEntry(short arg_type, LID arg_lid, unsigned long arg_counter) + : type(arg_type), lid(arg_lid), counter(arg_counter){}; + + ~CallStackEntry() { + if (DBG) { + cout << "DBG: deleted CallStackEntry of type: " << toString() << "\n"; + } + } + + CallStackEntry *getCopy(); + + std::string toString(); + + bool operator==(const CallStackEntry &rhs) const { + if (type != rhs.type) + return false; + if (counter != rhs.counter) + return false; + if (lid != rhs.lid) + return false; + return true; + } + + inline bool isLoop(); + + inline bool isFunction(); +}; + +struct CallStack { + // Constructors + CallStack() { + if (DBG) { + cout << "DBG: Created CallStack\n"; + } + }; + // Destructors + ~CallStack() { + if (DBG) { + cout << "DBG: Deleting CallStack\n"; + } + while (stack.size() > 0) { + pop(); + } + if (DBG) { + cout << "DBG: CallStack deleted\n"; + } + }; + + CallStack *getCopy() { + CallStack *copy = new CallStack(); + for (auto elem : stack) { + copy->stack.push_back(elem->getCopy()); + } + if (DBG) { + cout << "DBG: Copied CallStack\n"; + + cout << "Original: \n"; + print(); + cout << "Copy: \n"; + copy->print(); + cout << "\n"; + } + return copy; + }; + + // Functions + void push(CallStackEntry *cse) { + // prevent duplicate push of loop + // this is an artifact of the implementation of __dp_func_entry, as it + // relies on the "loops" hashmap to remove duplicates upon "insert" + if (stack.size() > 0) { + if (stack.back()->lid == cse->lid && stack.back()->type == 1 && cse->type == 1) { + return; + } + } + + stack.push_back(cse); + if (DBG) { + cout << "DBG: push type: " << to_string(cse->type) << "\n"; + ; + } + } + + void pop() { + CallStackEntry *p_cse = stack.back(); + if (DBG) { + cout << "DBG: pop type: " << to_string(p_cse->type) << "\n"; + ; + } + stack.pop_back(); + delete p_cse; + } + + void popLoop() { + if (stack.back()->type == 1) { + pop(); + } + } + + void popFunction() { + if (stack.back()->type == 0) { + pop(); + } + } + + void incrementIterationCounter() { stack.back()->counter++; } + + void print() const { + cout << "CallStack: \n"; + cout << "--> Length: " << stack.size() << "\n"; + for (CallStackEntry *entry : stack) { + cout << " " << entry->toString() << " ptr: " << entry << "\n"; + } + + cout << "\n"; + }; + + int size() { return stack.size(); } + + CallStackEntry *getElement(int n) { return stack.at(n); } + + void util_compare_callstacks(CallStack *cs_1, CallStack *cs_2, std::set *intra_iteration_dependencies, + std::set *inter_iteration_dependencies, std::set *intra_call_dependencies, + std::set *inter_call_dependencies); + + // Values + std::vector stack; +}; + +/* +void compare_callstacks(CallStack* cs_1, CallStack* cs_2, std::set* +intra_iteration_dependencies, std::set* inter_iteration_dependencies, +std::set* intra_call_dependencies, std::set* inter_call_dependencies){ + + // if any are nullptr, no information on the dependency type is contained + if((!cs_1) || (!cs_2)){ + return; + } + + if(DBG) + cout << "compare CallStacks: \n"; + + // iterate along CallStacks (check equal call paths) + bool deviated_before = false; + for(int i = 0; i < min(cs_1->size(), cs_2->size()); i++){ + CallStackEntry* element_1 = cs_1->getElement(i); + CallStackEntry* element_2 = cs_2->getElement(i); + if(DBG){ + cout << "i: " << i << "\n"; + cout << " element_1: " << element_1->toString() << "\n"; + cout << " element_2: " << element_2->toString() << "\n"; + } + + // check for deviations in the CallStack + bool elements_differ = false; + if(!(*element_1 == *element_2)){ + elements_differ = true; + } + + // check for intra iteration dependencies + if(! deviated_before){ + if(!elements_differ){ + if(element_1->isLoop()){ + intra_iteration_dependencies->insert(element_1->lid); + } + } + } + + // check for inter iteration dependencies + if(! deviated_before){ + if(elements_differ){ + if(element_1->isLoop() && element_2->isLoop()){ + if(element_1->lid == element_2->lid){ + if(element_1->counter != element_2->counter){ + inter_iteration_dependencies->insert(element_1->lid); + } + } + } + } + } + + // check for intra call dependencies + if(!deviated_before){ + if(!elements_differ){ + if(element_1->isFunction()){ + intra_call_dependencies->insert(element_1->lid); + } + } + } + + // check for inter call dependencies + if(!deviated_before){ + if(elements_differ){ + if(element_1->isFunction() && element_2->isFunction()){ + if(element_1->lid == element_2->lid){ + if(element_1->counter != element_2->counter){ + inter_call_dependencies->insert(element_1->lid); + } + } + } + } + } + + // register deviation for successive iterations + if(elements_differ){ + deviated_before = true; + } + } + + // check differing call paths + // TODO check all combinations of call stack entrys to support multiple +entry points and call stacks of variable length for(CallStackEntry* element_1 : +cs_1->stack){ for(CallStackEntry* element_2 : cs_2->stack){ + + // check for inter call dependencies + if(element_1->isFunction() && element_2->isFunction()){ + if(element_1->lid == element_2->lid){ + if(element_1->counter != element_2->counter){ + inter_call_dependencies->insert(element_1->lid); + } + } + } + } + } + if(DBG) + cout << "\n"; + +} +*/ \ No newline at end of file diff --git a/rtlib/functions/FunctionManager.hpp b/rtlib/functions/FunctionManager.hpp index 810d5461e..c90e4663b 100644 --- a/rtlib/functions/FunctionManager.hpp +++ b/rtlib/functions/FunctionManager.hpp @@ -31,79 +31,67 @@ typedef std::set ENDFuncList; class FunctionManager { public: - FunctionManager() { - } + FunctionManager() {} - ~FunctionManager() { - } + ~FunctionManager() {} - void log_call(const LID current_lid) { - lastCallOrInvoke = current_lid; - } + void log_call(const LID current_lid) { lastCallOrInvoke = current_lid; } - void reset_call(const LID current_lid) { - lastCallOrInvoke = 0; - lastProcessedLine = current_lid; - } + void reset_call(const LID current_lid) { + lastCallOrInvoke = 0; + lastProcessedLine = current_lid; + } - void increase_stack_level() { - ++FuncStackLevel; - } + void increase_stack_level() { ++FuncStackLevel; } - void decrease_stack_level() { - --FuncStackLevel; - } + void decrease_stack_level() { --FuncStackLevel; } - void register_function_end(const LID current_lid) { - endFuncs.insert(current_lid); - } + void register_function_end(const LID current_lid) { endFuncs.insert(current_lid); } - std::int32_t get_current_stack_level() { - return FuncStackLevel; - } + std::int32_t get_current_stack_level() { return FuncStackLevel; } - void register_function_start(const LID current_lid) { - // Process ordinary function call/invoke. - - if (lastCallOrInvoke == 0) - lastCallOrInvoke = lastProcessedLine; - ++FuncStackLevel; + void register_function_start(const LID current_lid) { + // Process ordinary function call/invoke. + + if (lastCallOrInvoke == 0) + lastCallOrInvoke = lastProcessedLine; + ++FuncStackLevel; #ifdef DP_DEBUG - std::cout << "Entering function LID " << std::dec << dputil::decodeLID(lid) << std::endl; - std::cout << "Function stack level = " << std::dec << FuncStackLevel << std::endl; + std::cout << "Entering function LID " << std::dec << dputil::decodeLID(lid) << std::endl; + std::cout << "Function stack level = " << std::dec << FuncStackLevel << std::endl; #endif - BGNFuncList::iterator func = beginFuncs.find(lastCallOrInvoke); - if (func == beginFuncs.end()) { - std::set tmp{}; - tmp.insert(current_lid); - beginFuncs.emplace(lastCallOrInvoke, std::move(tmp)); - } else { - func->second.insert(current_lid); - } + BGNFuncList::iterator func = beginFuncs.find(lastCallOrInvoke); + if (func == beginFuncs.end()) { + std::set tmp{}; + tmp.insert(current_lid); + beginFuncs.emplace(lastCallOrInvoke, std::move(tmp)); + } else { + func->second.insert(current_lid); + } + } + + void output_functions(std::ostream &stream) { + for (const auto &func_begin : beginFuncs) { + for (auto fb : func_begin.second) { + stream << dputil::decodeLID(func_begin.first) << " BGN func "; + stream << dputil::decodeLID(fb) << std::endl; + } } - void output_functions(std::ostream& stream) { - for (const auto &func_begin : beginFuncs) { - for (auto fb : func_begin.second) { - stream << dputil::decodeLID(func_begin.first) << " BGN func "; - stream << dputil::decodeLID(fb) << std::endl; - } - } - - for (auto fe : endFuncs) { - stream << dputil::decodeLID(fe) << " END func" << std::endl; - } + for (auto fe : endFuncs) { + stream << dputil::decodeLID(fe) << " END func" << std::endl; } + } private: - BGNFuncList beginFuncs; // function entries - ENDFuncList endFuncs; // function returns + BGNFuncList beginFuncs; // function entries + ENDFuncList endFuncs; // function returns - LID lastCallOrInvoke = 0; - LID lastProcessedLine = 0; - std::int32_t FuncStackLevel = 0; + LID lastCallOrInvoke = 0; + LID lastProcessedLine = 0; + std::int32_t FuncStackLevel = 0; }; } // namespace __dp diff --git a/rtlib/iFunctions.cpp b/rtlib/iFunctions.cpp index c4b87b710..cfbffadd8 100644 --- a/rtlib/iFunctions.cpp +++ b/rtlib/iFunctions.cpp @@ -15,24 +15,24 @@ #include "DPUtils.hpp" +#include "../share/include/debug_print.hpp" +#include "../share/include/timer.hpp" +#include "injected_functions/all.hpp" #include "loop/Makros.hpp" #include "memory/PerfectShadow.hpp" #include "memory/ShadowMemory.hpp" #include "memory/Signature.hpp" -#include "injected_functions/all.hpp" -#include "../share/include/debug_print.hpp" -#include "../share/include/timer.hpp" +#include #include +#include #include #include #include -#include -#include -#include #include #include #include +#include #include #include #include @@ -55,18 +55,59 @@ namespace __dp { /******* Helper functions *******/ -void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, - bool isStackAccess, ADDR addr, bool addrIsFirstWrittenInScope, +void addDep(depType type, LID curr, CallStack *currCallStack, LID depOn, CallStack *depOnCallStack, const char *var, + string AAvar, bool isStackAccess, ADDR addr, bool addrIsFirstWrittenInScope, bool positiveScopeChangeOccuredSinceLastAccess) { #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::ADD_DEP); #endif - + // hybrid analysis if (depOn == 0 && type == WAW) type = INIT; // End HA + // DEBUG + std::set intra_iteration_dependencies; + std::set inter_iteration_dependencies; + std::set intra_call_dependencies; + std::set inter_call_dependencies; +#if DP_CALLSTACK_PROFILING + bool CALLSTACK_DBG = false; + if (CALLSTACK_DBG) { + if (currCallStack || depOnCallStack) { + cout << "### addDep ###\n"; + } + + if (currCallStack) { + cout << "CURR CALLSTACK:\n"; + currCallStack->print(); + } + if (depOnCallStack) { + cout << "DEPON CALLSTACK:\n"; + depOnCallStack->print(); + } + if (currCallStack || depOnCallStack) { + cout << "\n\n"; + } + } + //! DEBUG + + // TEST + callStack->util_compare_callstacks(currCallStack, depOnCallStack, &intra_iteration_dependencies, + &inter_iteration_dependencies, &intra_call_dependencies, &inter_call_dependencies); + + if (CALLSTACK_DBG) { + if (currCallStack || depOnCallStack) { + cout << "Intra_iteration_dependencies: " << intra_iteration_dependencies.size() << "\n"; + cout << "Inter_iteration_dependencies: " << inter_iteration_dependencies.size() << "\n"; + cout << "Intra_call_dependencies: " << intra_call_dependencies.size() << "\n"; + cout << "Inter_call_dependencies: " << inter_call_dependencies.size() << "\n"; + } + } +#endif + // !TEST + depType originalType = type; int loopIterationOffset = 0; @@ -76,59 +117,47 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, // are overwritten (not 0xFF anymore) and check for intra-iteration // dependencies Intra-Iteration dependency exists, if LoopId's and Iteration // Id's are equal - if (unpackLIDMetadata_getLoopID(curr) != (LID)0xFF && - unpackLIDMetadata_getLoopID(depOn) != (LID)0xFF) { - if (unpackLIDMetadata_getLoopID(curr) == - unpackLIDMetadata_getLoopID(depOn)) { + if (unpackLIDMetadata_getLoopID(curr) != (LID)0xFF && unpackLIDMetadata_getLoopID(depOn) != (LID)0xFF) { + if (unpackLIDMetadata_getLoopID(curr) == unpackLIDMetadata_getLoopID(depOn)) { // determine iteration count offset in case a new loop has been entered // between curr and depOn - loopIterationOffset = checkLIDMetadata_getLoopIterationValidity_0(curr) + - checkLIDMetadata_getLoopIterationValidity_1(curr) + - checkLIDMetadata_getLoopIterationValidity_2(curr) - - checkLIDMetadata_getLoopIterationValidity_0(depOn) - - checkLIDMetadata_getLoopIterationValidity_1(depOn) - - checkLIDMetadata_getLoopIterationValidity_2(depOn); + loopIterationOffset = + checkLIDMetadata_getLoopIterationValidity_0(curr) + checkLIDMetadata_getLoopIterationValidity_1(curr) + + checkLIDMetadata_getLoopIterationValidity_2(curr) - checkLIDMetadata_getLoopIterationValidity_0(depOn) - + checkLIDMetadata_getLoopIterationValidity_1(depOn) - checkLIDMetadata_getLoopIterationValidity_2(depOn); if (loopIterationOffset == 0) { - if (checkLIDMetadata_getLoopIterationValidity_0(curr) && - checkLIDMetadata_getLoopIterationValidity_0(depOn)) { - if (checkLIDMetadata_getLoopIterationValidity_1(curr) && - checkLIDMetadata_getLoopIterationValidity_1(depOn)) { + if (checkLIDMetadata_getLoopIterationValidity_0(curr) && checkLIDMetadata_getLoopIterationValidity_0(depOn)) { + if (checkLIDMetadata_getLoopIterationValidity_1(curr) && checkLIDMetadata_getLoopIterationValidity_1(depOn)) { if (checkLIDMetadata_getLoopIterationValidity_2(curr) && checkLIDMetadata_getLoopIterationValidity_2(depOn)) { // loop 0+1+2 valid - if (unpackLIDMetadata_getLoopIteration_2(curr) == - unpackLIDMetadata_getLoopIteration_2(depOn)) { + if (unpackLIDMetadata_getLoopIteration_2(curr) == unpackLIDMetadata_getLoopIteration_2(depOn)) { identifiedDepTypes.push_back(II_2); dependencyRegistered = true; - if (unpackLIDMetadata_getLoopIteration_1(curr) == - unpackLIDMetadata_getLoopIteration_1(depOn)) { + if (unpackLIDMetadata_getLoopIteration_1(curr) == unpackLIDMetadata_getLoopIteration_1(depOn)) { identifiedDepTypes.push_back(II_1); - if (unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_0(depOn)) { + if (unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_0(depOn)) { identifiedDepTypes.push_back(II_0); } } } } else { // loop 0+1 valid - if (unpackLIDMetadata_getLoopIteration_1(curr) == - unpackLIDMetadata_getLoopIteration_1(depOn)) { + if (unpackLIDMetadata_getLoopIteration_1(curr) == unpackLIDMetadata_getLoopIteration_1(depOn)) { identifiedDepTypes.push_back(II_1); dependencyRegistered = true; - if (unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_0(depOn)) { + if (unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_0(depOn)) { identifiedDepTypes.push_back(II_0); } } } } else { // loop 0 valid - if (unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_0(depOn)) { + if (unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_0(depOn)) { identifiedDepTypes.push_back(II_0); dependencyRegistered = true; } @@ -139,17 +168,14 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, } else if (loopIterationOffset == 1) { // check outer loop - if ((unpackLIDMetadata_getLoopIteration_2(curr) == - unpackLIDMetadata_getLoopIteration_1(depOn)) && - checkLIDMetadata_getLoopIterationValidity_2(curr) && - checkLIDMetadata_getLoopIterationValidity_1(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_2(curr) == unpackLIDMetadata_getLoopIteration_1(depOn)) && + checkLIDMetadata_getLoopIterationValidity_2(curr) && checkLIDMetadata_getLoopIterationValidity_1(depOn)) { // II 2 identifiedDepTypes.push_back(II_2); dependencyRegistered = true; } // check second loop - else if ((unpackLIDMetadata_getLoopIteration_1(curr) == - unpackLIDMetadata_getLoopIteration_0(depOn)) && + else if ((unpackLIDMetadata_getLoopIteration_1(curr) == unpackLIDMetadata_getLoopIteration_0(depOn)) && checkLIDMetadata_getLoopIterationValidity_1(curr) && checkLIDMetadata_getLoopIterationValidity_0(depOn)) { // II 1 @@ -158,10 +184,8 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, } } else if (loopIterationOffset == 2) { // check outer loop - if ((unpackLIDMetadata_getLoopIteration_2(curr) == - unpackLIDMetadata_getLoopIteration_0(depOn)) && - checkLIDMetadata_getLoopIterationValidity_2(curr) && - checkLIDMetadata_getLoopIterationValidity_0(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_2(curr) == unpackLIDMetadata_getLoopIteration_0(depOn)) && + checkLIDMetadata_getLoopIterationValidity_2(curr) && checkLIDMetadata_getLoopIterationValidity_0(depOn)) { // II 2 identifiedDepTypes.push_back(II_2); dependencyRegistered = true; @@ -169,28 +193,22 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, } else if (loopIterationOffset == -2) { // example: depOn inside an inner loop, curr happens after this inner // loop - if ((unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_2(depOn)) && - checkLIDMetadata_getLoopIterationValidity_0(curr) && - checkLIDMetadata_getLoopIterationValidity_2(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_2(depOn)) && + checkLIDMetadata_getLoopIterationValidity_0(curr) && checkLIDMetadata_getLoopIterationValidity_2(depOn)) { // II 0 identifiedDepTypes.push_back(II_0); dependencyRegistered = true; } } else if (loopIterationOffset == -1) { // check second loop - if ((unpackLIDMetadata_getLoopIteration_1(curr) == - unpackLIDMetadata_getLoopIteration_2(depOn)) && - checkLIDMetadata_getLoopIterationValidity_1(curr) && - checkLIDMetadata_getLoopIterationValidity_2(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_1(curr) == unpackLIDMetadata_getLoopIteration_2(depOn)) && + checkLIDMetadata_getLoopIterationValidity_1(curr) && checkLIDMetadata_getLoopIterationValidity_2(depOn)) { // II 1 identifiedDepTypes.push_back(II_1); dependencyRegistered = true; // check first loop - if ((unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_1(depOn)) && - checkLIDMetadata_getLoopIterationValidity_0(curr) && - checkLIDMetadata_getLoopIterationValidity_1(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_1(depOn)) && + checkLIDMetadata_getLoopIterationValidity_0(curr) && checkLIDMetadata_getLoopIterationValidity_1(depOn)) { // II 0 identifiedDepTypes.push_back(II_0); dependencyRegistered = true; @@ -198,10 +216,8 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, } // check first loop else { - if ((unpackLIDMetadata_getLoopIteration_0(curr) == - unpackLIDMetadata_getLoopIteration_1(depOn)) && - checkLIDMetadata_getLoopIterationValidity_0(curr) && - checkLIDMetadata_getLoopIterationValidity_1(depOn)) { + if ((unpackLIDMetadata_getLoopIteration_0(curr) == unpackLIDMetadata_getLoopIteration_1(depOn)) && + checkLIDMetadata_getLoopIterationValidity_0(curr) && checkLIDMetadata_getLoopIterationValidity_1(depOn)) { // II 0 identifiedDepTypes.push_back(II_0); dependencyRegistered = true; @@ -290,41 +306,36 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, break; } - if (isStackAccess && - (modified_type == WAR || modified_type == RAW || - modified_type == WAW) && - addrIsFirstWrittenInScope && - positiveScopeChangeOccuredSinceLastAccess) { + if (isStackAccess && (modified_type == WAR || modified_type == RAW || modified_type == WAW) && + addrIsFirstWrittenInScope && positiveScopeChangeOccuredSinceLastAccess) { // IGNORE ACCESS } else { // register dependency - dependenciesToBeRegistered.emplace_back(Dep(modified_type, depOn, var, AAvar), curr); + // depType T, LID dep, char *var, std::string AAvar, std::set iaid, + // std::set ieid, std::set iacd, std::set iecd + dependenciesToBeRegistered.emplace_back(Dep(modified_type, depOn, var, AAvar, intra_iteration_dependencies, + inter_iteration_dependencies, intra_call_dependencies, + inter_call_dependencies), + curr); } if (print_debug_info) { - cout << "AddDep: CURR: " << decodeLID(curr) - << " DepOn: " << decodeLID(dbg_depOn) << " LoopIDS: " << hex - << unpackLIDMetadata_getLoopID(dbg_curr) << ";" << hex - << unpackLIDMetadata_getLoopID(dbg_depOn) << "\n"; + cout << "AddDep: CURR: " << decodeLID(curr) << " DepOn: " << decodeLID(dbg_depOn) << " LoopIDS: " << hex + << unpackLIDMetadata_getLoopID(dbg_curr) << ";" << hex << unpackLIDMetadata_getLoopID(dbg_depOn) << "\n"; cout << " Var: " << var << "\n"; - cout << " Loop Iterations(curr): " << hex - << unpackLIDMetadata_getLoopIteration_0(dbg_curr) << ";" << hex + cout << " Loop Iterations(curr): " << hex << unpackLIDMetadata_getLoopIteration_0(dbg_curr) << ";" << hex << unpackLIDMetadata_getLoopIteration_1(dbg_curr) << ";" << hex << unpackLIDMetadata_getLoopIteration_2(dbg_curr) << "\n"; - cout << " Loop Iterations(depOn): " << hex - << unpackLIDMetadata_getLoopIteration_0(dbg_depOn) << ";" << hex + cout << " Loop Iterations(depOn): " << hex << unpackLIDMetadata_getLoopIteration_0(dbg_depOn) << ";" << hex << unpackLIDMetadata_getLoopIteration_1(dbg_depOn) << ";" << hex << unpackLIDMetadata_getLoopIteration_2(dbg_depOn) << "\n"; - cout << " Valid(cur): " - << checkLIDMetadata_getLoopIterationValidity_0(dbg_curr) << ";" + cout << " Valid(cur): " << checkLIDMetadata_getLoopIterationValidity_0(dbg_curr) << ";" << checkLIDMetadata_getLoopIterationValidity_1(dbg_curr) << ";" << checkLIDMetadata_getLoopIterationValidity_2(dbg_curr) << ";\n"; - cout << " Valid(dep): " - << checkLIDMetadata_getLoopIterationValidity_0(dbg_depOn) << ";" + cout << " Valid(dep): " << checkLIDMetadata_getLoopIterationValidity_0(dbg_depOn) << ";" << checkLIDMetadata_getLoopIterationValidity_1(dbg_depOn) << ";" << checkLIDMetadata_getLoopIterationValidity_2(dbg_depOn) << ";\n"; - cout << " LoopIterationOffset: " << to_string(loopIterationOffset) - << "\n"; + cout << " LoopIterationOffset: " << to_string(loopIterationOffset) << "\n"; cout << " orig.type: " << originalType << "\n"; cout << " final.type: " << modified_type << "\n\n"; } @@ -335,12 +346,14 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, depMap::iterator posInDeps = myMap->find(pair.second); if (posInDeps == myMap->end()) { depSet *tmp_depSet = new depSet(); - tmp_depSet->insert(Dep(pair.first.type, pair.first.depOn, pair.first.var, - pair.first.AAvar)); + tmp_depSet->insert(Dep(pair.first.type, pair.first.depOn, pair.first.var, pair.first.AAvar, + pair.first.intra_iteration_dependencies, pair.first.inter_iteration_dependencies, + pair.first.intra_call_dependencies, pair.first.inter_call_dependencies)); myMap->insert(std::pair(pair.second, tmp_depSet)); } else { - posInDeps->second->insert(Dep(pair.first.type, pair.first.depOn, - pair.first.var, pair.first.AAvar)); + posInDeps->second->insert(Dep(pair.first.type, pair.first.depOn, pair.first.var, pair.first.AAvar, + pair.first.intra_iteration_dependencies, pair.first.inter_iteration_dependencies, + pair.first.intra_call_dependencies, pair.first.inter_call_dependencies)); } if (DP_DEBUG) { @@ -361,8 +374,7 @@ void addDep(depType type, LID curr, LID depOn, const char *var, string AAvar, default: break; } - cout << ", " << decodeLID(pair.first.depOn) << "] into deps (" - << myMap->size() << ")" << endl; + cout << ", " << decodeLID(pair.first.depOn) << "] into deps (" << myMap->size() << ")" << endl; } } } @@ -426,9 +438,48 @@ void generateStringDepMap() { break; } + // construct metadata string + string metadata = "["; + // add intra iteration dependencies + if (d.intra_iteration_dependencies.size() > 0) { + metadata += "intra_iteration_dep:"; + for (auto entry_lid : d.intra_iteration_dependencies) { + metadata += decodeLID(entry_lid) + ","; + } + metadata += ";"; + } + // add inter iteration dependencies + if (d.inter_iteration_dependencies.size() > 0) { + metadata += "inter_iteration_dep:"; + for (auto entry_lid : d.inter_iteration_dependencies) { + metadata += decodeLID(entry_lid) + ","; + } + metadata += ";"; + } + // add intra call dependencies + if (d.intra_call_dependencies.size() > 0) { + metadata += "intra_call_dep:"; + for (auto entry_lid : d.intra_call_dependencies) { + metadata += decodeLID(entry_lid) + ","; + } + metadata += ";"; + } + // add inter call dependencies + if (d.inter_call_dependencies.size() > 0) { + metadata += "inter_call_dep:"; + for (auto entry_lid : d.inter_call_dependencies) { + metadata += decodeLID(entry_lid) + ","; + } + metadata += ";"; + } + metadata += "]"; + // Done: construct metadata string + dep += ' ' + decodeLID(d.depOn); dep += "|" + string(d.var); dep += "(" + string(d.AAvar) + ")"; + dep += metadata; + lineDeps.insert(dep); } @@ -442,7 +493,7 @@ void generateStringDepMap() { } } -void outputDeps() { +void outputDeps() { #ifdef DP_RTLIB_VERBOSE const auto debug_print = make_debug_print("outputDeps"); #endif @@ -460,7 +511,7 @@ void outputDeps() { } // End HA -void readRuntimeInfo() { +void readRuntimeInfo() { #ifdef DP_RTLIB_VERBOSE cout << "enter readRuntimeInfo\n"; #endif @@ -475,10 +526,8 @@ void readRuntimeInfo() { if (substrings->size() == 2) { string variable = (*substrings)[0]; string value = (*substrings)[1]; - variable.erase(std::remove_if(variable.begin(), variable.end(), func), - variable.end()); - value.erase(std::remove_if(value.begin(), value.end(), func), - value.end()); + variable.erase(std::remove_if(variable.begin(), variable.end(), func), variable.end()); + value.erase(std::remove_if(value.begin(), value.end(), func), value.end()); int32_t intValue = (int32_t)atoi(value.c_str()); if (intValue > 0) { @@ -517,7 +566,7 @@ void readRuntimeInfo() { #endif } -void initParallelization() { +void initParallelization() { #ifdef DP_RTLIB_VERBOSE const auto debug_print = make_debug_print("initParallelization"); #endif @@ -575,16 +624,20 @@ void initSingleThreadedExecution() { } string getMemoryRegionIdFromAddr(string fallback, ADDR addr) { +#if DP_MEMORY_REGION_DEALIASING #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::GET_MEMORY_REGION_ID_FROM_ADDR); #endif return fallback + '-' + memory_manager->get_memory_region_id(addr, fallback); +#else + return fallback; +#endif } -void mergeDeps() { +void mergeDeps() { depSet *tmp_depSet = nullptr; // pointer to the current processing set of dps - depMap::iterator globalPos; // position of the current processing lid in allDeps + depMap::iterator globalPos; // position of the current processing lid in allDeps pthread_mutex_lock(&allDepsLock); #ifdef DP_INTERNAL_TIMER @@ -607,11 +660,11 @@ void mergeDeps() { tmp_depSet->insert(d); } } - + pthread_mutex_unlock(&allDepsLock); } -void analyzeSingleAccess(__dp::AbstractShadow* SMem, __dp::AccessInfo& access){ +void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access) { // analyze data dependences #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::ANALYZE_SINGLE_ACCESS); @@ -621,52 +674,92 @@ void analyzeSingleAccess(__dp::AbstractShadow* SMem, __dp::AccessInfo& access){ // hybrid analysis if (access.skip) { SMem->insertToRead(access.addr, access.lid); +#if DP_CALLSTACK_PROFILING + SMem->setLastReadAccessCallStack(access.addr, access.callStack->getCopy()); +#endif return; } // End HA sigElement lastWrite = SMem->testInWrite(access.addr); +#if DP_CALLSTACK_PROFILING + CallStack *lastWriteCallStack = SMem->getLastWriteAccessCallStack(access.addr); +#endif if (lastWrite != 0) { // RAW SMem->insertToRead(access.addr, access.lid); - addDep(RAW, access.lid, lastWrite, access.var, access.AAvar, - access.isStackAccess, access.addr, - access.addrIsOwnedByScope, - access.positiveScopeChangeOccuredSinceLastAccess); +#if DP_CALLSTACK_PROFILING + SMem->setLastReadAccessCallStack(access.addr, access.callStack->getCopy()); + addDep(RAW, access.lid, access.callStack, lastWrite, lastWriteCallStack, access.var, access.AAvar, + access.isStackAccess, access.addr, access.addrIsOwnedByScope, + access.positiveScopeChangeOccuredSinceLastAccess); + } +#else + addDep(RAW, access.lid, access.callStack, lastWrite, nullptr, access.var, access.AAvar, access.isStackAccess, + access.addr, access.addrIsOwnedByScope, access.positiveScopeChangeOccuredSinceLastAccess); } +#endif } else { sigElement lastWrite = SMem->insertToWrite(access.addr, access.lid); +#if DP_CALLSTACK_PROFILING + CallStack *lastWriteCallStack = SMem->getLastWriteAccessCallStack(access.addr); + if (lastWriteCallStack) { + // create a temporary copy of the call stack as the entry in SMem will be + // deleted when overwritten + lastWriteCallStack = lastWriteCallStack->getCopy(); + } + SMem->setLastWriteAccessCallStack(access.addr, access.callStack); +#endif if (lastWrite == 0) { // INIT - addDep(INIT, access.lid, 0, access.var, access.AAvar, - access.isStackAccess, access.addr, - access.addrIsOwnedByScope, - access.positiveScopeChangeOccuredSinceLastAccess); + addDep(INIT, access.lid, access.callStack, 0, nullptr, access.var, access.AAvar, access.isStackAccess, + access.addr, access.addrIsOwnedByScope, access.positiveScopeChangeOccuredSinceLastAccess); } else { sigElement lastRead = SMem->testInRead(access.addr); +#if DP_CALLSTACK_PROFILING + CallStack *lastReadCallStack = SMem->getLastReadAccessCallStack(access.addr); +#endif if (lastRead != 0) { // WAR - addDep(WAR, access.lid, lastRead, access.var, access.AAvar, - access.isStackAccess, access.addr, - access.addrIsOwnedByScope, - access.positiveScopeChangeOccuredSinceLastAccess); +#if DP_CALLSTACK_PROFILING + addDep(WAR, access.lid, access.callStack, lastRead, lastReadCallStack, access.var, access.AAvar, + access.isStackAccess, access.addr, access.addrIsOwnedByScope, + access.positiveScopeChangeOccuredSinceLastAccess); +#else + addDep(WAR, access.lid, access.callStack, lastRead, nullptr, access.var, access.AAvar, access.isStackAccess, + access.addr, access.addrIsOwnedByScope, access.positiveScopeChangeOccuredSinceLastAccess); +#endif // Clear intermediate read ops SMem->insertToRead(access.addr, 0); +#if DP_CALLSTACK_PROFILING + SMem->cleanReadAccessCallStack(access.addr); +#endif } else { // WAW - addDep(WAW, access.lid, lastWrite, access.var, access.AAvar, - access.isStackAccess, access.addr, - access.addrIsOwnedByScope, - access.positiveScopeChangeOccuredSinceLastAccess); +#if DP_CALLSTACK_PROFILING + addDep(WAW, access.lid, access.callStack, lastWrite, lastWriteCallStack, access.var, access.AAvar, + access.isStackAccess, access.addr, access.addrIsOwnedByScope, + access.positiveScopeChangeOccuredSinceLastAccess); +#else + addDep(WAW, access.lid, access.callStack, lastWrite, nullptr, access.var, access.AAvar, access.isStackAccess, + access.addr, access.addrIsOwnedByScope, access.positiveScopeChangeOccuredSinceLastAccess); + +#endif } } +#if DP_CALLSTACK_PROFILING + if (lastWriteCallStack) { + // cleanup temporary copy + delete lastWriteCallStack; + } +#endif } } -void* analyzeDeps(void *arg) { +void *analyzeDeps(void *arg) { #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::ANALYZE_DEPS); #endif - + int64_t id = (int64_t)arg; AbstractShadow *SMem; if (USE_PERFECT) { @@ -697,7 +790,7 @@ void* analyzeDeps(void *arg) { // analyze data dependences for (unsigned short i = 0; i < CHUNK_SIZE; ++i) { - + access = accesses[i]; analyzeSingleAccess(SMem, access); } @@ -805,19 +898,21 @@ void finalizeSingleThreadedExecution() { } } +#if DP_STACK_ACCESS_DETECTION void clearStackAccesses(ADDR stack_lower_bound, ADDR stack_upper_bound) { #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::CLEAR_STACK_ACCESSES); #endif - const auto& current_scope = memory_manager->getCurrentScope(); - const auto& writes = current_scope.get_first_write(); + const auto ¤t_scope = memory_manager->getCurrentScope(); + const auto &writes = current_scope.get_first_write(); for (ADDR addr : writes) { - //cleanup reads + // cleanup reads __dp_read(0, addr, ""); - //cleanup writes + // cleanup writes __dp_write(0, addr, ""); } } +#endif } // namespace __dp diff --git a/rtlib/iFunctions.hpp b/rtlib/iFunctions.hpp index f77a456ed..da9cd351c 100644 --- a/rtlib/iFunctions.hpp +++ b/rtlib/iFunctions.hpp @@ -35,9 +35,9 @@ void initSingleThreadedExecution(); void mergeDeps(); -void* analyzeDeps(void *arg); +void *analyzeDeps(void *arg); -void analyzeSingleAccess(__dp::AbstractShadow* SMem, __dp::AccessInfo& access); +void analyzeSingleAccess(__dp::AbstractShadow *SMem, __dp::AccessInfo &access); std::string getMemoryRegionIdFromAddr(std::string fallback, ADDR addr); @@ -45,5 +45,7 @@ void finalizeParallelization(); void finalizeSingleThreadedExecution(); +#if DP_STACK_ACCESS_DETECTION void clearStackAccesses(ADDR stack_lower_bound, ADDR stack_upper_bound); +#endif } // namespace __dp diff --git a/rtlib/iFunctionsGlobals.cpp b/rtlib/iFunctionsGlobals.cpp index 7b007ed43..aace1ed23 100644 --- a/rtlib/iFunctionsGlobals.cpp +++ b/rtlib/iFunctionsGlobals.cpp @@ -25,13 +25,13 @@ namespace __dp { bool DP_DEBUG = false; // debug flag -Timers* timers = nullptr; +Timers *timers = nullptr; std::mutex pthread_compatibility_mutex; -FunctionManager* function_manager = nullptr; -LoopManager* loop_manager= nullptr; -MemoryManager* memory_manager = nullptr; +FunctionManager *function_manager = nullptr; +LoopManager *loop_manager = nullptr; +MemoryManager *memory_manager = nullptr; // hybrid analysis ReportedBBSet *bbList = nullptr; @@ -40,7 +40,7 @@ stringDepMap *outPutDeps = nullptr; std::unordered_map cuec; -bool dpInited = false; // library initialization flag +bool dpInited = false; // library initialization flag bool targetTerminated = false; // whether the target program has returned from main() // In C++, destructors of global objects can run after main(). // However, when the target program returns from main(), dp @@ -51,6 +51,10 @@ bool targetTerminated = false; // whether the target program has returned from m // Runtime merging structures depMap *allDeps = nullptr; +#if DP_CALLSTACK_PROFILING +CallStack *callStack = nullptr; // call stack profiling +extern unsigned long funcCallCounter = 0; +#endif std::ofstream *out = nullptr; /******* BEGIN: parallelization section *******/ @@ -70,22 +74,18 @@ int32_t NUM_WORKERS = 3; // default number of worker threads (multiple workers #endif #pragma message "Profiler: set NUM_WORKERS to " XSTR(NUM_WORKERS) -AbstractShadow* singleThreadedExecutionSMem = nullptr; // used if NUM_WORKERS==0 - -int32_t CHUNK_SIZE = 500; // default number of addresses in each chunk -std::queue *chunks = - nullptr; // one queue of access info chunks for each worker thread -bool *addrChunkPresent = - nullptr; // addrChunkPresent[thread_id] denotes whether or not a new chunk - // is available for the corresponding thread -AccessInfo **tempAddrChunks = - nullptr; // tempAddrChunks[thread_id] is the temporary chunk to collect - // memory accesses for the corresponding thread -int32_t *tempAddrCount = - nullptr; // tempAddrCount[thread_id] denotes the current number of accesses - // in the temporary chunk -bool stop = false; // ONLY set stop to true if no more accessed addresses will - // be collected +AbstractShadow *singleThreadedExecutionSMem = nullptr; // used if NUM_WORKERS==0 + +int32_t CHUNK_SIZE = 500; // default number of addresses in each chunk +std::queue *chunks = nullptr; // one queue of access info chunks for each worker thread +bool *addrChunkPresent = nullptr; // addrChunkPresent[thread_id] denotes whether or not a new chunk + // is available for the corresponding thread +AccessInfo **tempAddrChunks = nullptr; // tempAddrChunks[thread_id] is the temporary chunk to collect + // memory accesses for the corresponding thread +int32_t *tempAddrCount = nullptr; // tempAddrCount[thread_id] denotes the current number of accesses + // in the temporary chunk +bool stop = false; // ONLY set stop to true if no more accessed addresses will + // be collected thread_local depMap *myMap = nullptr; /******* END: parallelization section *******/ diff --git a/rtlib/iFunctionsGlobals.hpp b/rtlib/iFunctionsGlobals.hpp index 7c5c0f111..69dfce6ae 100644 --- a/rtlib/iFunctionsGlobals.hpp +++ b/rtlib/iFunctionsGlobals.hpp @@ -12,8 +12,8 @@ #pragma once -#include "iFunctionsTypes.hpp" #include "../share/include/timer.hpp" +#include "iFunctionsTypes.hpp" #include "memory/AbstractShadow.hpp" #include @@ -42,22 +42,22 @@ namespace __dp { extern bool DP_DEBUG; // debug flag -extern Timers* timers; +extern Timers *timers; extern std::mutex pthread_compatibility_mutex; -extern FunctionManager* function_manager; -extern LoopManager* loop_manager; -extern MemoryManager* memory_manager; +extern FunctionManager *function_manager; +extern LoopManager *loop_manager; +extern MemoryManager *memory_manager; // hybrid analysis extern ReportedBBSet *bbList; extern stringDepMap *outPutDeps; -// end hybrid analysis +// end hybrid analysis extern std::unordered_map cuec; -extern bool dpInited; // library initialization flag +extern bool dpInited; // library initialization flag extern bool targetTerminated; // whether the target program has returned from main() // In C++, destructors of global objects can run after main(). // However, when the target program returns from main(), dp @@ -68,6 +68,10 @@ extern bool targetTerminated; // whether the target program has returned from ma // Runtime merging structures extern depMap *allDeps; +#if DP_CALLSTACK_PROFILING +extern CallStack *callStack; // call stack profiling +extern unsigned long funcCallCounter; +#endif extern std::ofstream *out; extern pthread_cond_t *addrChunkPresentConds; // condition variables @@ -75,21 +79,21 @@ extern pthread_mutex_t *addrChunkMutexes; // associated mutexes extern pthread_mutex_t allDepsLock; extern pthread_t *workers; // worker threads -extern AbstractShadow* singleThreadedExecutionSMem; +extern AbstractShadow *singleThreadedExecutionSMem; -extern int32_t NUM_WORKERS; +extern int32_t NUM_WORKERS; -extern int32_t CHUNK_SIZE; // default number of addresses in each chunk +extern int32_t CHUNK_SIZE; // default number of addresses in each chunk extern std::queue *chunks; // one queue of access info chunks for each worker thread -extern bool *addrChunkPresent; // addrChunkPresent[thread_id] denotes whether or not a new chunk - // is available for the corresponding thread - -extern AccessInfo **tempAddrChunks; // tempAddrChunks[thread_id] is the temporary chunk to collect - // memory accesses for the corresponding thread -extern int32_t *tempAddrCount; // tempAddrCount[thread_id] denotes the current number of accesses - // in the temporary chunk -extern bool stop; // ONLY set stop to true if no more accessed addresses will - // be collected +extern bool *addrChunkPresent; // addrChunkPresent[thread_id] denotes whether or not a + // new chunk is available for the corresponding thread + +extern AccessInfo **tempAddrChunks; // tempAddrChunks[thread_id] is the temporary chunk to + // collect memory accesses for the corresponding thread +extern int32_t *tempAddrCount; // tempAddrCount[thread_id] denotes the current + // number of accesses in the temporary chunk +extern bool stop; // ONLY set stop to true if no more accessed addresses will + // be collected extern thread_local depMap *myMap; } // namespace __dp diff --git a/rtlib/iFunctionsTypes.hpp b/rtlib/iFunctionsTypes.hpp index 05e937f46..594fc556a 100644 --- a/rtlib/iFunctionsTypes.hpp +++ b/rtlib/iFunctionsTypes.hpp @@ -14,18 +14,19 @@ #include "DPTypes.hpp" +#include "callstack/CallStack.hpp" #include "functions/FunctionManager.hpp" #include "loop/LoopManager.hpp" #include "memory/MemoryManager.hpp" #include -#include #include #include +#include #include namespace __dp { - /******* Data structures *******/ +/******* Data structures *******/ typedef enum { RAW, @@ -53,12 +54,10 @@ typedef enum { } depTypeModifier; struct AccessInfo { - AccessInfo(bool isRead, LID lid, char *var, std::string AAvar, ADDR addr, - bool skip = false) - : isRead(isRead), lid(lid), var(var), AAvar(AAvar), addr(addr), - skip(skip) {} + AccessInfo(bool isRead, LID lid, char *var, std::string AAvar, ADDR addr, bool skip = false) + : isRead(isRead), lid(lid), var(var), AAvar(AAvar), addr(addr), skip(skip) {} - AccessInfo() : isRead(false), lid(0), var(""), AAvar(""), addr(0), skip(false) {} + AccessInfo() : isRead(false), lid(0), var(""), AAvar(""), addr(0), skip(false), callStack(nullptr) {} bool isRead; // hybrid analysis @@ -68,6 +67,7 @@ struct AccessInfo { const char *var; std::string AAvar; // name of allocated variable -> "Anti Aliased Variable" ADDR addr; + CallStack *callStack; bool isStackAccess = false; bool addrIsOwnedByScope = false; bool positiveScopeChangeOccuredSinceLastAccess = false; @@ -75,13 +75,19 @@ struct AccessInfo { // For runtime dependency merging struct Dep { - Dep(depType T, LID dep, const char *var, std::string AAvar) - : type(T), depOn(dep), var(var), AAvar(AAvar) {} + Dep(depType T, LID dep, const char *var, std::string AAvar, std::set iaid, std::set ieid, + std::set iacd, std::set iecd) + : type(T), depOn(dep), var(var), AAvar(AAvar), intra_iteration_dependencies(iaid), + inter_iteration_dependencies(ieid), intra_call_dependencies(iacd), inter_call_dependencies(iecd) {} depType type; LID depOn; const char *var; std::string AAvar; + std::set intra_iteration_dependencies; + std::set inter_iteration_dependencies; + std::set intra_call_dependencies; + std::set inter_call_dependencies; }; struct compDep { @@ -93,8 +99,7 @@ struct compDep { } // comparison between string is very time-consuming. So just compare // variable names according to address (we only need to distinguish them) - else if (a.type == b.type && a.depOn == b.depOn && - ((size_t)a.var < (size_t)b.var)) { + else if (a.type == b.type && a.depOn == b.depOn && ((size_t)a.var < (size_t)b.var)) { return true; } diff --git a/rtlib/injected_functions/dp_add_bb_deps.cpp b/rtlib/injected_functions/dp_add_bb_deps.cpp index 7c4b63fa6..8c6b3cf92 100644 --- a/rtlib/injected_functions/dp_add_bb_deps.cpp +++ b/rtlib/injected_functions/dp_add_bb_deps.cpp @@ -33,7 +33,7 @@ void __dp_add_bb_deps(char *depStringPtr) { if (!dpInited || targetTerminated) { return; } - + #ifdef DP_PTHREAD_COMPATIBILITY_MODE std::lock_guard guard(pthread_compatibility_mutex); #endif @@ -45,8 +45,7 @@ void __dp_add_bb_deps(char *depStringPtr) { #endif std::string depString(depStringPtr); - std::regex r0("[^\\/]+"), r1("[^=]+"), r2("[^,]+"), r3("[0-9]+:[0-9]+"), - r4("(INIT|(R|W)A(R|W)).*"); + std::regex r0("[^\\/]+"), r1("[^=]+"), r2("[^,]+"), r3("[0-9]+:[0-9]+"), r4("(INIT|(R|W)A(R|W)).*"); std::smatch res0, res1, res2, res3; while (regex_search(depString, res0, r0)) { diff --git a/rtlib/injected_functions/dp_add_bb_deps.hpp b/rtlib/injected_functions/dp_add_bb_deps.hpp index de9557350..8e68d5968 100644 --- a/rtlib/injected_functions/dp_add_bb_deps.hpp +++ b/rtlib/injected_functions/dp_add_bb_deps.hpp @@ -22,7 +22,6 @@ extern "C" { // hybrid analysis void __dp_add_bb_deps(char *depStringPtr); // End HA - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_alloca.cpp b/rtlib/injected_functions/dp_alloca.cpp index 79d2fd3ab..8aca0f553 100644 --- a/rtlib/injected_functions/dp_alloca.cpp +++ b/rtlib/injected_functions/dp_alloca.cpp @@ -31,8 +31,7 @@ namespace __dp { /******* Instrumentation function *******/ extern "C" { -void __dp_alloca(LID lid, char *var, ADDR startAddr, ADDR endAddr, - int64_t numBytes, int64_t numElements) { +void __dp_alloca(LID lid, char *var, ADDR startAddr, ADDR endAddr, int64_t numBytes, int64_t numElements) { if (!dpInited || targetTerminated) { return; } @@ -46,18 +45,20 @@ void __dp_alloca(LID lid, char *var, ADDR startAddr, ADDR endAddr, #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::ALLOCA); #endif - + +#if DP_MEMORY_REGION_DEALIASING // create entry to list of allocatedMemoryRegions const std::string allocId = memory_manager->allocate_stack_memory(lid, startAddr, endAddr, numBytes, numElements); - // std::cout << "alloca: " << var << " (" << allocId << ") @ " << dputil::decodeLID(lid) << " : " << std::hex << startAddr << " - " << std::hex << endAddr << " -> #allocations: " << memory_manager->get_number_allocations() << "\n"; + // std::cout << "alloca: " << var << " (" << allocId << ") @ " << + // dputil::decodeLID(lid) << " : " << std::hex << startAddr << " - " << + // std::hex << endAddr << " -> #allocations: " << + // memory_manager->get_number_allocations() << "\n"; #ifdef DP_DEBUG - cout << "alloca: " << var << " (" << allocId << ") @ " << dputil::decodeLID(lid) - << " : " << std::hex << startAddr << " - " << std::hex << endAddr - << " -> #allocations: " << memory_manager->get_number_allocations() - << "\n"; + cout << "alloca: " << var << " (" << allocId << ") @ " << dputil::decodeLID(lid) << " : " << std::hex << startAddr + << " - " << std::hex << endAddr << " -> #allocations: " << memory_manager->get_number_allocations() << "\n"; +#endif #endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_alloca.hpp b/rtlib/injected_functions/dp_alloca.hpp index 881d039e8..bfe1f1ffe 100644 --- a/rtlib/injected_functions/dp_alloca.hpp +++ b/rtlib/injected_functions/dp_alloca.hpp @@ -24,7 +24,6 @@ void __dp_alloca(LID lid, char *var, ADDR startAddr, ADDR endAddr, int64_t numBy #else void __dp_alloca(LID lid, char *var, ADDR startAddr, ADDR endAddr, int64_t numBytes, int64_t numElements); #endif - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_call.cpp b/rtlib/injected_functions/dp_call.cpp index 3ee9fa9ce..677850247 100644 --- a/rtlib/injected_functions/dp_call.cpp +++ b/rtlib/injected_functions/dp_call.cpp @@ -47,7 +47,6 @@ void __dp_call(LID lid) { function_manager->log_call(lid); } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_call.hpp b/rtlib/injected_functions/dp_call.hpp index 0acbd7e97..5bbee5aaf 100644 --- a/rtlib/injected_functions/dp_call.hpp +++ b/rtlib/injected_functions/dp_call.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_call(LID lid); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_decl.cpp b/rtlib/injected_functions/dp_decl.cpp index b88b99b1a..59a52ff00 100644 --- a/rtlib/injected_functions/dp_decl.cpp +++ b/rtlib/injected_functions/dp_decl.cpp @@ -12,8 +12,8 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -53,7 +53,8 @@ void __dp_decl(LID lid, ADDR addr, char *var) { if (targetTerminated) { if (DP_DEBUG) { - std::cout << "__dp_write() is not executed since target program has returned from main().\n"; + std::cout << "__dp_write() is not executed since target program has " + "returned from main().\n"; } return; } @@ -67,12 +68,11 @@ void __dp_decl(LID lid, ADDR addr, char *var) { function_manager->reset_call(lid); if (DP_DEBUG) { - cout << "instStore at encoded LID " << std::dec << dputil::decodeLID(lid) - << " and addr " << std::hex << addr << endl; + cout << "instStore at encoded LID " << std::dec << dputil::decodeLID(lid) << " and addr " << std::hex << addr + << endl; } - int64_t workerID = - ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" + int64_t workerID = ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" AccessInfo ¤t = tempAddrChunks[workerID][tempAddrCount[workerID]++]; current.isRead = false; current.lid = loop_manager->update_lid(0); @@ -91,7 +91,6 @@ void __dp_decl(LID lid, ADDR addr, char *var) { tempAddrCount[workerID] = 0; } } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_decl.hpp b/rtlib/injected_functions/dp_decl.hpp index 397b56fe1..f8152f4b6 100644 --- a/rtlib/injected_functions/dp_decl.hpp +++ b/rtlib/injected_functions/dp_decl.hpp @@ -28,7 +28,6 @@ void __dp_decl(LID lid, ADDR addr, char *var, ADDR lastaddr, int64_t count); void __dp_decl(LID lid, ADDR addr, char *var); // End HA #endif - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_delete.cpp b/rtlib/injected_functions/dp_delete.cpp index a858da1a3..e597f7556 100644 --- a/rtlib/injected_functions/dp_delete.cpp +++ b/rtlib/injected_functions/dp_delete.cpp @@ -34,7 +34,7 @@ void __dp_delete(LID lid, ADDR startAddr) { if (!dpInited || targetTerminated) { return; } - + #ifdef DP_PTHREAD_COMPATIBILITY_MODE std::lock_guard guard(pthread_compatibility_mutex); #endif @@ -50,20 +50,19 @@ void __dp_delete(LID lid, ADDR startAddr) { // TODO more efficient implementation // find memory region to be deleted -/* for(tuple entry : - allocatedMemoryRegions){ if(get<2>(entry) == startAddr){ - // delete memory region - cout << "delete/free: " << decodeLID(lid) << ", " << - get<1>(entry) << ", " << std::hex << startAddr << "\n"; - allocatedMemoryRegions.remove(entry); - return; - } - } - cout << "__dp_delete: Could not find base addr: " << std::hex << - startAddr << "\n"; -*/ + /* for(tuple entry : + allocatedMemoryRegions){ if(get<2>(entry) == startAddr){ + // delete memory region + cout << "delete/free: " << decodeLID(lid) << ", " << + get<1>(entry) << ", " << std::hex << startAddr << "\n"; + allocatedMemoryRegions.remove(entry); + return; + } + } + cout << "__dp_delete: Could not find base addr: " << std::hex << + startAddr << "\n"; + */ } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_delete.hpp b/rtlib/injected_functions/dp_delete.hpp index b956815ff..9490c46a4 100644 --- a/rtlib/injected_functions/dp_delete.hpp +++ b/rtlib/injected_functions/dp_delete.hpp @@ -24,7 +24,6 @@ extern "C" { void __dp_delete(LID lid, ADDR startAddr); // End HA #endif - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_finalize.cpp b/rtlib/injected_functions/dp_finalize.cpp index 12c322d21..8e8681425 100644 --- a/rtlib/injected_functions/dp_finalize.cpp +++ b/rtlib/injected_functions/dp_finalize.cpp @@ -12,8 +12,8 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -74,13 +74,11 @@ void __dp_finalize(LID lid) { #endif // Returning from main or exit from somewhere, clear up everything. - assert(function_manager->get_current_stack_level() == -1 && - "Program terminates without clearing function stack!"); - assert(loop_manager->empty() && - "Program terminates but loop stack is not empty!"); + assert(function_manager->get_current_stack_level() == -1 && "Program terminates without clearing function stack!"); + assert(loop_manager->empty() && "Program terminates but loop stack is not empty!"); #ifdef DP_DEBUG - std::cout << "Program terminates at LID " << std::dec << dputil::decodeLID(lid) << ", clearing up" << std::endl; + std::cout << "Program terminates at LID " << std::dec << dputil::decodeLID(lid) << ", clearing up" << std::endl; #endif if (NUM_WORKERS > 0) { @@ -96,7 +94,7 @@ void __dp_finalize(LID lid) { #ifdef DP_INTERNAL_TIMER const auto timer = Timer(timers, TimerRegion::OUTPUT_LOOPS); #endif - + loop_manager->output(*out); }; output_loops(); @@ -120,7 +118,7 @@ void __dp_finalize(LID lid) { const auto timer = Timer(timers, TimerRegion::OUTPUT_ALLOCATIONS); #endif - const auto prepare_environment = [](){ + const auto prepare_environment = []() { // prepare environment variables const char *discopop_env = getenv("DOT_DISCOPOP"); if (discopop_env == NULL) { @@ -138,7 +136,9 @@ void __dp_finalize(LID lid) { const auto path = prepare_environment(); auto allocationsFileStream = ofstream(path, ios::out); +#if DP_MEMORY_REGION_DEALIASING memory_manager->output_memory_regions(allocationsFileStream); +#endif }; output_allocations(); @@ -153,6 +153,10 @@ void __dp_finalize(LID lid) { delete bbList; // End HA +#if DP_CALLSTACK_PROFILING + delete callStack; +#endif + delete function_manager; delete loop_manager; @@ -166,10 +170,9 @@ void __dp_finalize(LID lid) { targetTerminated = true; // mark the target program has returned from main() #ifdef DP_DEBUG - std::cout << "Program terminated." << std::endl; + std::cout << "Program terminated." << std::endl; #endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_finalize.hpp b/rtlib/injected_functions/dp_finalize.hpp index 8314d14a5..28ac91b68 100644 --- a/rtlib/injected_functions/dp_finalize.hpp +++ b/rtlib/injected_functions/dp_finalize.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_finalize(LID lid); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_func_entry.cpp b/rtlib/injected_functions/dp_func_entry.cpp index 3bb7fa1cf..e5dc73988 100644 --- a/rtlib/injected_functions/dp_func_entry.cpp +++ b/rtlib/injected_functions/dp_func_entry.cpp @@ -12,8 +12,10 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" + +#include "../callstack/CallStack.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -35,8 +37,9 @@ extern "C" { void __dp_func_entry(LID lid, int32_t isStart) { if (targetTerminated) { - // prevent deleting generated results after the main function has been exited. - // This might happen, e.g., if a destructor of a global struct is called after exiting the main function. + // prevent deleting generated results after the main function has been + // exited. This might happen, e.g., if a destructor of a global struct is + // called after exiting the main function. return; } @@ -52,12 +55,15 @@ void __dp_func_entry(LID lid, int32_t isStart) { readRuntimeInfo(); timers = new Timers(); #ifdef DP_INTERNAL_TIMER - const auto timer = Timer(timers, TimerRegion::FUNC_ENTRY); + const auto timer = Timer(timers, TimerRegion::FUNC_ENTRY); #endif function_manager = new FunctionManager(); loop_manager = new LoopManager(); memory_manager = new MemoryManager(); +#if DP_CALLSTACK_PROFILING + callStack = new CallStack(); +#endif out = new ofstream(); // hybrid analysis @@ -65,7 +71,7 @@ void __dp_func_entry(LID lid, int32_t isStart) { outPutDeps = new stringDepMap(); bbList = new ReportedBBSet(); // End HA - + memory_manager->allocate_dummy_region(); #ifdef __linux__ @@ -102,7 +108,7 @@ void __dp_func_entry(LID lid, int32_t isStart) { cout << "DP initialized at LID " << std::dec << dputil::decodeLID(lid) << endl; } dpInited = true; - if(NUM_WORKERS > 0) { + if (NUM_WORKERS > 0) { initParallelization(); } else { initSingleThreadedExecution(); @@ -110,28 +116,32 @@ void __dp_func_entry(LID lid, int32_t isStart) { } else if (targetTerminated) { if (DP_DEBUG) { cout << "Entering function LID " << std::dec << dputil::decodeLID(lid); - cout << " but target program has returned from main(). Destructors?" - << endl; + cout << " but target program has returned from main(). Destructors?" << endl; } } else { function_manager->register_function_start(lid); } #ifdef DP_INTERNAL_TIMER - const auto timer = Timer(timers, TimerRegion::FUNC_ENTRY); + const auto timer = Timer(timers, TimerRegion::FUNC_ENTRY); #endif - // TEST + +#if DP_STACK_ACCESS_DETECTION memory_manager->enter_new_function(); memory_manager->enterScope("function", lid); - // !TEST +#endif if (isStart) *out << "START " << dputil::decodeLID(lid) << endl; +#if DP_CALLSTACK_PROFILING + funcCallCounter++; + callStack->push(new CallStackEntry(0, lid, funcCallCounter)); +#endif + // Reset last call tracker function_manager->log_call(0); } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_func_entry.hpp b/rtlib/injected_functions/dp_func_entry.hpp index eff8d854f..2e2040331 100644 --- a/rtlib/injected_functions/dp_func_entry.hpp +++ b/rtlib/injected_functions/dp_func_entry.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_func_entry(LID lid, int32_t isStart); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_func_exit.cpp b/rtlib/injected_functions/dp_func_exit.cpp index 0182f6c10..f2a08b7ce 100644 --- a/rtlib/injected_functions/dp_func_exit.cpp +++ b/rtlib/injected_functions/dp_func_exit.cpp @@ -12,8 +12,8 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -35,8 +35,7 @@ void __dp_func_exit(LID lid, int32_t isExit) { if (targetTerminated) { if (DP_DEBUG) { cout << "Exiting function LID " << std::dec << dputil::decodeLID(lid); - cout << " but target program has returned from main(). Destructors?" - << endl; + cout << " but target program has returned from main(). Destructors?" << endl; } return; } @@ -54,23 +53,42 @@ void __dp_func_exit(LID lid, int32_t isExit) { loop_manager->clean_function_exit(function_manager->get_current_stack_level(), lid); +#if DP_CALLSTACK_PROFILING + callStack->popLoop(); +#endif + function_manager->reset_call(lid); function_manager->decrease_stack_level(); +#if DP_CALLSTACK_PROFILING + callStack->popFunction(); +#endif + // TEST // clear information on allocated stack addresses +#if DP_STACK_ACCESS_DETECTION const auto last_addresses = memory_manager->pop_last_stack_address(); +#endif + #ifdef DP_PTHREAD_COMPATIBILITY_MODE pthread_compatibility_mutex.unlock(); #endif - clearStackAccesses(last_addresses.first, last_addresses.second); // insert accesses with LID 0 to the queues + +#if DP_STACK_ACCESS_DETECTION + clearStackAccesses(last_addresses.first, + last_addresses.second); // insert accesses with LID 0 to the queues +#endif + #ifdef DP_PTHREAD_COMPATIBILITY_MODE pthread_compatibility_mutex.lock(); #endif + +#if DP_STACK_ACCESS_DETECTION memory_manager->leaveScope("function", lid); +#endif // !TEST - if (isExit == 0){ + if (isExit == 0) { function_manager->register_function_end(lid); } @@ -82,7 +100,6 @@ void __dp_func_exit(LID lid, int32_t isExit) { pthread_compatibility_mutex.unlock(); #endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_func_exit.hpp b/rtlib/injected_functions/dp_func_exit.hpp index fe984d4f3..9b48e0c1d 100644 --- a/rtlib/injected_functions/dp_func_exit.hpp +++ b/rtlib/injected_functions/dp_func_exit.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_func_exit(LID lid, int32_t isExit); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_incr_taken_branch_counter.cpp b/rtlib/injected_functions/dp_incr_taken_branch_counter.cpp index 15d6b87ec..3bf1bfbe4 100644 --- a/rtlib/injected_functions/dp_incr_taken_branch_counter.cpp +++ b/rtlib/injected_functions/dp_incr_taken_branch_counter.cpp @@ -32,7 +32,6 @@ void __dp_incr_taken_branch_counter(char *source_and_target, int cmp_res, int ac } } } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_incr_taken_branch_counter.hpp b/rtlib/injected_functions/dp_incr_taken_branch_counter.hpp index 323340e1a..2658f2609 100644 --- a/rtlib/injected_functions/dp_incr_taken_branch_counter.hpp +++ b/rtlib/injected_functions/dp_incr_taken_branch_counter.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_incr_taken_branch_counter(char *source_and_target, int cmp_res, int active_on); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_entry.cpp b/rtlib/injected_functions/dp_loop_entry.cpp index 245256621..370953a70 100644 --- a/rtlib/injected_functions/dp_loop_entry.cpp +++ b/rtlib/injected_functions/dp_loop_entry.cpp @@ -14,6 +14,8 @@ #include "../iFunctionsGlobals.hpp" +#include "../callstack/CallStack.hpp" + #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -53,16 +55,26 @@ void __dp_loop_entry(LID lid, int32_t loopID) { } return; } - + const auto function_stack_level = function_manager->get_current_stack_level(); const auto is_new_loop = loop_manager->is_new_loop(loopID); - + if (is_new_loop) { - loop_manager->create_new_loop(function_stack_level, loopID, lid); + loop_manager->create_new_loop(function_stack_level, loopID, lid); + +#if DP_STACK_ACCESS_DETECTION memory_manager->enterScope("loop", lid); +#endif + +#if DP_CALLSTACK_PROFILING + callStack->push(new CallStackEntry(1, lid, 0)); +#endif } else { // The same loop iterates again loop_manager->iterate_loop(function_stack_level); +#if DP_CALLSTACK_PROFILING + callStack->incrementIterationCounter(); +#endif // Handle error made in instrumentation. // When recorded loopStack->top().funcLevel is different @@ -78,11 +90,12 @@ void __dp_loop_entry(LID lid, int32_t loopID) { loop_manager->correct_func_level(function_stack_level); +#if DP_STACK_ACCESS_DETECTION memory_manager->leaveScope("loop_iteration", lid); memory_manager->enterScope("loop_iteration", lid); +#endif } } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_entry.hpp b/rtlib/injected_functions/dp_loop_entry.hpp index 9b1018d95..ae371313a 100644 --- a/rtlib/injected_functions/dp_loop_entry.hpp +++ b/rtlib/injected_functions/dp_loop_entry.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_loop_entry(LID lid, int32_t loopID); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_exit.cpp b/rtlib/injected_functions/dp_loop_exit.cpp index d7feea33e..89be93081 100644 --- a/rtlib/injected_functions/dp_loop_exit.cpp +++ b/rtlib/injected_functions/dp_loop_exit.cpp @@ -69,9 +69,14 @@ void __dp_loop_exit(LID lid, int32_t loopID) { loop_manager->correct_func_level(function_stack_level); loop_manager->exit_loop(lid); +#if DP_CALLSTACK_PROFILING + callStack->popLoop(); +#endif + +#if DP_STACK_ACCESS_DETECTION memory_manager->leaveScope("loop", lid); +#endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_exit.hpp b/rtlib/injected_functions/dp_loop_exit.hpp index e840959c0..85c4c1f9e 100644 --- a/rtlib/injected_functions/dp_loop_exit.hpp +++ b/rtlib/injected_functions/dp_loop_exit.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_loop_exit(LID lid, int32_t loopID); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_incr.cpp b/rtlib/injected_functions/dp_loop_incr.cpp index 6e1949255..9faa0d56f 100644 --- a/rtlib/injected_functions/dp_loop_incr.cpp +++ b/rtlib/injected_functions/dp_loop_incr.cpp @@ -19,7 +19,7 @@ namespace __dp { /******* Instrumentation function *******/ extern "C" { -void __dp_loop_incr(const int loop_id){ +void __dp_loop_incr(const int loop_id) { if (!dpInited || targetTerminated) { return; } @@ -27,10 +27,9 @@ void __dp_loop_incr(const int loop_id){ if (loop_manager->is_done()) { return; } - + loop_manager->incr_loop_counter(loop_id); } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_incr.hpp b/rtlib/injected_functions/dp_loop_incr.hpp index e6134b38f..8fca0b32c 100644 --- a/rtlib/injected_functions/dp_loop_incr.hpp +++ b/rtlib/injected_functions/dp_loop_incr.hpp @@ -18,7 +18,6 @@ namespace __dp { extern "C" { void __dp_loop_incr(int loop_id); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_output.cpp b/rtlib/injected_functions/dp_loop_output.cpp index 7360f27df..858483e32 100644 --- a/rtlib/injected_functions/dp_loop_output.cpp +++ b/rtlib/injected_functions/dp_loop_output.cpp @@ -44,8 +44,7 @@ void __dp_loop_output() { ifile.open(tmp.data()); while (std::getline(ifile, line)) { loop_info_t loop_info; - int cnt = sscanf(line.c_str(), "%d %d %d", &loop_info.file_id_, - &loop_info.loop_id_, &loop_info.line_nr_); + int cnt = sscanf(line.c_str(), "%d %d %d", &loop_info.file_id_, &loop_info.loop_id_, &loop_info.line_nr_); if (cnt == 3) { loop_infos.push_back(loop_info); } @@ -56,8 +55,8 @@ void __dp_loop_output() { std::string tmp2(getenv("DOT_DISCOPOP_PROFILER")); tmp2 += "/loop_counter_output.txt"; ofile.open(tmp2.data()); - const auto& loop_counters = loop_manager->get_loop_counters(); - + const auto &loop_counters = loop_manager->get_loop_counters(); + for (auto i = 1; i < loop_counters.size(); ++i) { loop_info_t &loop_info = loop_infos[i]; ofile << loop_info.file_id_ << " "; @@ -70,7 +69,6 @@ void __dp_loop_output() { loop_manager->set_done(); } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_loop_output.hpp b/rtlib/injected_functions/dp_loop_output.hpp index c602bbab9..355e9ad33 100644 --- a/rtlib/injected_functions/dp_loop_output.hpp +++ b/rtlib/injected_functions/dp_loop_output.hpp @@ -18,7 +18,6 @@ namespace __dp { extern "C" { void __dp_loop_output(); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_new.cpp b/rtlib/injected_functions/dp_new.cpp index b2a64e2ea..75cf6aaed 100644 --- a/rtlib/injected_functions/dp_new.cpp +++ b/rtlib/injected_functions/dp_new.cpp @@ -45,6 +45,7 @@ void __dp_new(LID lid, ADDR startAddr, ADDR endAddr, int64_t numBytes) { const auto timer = Timer(timers, TimerRegion::NEW); #endif +#if DP_MEMORY_REGION_DEALIASING // calculate endAddr of memory region endAddr = startAddr + numBytes; @@ -52,12 +53,12 @@ void __dp_new(LID lid, ADDR startAddr, ADDR endAddr, int64_t numBytes) { std::string allocID = memory_manager->allocate_memory(lid, startAddr, endAddr, numBytes, -1); if (DP_DEBUG) { - cout << "new/malloc: " << dputil::decodeLID(lid) << ", " << allocID << ", " - << std::hex << startAddr << " - " << std::hex << endAddr; + cout << "new/malloc: " << dputil::decodeLID(lid) << ", " << allocID << ", " << std::hex << startAddr << " - " + << std::hex << endAddr; printf(" NumBytes: %lld\n", numBytes); } +#endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_new.hpp b/rtlib/injected_functions/dp_new.hpp index 26388cc24..fccae547a 100644 --- a/rtlib/injected_functions/dp_new.hpp +++ b/rtlib/injected_functions/dp_new.hpp @@ -24,7 +24,6 @@ extern "C" { void __dp_new(LID lid, ADDR startAddr, ADDR endAddr, int64_t numBytes); // End HA #endif - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_read.cpp b/rtlib/injected_functions/dp_read.cpp index 2206caf64..f59777d5f 100644 --- a/rtlib/injected_functions/dp_read.cpp +++ b/rtlib/injected_functions/dp_read.cpp @@ -12,8 +12,8 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -68,20 +68,21 @@ void __dp_read(LID lid, ADDR addr, const char *var) { function_manager->reset_call(lid); if (DP_DEBUG) { - cout << "instLoad at encoded LID " << std::dec << dputil::decodeLID(lid) - << " and addr " << std::hex << addr << endl; + cout << "instLoad at encoded LID " << std::dec << dputil::decodeLID(lid) << " and addr " << std::hex << addr + << endl; } // TEST // check for stack access +#if DP_STACK_ACCESS_DETECTION bool is_stack_access = memory_manager->is_stack_access(addr); +#endif // !TEST #if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0 AccessInfo current; #else - int64_t workerID = - ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" + int64_t workerID = ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" AccessInfo ¤t = tempAddrChunks[workerID][tempAddrCount[workerID]++]; #endif current.isRead = true; @@ -89,18 +90,22 @@ void __dp_read(LID lid, ADDR addr, const char *var) { current.var = var; current.AAvar = getMemoryRegionIdFromAddr(var, addr); current.addr = addr; - current.isStackAccess = is_stack_access; - current.addrIsOwnedByScope = - memory_manager->isFirstWrittenInScope(addr, false); - current.positiveScopeChangeOccuredSinceLastAccess = - memory_manager->positiveScopeChangeOccuredSinceLastAccess(addr); +#if DP_CALLSTACK_PROFILING + current.callStack = callStack->getCopy(); +#endif + +#if DP_STACK_ACCESS_DETECTION + current.isStackAccess = is_stack_access; + current.addrIsOwnedByScope = memory_manager->isFirstWrittenInScope(addr, false); + current.positiveScopeChangeOccuredSinceLastAccess = memory_manager->positiveScopeChangeOccuredSinceLastAccess(addr); if (is_stack_access) { // register stack read after check for // positiveScopeChangeOccuredSinceLastAccess memory_manager->registerStackRead(addr, lid, var); } - +#endif + #if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0 analyzeSingleAccess(singleThreadedExecutionSMem, current); #else @@ -115,7 +120,6 @@ void __dp_read(LID lid, ADDR addr, const char *var) { } #endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_read.hpp b/rtlib/injected_functions/dp_read.hpp index fc45e20b6..dca354047 100644 --- a/rtlib/injected_functions/dp_read.hpp +++ b/rtlib/injected_functions/dp_read.hpp @@ -24,7 +24,6 @@ void __dp_read(LID lid, ADDR addr, char *var, ADDR lastaddr, int64_t count); #else void __dp_read(LID lid, ADDR addr, const char *var); #endif - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_report_bb.cpp b/rtlib/injected_functions/dp_report_bb.cpp index 95411c28f..30c14b974 100644 --- a/rtlib/injected_functions/dp_report_bb.cpp +++ b/rtlib/injected_functions/dp_report_bb.cpp @@ -34,7 +34,7 @@ void __dp_report_bb(uint32_t bbIndex) { if (!dpInited || targetTerminated) { return; } - + #ifdef DP_PTHREAD_COMPATIBILITY_MODE std::lock_guard guard(pthread_compatibility_mutex); #endif @@ -48,7 +48,6 @@ void __dp_report_bb(uint32_t bbIndex) { bbList->insert(bbIndex); } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_report_bb.hpp b/rtlib/injected_functions/dp_report_bb.hpp index 98790c22f..9a777b1af 100644 --- a/rtlib/injected_functions/dp_report_bb.hpp +++ b/rtlib/injected_functions/dp_report_bb.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_report_bb(uint32_t bbIndex); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_report_bb_pair.cpp b/rtlib/injected_functions/dp_report_bb_pair.cpp index 1ae18757d..40a8daee0 100644 --- a/rtlib/injected_functions/dp_report_bb_pair.cpp +++ b/rtlib/injected_functions/dp_report_bb_pair.cpp @@ -34,7 +34,7 @@ void __dp_report_bb_pair(int32_t semaphore, uint32_t bbIndex) { if (!dpInited || targetTerminated) { return; } - + #ifdef DP_PTHREAD_COMPATIBILITY_MODE std::lock_guard guard(pthread_compatibility_mutex); #endif @@ -49,7 +49,6 @@ void __dp_report_bb_pair(int32_t semaphore, uint32_t bbIndex) { bbList->insert(bbIndex); } } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_report_bb_pair.hpp b/rtlib/injected_functions/dp_report_bb_pair.hpp index 7e4e64899..b46aa20cd 100644 --- a/rtlib/injected_functions/dp_report_bb_pair.hpp +++ b/rtlib/injected_functions/dp_report_bb_pair.hpp @@ -22,7 +22,6 @@ extern "C" { // hybrid analysis void __dp_report_bb_pair(int32_t counter, uint32_t bbIndex); // End HA - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_taken_branch_counter_output.cpp b/rtlib/injected_functions/dp_taken_branch_counter_output.cpp index 6fa1b99ba..e65c18f98 100644 --- a/rtlib/injected_functions/dp_taken_branch_counter_output.cpp +++ b/rtlib/injected_functions/dp_taken_branch_counter_output.cpp @@ -41,7 +41,6 @@ void __dp_taken_branch_counter_output() { std::cout << "done" << std::endl; } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_taken_branch_counter_output.hpp b/rtlib/injected_functions/dp_taken_branch_counter_output.hpp index 4f10469e0..815ab08ce 100644 --- a/rtlib/injected_functions/dp_taken_branch_counter_output.hpp +++ b/rtlib/injected_functions/dp_taken_branch_counter_output.hpp @@ -20,7 +20,6 @@ namespace __dp { extern "C" { void __dp_taken_branch_counter_output(); - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_write.cpp b/rtlib/injected_functions/dp_write.cpp index b29bd5386..fd5d4ed92 100644 --- a/rtlib/injected_functions/dp_write.cpp +++ b/rtlib/injected_functions/dp_write.cpp @@ -12,8 +12,8 @@ #include "../DPTypes.hpp" -#include "../iFunctionsGlobals.hpp" #include "../iFunctions.hpp" +#include "../iFunctionsGlobals.hpp" #include "../../share/include/debug_print.hpp" #include "../../share/include/timer.hpp" @@ -70,20 +70,21 @@ void __dp_write(LID lid, ADDR addr, const char *var) { function_manager->reset_call(lid); if (DP_DEBUG) { - cout << "instStore at encoded LID " << std::dec << dputil::decodeLID(lid) - << " and addr " << std::hex << addr << endl; + cout << "instStore at encoded LID " << std::dec << dputil::decodeLID(lid) << " and addr " << std::hex << addr + << endl; } // TEST // check for stack access +#if DP_STACK_ACCESS_DETECTION bool is_stack_access = memory_manager->is_stack_access(addr); +#endif // !TEST #if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0 AccessInfo current; #else - int64_t workerID = - ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" + int64_t workerID = ((addr - (addr % 4)) % (NUM_WORKERS * 4)) / 4; // implicit "floor" AccessInfo ¤t = tempAddrChunks[workerID][tempAddrCount[workerID]++]; #endif current.isRead = false; @@ -91,17 +92,22 @@ void __dp_write(LID lid, ADDR addr, const char *var) { current.var = var; current.AAvar = getMemoryRegionIdFromAddr(var, addr); current.addr = addr; + +#if DP_CALLSTACK_PROFILING + current.callStack = callStack->getCopy(); +#endif + +#if DP_STACK_ACCESS_DETECTION current.isStackAccess = is_stack_access; - current.addrIsOwnedByScope = - memory_manager->isFirstWrittenInScope(addr, true); - current.positiveScopeChangeOccuredSinceLastAccess = - memory_manager->positiveScopeChangeOccuredSinceLastAccess(addr); + current.addrIsOwnedByScope = memory_manager->isFirstWrittenInScope(addr, true); + current.positiveScopeChangeOccuredSinceLastAccess = memory_manager->positiveScopeChangeOccuredSinceLastAccess(addr); if (is_stack_access) { // register stack write after check for // positiveScopeChangeOccuredSinceLastAccess memory_manager->registerStackWrite(addr, lid, var); } +#endif #if defined DP_NUM_WORKERS && DP_NUM_WORKERS == 0 analyzeSingleAccess(singleThreadedExecutionSMem, current); @@ -117,7 +123,6 @@ void __dp_write(LID lid, ADDR addr, const char *var) { } #endif } - } } // namespace __dp diff --git a/rtlib/injected_functions/dp_write.hpp b/rtlib/injected_functions/dp_write.hpp index 3e0e8969b..d79a23d44 100644 --- a/rtlib/injected_functions/dp_write.hpp +++ b/rtlib/injected_functions/dp_write.hpp @@ -24,7 +24,6 @@ void __dp_write(LID lid, ADDR addr, char *var, ADDR lastaddr, int64_t count); #else void __dp_write(LID lid, ADDR addr, const char *var); #endif - } } // namespace __dp diff --git a/rtlib/loop/LoopCounter.hpp b/rtlib/loop/LoopCounter.hpp index 999e8d96f..8a659c0b3 100644 --- a/rtlib/loop/LoopCounter.hpp +++ b/rtlib/loop/LoopCounter.hpp @@ -28,9 +28,7 @@ class LoopCounter { loop_counters_[loop_id] += 1; } - const std::vector& get_loop_counters() const noexcept { - return loop_counters_; - } + const std::vector &get_loop_counters() const noexcept { return loop_counters_; } private: std::vector loop_counters_; diff --git a/rtlib/loop/LoopInfo.hpp b/rtlib/loop/LoopInfo.hpp index 45d6f71d8..629edac7e 100644 --- a/rtlib/loop/LoopInfo.hpp +++ b/rtlib/loop/LoopInfo.hpp @@ -19,11 +19,11 @@ struct loop_info_t { int loop_id_ = 0; int file_id_ = 0; - bool operator==(const loop_info_t& other) const noexcept { + bool operator==(const loop_info_t &other) const noexcept { return line_nr_ == other.line_nr_ && loop_id_ == other.loop_id_ && file_id_ == other.file_id_; } - bool operator!=(const loop_info_t& other) const noexcept { return !(*this == other); } + bool operator!=(const loop_info_t &other) const noexcept { return !(*this == other); } }; } // namespace __dp diff --git a/rtlib/loop/LoopManager.hpp b/rtlib/loop/LoopManager.hpp index 050f6d9b5..bc62372d0 100644 --- a/rtlib/loop/LoopManager.hpp +++ b/rtlib/loop/LoopManager.hpp @@ -24,158 +24,133 @@ namespace __dp { class LoopManager { public: - LoopManager() { - } + LoopManager() {} - ~LoopManager() { - for (auto loop : loops) { - delete loop.second; - } + ~LoopManager() { + for (auto loop : loops) { + delete loop.second; } + } - void create_new_loop(const std::int32_t function_level, const std::int32_t loop_id, const LID begin_line) { - loopStack.push(LoopTableEntry(function_level, loop_id, 0, begin_line)); - if (loops.find(begin_line) == loops.end()) { - loops.insert(pair(begin_line, new LoopRecord(0, 0, 0))); - } + void create_new_loop(const std::int32_t function_level, const std::int32_t loop_id, const LID begin_line) { + loopStack.push(LoopTableEntry(function_level, loop_id, 0, begin_line)); + if (loops.find(begin_line) == loops.end()) { + loops.insert(pair(begin_line, new LoopRecord(0, 0, 0))); + } #ifdef DP_DEBUG - std::cout << "(" << std::dec << FuncStackLevel << ")Loop " << loop_id << " enters." << std::endl; + std::cout << "(" << std::dec << FuncStackLevel << ")Loop " << loop_id << " enters." << std::endl; #endif - } + } - bool is_new_loop(const std::int32_t loop_id) const { - return loopStack.empty() || (loopStack.top().loopID != loop_id); - } + bool is_new_loop(const std::int32_t loop_id) const { + return loopStack.empty() || (loopStack.top().loopID != loop_id); + } - void iterate_loop(const std::int32_t function_level) { - loopStack.increment_top_count(); + void iterate_loop(const std::int32_t function_level) { + loopStack.increment_top_count(); #ifdef DP_DEBUG - std::cout << "(" << std::dec << loopStack.top().funcLevel << ")"; - std::cout << "Loop " << loopStack.top().loopID << " iterates " - << loopStack.top().count << " times." << std::endl; + std::cout << "(" << std::dec << loopStack.top().funcLevel << ")"; + std::cout << "Loop " << loopStack.top().loopID << " iterates " << loopStack.top().count << " times." << std::endl; #endif - } + } - void clean_function_exit(const std::int32_t function_level, const LID end_line) { - // Clear up all unfinished loops in the function. - // This usually happens when using return inside loop. - while (!loopStack.empty() && - (loopStack.top().funcLevel == function_level)) { - - // No way to get the real end line of loop. Use the line where - // function returns instead. - LoopRecords::iterator loop = loops.find(loopStack.top().begin); - assert(loop != loops.end() && "A loop ends without its entry being recorded."); - - if (loop->second->end == 0) { - loop->second->end = end_line; - } else { - // TODO: FIXME: loop end line > return line - } - - loop->second->total += loopStack.top().get_count(); - ++loop->second->nEntered; - - loopStack.debug_output(); - loopStack.pop(); - loopStack.debug_output(); - } - } + void clean_function_exit(const std::int32_t function_level, const LID end_line) { + // Clear up all unfinished loops in the function. + // This usually happens when using return inside loop. + while (!loopStack.empty() && (loopStack.top().funcLevel == function_level)) { - LID update_lid(LID lid) { - return loopStack.update_lid(lid); - } + // No way to get the real end line of loop. Use the line where + // function returns instead. + LoopRecords::iterator loop = loops.find(loopStack.top().begin); + assert(loop != loops.end() && "A loop ends without its entry being recorded."); - void exit_loop(const LID lid) { - LoopRecords::iterator loop = loops.find(loopStack.top().begin); - assert(loop != loops.end() && "A loop ends without its entry being recorded."); - if (loop->second->end == 0) { - loop->second->end = lid; - } else { - // New loop exit found and it's smaller than before. That means - // the current exit point can be the break inside the loop. - // In this case we ignore the current exit point and keep the - // regular one. - if (lid < loop->second->end) { - // loop->second->end = lid; - } - // New loop exit found and it's bigger than before. This can - // happen when the previous exit is a break inside the loop. - // In this case we update the loop exit to the bigger one. - else if (lid > loop->second->end) { - loop->second->end = lid; - } - // New loop exit found and it's the same as before. Good. - } - - if (loop->second->maxIterationCount < loopStack.top().get_count()) { - loop->second->maxIterationCount = loopStack.top().get_count(); - } - - loop->second->total += loopStack.top().get_count(); - ++loop->second->nEntered; - - loopStack.debug_output(); - loopStack.pop(); - loopStack.debug_output(); - } + if (loop->second->end == 0) { + loop->second->end = end_line; + } else { + // TODO: FIXME: loop end line > return line + } - bool is_single_exit(const std::int32_t loop_id) { - return loopStack.is_single_exit(loop_id); - } + loop->second->total += loopStack.top().get_count(); + ++loop->second->nEntered; - void correct_func_level(const std::int32_t function_level) { - loopStack.correct_func_level(function_level); + loopStack.debug_output(); + loopStack.pop(); + loopStack.debug_output(); } + } - std::int32_t get_current_loop_id() { - return loopStack.top().loopID; - } + LID update_lid(LID lid) { return loopStack.update_lid(lid); } - bool empty() { - return loopStack.empty(); + void exit_loop(const LID lid) { + LoopRecords::iterator loop = loops.find(loopStack.top().begin); + assert(loop != loops.end() && "A loop ends without its entry being recorded."); + if (loop->second->end == 0) { + loop->second->end = lid; + } else { + // New loop exit found and it's smaller than before. That means + // the current exit point can be the break inside the loop. + // In this case we ignore the current exit point and keep the + // regular one. + if (lid < loop->second->end) { + // loop->second->end = lid; + } + // New loop exit found and it's bigger than before. This can + // happen when the previous exit is a break inside the loop. + // In this case we update the loop exit to the bigger one. + else if (lid > loop->second->end) { + loop->second->end = lid; + } + // New loop exit found and it's the same as before. Good. } - void output(std::ostream& stream) { - for (const auto& loop : loops) { - stream << dputil::decodeLID(loop.first) << " BGN loop "; - stream << loop.second->total << ' '; - stream << loop.second->nEntered << ' '; - stream << static_cast(loop.second->total / loop.second->nEntered) << ' '; - stream << loop.second->maxIterationCount << std::endl; - stream << dputil::decodeLID(loop.second->end) << " END loop" << std::endl; - } + if (loop->second->maxIterationCount < loopStack.top().get_count()) { + loop->second->maxIterationCount = loopStack.top().get_count(); } - const LoopTable& get_stack() const { - return loopStack; - } + loop->second->total += loopStack.top().get_count(); + ++loop->second->nEntered; - const LoopRecords& get_loops() const { - return loops; - } + loopStack.debug_output(); + loopStack.pop(); + loopStack.debug_output(); + } - bool is_done() const noexcept { - return alreadyDone; - } + bool is_single_exit(const std::int32_t loop_id) { return loopStack.is_single_exit(loop_id); } - void set_done() noexcept { - alreadyDone = true; - } + void correct_func_level(const std::int32_t function_level) { loopStack.correct_func_level(function_level); } - void incr_loop_counter(int loop_id) { - lc.incr_loop_counter(loop_id); - } + std::int32_t get_current_loop_id() { return loopStack.top().loopID; } + + bool empty() { return loopStack.empty(); } - const std::vector& get_loop_counters() const { - return lc.get_loop_counters(); + void output(std::ostream &stream) { + for (const auto &loop : loops) { + stream << dputil::decodeLID(loop.first) << " BGN loop "; + stream << loop.second->total << ' '; + stream << loop.second->nEntered << ' '; + stream << static_cast(loop.second->total / loop.second->nEntered) << ' '; + stream << loop.second->maxIterationCount << std::endl; + stream << dputil::decodeLID(loop.second->end) << " END loop" << std::endl; } + } + + const LoopTable &get_stack() const { return loopStack; } + + const LoopRecords &get_loops() const { return loops; } + + bool is_done() const noexcept { return alreadyDone; } + + void set_done() noexcept { alreadyDone = true; } + + void incr_loop_counter(int loop_id) { lc.incr_loop_counter(loop_id); } + + const std::vector &get_loop_counters() const { return lc.get_loop_counters(); } private: - LoopTable loopStack; // loop stack tracking - LoopRecords loops; // loop merging - LoopCounter lc; // loop counter - bool alreadyDone; + LoopTable loopStack; // loop stack tracking + LoopRecords loops; // loop merging + LoopCounter lc; // loop counter + bool alreadyDone; }; } // namespace __dp diff --git a/rtlib/loop/LoopRecord.hpp b/rtlib/loop/LoopRecord.hpp index 6add957ee..50326d311 100644 --- a/rtlib/loop/LoopRecord.hpp +++ b/rtlib/loop/LoopRecord.hpp @@ -27,15 +27,16 @@ struct LoopRecord { LID end; std::int32_t total; std::int32_t nEntered; - + // maximum iterations executed during a single loop entry - std::int32_t maxIterationCount = 0; + std::int32_t maxIterationCount = 0; - bool operator==(const LoopRecord& other) const noexcept { - return end == other.end && total == other.total && nEntered == other.nEntered && maxIterationCount == other.maxIterationCount; + bool operator==(const LoopRecord &other) const noexcept { + return end == other.end && total == other.total && nEntered == other.nEntered && + maxIterationCount == other.maxIterationCount; } - bool operator!=(const LoopRecord& other) const noexcept { return !(*this == other); } + bool operator!=(const LoopRecord &other) const noexcept { return !(*this == other); } }; typedef std::unordered_map LoopRecords; diff --git a/rtlib/loop/LoopTable.hpp b/rtlib/loop/LoopTable.hpp index 956259f13..00070ebc8 100644 --- a/rtlib/loop/LoopTable.hpp +++ b/rtlib/loop/LoopTable.hpp @@ -22,34 +22,22 @@ namespace __dp { struct LoopTable { public: - LoopTable() { - contents.reserve(32); - } + LoopTable() { contents.reserve(32); } - const LoopTableEntry &top() const { - return contents.back(); - } + const LoopTableEntry &top() const { return contents.back(); } - const LoopTableEntry &first() const { - return contents[0]; - } + const LoopTableEntry &first() const { return contents[0]; } - const LoopTableEntry &topMinusN(const std::size_t n) const { - return contents[contents.size() - 1 - n]; - } + const LoopTableEntry &topMinusN(const std::size_t n) const { return contents[contents.size() - 1 - n]; } - void pop() { - contents.pop_back(); - } + void pop() { contents.pop_back(); } - bool empty() const { - return contents.empty(); - } + bool empty() const { return contents.empty(); } bool is_single_exit(const std::int32_t loopID) const { if (empty()) return true; - + if (top().loopID != loopID) return true; @@ -59,72 +47,63 @@ struct LoopTable { void correct_func_level(const std::int32_t func_level) { if (top().funcLevel != func_level) { #ifdef DP_DEBUG - std::cout << "WARNING: changing funcLevel of Loop " << top().loopID - << " from " << top().funcLevel << " to " << func_level - << std::endl; + std::cout << "WARNING: changing funcLevel of Loop " << top().loopID << " from " << top().funcLevel << " to " + << func_level << std::endl; #endif contents.back().funcLevel = func_level; } } - - void push(const LoopTableEntry newElement) { - contents.push_back(newElement); - } - std::size_t size() const { - return contents.size(); - } + void push(const LoopTableEntry newElement) { contents.push_back(newElement); } + + std::size_t size() const { return contents.size(); } LID update_lid(const LID old_lid) const { auto lid = old_lid; - + if (empty()) { return lid | (((LID)0xFF) << 56); } - // store loop iteration metadata (last 8 bits for loop id, 1 bit to mark loop - // iteration count as valid, last 7 bits for loop iteration) last 8 bits are - // sufficient, since metadata is only used to check for different iterations, - // not exact values. first 32 bits of lid are reserved for metadata - // and thus empty + // store loop iteration metadata (last 8 bits for loop id, 1 bit to mark + // loop iteration count as valid, last 7 bits for loop iteration) last 8 + // bits are sufficient, since metadata is only used to check for different + // iterations, not exact values. first 32 bits of lid are reserved for + // metadata and thus empty if (size() > 0) { - lid = lid | (((LID)(first().loopID & 0xFF)) << 56); // add masked loop id + lid = lid | (((LID)(first().loopID & 0xFF)) << 56); // add masked loop id lid = lid | (((LID)(top().get_count() & 0x7F)) << 48); // add masked loop count - lid = lid | (LID)0x0080000000000000; // mark loop count valid - } - + lid = lid | (LID)0x0080000000000000; // mark loop count valid + } + if (size() > 1) { lid = lid | (((LID)(topMinusN(1).get_count() & 0x7F)) << 40); // add masked loop count - lid = lid | (LID)0x0000800000000000; // mark loop count valid - } - - if (size() > 2) { + lid = lid | (LID)0x0000800000000000; // mark loop count valid + } + + if (size() > 2) { lid = lid | (((LID)(topMinusN(2).get_count() & 0x7F)) << 32); // add masked loop count - lid = lid | (LID)0x0000008000000000; // mark loop count valid + lid = lid | (LID)0x0000008000000000; // mark loop count valid } return lid; } - void increment_top_count() { - contents.back().increment_count(); - } + void increment_top_count() { contents.back().increment_count(); } void debug_output() const { #ifdef DP_DEBUG - if (empty()) - std::cout << "Loop Stack is empty." << endl; - else { - std::cout << "TOP: (" << std::dec << top().funcLevel << ")"; - std::cout << "Loop " << top().loopID << "." << std::endl; - } + if (empty()) + std::cout << "Loop Stack is empty." << endl; + else { + std::cout << "TOP: (" << std::dec << top().funcLevel << ")"; + std::cout << "Loop " << top().loopID << "." << std::endl; + } #endif } - -private: - +private: std::vector contents; }; diff --git a/rtlib/loop/LoopTableEntry.hpp b/rtlib/loop/LoopTableEntry.hpp index 774ff6140..022393df1 100644 --- a/rtlib/loop/LoopTableEntry.hpp +++ b/rtlib/loop/LoopTableEntry.hpp @@ -27,11 +27,11 @@ struct LoopTableEntry { std::int32_t loopID; LID begin; - bool operator==(const LoopTableEntry& other) const noexcept { + bool operator==(const LoopTableEntry &other) const noexcept { return funcLevel == other.funcLevel && loopID == other.loopID && count == other.count && begin == other.begin; } - bool operator!=(const LoopTableEntry& other) const noexcept { return !(*this == other); } + bool operator!=(const LoopTableEntry &other) const noexcept { return !(*this == other); } std::int32_t get_count() const noexcept { return count; } diff --git a/rtlib/loop/Makros.hpp b/rtlib/loop/Makros.hpp index 9795ae997..99fecf15e 100644 --- a/rtlib/loop/Makros.hpp +++ b/rtlib/loop/Makros.hpp @@ -12,23 +12,16 @@ #pragma once -#define unpackLIDMetadata_getLoopID(lid) \ - ((lid) >> 56) +#define unpackLIDMetadata_getLoopID(lid) ((lid) >> 56) -#define unpackLIDMetadata_getLoopIteration_0(lid) \ - (((lid) >> 48) & 0x7F) +#define unpackLIDMetadata_getLoopIteration_0(lid) (((lid) >> 48) & 0x7F) -#define unpackLIDMetadata_getLoopIteration_1(lid) \ - (((lid) >> 40) & 0x7F) +#define unpackLIDMetadata_getLoopIteration_1(lid) (((lid) >> 40) & 0x7F) -#define unpackLIDMetadata_getLoopIteration_2(lid) \ - (((lid) >> 32) & 0x7F) +#define unpackLIDMetadata_getLoopIteration_2(lid) (((lid) >> 32) & 0x7F) -#define checkLIDMetadata_getLoopIterationValidity_0(lid) \ - (((lid) & 0x0080000000000000) >> 55) +#define checkLIDMetadata_getLoopIterationValidity_0(lid) (((lid)&0x0080000000000000) >> 55) -#define checkLIDMetadata_getLoopIterationValidity_1(lid) \ - (((lid) & 0x0000800000000000) >> 47) +#define checkLIDMetadata_getLoopIterationValidity_1(lid) (((lid)&0x0000800000000000) >> 47) -#define checkLIDMetadata_getLoopIterationValidity_2(lid) \ - (((lid) & 0x0000008000000000) >> 39) +#define checkLIDMetadata_getLoopIterationValidity_2(lid) (((lid)&0x0000008000000000) >> 39) diff --git a/rtlib/loop/VarCounter.hpp b/rtlib/loop/VarCounter.hpp index 29e099ce4..0b2da556c 100644 --- a/rtlib/loop/VarCounter.hpp +++ b/rtlib/loop/VarCounter.hpp @@ -19,11 +19,12 @@ struct VarCounter { long long mem_addr_ = 0; bool valid_ = true; - bool operator==(const VarCounter& other) const noexcept { - return counters_[0] == other.counters_[0] && counters_[1] == other.counters_[1] && mem_addr_ == other.mem_addr_ && valid_ == other.valid_; + bool operator==(const VarCounter &other) const noexcept { + return counters_[0] == other.counters_[0] && counters_[1] == other.counters_[1] && mem_addr_ == other.mem_addr_ && + valid_ == other.valid_; } - bool operator!=(const VarCounter& other) const noexcept { return !(*this == other); } + bool operator!=(const VarCounter &other) const noexcept { return !(*this == other); } }; } // namespace __dp diff --git a/rtlib/loop/VarInfo.hpp b/rtlib/loop/VarInfo.hpp index cce392a27..b3dd1703d 100644 --- a/rtlib/loop/VarInfo.hpp +++ b/rtlib/loop/VarInfo.hpp @@ -24,12 +24,12 @@ struct var_info_t { int instr_line_ = 0; char operation_ = 0; - bool operator==(const var_info_t& other) const noexcept { + bool operator==(const var_info_t &other) const noexcept { return var_name_ == other.var_name_ && file_id_ == other.file_id_ && instr_id_ == other.instr_id_ && loop_line_nr_ == other.loop_line_nr_ && instr_line_ == other.instr_line_ && operation_ == other.operation_; } - bool operator!=(const var_info_t& other) const noexcept { return !(*this == other); } + bool operator!=(const var_info_t &other) const noexcept { return !(*this == other); } }; } // namespace __dp diff --git a/rtlib/memory/AbstractShadow.hpp b/rtlib/memory/AbstractShadow.hpp index 6eaf27086..635412b9d 100644 --- a/rtlib/memory/AbstractShadow.hpp +++ b/rtlib/memory/AbstractShadow.hpp @@ -39,8 +39,21 @@ class AbstractShadow { virtual void removeFromWrite(std::int64_t memAddr) = 0; - virtual std::unordered_set getAddrsInRange(std::int64_t startAddr, - std::int64_t endAddr) = 0; + virtual std::unordered_set getAddrsInRange(std::int64_t startAddr, std::int64_t endAddr) = 0; + +#if DP_CALLSTACK_PROFILING + virtual CallStack *getLastReadAccessCallStack(int64_t memAddr); + + virtual void setLastReadAccessCallStack(int64_t memAddr, CallStack *p_cs); + + virtual void cleanReadAccessCallStack(int64_t memAddr); + + virtual CallStack *getLastWriteAccessCallStack(int64_t memAddr); + + virtual void setLastWriteAccessCallStack(int64_t memAddr, CallStack *p_cs); + + virtual void cleanWriteAccessCallStack(int64_t memAddr); +#endif }; } // namespace __dp diff --git a/rtlib/memory/MemoryManager.cpp b/rtlib/memory/MemoryManager.cpp index ac6e2ae85..c645df60f 100644 --- a/rtlib/memory/MemoryManager.cpp +++ b/rtlib/memory/MemoryManager.cpp @@ -14,44 +14,51 @@ #include "../iFunctionsGlobals.hpp" -std::string __dp::MemoryManager::allocate_memory(const LID line_id, const ADDR start_address, const ADDR end_address, const std::int64_t number_bytes, const std::int64_t number_elements) { - const auto memory_region_id = get_next_free_memory_region_id(); - const auto memory_region_id_str = std::to_string(memory_region_id); +std::string __dp::MemoryManager::allocate_memory(const LID line_id, const ADDR start_address, const ADDR end_address, + const std::int64_t number_bytes, const std::int64_t number_elements) { + const auto memory_region_id = get_next_free_memory_region_id(); + const auto memory_region_id_str = std::to_string(memory_region_id); - allocatedMemRegTree.allocate_region(start_address, end_address, memory_region_id); - allocatedMemoryRegions.emplace_back(line_id, memory_region_id_str, start_address, end_address, number_bytes, number_elements); + allocatedMemRegTree.allocate_region(start_address, end_address, memory_region_id); + allocatedMemoryRegions.emplace_back(line_id, memory_region_id_str, start_address, end_address, number_bytes, + number_elements); - if (start_address < smallestAllocatedADDR) { - smallestAllocatedADDR = start_address; - } + if (start_address < smallestAllocatedADDR) { + smallestAllocatedADDR = start_address; + } - if (end_address > largestAllocatedADDR) { - largestAllocatedADDR = end_address; - } + if (end_address > largestAllocatedADDR) { + largestAllocatedADDR = end_address; + } - return memory_region_id_str; + return memory_region_id_str; } -std::string __dp::MemoryManager::allocate_stack_memory(const LID line_id, const ADDR start_address, const ADDR end_address, const std::int64_t number_bytes, const std::int64_t number_elements) { - const auto memory_region_id = get_next_free_memory_region_id(); - const auto memory_region_id_str = std::to_string(memory_region_id); +std::string __dp::MemoryManager::allocate_stack_memory(const LID line_id, const ADDR start_address, + const ADDR end_address, const std::int64_t number_bytes, + const std::int64_t number_elements) { + const auto memory_region_id = get_next_free_memory_region_id(); + const auto memory_region_id_str = std::to_string(memory_region_id); - allocatedMemRegTree.allocate_region(start_address, end_address, memory_region_id); - allocatedMemoryRegions.emplace_back(line_id, memory_region_id_str, start_address, end_address, number_bytes, number_elements); + allocatedMemRegTree.allocate_region(start_address, end_address, memory_region_id); + allocatedMemoryRegions.emplace_back(line_id, memory_region_id_str, start_address, end_address, number_bytes, + number_elements); - if (start_address < smallestAllocatedADDR) { - smallestAllocatedADDR = start_address; - } + if (start_address < smallestAllocatedADDR) { + smallestAllocatedADDR = start_address; + } - if (end_address > largestAllocatedADDR) { - largestAllocatedADDR = end_address; - } + if (end_address > largestAllocatedADDR) { + largestAllocatedADDR = end_address; + } - if (number_elements >= 0) { - assert (start_address <= end_address && "start_address <= end_address is violated!"); - // update stack base address, if not already set - update_stack_addresses(start_address, end_address); - } +#if DP_STACK_ACCESS_DETECTION + if (number_elements >= 0) { + assert(start_address <= end_address && "start_address <= end_address is violated!"); + // update stack base address, if not already set + update_stack_addresses(start_address, end_address); + } +#endif - return memory_region_id_str; + return memory_region_id_str; } diff --git a/rtlib/memory/MemoryManager.hpp b/rtlib/memory/MemoryManager.hpp index e9df9bc51..b8df27087 100644 --- a/rtlib/memory/MemoryManager.hpp +++ b/rtlib/memory/MemoryManager.hpp @@ -28,152 +28,136 @@ namespace __dp { class MemoryManager { public: - MemoryManager() { - nextFreeMemoryRegionId = 1; - - smallestAllocatedADDR = std::numeric_limits::max(); - largestAllocatedADDR = std::numeric_limits::min(); - } + MemoryManager() { + nextFreeMemoryRegionId = 1; - MemoryManager(const MemoryManager& other) = delete; - MemoryManager(MemoryManager&& other) = delete; + smallestAllocatedADDR = std::numeric_limits::max(); + largestAllocatedADDR = std::numeric_limits::min(); + } - MemoryManager& operator=(const MemoryManager& other) = delete; - MemoryManager& operator=(MemoryManager&& other) = delete; + MemoryManager(const MemoryManager &other) = delete; + MemoryManager(MemoryManager &&other) = delete; - std::int64_t get_next_free_memory_region_id() noexcept { - const auto old_value = nextFreeMemoryRegionId; - nextFreeMemoryRegionId++; - return old_value; - } + MemoryManager &operator=(const MemoryManager &other) = delete; + MemoryManager &operator=(MemoryManager &&other) = delete; - void enter_new_function() { - stackAddrs.emplace(0, 0); - } + std::int64_t get_next_free_memory_region_id() noexcept { + const auto old_value = nextFreeMemoryRegionId; + nextFreeMemoryRegionId++; + return old_value; + } - void update_stack_addresses(const ADDR start, const ADDR end) { - auto& top = stackAddrs.top(); - if (top.first == 0) { - top.first = start; - } - else if (top.first > start) { - top.first = start; - } - - if (top.second == 0) { - top.second = end; - } - else if (top.second < end) { - top.second = end; - } - } + void enter_new_function() { stackAddrs.emplace(0, 0); } - std::pair pop_last_stack_address() { - const auto val = stackAddrs.top(); - stackAddrs.pop(); - return val; + void update_stack_addresses(const ADDR start, const ADDR end) { + auto &top = stackAddrs.top(); + if (top.first == 0) { + top.first = start; + } else if (top.first > start) { + top.first = start; } - bool is_stack_access(const ADDR address) noexcept { - if (stackAddrs.empty()) { - return false; - } + if (top.second == 0) { + top.second = end; + } else if (top.second < end) { + top.second = end; + } + } - const auto& addrs = stackAddrs.top(); - if (addrs.first == 0 || addrs.second == 0) { - return false; - } + std::pair pop_last_stack_address() { + const auto val = stackAddrs.top(); + stackAddrs.pop(); + return val; + } - return addrs.first <= address && address <= addrs.second; - // return address <= addrs.first && addrs.second <= address; + bool is_stack_access(const ADDR address) noexcept { + if (stackAddrs.empty()) { + return false; } - void enterScope(std::string type, const LID debug_lid) { - scopeManager.enterScope(type.c_str(), debug_lid); + const auto &addrs = stackAddrs.top(); + if (addrs.first == 0 || addrs.second == 0) { + return false; } - void leaveScope(std::string type, const LID debug_lid) { - scopeManager.leaveScope(type.c_str(), debug_lid); - } + return addrs.first <= address && address <= addrs.second; + // return address <= addrs.first && addrs.second <= address; + } - void registerStackRead(const ADDR address, const LID debug_lid, const char *debug_var) { - scopeManager.registerStackRead(address, debug_lid, debug_var); - } + void enterScope(std::string type, const LID debug_lid) { scopeManager.enterScope(type.c_str(), debug_lid); } - void registerStackWrite(const ADDR address, const LID debug_lid, const char *debug_var) { - scopeManager.registerStackWrite(address, debug_lid, debug_var); - } + void leaveScope(std::string type, const LID debug_lid) { scopeManager.leaveScope(type.c_str(), debug_lid); } - bool isFirstWrittenInScope(const ADDR addr, const bool currentAccessIsWrite) { - return scopeManager.isOwnedByScope(addr, currentAccessIsWrite); - } + void registerStackRead(const ADDR address, const LID debug_lid, const char *debug_var) { + scopeManager.registerStackRead(address, debug_lid, debug_var); + } - bool positiveScopeChangeOccuredSinceLastAccess(const ADDR addr) { - return scopeManager.positiveScopeChangeOccuredSinceLastAccess(addr); - } + void registerStackWrite(const ADDR address, const LID debug_lid, const char *debug_var) { + scopeManager.registerStackWrite(address, debug_lid, debug_var); + } - const Scope& getCurrentScope() { - return scopeManager.getCurrentScope(); - } + bool isFirstWrittenInScope(const ADDR addr, const bool currentAccessIsWrite) { + return scopeManager.isOwnedByScope(addr, currentAccessIsWrite); + } - std::size_t number_open_scopes() const noexcept { - return scopeManager.number_open_scopes(); - } + bool positiveScopeChangeOccuredSinceLastAccess(const ADDR addr) { + return scopeManager.positiveScopeChangeOccuredSinceLastAccess(addr); + } - std::string get_memory_region_id(const ADDR addr, std::string fallback) { - return allocatedMemRegTree.get_memory_region_id_string(addr, fallback.c_str()); - } + const Scope &getCurrentScope() { return scopeManager.getCurrentScope(); } - std::string allocate_memory(const LID line_id, const ADDR start_address, const ADDR end_address, const std::int64_t number_bytes, const std::int64_t number_elements); - - std::string allocate_stack_memory(const LID line_id, const ADDR start_address, const ADDR end_address, const std::int64_t number_bytes, const std::int64_t number_elements); + std::size_t number_open_scopes() const noexcept { return scopeManager.number_open_scopes(); } - void allocate_dummy_region() { - allocatedMemoryRegions.emplace_back(0, std::string("%%dummy%%"), 0, 0, 0, 0); - } + std::string get_memory_region_id(const ADDR addr, std::string fallback) { + return allocatedMemRegTree.get_memory_region_id_string(addr, fallback.c_str()); + } - std::size_t get_number_allocations() { - return allocatedMemoryRegions.size(); - } + std::string allocate_memory(const LID line_id, const ADDR start_address, const ADDR end_address, + const std::int64_t number_bytes, const std::int64_t number_elements); - const std::vector>& - get_allocated_memory_regions() { - return allocatedMemoryRegions; - } + std::string allocate_stack_memory(const LID line_id, const ADDR start_address, const ADDR end_address, + const std::int64_t number_bytes, const std::int64_t number_elements); - void output_memory_regions(std::ostream& stream) { - for (const auto& memoryRegion : allocatedMemoryRegions) { - const auto lid = get<0>(memoryRegion); - const auto& id = get<1>(memoryRegion); - const auto num_bytes = get<4>(memoryRegion); + void allocate_dummy_region() { allocatedMemoryRegions.emplace_back(0, std::string("%%dummy%%"), 0, 0, 0, 0); } - dputil::decodeLID(lid, stream); - stream << ' ' << id << ' ' << num_bytes << endl; - } - } + std::size_t get_number_allocations() { return allocatedMemoryRegions.size(); } - ADDR get_smallest_allocated_addr() const noexcept { - return smallestAllocatedADDR; - } + const std::vector> & + get_allocated_memory_regions() { + return allocatedMemoryRegions; + } + + void output_memory_regions(std::ostream &stream) { + for (const auto &memoryRegion : allocatedMemoryRegions) { + const auto lid = get<0>(memoryRegion); + const auto &id = get<1>(memoryRegion); + const auto num_bytes = get<4>(memoryRegion); - ADDR get_largest_allocated_addr() const noexcept { - return largestAllocatedADDR; + dputil::decodeLID(lid, stream); + stream << ' ' << id << ' ' << num_bytes << endl; } + } + + ADDR get_smallest_allocated_addr() const noexcept { return smallestAllocatedADDR; } + + ADDR get_largest_allocated_addr() const noexcept { return largestAllocatedADDR; } private: - std::int64_t nextFreeMemoryRegionId; // 0 is reserved as the identifier for "no region" in the MemoryRegionTree + std::int64_t nextFreeMemoryRegionId; // 0 is reserved as the identifier for + // "no region" in the MemoryRegionTree + + ADDR smallestAllocatedADDR; + ADDR largestAllocatedADDR; - ADDR smallestAllocatedADDR; - ADDR largestAllocatedADDR; + std::stack> stackAddrs; // track stack adresses for entered functions - std::stack> stackAddrs; // track stack adresses for entered functions + ScopeManager scopeManager; - ScopeManager scopeManager; + MemoryRegionTree allocatedMemRegTree; - MemoryRegionTree allocatedMemRegTree; - - // (LID, identifier, startAddr, endAddr, numBytes, numElements) - std::vector> allocatedMemoryRegions; + // (LID, identifier, startAddr, endAddr, numBytes, numElements) + std::vector> + allocatedMemoryRegions; }; } // namespace __dp diff --git a/rtlib/memory/MemoryRegionTree.hpp b/rtlib/memory/MemoryRegionTree.hpp index 9419510d5..fdae0ce06 100644 --- a/rtlib/memory/MemoryRegionTree.hpp +++ b/rtlib/memory/MemoryRegionTree.hpp @@ -14,8 +14,7 @@ #include "../DPUtils.hpp" -#define get_char_at_level(addr, level) \ - ((((addr) << ((level) * 4)) >> 60) & 0x000000000000000F) +#define get_char_at_level(addr, level) ((((addr) << ((level)*4)) >> 60) & 0x000000000000000F) inline ADDR get_level_shifting_mask(int level) { switch (level) { @@ -99,40 +98,27 @@ namespace __dp { class MRTNode { public: - MRTNode(const ADDR first_addr, const ADDR last_addr, const short level) : first_addr(first_addr), last_addr(last_addr), level(level) {} + MRTNode(const ADDR first_addr, const ADDR last_addr, const short level) + : first_addr(first_addr), last_addr(last_addr), level(level) {} - ADDR get_first_addr() const noexcept { - return first_addr; - } + ADDR get_first_addr() const noexcept { return first_addr; } - ADDR get_last_addr() const noexcept { - return last_addr; - } + ADDR get_last_addr() const noexcept { return last_addr; } - void set_memory_region_id(const unsigned int memory_region_id) noexcept { - this->memory_region_id = memory_region_id; - } + void set_memory_region_id(const unsigned int memory_region_id) noexcept { this->memory_region_id = memory_region_id; } - unsigned int get_memory_region_id() const noexcept { - return memory_region_id; - } + unsigned int get_memory_region_id() const noexcept { return memory_region_id; } - short get_level() const noexcept { - return level; - } - - const std::array& get_children() const noexcept { - return children; - } + short get_level() const noexcept { return level; } + + const std::array &get_children() const noexcept { return children; } void delete_child(const unsigned int index) { delete children[index]; children[index] = nullptr; } - MRTNode* get_child(const unsigned int index) const noexcept { - return children[index]; - } + MRTNode *get_child(const unsigned int index) const noexcept { return children[index]; } int get_child_index(const ADDR addr) const noexcept { if (addr < first_addr || addr > last_addr) { @@ -141,7 +127,7 @@ class MRTNode { const auto shift = get_shift(level); const auto mask = get_level_shifting_mask(level); - const auto index = (addr & mask) >> shift; + const auto index = (addr & mask) >> shift; return index; } @@ -150,9 +136,9 @@ class MRTNode { assert(children[index] == nullptr && "Child already exists"); const auto shift = get_shift(level); - + const auto child_start = first_addr | (static_cast(index) << shift); - const auto child_end = child_start | ((1ULL << shift) - 1ULL); + const auto child_end = child_start | ((1ULL << shift) - 1ULL); children[index] = new MRTNode(child_start, child_end, level + 1); } @@ -164,42 +150,36 @@ class MRTNode { unsigned int memory_region_id = 0U; unsigned short level = 65535; - std::array children = {}; + std::array children = {}; }; class MemoryRegionTree { public: - MemoryRegionTree() { - root = new MRTNode(0x0000000000000000, 0x7FFFFFFFFFFFFFFF, 0); - } + MemoryRegionTree() { root = new MRTNode(0x0000000000000000, 0x7FFFFFFFFFFFFFFF, 0); } - MemoryRegionTree(const MemoryRegionTree&) = delete; - MemoryRegionTree& operator=(const MemoryRegionTree&) = delete; + MemoryRegionTree(const MemoryRegionTree &) = delete; + MemoryRegionTree &operator=(const MemoryRegionTree &) = delete; - MemoryRegionTree(MemoryRegionTree&& other) noexcept { + MemoryRegionTree(MemoryRegionTree &&other) noexcept { root = other.root; other.root = nullptr; } - MemoryRegionTree& operator=(MemoryRegionTree&& other) noexcept { - auto* temp = root; + MemoryRegionTree &operator=(MemoryRegionTree &&other) noexcept { + auto *temp = root; root = other.root; other.root = temp; return *this; - } + } ~MemoryRegionTree() { delete_nodes(root); delete root; } - MRTNode* get_root() noexcept { - return root; - } + MRTNode *get_root() noexcept { return root; } - const MRTNode* get_root() const noexcept { - return root; - } + const MRTNode *get_root() const noexcept { return root; } void allocate_region(const ADDR start, const ADDR end, const unsigned int memory_region_id) { assert(start <= end && "Invalid memory region"); @@ -208,7 +188,7 @@ class MemoryRegionTree { } unsigned int get_memory_region_id(const ADDR addr) { - auto* node = root; + auto *node = root; while (true) { if (node->get_memory_region_id() != 0) { @@ -235,7 +215,7 @@ class MemoryRegionTree { return 0xFFFF'FFFFU; } - std::string get_memory_region_id_string(const ADDR addr, const char* fallback) { + std::string get_memory_region_id_string(const ADDR addr, const char *fallback) { const auto memory_region_id = get_memory_region_id(addr); if (memory_region_id == 0xFFFF'FFFFU) { return fallback; @@ -245,8 +225,9 @@ class MemoryRegionTree { } void free_region(const ADDR start) { - // NOTE: Given an allocation [start, end], this function can also handle free(x) for x in (start, end]. - // Not sure if this functionality is required. + // NOTE: Given an allocation [start, end], this function can also handle + // free(x) for x in (start, end]. Not sure if this functionality is + // required. const auto memory_region_id = get_memory_region_id(start); if (memory_region_id == 0xFFFF'FFFFU) { @@ -255,18 +236,19 @@ class MemoryRegionTree { // This actually searches the whole tree again, but it's fine for now const auto clean_root = free(start, memory_region_id, root); - + // We never delete the root node } private: - static void allocate(const ADDR start, const ADDR end, const unsigned int memory_region_id, MRTNode* node) { + static void allocate(const ADDR start, const ADDR end, const unsigned int memory_region_id, MRTNode *node) { assert(node != nullptr && "Node is null"); assert(start >= node->get_first_addr() && end <= node->get_last_addr() && "Invalid memory region for node"); if (start == node->get_first_addr() && end == node->get_last_addr()) { // This assert is valid once dp_delete is implemented - // assert(node->get_memory_region_id() == 0 && "Memory region already allocated"); + // assert(node->get_memory_region_id() == 0 && "Memory region already + // allocated"); node->set_memory_region_id(memory_region_id); return; @@ -280,7 +262,7 @@ class MemoryRegionTree { node->add_child(index); } - auto* child = node->get_child(index); + auto *child = node->get_child(index); const auto child_start = child->get_first_addr(); const auto child_end = child->get_last_addr(); @@ -292,7 +274,7 @@ class MemoryRegionTree { } } - static bool free(const ADDR start, const unsigned int memory_region_id, MRTNode* node) { + static bool free(const ADDR start, const unsigned int memory_region_id, MRTNode *node) { assert(node != nullptr && "Node is null"); const auto memory_region_id_node = node->get_memory_region_id(); @@ -315,7 +297,7 @@ class MemoryRegionTree { } for (auto index = start_index; index < 16; index++) { - auto* child = node->get_child(index); + auto *child = node->get_child(index); if (child == nullptr) { // We might need to clean node -> no return here break; @@ -342,13 +324,13 @@ class MemoryRegionTree { return true; } - static void delete_nodes(MRTNode* node) { + static void delete_nodes(MRTNode *node) { if (node == nullptr) { return; } - + for (auto i = 0; i < 16; i++) { - auto* child = node->get_child(i); + auto *child = node->get_child(i); if (child != nullptr) { delete_nodes(child); delete child; @@ -356,7 +338,7 @@ class MemoryRegionTree { } } - MRTNode* root{}; + MRTNode *root{}; }; } // namespace __dp diff --git a/rtlib/memory/PerfectShadow.hpp b/rtlib/memory/PerfectShadow.hpp index bc3876706..22d95372f 100644 --- a/rtlib/memory/PerfectShadow.hpp +++ b/rtlib/memory/PerfectShadow.hpp @@ -16,6 +16,7 @@ #include "../DPTypes.hpp" +#include "../callstack/CallStack.hpp" #include #include #include @@ -29,10 +30,14 @@ class PerfectShadow : public AbstractShadow { PerfectShadow() { sigRead = new std::unordered_map(); sigWrite = new std::unordered_map(); +#if DP_CALLSTACK_PROFILING + addrToLastReadAccessCallStack = new std::unordered_map(); + addrToLastWriteAccessCallStack = new std::unordered_map(); +#endif } - PerfectShadow(const PerfectShadow& other) = delete; - PerfectShadow(PerfectShadow&& other) { + PerfectShadow(const PerfectShadow &other) = delete; + PerfectShadow(PerfectShadow &&other) { sigRead = other.sigRead; sigWrite = other.sigWrite; @@ -40,8 +45,8 @@ class PerfectShadow : public AbstractShadow { other.sigWrite = nullptr; } - PerfectShadow& operator=(const PerfectShadow& other) = delete; - PerfectShadow& operator=(PerfectShadow&& other) { + PerfectShadow &operator=(const PerfectShadow &other) = delete; + PerfectShadow &operator=(PerfectShadow &&other) { std::swap(sigRead, other.sigRead); std::swap(sigWrite, other.sigWrite); @@ -51,15 +56,22 @@ class PerfectShadow : public AbstractShadow { ~PerfectShadow() { delete sigRead; delete sigWrite; - } - inline sigElement testInRead(std::int64_t memAddr) { - return (*sigRead)[memAddr]; +#if DP_CALLSTACK_PROFILING + for (auto elem : *addrToLastReadAccessCallStack) { + cleanReadAccessCallStack(elem.first); + } + for (auto elem : *addrToLastWriteAccessCallStack) { + cleanWriteAccessCallStack(elem.first); + } + delete addrToLastReadAccessCallStack; + delete addrToLastWriteAccessCallStack; +#endif } - inline sigElement testInWrite(std::int64_t memAddr) { - return (*sigWrite)[memAddr]; - } + inline sigElement testInRead(std::int64_t memAddr) { return (*sigRead)[memAddr]; } + + inline sigElement testInWrite(std::int64_t memAddr) { return (*sigWrite)[memAddr]; } inline sigElement insertToRead(std::int64_t memAddr, sigElement value) { sigElement oldValue = testInRead(memAddr); @@ -73,20 +85,15 @@ class PerfectShadow : public AbstractShadow { return oldValue; } - inline void updateInRead(std::int64_t memAddr, sigElement newValue) { - (*sigRead)[memAddr] = newValue; - } + inline void updateInRead(std::int64_t memAddr, sigElement newValue) { (*sigRead)[memAddr] = newValue; } - inline void updateInWrite(std::int64_t memAddr, sigElement newValue) { - (*sigWrite)[memAddr] = newValue; - } + inline void updateInWrite(std::int64_t memAddr, sigElement newValue) { (*sigWrite)[memAddr] = newValue; } inline void removeFromRead(std::int64_t memAddr) { (*sigRead)[memAddr] = 0; } inline void removeFromWrite(std::int64_t memAddr) { (*sigWrite)[memAddr] = 0; } - inline std::unordered_set getAddrsInRange(std::int64_t startAddr, - std::int64_t endAddr) { + inline std::unordered_set getAddrsInRange(std::int64_t startAddr, std::int64_t endAddr) { std::unordered_set result; for (auto pair : (*sigWrite)) { if ((pair.first >= startAddr) && (pair.first <= endAddr)) { @@ -101,91 +108,149 @@ class PerfectShadow : public AbstractShadow { return result; } - const std::unordered_map* getSigRead() const noexcept { - return sigRead; + const std::unordered_map *getSigRead() const noexcept { return sigRead; } + + const std::unordered_map *getSigWrite() const noexcept { return sigWrite; } + +#if DP_CALLSTACK_PROFILING + inline CallStack *getLastReadAccessCallStack(int64_t memAddr) { return (*addrToLastReadAccessCallStack)[memAddr]; } + + inline void setLastReadAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastReadAccessCallStack).find(memAddr); + if (got == (*addrToLastReadAccessCallStack).end()) { + // no entry exists + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastReadAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } + } + + inline void cleanReadAccessCallStack(int64_t memAddr) { + if ((*addrToLastReadAccessCallStack)[memAddr]) { + delete (*addrToLastReadAccessCallStack)[memAddr]; + (*addrToLastReadAccessCallStack)[memAddr] = nullptr; + } + } + + inline CallStack *getLastWriteAccessCallStack(int64_t memAddr) { return (*addrToLastWriteAccessCallStack)[memAddr]; } + + inline void setLastWriteAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastWriteAccessCallStack).find(memAddr); + if (got == (*addrToLastWriteAccessCallStack).end()) { + // no entry exists + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastWriteAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } } - const std::unordered_map* getSigWrite() const noexcept { - return sigWrite; + inline void cleanWriteAccessCallStack(int64_t memAddr) { + if ((*addrToLastWriteAccessCallStack)[memAddr]) { + delete (*addrToLastWriteAccessCallStack)[memAddr]; + (*addrToLastWriteAccessCallStack)[memAddr] = nullptr; + } } +#endif private: std::unordered_map *sigRead; std::unordered_map *sigWrite; +#if DP_CALLSTACK_PROFILING + std::unordered_map *addrToLastReadAccessCallStack; + std::unordered_map *addrToLastWriteAccessCallStack; +#endif }; // Hopefully faster version class PerfectShadow2 : public AbstractShadow { -public: +public: PerfectShadow2() { read_cache.reserve(1024); write_cache.reserve(1024); +#if DP_CALLSTACK_PROFILING + addrToLastReadAccessCallStack = new std::unordered_map(); + addrToLastWriteAccessCallStack = new std::unordered_map(); +#endif } - sigElement testInRead(const std::int64_t memAddr) noexcept { - return read_cache[memAddr]; + ~PerfectShadow2() { +#if DP_CALLSTACK_PROFILING + for (auto elem : *addrToLastReadAccessCallStack) { + cleanReadAccessCallStack(elem.first); + } + for (auto elem : *addrToLastWriteAccessCallStack) { + cleanWriteAccessCallStack(elem.first); + } + delete addrToLastReadAccessCallStack; + delete addrToLastWriteAccessCallStack; +#endif } - sigElement testInWrite(const std::int64_t memAddr) noexcept { - return write_cache[memAddr]; - } + sigElement testInRead(const std::int64_t memAddr) noexcept { return read_cache[memAddr]; } + + sigElement testInWrite(const std::int64_t memAddr) noexcept { return write_cache[memAddr]; } sigElement insertToRead(const std::int64_t memAddr, const sigElement value) { - const auto iterator = read_cache.find(memAddr); - - if (iterator == read_cache.end()) { - read_cache[memAddr] = value; - return 0; - } + const auto iterator = read_cache.find(memAddr); + + if (iterator == read_cache.end()) { + read_cache[memAddr] = value; + return 0; + } - const auto old_value = iterator->second; - iterator->second = value; - return old_value; + const auto old_value = iterator->second; + iterator->second = value; + return old_value; } sigElement insertToWrite(const std::int64_t memAddr, const sigElement value) { - const auto iterator = write_cache.find(memAddr); - - if (iterator == write_cache.end()) { - write_cache[memAddr] = value; - return 0; - } + const auto iterator = write_cache.find(memAddr); - const auto old_value = iterator->second; - iterator->second = value; - return old_value; - } + if (iterator == write_cache.end()) { + write_cache[memAddr] = value; + return 0; + } - void updateInRead(const std::int64_t memAddr, const sigElement newValue) noexcept { - read_cache[memAddr] = newValue; + const auto old_value = iterator->second; + iterator->second = value; + return old_value; } + void updateInRead(const std::int64_t memAddr, const sigElement newValue) noexcept { read_cache[memAddr] = newValue; } + void updateInWrite(const std::int64_t memAddr, const sigElement newValue) noexcept { write_cache[memAddr] = newValue; } - void removeFromRead(const std::int64_t memAddr) { - read_cache[memAddr] = 0; - } + void removeFromRead(const std::int64_t memAddr) { read_cache[memAddr] = 0; } - void removeFromWrite(const std::int64_t memAddr) { - write_cache[memAddr] = 0; - } + void removeFromWrite(const std::int64_t memAddr) { write_cache[memAddr] = 0; } - std::unordered_set getAddrsInRange(const std::int64_t startAddr, - const std::int64_t endAddr) noexcept { + std::unordered_set getAddrsInRange(const std::int64_t startAddr, const std::int64_t endAddr) noexcept { std::unordered_set result{}; result.reserve(read_cache.size() + write_cache.size()); - for (const auto& pair : read_cache) { + for (const auto &pair : read_cache) { const auto addr = pair.first; if (addr >= startAddr && addr <= endAddr) { result.insert(addr); } } - for (const auto& pair : write_cache) { + for (const auto &pair : write_cache) { const auto addr = pair.first; if (addr >= startAddr && addr <= endAddr) { result.insert(addr); @@ -195,17 +260,69 @@ class PerfectShadow2 : public AbstractShadow { return result; } - const hashmap* getSigRead() const noexcept { - return &read_cache; + const hashmap *getSigRead() const noexcept { return &read_cache; } + + const hashmap *getSigWrite() const noexcept { return &write_cache; } + +#if DP_CALLSTACK_PROFILING + inline CallStack *getLastReadAccessCallStack(int64_t memAddr) { return (*addrToLastReadAccessCallStack)[memAddr]; } + + inline void setLastReadAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastReadAccessCallStack).find(memAddr); + if (got == (*addrToLastReadAccessCallStack).end()) { + // no entry exists + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastReadAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } + } + + inline void cleanReadAccessCallStack(int64_t memAddr) { + if ((*addrToLastReadAccessCallStack)[memAddr]) { + delete (*addrToLastReadAccessCallStack)[memAddr]; + (*addrToLastReadAccessCallStack)[memAddr] = nullptr; + } } - const hashmap* getSigWrite() const noexcept { - return &write_cache; + inline CallStack *getLastWriteAccessCallStack(int64_t memAddr) { return (*addrToLastWriteAccessCallStack)[memAddr]; } + + inline void setLastWriteAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastWriteAccessCallStack).find(memAddr); + if (got == (*addrToLastWriteAccessCallStack).end()) { + // no entry exists + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastWriteAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } + } + + inline void cleanWriteAccessCallStack(int64_t memAddr) { + if ((*addrToLastWriteAccessCallStack)[memAddr]) { + delete (*addrToLastWriteAccessCallStack)[memAddr]; + (*addrToLastWriteAccessCallStack)[memAddr] = nullptr; + } } +#endif private: hashmap read_cache{}; hashmap write_cache{}; +#if DP_CALLSTACK_PROFILING + std::unordered_map *addrToLastReadAccessCallStack; + std::unordered_map *addrToLastWriteAccessCallStack; +#endif }; } // namespace __dp diff --git a/rtlib/memory/Scope.hpp b/rtlib/memory/Scope.hpp index 97355a2f2..0c176d23d 100644 --- a/rtlib/memory/Scope.hpp +++ b/rtlib/memory/Scope.hpp @@ -15,11 +15,11 @@ #include "../DPTypes.hpp" #include +#include #include #include #include #include -#include namespace __dp { @@ -39,17 +39,11 @@ struct Scope { } } - unsigned long get_id() const noexcept { - return scope_id; - } + unsigned long get_id() const noexcept { return scope_id; } - const std::unordered_set& get_first_read() const noexcept { - return first_read; - } + const std::unordered_set &get_first_read() const noexcept { return first_read; } - const std::unordered_set& get_first_write() const noexcept { - return first_written; - } + const std::unordered_set &get_first_write() const noexcept { return first_written; } private: unsigned long scope_id; @@ -59,21 +53,13 @@ struct Scope { // Data structure for stack access management in scopes struct ScopeManager { - const Scope& getCurrentScope() { - return scopeStack.back(); - } + const Scope &getCurrentScope() { return scopeStack.back(); } - std::size_t number_open_scopes() const noexcept { - return scopeStack.size(); - } + std::size_t number_open_scopes() const noexcept { return scopeStack.size(); } - void enterScope(std::string type, LID debug_lid) { - scopeStack.push_back(Scope(next_scope_id++)); - } + void enterScope(std::string type, LID debug_lid) { scopeStack.push_back(Scope(next_scope_id++)); } - void leaveScope(std::string type, LID debug_lid) { - scopeStack.pop_back(); - } + void leaveScope(std::string type, LID debug_lid) { scopeStack.pop_back(); } void registerStackRead(ADDR address, LID debug_lid, const char *debug_var) { scopeStack.back().registerStackRead(address, debug_lid, debug_var); @@ -87,24 +73,24 @@ struct ScopeManager { bool isOwnedByScope(ADDR addr, bool currentAccessIsWrite) { // currentAccessIsWrite is used in case no access to addr has been - - // check for first_writes in previous scopes (i.e.: search for the "owner" of the stack variable) + + // check for first_writes in previous scopes (i.e.: search for the "owner" + // of the stack variable) int idx = 0; - for(auto scope: scopeStack){ - if(scope.get_first_write().count(addr) > 0){ - if(idx == scopeStack.size()-1){ + for (auto scope : scopeStack) { + if (scope.get_first_write().count(addr) > 0) { + if (idx == scopeStack.size() - 1) { return true; - } - else{ + } else { // scope variable "belongs" to a parent scope. - // Thus, it may not be considered a scope variable for the inner scope. + // Thus, it may not be considered a scope variable for the inner + // scope. return false; } } idx++; - } - + // registered already if (scopeStack.back().get_first_write().count(addr) > 0) { return true; @@ -159,7 +145,8 @@ struct Scope2 { void registerStackRead(ADDR address, LID debug_lid, char *debug_var) { const auto not_found = first_written.find(address) == first_written.end(); - // const auto not_found = std::find(first_written.begin(), first_written.end(), address) == first_written.end(); + // const auto not_found = std::find(first_written.begin(), + // first_written.end(), address) == first_written.end(); if (not_found) { first_read.insert(address); // first_read.emplace_back(address); @@ -168,24 +155,19 @@ struct Scope2 { void registerStackWrite(ADDR address, LID debug_lid, char *debug_var) { const auto not_found = first_read.find(address) == first_read.end(); - // const auto not_found = std::find(first_read.begin(), first_read.end(), address) == first_read.end(); + // const auto not_found = std::find(first_read.begin(), first_read.end(), + // address) == first_read.end(); if (not_found) { first_written.insert(address); // first_written.emplace_back(address); } } - unsigned long get_id() const noexcept { - return scope_id; - } + unsigned long get_id() const noexcept { return scope_id; } - const hashset& get_first_read() const noexcept { - return first_read; - } + const hashset &get_first_read() const noexcept { return first_read; } - const hashset& get_first_write() const noexcept { - return first_written; - } + const hashset &get_first_write() const noexcept { return first_written; } private: unsigned long scope_id; @@ -199,31 +181,23 @@ struct ScopeManager2 { addrToLastAccessScopeID.reserve(1024); } - const Scope2& getCurrentScope() const noexcept { - return scopeStack.back(); - } + const Scope2 &getCurrentScope() const noexcept { return scopeStack.back(); } - std::size_t number_open_scopes() const noexcept { - return scopeStack.size(); - } + std::size_t number_open_scopes() const noexcept { return scopeStack.size(); } - void enterScope(const char* type, LID debug_lid) { - scopeStack.emplace_back(next_scope_id++); - } + void enterScope(const char *type, LID debug_lid) { scopeStack.emplace_back(next_scope_id++); } - void leaveScope(const char* type, LID debug_lid) { - scopeStack.pop_back(); - } + void leaveScope(const char *type, LID debug_lid) { scopeStack.pop_back(); } void registerStackRead(ADDR address, LID debug_lid, char *debug_var) { - auto& current_scope = scopeStack.back(); + auto ¤t_scope = scopeStack.back(); current_scope.registerStackRead(address, debug_lid, debug_var); addrToLastAccessScopeID[address] = current_scope.get_id(); } void registerStackWrite(ADDR address, LID debug_lid, char *debug_var) { - auto& current_scope = scopeStack.back(); + auto ¤t_scope = scopeStack.back(); current_scope.registerStackWrite(address, debug_lid, debug_var); addrToLastAccessScopeID[address] = current_scope.get_id(); @@ -231,24 +205,24 @@ struct ScopeManager2 { bool isOwnedByScope(ADDR addr, bool currentAccessIsWrite) { // currentAccessIsWrite is used in case no access to addr has been - - // check for first_writes in previous scopes (i.e.: search for the "owner" of the stack variable) + + // check for first_writes in previous scopes (i.e.: search for the "owner" + // of the stack variable) int idx = 0; - for(auto scope: scopeStack){ - if(scope.get_first_write().count(addr) > 0){ - if(idx == scopeStack.size()-1){ + for (auto scope : scopeStack) { + if (scope.get_first_write().count(addr) > 0) { + if (idx == scopeStack.size() - 1) { return true; - } - else{ + } else { // scope variable "belongs" to a parent scope. - // Thus, it may not be considered a scope variable for the inner scope. + // Thus, it may not be considered a scope variable for the inner + // scope. return false; } } idx++; - } - + // registered already if (scopeStack.back().get_first_write().count(addr) > 0) { return true; diff --git a/rtlib/memory/ShadowMemory.hpp b/rtlib/memory/ShadowMemory.hpp index 187f24cc2..6a1b5330a 100644 --- a/rtlib/memory/ShadowMemory.hpp +++ b/rtlib/memory/ShadowMemory.hpp @@ -15,8 +15,8 @@ #include "AbstractShadow.hpp" #include "Signature.hpp" -#include #include +#include using namespace std; @@ -27,43 +27,97 @@ class ShadowMemory : public AbstractShadow { ShadowMemory(int slotSize, int size, int numHash) { sigRead = new Signature(slotSize, size, numHash); sigWrite = new Signature(slotSize, size, numHash); +#if DP_CALLSTACK_PROFILING + addrToLastReadAccessCallStack = new std::unordered_map(); + addrToLastWriteAccessCallStack = new std::unordered_map(); +#endif } ~ShadowMemory() { delete sigRead; delete sigWrite; - } - inline sigElement testInRead(std::int64_t memAddr) { - return sigRead->membershipCheck(memAddr); +#if DP_CALLSTACK_PROFILING + for (auto elem : *addrToLastReadAccessCallStack) { + cleanReadAccessCallStack(elem.first); + } + for (auto elem : *addrToLastWriteAccessCallStack) { + cleanWriteAccessCallStack(elem.first); + } + delete addrToLastReadAccessCallStack; + delete addrToLastWriteAccessCallStack; +#endif } - inline sigElement testInWrite(std::int64_t memAddr) { - return sigWrite->membershipCheck(memAddr); - } + inline sigElement testInRead(std::int64_t memAddr) { return sigRead->membershipCheck(memAddr); } - inline sigElement insertToRead(std::int64_t memAddr, sigElement value) { - return sigRead->insert(memAddr, value); - } + inline sigElement testInWrite(std::int64_t memAddr) { return sigWrite->membershipCheck(memAddr); } - inline sigElement insertToWrite(std::int64_t memAddr, sigElement value) { - return sigWrite->insert(memAddr, value); - } + inline sigElement insertToRead(std::int64_t memAddr, sigElement value) { return sigRead->insert(memAddr, value); } - inline void updateInRead(std::int64_t memAddr, sigElement newValue) { - sigRead->update(memAddr, newValue); - } + inline sigElement insertToWrite(std::int64_t memAddr, sigElement value) { return sigWrite->insert(memAddr, value); } - inline void updateInWrite(std::int64_t memAddr, sigElement newValue) { - sigWrite->update(memAddr, newValue); - } + inline void updateInRead(std::int64_t memAddr, sigElement newValue) { sigRead->update(memAddr, newValue); } + + inline void updateInWrite(std::int64_t memAddr, sigElement newValue) { sigWrite->update(memAddr, newValue); } inline void removeFromRead(std::int64_t memAddr) { sigRead->remove(memAddr); } inline void removeFromWrite(std::int64_t memAddr) { sigWrite->remove(memAddr); } - inline std::unordered_set getAddrsInRange(std::int64_t startAddr, - std::int64_t endAddr) { +#if DP_CALLSTACK_PROFILING + inline CallStack *getLastReadAccessCallStack(int64_t memAddr) { return (*addrToLastReadAccessCallStack)[memAddr]; } + + inline void setLastReadAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastReadAccessCallStack).find(memAddr); + if (got == (*addrToLastReadAccessCallStack).end()) { + // no entry exists + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastReadAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastReadAccessCallStack)[memAddr] = p_cs; + } + } + + inline void cleanReadAccessCallStack(int64_t memAddr) { + if ((*addrToLastReadAccessCallStack)[memAddr]) { + delete (*addrToLastReadAccessCallStack)[memAddr]; + (*addrToLastReadAccessCallStack)[memAddr] = nullptr; + } + } + + inline CallStack *getLastWriteAccessCallStack(int64_t memAddr) { return (*addrToLastWriteAccessCallStack)[memAddr]; } + + inline void setLastWriteAccessCallStack(int64_t memAddr, CallStack *p_cs) { + // check if entry exists already + std::unordered_map::const_iterator got = (*addrToLastWriteAccessCallStack).find(memAddr); + if (got == (*addrToLastWriteAccessCallStack).end()) { + // no entry exists + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } else { + // entry exists already. Cleanup the old CallStack and save the new one. + CallStack *p_old_cs = (CallStack *)(*addrToLastWriteAccessCallStack)[memAddr]; + if (p_old_cs) { + delete p_old_cs; + } + (*addrToLastWriteAccessCallStack)[memAddr] = p_cs; + } + } + + inline void cleanWriteAccessCallStack(int64_t memAddr) { + if ((*addrToLastWriteAccessCallStack)[memAddr]) { + delete (*addrToLastWriteAccessCallStack)[memAddr]; + (*addrToLastWriteAccessCallStack)[memAddr] = nullptr; + } + } +#endif + + inline std::unordered_set getAddrsInRange(std::int64_t startAddr, std::int64_t endAddr) { // not possible for Shadow, since not all addresses are kept std::unordered_set result; return result; @@ -72,6 +126,10 @@ class ShadowMemory : public AbstractShadow { private: Signature *sigRead; Signature *sigWrite; +#if DP_CALLSTACK_PROFILING + std::unordered_map *addrToLastReadAccessCallStack; + std::unordered_map *addrToLastWriteAccessCallStack; +#endif }; } // namespace __dp diff --git a/rtlib/memory/Signature.hpp b/rtlib/memory/Signature.hpp index 8b863b80f..e4d9252da 100644 --- a/rtlib/memory/Signature.hpp +++ b/rtlib/memory/Signature.hpp @@ -25,8 +25,7 @@ class Signature { public: Signature(std::int32_t slotSize, std::int32_t size, std::int32_t numOfHash = 1) : sigSlotSize(slotSize), numSlot(size), numHash(numOfHash) { - assert((slotSize % 8 == 0) && (slotSize <= 32 && slotSize >= 8) && - "slotSize must be byte aligned!"); + assert((slotSize % 8 == 0) && (slotSize <= 32 && slotSize >= 8) && "slotSize must be byte aligned!"); sigSlotSizeInByte = sigSlotSize / 8; sigSizeInByte = sigSlotSizeInByte * numSlot; @@ -64,9 +63,7 @@ class Signature { std::int32_t insertedElem; std::int32_t conflictElem; - std::uint32_t hash(std::int64_t value) { - return (std::uint32_t)((value >> 8) + value) % numSlot; - } + std::uint32_t hash(std::int64_t value) { return (std::uint32_t)((value >> 8) + value) % numSlot; } }; } // namespace __dp diff --git a/rtlib/simple-alias-detection/BinCallBack.hpp b/rtlib/simple-alias-detection/BinCallBack.hpp index e0b65865c..dda9a65f5 100644 --- a/rtlib/simple-alias-detection/BinCallBack.hpp +++ b/rtlib/simple-alias-detection/BinCallBack.hpp @@ -21,14 +21,11 @@ using namespace clang; class BinCallBack : public MatchFinder::MatchCallback { public: void run(const MatchFinder::MatchResult &r) override { - const clang::Stmt *simpleStatement = - r.Nodes.getNodeAs("simpleStatement"); + const clang::Stmt *simpleStatement = r.Nodes.getNodeAs("simpleStatement"); ASTContext *ctx = r.Context; - simpleStatement->getSourceRange().getBegin().print(llvm::outs(), - ctx->getSourceManager()); + simpleStatement->getSourceRange().getBegin().print(llvm::outs(), ctx->getSourceManager()); llvm::outs() << ": "; - simpleStatement->printPretty(llvm::outs(), nullptr, - ctx->getPrintingPolicy()); + simpleStatement->printPretty(llvm::outs(), nullptr, ctx->getPrintingPolicy()); llvm::outs() << "\n\n"; } }; diff --git a/rtlib/simple-alias-detection/main.cpp b/rtlib/simple-alias-detection/main.cpp index 0f99cf29c..8a5323e64 100644 --- a/rtlib/simple-alias-detection/main.cpp +++ b/rtlib/simple-alias-detection/main.cpp @@ -36,11 +36,9 @@ int main(int argc, const char **argv) { CommonOptionsParser op(argc, argv, SimpleStatement); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); StatementMatcher bin_stmt = - clang::ast_matchers::binaryOperator(anything(), isExpansionInMainFile()) - .bind("simpleStatement"); + clang::ast_matchers::binaryOperator(anything(), isExpansionInMainFile()).bind("simpleStatement"); StatementMatcher decl_stmt = - clang::ast_matchers::declStmt(anything(), isExpansionInMainFile()) - .bind("simpleStatement"); + clang::ast_matchers::declStmt(anything(), isExpansionInMainFile()).bind("simpleStatement"); MatchFinder finder; BinCallBack bin_cb; finder.addMatcher(bin_stmt, &bin_cb); diff --git a/scripts/dev/check-license.sh b/scripts/dev/check-license.sh index abea9ee4e..28af2511c 100755 --- a/scripts/dev/check-license.sh +++ b/scripts/dev/check-license.sh @@ -42,6 +42,7 @@ for file in "$@"; do [[ "$file" = *"build/"* ]] && continue [[ "$file" = *"LICENSE" ]] && continue [[ "$file" = *"VERSION" ]] && continue + [[ "$file" = *".clang-format" ]] && continue # third-party software [[ "$file" = *"third_party/"* ]] && continue diff --git a/scripts/dev/clang-format.sh b/scripts/dev/clang-format.sh index 558d41811..62221131e 100755 --- a/scripts/dev/clang-format.sh +++ b/scripts/dev/clang-format.sh @@ -1,36 +1,36 @@ -#!/usr/bin/env bash - -# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de) -# -# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany -# -# This software may be modified and distributed under the terms of -# the 3-Clause BSD License. See the LICENSE file in the package base -# directory for details. - -# This script executes clang-format on all C/C++ files in the project - -# Usage: ./clang-format.sh - -# change directory to discopop -cd ../.. - -# loop over all C/C++ source and header files in the project -C_CPP_FILES=$(find . -name *.c -or -name *.cpp -or -name *.h -or -name *.hpp) -for file in $C_CPP_FILES; do - # execute clang-format for each file - - # ignore third-party libraries - if [[ "$file" == "./third_party/"* ]]; then - echo "Skipping third-party file: $file" - continue - fi - - # ignore build folder - if [[ "$file" == "./build/"* ]]; then - echo "Skipping build file: $file" - continue - fi - - clang-format $file -i --verbose -done \ No newline at end of file +#!/usr/bin/env bash + +# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de) +# +# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany +# +# This software may be modified and distributed under the terms of +# the 3-Clause BSD License. See the LICENSE file in the package base +# directory for details. + +# This script executes clang-format on all C/C++ files in the project + +# Usage: ./clang-format.sh + +# change directory to discopop +cd ../.. + +# loop over all C/C++ source and header files in the project +C_CPP_FILES=$(find . -name *.c -or -name *.cpp -or -name *.h -or -name *.hpp) +for file in $C_CPP_FILES; do + # execute clang-format for each file + + # ignore third-party libraries + if [[ "$file" == "./third_party/"* ]]; then + echo "Skipping third-party file: $file" + continue + fi + + # ignore build folder + if [[ "$file" == "./build/"* ]]; then + echo "Skipping build file: $file" + continue + fi + + clang-format --style=file $file -i --verbose +done diff --git a/share/include/DPUtils.hpp b/share/include/DPUtils.hpp index 822e6f451..6bac01d57 100644 --- a/share/include/DPUtils.hpp +++ b/share/include/DPUtils.hpp @@ -63,11 +63,10 @@ #include #define LIDSIZE 14 // Number of bits for holding LID -#define LIDMETADATASIZE \ - 32 // Number of bits for holding LID Metadata (Column + Loop ID + Loop - // Iteration) -#define MAXLNO \ - 16384 // Maximum number of lines in a single file. Has to be 2^LIDSIZE. +#define LIDMETADATASIZE \ + 32 // Number of bits for holding LID Metadata (Column + Loop ID + Loop + // Iteration) +#define MAXLNO 16384 // Maximum number of lines in a single file. Has to be 2^LIDSIZE. typedef int64_t LID; typedef int64_t ADDR; diff --git a/share/include/debug_print.hpp b/share/include/debug_print.hpp index a4a7aab53..02776abf1 100644 --- a/share/include/debug_print.hpp +++ b/share/include/debug_print.hpp @@ -14,26 +14,22 @@ #include -template -class DebugPrint { +template class DebugPrint { public: - DebugPrint(const char message[N]) { - for (auto i = 0; i < N; i++) { - buffer[i] = message[i]; - } - - std::cout << "enter: " << buffer << '\n'; + DebugPrint(const char message[N]) { + for (auto i = 0; i < N; i++) { + buffer[i] = message[i]; } - ~DebugPrint() { - std::cout << "exit: " << buffer << '\n'; - } + std::cout << "enter: " << buffer << '\n'; + } + + ~DebugPrint() { std::cout << "exit: " << buffer << '\n'; } private: - char buffer[N]; + char buffer[N]; }; -template -inline DebugPrint make_debug_print(const char(&message)[N]) { - return DebugPrint(message); +template inline DebugPrint make_debug_print(const char (&message)[N]) { + return DebugPrint(message); } diff --git a/share/include/timer.hpp b/share/include/timer.hpp index 9c4bb7726..2a06e2115 100644 --- a/share/include/timer.hpp +++ b/share/include/timer.hpp @@ -16,274 +16,282 @@ #include #include #include +#include #include #include +#include /** * This type allows type-safe specification of a specific timer */ enum class TimerRegion : unsigned int { - // These are directly inserted calls - ADD_BB_DEPS = 0, - ALLOCA, - CALL, - DECL, - DELETE, - FINALIZE, - FUNC_ENTRY, - FUNC_EXIT, - LOOP_ENTRY, - LOOP_EXIT, - NEW, - READ, - REPORT_BB, - REPORT_BB_PAIR, - WRITE, - - // These are indirectly inserted calls - ADD_DEP, - GENERATE_STRING_DEP_MAP, - OUTPUT_DEPS, - OUTPUT_LOOPS, - OUTPUT_FUNCS, - OUTPUT_ALLOCATIONS, - READ_RUNTIME_INFO, - INIT_PARALLELIZATION, - GET_MEMORY_REGION_ID_FROM_ADDR, - MERGE_DEPS, - ANALYZE_DEPS, - ANALYZE_SINGLE_ACCESS, - FINALIZE_PARALLELIZATION, - CLEAR_STACK_ACCESSES, - - // These are statistics regarding stack access detection - STACK_CHECK_READ_ACCESS, - STACK_CHECK_WRITE_ACCESS, - STACK_FOUND_READ_ACCESS, - STACK_FOUND_WRITE_ACCESS, - STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE, - STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE_TRUE, - - SIZE_DONT_USE, + // These are directly inserted calls + ADD_BB_DEPS = 0, + ALLOCA, + CALL, + DECL, + DELETE, + FINALIZE, + FUNC_ENTRY, + FUNC_EXIT, + LOOP_ENTRY, + LOOP_EXIT, + NEW, + READ, + REPORT_BB, + REPORT_BB_PAIR, + WRITE, + + // These are indirectly inserted calls + ADD_DEP, + GENERATE_STRING_DEP_MAP, + OUTPUT_DEPS, + OUTPUT_LOOPS, + OUTPUT_FUNCS, + OUTPUT_ALLOCATIONS, + READ_RUNTIME_INFO, + INIT_PARALLELIZATION, + GET_MEMORY_REGION_ID_FROM_ADDR, + MERGE_DEPS, + ANALYZE_DEPS, + ANALYZE_SINGLE_ACCESS, + FINALIZE_PARALLELIZATION, + CLEAR_STACK_ACCESSES, + + // These are statistics regarding stack access detection + STACK_CHECK_READ_ACCESS, + STACK_CHECK_WRITE_ACCESS, + STACK_FOUND_READ_ACCESS, + STACK_FOUND_WRITE_ACCESS, + STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE, + STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE_TRUE, + + SIZE_DONT_USE, }; /** - * This number is used as a shortcut to count the number of values valid for TimerRegion + * This number is used as a shortcut to count the number of values valid for + * TimerRegion */ constexpr std::size_t NUMBER_TIMERS = static_cast(TimerRegion::SIZE_DONT_USE); /** - * This class is used to collect all sorts of different timers (see TimerRegion). - * It provides an interface to start, stop, and print the timers + * This class is used to collect all sorts of different timers (see + * TimerRegion). It provides an interface to start, stop, and print the timers */ class Timers { - using time_point = std::chrono::high_resolution_clock::time_point; - using index_type = std::vector::size_type; + using time_point = std::chrono::high_resolution_clock::time_point; + using index_type = std::vector::size_type; public: - Timers() { - time_start = std::vector { NUMBER_TIMERS }; - time_stop = std::vector { NUMBER_TIMERS }; - - number_called = std::vector (NUMBER_TIMERS, std::size_t(0)); - time_elapsed = std::vector{ NUMBER_TIMERS }; - } - - /** - * @brief Starts the respective timer - * @param timer The timer to start - */ - void start(const TimerRegion timer) { - const auto timer_id = get_timer_index(timer); - number_called[timer_id]++; - time_start[timer_id] = std::chrono::high_resolution_clock::now(); - } - - /** - * @brief Stops the respective timer - * @param timer The timer to stops - */ - void stop(const TimerRegion timer) { - const auto timer_id = get_timer_index(timer); - time_stop[timer_id] = std::chrono::high_resolution_clock::now(); - } - - /** - * @brief Stops the respective timer and adds the elapsed time - * @param timer The timer to stops - */ - void stop_and_add(const TimerRegion timer) { - stop(timer); - add_start_stop_diff_to_elapsed(timer); - } - - /** - * @brief Adds the difference between the current start and stop time points to the elapsed time - * @param timer The timer for which to add the difference - */ - void add_start_stop_diff_to_elapsed(const TimerRegion timer) { - const auto timer_id = get_timer_index(timer); - time_elapsed[timer_id] += (time_stop[timer_id] - time_start[timer_id]); - } - - /** - * @brief Resets the elapsed time for the timer - * @param timer The timer for which to reset the elapsed time - */ - void reset_elapsed(const TimerRegion timer) { - const auto timer_id = get_timer_index(timer); - time_elapsed[timer_id] = std::chrono::nanoseconds(0); - } - - /** - * @brief Returns the elapsed time for the respective timer - * @param timer The timer for which to return the elapsed time - * @return The elapsed time - */ - [[nodiscard]] std::chrono::nanoseconds get_elapsed(const TimerRegion timer) { - const auto timer_id = get_timer_index(timer); - return time_elapsed[timer_id]; - } - - /** - * @brief Prints a formatted output to the stream - * @param stream The out stream - */ - void print(std::ostream& stream) { - stream << "\n========== DiscoPoP TIMERS: Inserted calls ==========\n"; - print(stream, " Function call : ", TimerRegion::CALL); - print(stream, " Function entry : ", TimerRegion::FUNC_ENTRY); - print(stream, " Function exit : ", TimerRegion::FUNC_EXIT); - stream << '\n'; - print(stream, " Loop entry : ", TimerRegion::LOOP_ENTRY); - print(stream, " Loop exit : ", TimerRegion::LOOP_EXIT); - stream << '\n'; - print(stream, " Add basic block dependencies : ", TimerRegion::ADD_BB_DEPS); - print(stream, " Report a basic block : ", TimerRegion::REPORT_BB); - print(stream, " Report a pair of basic blocks : ", TimerRegion::REPORT_BB_PAIR); - stream << '\n'; - print(stream, " New memory on the stack : ", TimerRegion::ALLOCA); - print(stream, " New memory on the heap : ", TimerRegion::NEW); - print(stream, " Delete memory : ", TimerRegion::DELETE); - stream << '\n'; - print(stream, " Read from memory : ", TimerRegion::READ); - print(stream, " Write to memory : ", TimerRegion::WRITE); - stream << '\n'; - print(stream, " Decl : ", TimerRegion::DECL); - print(stream, " Finalize : ", TimerRegion::FINALIZE); - stream << '\n'; - - stream << "\n========== DiscoPoP TIMERS: Indirect calls ==========\n"; - print(stream, " Reading the runtime info : ", TimerRegion::READ_RUNTIME_INFO); - print(stream, " Initializing the parallelization : ", TimerRegion::INIT_PARALLELIZATION); - print(stream, " Finalizing the parallelization : ", TimerRegion::FINALIZE_PARALLELIZATION); - stream << '\n'; - print(stream, " Generate the dependency map : ", TimerRegion::GENERATE_STRING_DEP_MAP); - print(stream, " Add a dependency : ", TimerRegion::ADD_DEP); - print(stream, " Merge dendencies : ", TimerRegion::MERGE_DEPS); - print(stream, " Analyze the dependencies (incorrect!) : ", TimerRegion::ANALYZE_DEPS); // Incorrect due to multithreading - print(stream, " Analyze singe accesses : ", TimerRegion::ANALYZE_SINGLE_ACCESS); - stream << '\n'; - print(stream, " Output the dependencies : ", TimerRegion::OUTPUT_DEPS); - print(stream, " Output the loops : ", TimerRegion::OUTPUT_LOOPS); - print(stream, " Output the functions : ", TimerRegion::OUTPUT_FUNCS); - print(stream, " Output the allocations : ", TimerRegion::OUTPUT_ALLOCATIONS); - stream << '\n'; - print(stream, " Get memory region by id from address : ", TimerRegion::GET_MEMORY_REGION_ID_FROM_ADDR); - print(stream, " Clear the stack accesses : ", TimerRegion::CLEAR_STACK_ACCESSES); - stream << '\n'; - - stream << "\n========== DiscoPoP TIMERS: stack access detection ==\n"; - stream << " NOTE: times to detect stack access in read and write contained in \n"; - stream << " reported times to read and write from / to memory. \n"; - print(stream, " Check for read access to stack : ", TimerRegion::STACK_CHECK_READ_ACCESS); - print(stream, " Check for write access to stack : ", TimerRegion::STACK_CHECK_WRITE_ACCESS); - print(stream, " Found read access to stack : ", TimerRegion::STACK_FOUND_READ_ACCESS); - print(stream, " Found write access to stack : ", TimerRegion::STACK_FOUND_WRITE_ACCESS); - print(stream, " Check for addr is owned by scope : ", TimerRegion::STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE); - print(stream, " Found addr is owned by scope : ", TimerRegion::STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE_TRUE); - } - - /** - * @brief Returns the current time as a string - * @return The current time as a string - */ - [[nodiscard]] std::string wall_clock_time() { - // The time is printed with 24 interesting characters followed by '\n' - constexpr auto size_of_date_string = 24; + Timers() { + time_start = std::vector{NUMBER_TIMERS}; + time_stop = std::vector{NUMBER_TIMERS}; + + number_called = std::vector(NUMBER_TIMERS, std::size_t(0)); + time_elapsed = std::vector{NUMBER_TIMERS}; + } + + /** + * @brief Starts the respective timer + * @param timer The timer to start + */ + void start(const TimerRegion timer) { + const auto timer_id = get_timer_index(timer); + number_called[timer_id]++; + time_start[timer_id] = std::chrono::high_resolution_clock::now(); + } + + /** + * @brief Stops the respective timer + * @param timer The timer to stops + */ + void stop(const TimerRegion timer) { + const auto timer_id = get_timer_index(timer); + time_stop[timer_id] = std::chrono::high_resolution_clock::now(); + } + + /** + * @brief Stops the respective timer and adds the elapsed time + * @param timer The timer to stops + */ + void stop_and_add(const TimerRegion timer) { + stop(timer); + add_start_stop_diff_to_elapsed(timer); + } + + /** + * @brief Adds the difference between the current start and stop time points + * to the elapsed time + * @param timer The timer for which to add the difference + */ + void add_start_stop_diff_to_elapsed(const TimerRegion timer) { + const auto timer_id = get_timer_index(timer); + time_elapsed[timer_id] += (time_stop[timer_id] - time_start[timer_id]); + } + + /** + * @brief Resets the elapsed time for the timer + * @param timer The timer for which to reset the elapsed time + */ + void reset_elapsed(const TimerRegion timer) { + const auto timer_id = get_timer_index(timer); + time_elapsed[timer_id] = std::chrono::nanoseconds(0); + } + + /** + * @brief Returns the elapsed time for the respective timer + * @param timer The timer for which to return the elapsed time + * @return The elapsed time + */ + [[nodiscard]] std::chrono::nanoseconds get_elapsed(const TimerRegion timer) { + const auto timer_id = get_timer_index(timer); + return time_elapsed[timer_id]; + } + + /** + * @brief Prints a formatted output to the stream + * @param stream The out stream + */ + void print(std::ostream &stream) { + stream << "\n========== DiscoPoP TIMERS: Inserted calls ==========\n"; + print(stream, " Function call : ", TimerRegion::CALL); + print(stream, " Function entry : ", TimerRegion::FUNC_ENTRY); + print(stream, " Function exit : ", TimerRegion::FUNC_EXIT); + stream << '\n'; + print(stream, " Loop entry : ", TimerRegion::LOOP_ENTRY); + print(stream, " Loop exit : ", TimerRegion::LOOP_EXIT); + stream << '\n'; + print(stream, " Add basic block dependencies : ", TimerRegion::ADD_BB_DEPS); + print(stream, " Report a basic block : ", TimerRegion::REPORT_BB); + print(stream, " Report a pair of basic blocks : ", TimerRegion::REPORT_BB_PAIR); + stream << '\n'; + print(stream, " New memory on the stack : ", TimerRegion::ALLOCA); + print(stream, " New memory on the heap : ", TimerRegion::NEW); + print(stream, " Delete memory : ", TimerRegion::DELETE); + stream << '\n'; + print(stream, " Read from memory : ", TimerRegion::READ); + print(stream, " Write to memory : ", TimerRegion::WRITE); + stream << '\n'; + print(stream, " Decl : ", TimerRegion::DECL); + print(stream, " Finalize : ", TimerRegion::FINALIZE); + stream << '\n'; + + stream << "\n========== DiscoPoP TIMERS: Indirect calls ==========\n"; + print(stream, " Reading the runtime info : ", TimerRegion::READ_RUNTIME_INFO); + print(stream, " Initializing the parallelization : ", TimerRegion::INIT_PARALLELIZATION); + print(stream, " Finalizing the parallelization : ", TimerRegion::FINALIZE_PARALLELIZATION); + stream << '\n'; + print(stream, " Generate the dependency map : ", TimerRegion::GENERATE_STRING_DEP_MAP); + print(stream, " Add a dependency : ", TimerRegion::ADD_DEP); + print(stream, " Merge dendencies : ", TimerRegion::MERGE_DEPS); + print(stream, " Analyze the dependencies (incorrect!) : ", + TimerRegion::ANALYZE_DEPS); // Incorrect due to multithreading + print(stream, " Analyze singe accesses : ", TimerRegion::ANALYZE_SINGLE_ACCESS); + stream << '\n'; + print(stream, " Output the dependencies : ", TimerRegion::OUTPUT_DEPS); + print(stream, " Output the loops : ", TimerRegion::OUTPUT_LOOPS); + print(stream, " Output the functions : ", TimerRegion::OUTPUT_FUNCS); + print(stream, " Output the allocations : ", TimerRegion::OUTPUT_ALLOCATIONS); + stream << '\n'; + print(stream, " Get memory region by id from address : ", TimerRegion::GET_MEMORY_REGION_ID_FROM_ADDR); + print(stream, " Clear the stack accesses : ", TimerRegion::CLEAR_STACK_ACCESSES); + stream << '\n'; + + stream << "\n========== DiscoPoP TIMERS: stack access detection ==\n"; + stream << " NOTE: times to detect stack access in read and write contained " + "in \n"; + stream << " reported times to read and write from / to memory. \n"; + print(stream, " Check for read access to stack : ", TimerRegion::STACK_CHECK_READ_ACCESS); + print(stream, " Check for write access to stack : ", TimerRegion::STACK_CHECK_WRITE_ACCESS); + print(stream, " Found read access to stack : ", TimerRegion::STACK_FOUND_READ_ACCESS); + print(stream, " Found write access to stack : ", TimerRegion::STACK_FOUND_WRITE_ACCESS); + print(stream, + " Check for addr is owned by scope : ", TimerRegion::STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE); + print(stream, + " Found addr is owned by scope : ", TimerRegion::STACK_CHECK_ADDR_IS_OWNED_BY_SCOPE_TRUE); + } + + /** + * @brief Returns the current time as a string + * @return The current time as a string + */ + [[nodiscard]] std::string wall_clock_time() { + // The time is printed with 24 interesting characters followed by '\n' + constexpr auto size_of_date_string = 24; #ifdef __linux__ - time_t raw_time = 0; - time(&raw_time); - // NOLINTNEXTLINE - struct tm* time_info = localtime(&raw_time); - // NOLINTNEXTLINE - char* string = asctime(time_info); - - // Avoid '\n' - return std::string(string, size_of_date_string); + time_t raw_time = 0; + time(&raw_time); + // NOLINTNEXTLINE + struct tm *time_info = localtime(&raw_time); + // NOLINTNEXTLINE + char *string = asctime(time_info); + + // Avoid '\n' + return std::string(string, size_of_date_string); #else - time_t raw_time = 0; - struct tm time_info; + time_t raw_time = 0; + struct tm time_info; - // Need some more space for '\n' and other checks - char char_buff[size_of_date_string + 3]; + // Need some more space for '\n' and other checks + char char_buff[size_of_date_string + 3]; - time(&raw_time); - localtime_s(&time_info, &raw_time); - asctime_s(char_buff, &time_info); + time(&raw_time); + localtime_s(&time_info, &raw_time); + asctime_s(char_buff, &time_info); - // Avoid '\n' - return std::string(char_buff, size_of_date_string); + // Avoid '\n' + return std::string(char_buff, size_of_date_string); #endif - } + } private: - /** - * @brief Casts the value of timer to an index for the vectors - * @param timer The timer as an enum value - * @result The timer as an index - */ - [[nodiscard]] index_type get_timer_index(const TimerRegion timer) noexcept { - const auto timer_id = static_cast(timer); - return timer_id; - } + /** + * @brief Casts the value of timer to an index for the vectors + * @param timer The timer as an enum value + * @result The timer as an index + */ + [[nodiscard]] index_type get_timer_index(const TimerRegion timer) noexcept { + const auto timer_id = static_cast(timer); + return timer_id; + } - void print(std::ostream& stream, const char* message, const TimerRegion region) { - const auto index = get_timer_index(region); + void print(std::ostream &stream, const char *message, const TimerRegion region) { + const auto index = get_timer_index(region); - const auto counted = time_elapsed[index].count(); - const auto seconds = static_cast(counted) * 1e-9; + const auto counted = time_elapsed[index].count(); + const auto seconds = static_cast(counted) * 1e-9; - const auto called = number_called[index]; + const auto called = number_called[index]; - stream << message << std::setw(8) << std::fixed << seconds << "\t(" << called << " times called)\n"; - } + stream << message << std::setw(8) << std::fixed << seconds << "\t(" << called << " times called)\n"; + } - std::vector time_start; - std::vector time_stop; + std::vector time_start; + std::vector time_stop; - std::vector number_called; - std::vector time_elapsed; + std::vector number_called; + std::vector time_elapsed; }; class Timer { public: - Timer(Timers* timers, TimerRegion region, bool also_print = false) - : timers(timers), region(region), print(also_print) { - assert(timers != nullptr && "Timer started but timers is nullptr"); - timers->start(region); + Timer(Timers *timers, TimerRegion region, bool also_print = false) + : timers(timers), region(region), print(also_print) { + assert(timers != nullptr && "Timer started but timers is nullptr"); + timers->start(region); + } + + ~Timer() { + timers->stop_and_add(region); + if (print) { + timers->print(std::cout); } + } - ~Timer() { - timers->stop_and_add(region); - if (print) { - timers->print(std::cout); - } - } - private: - Timers* timers; - TimerRegion region; - bool print; + Timers *timers; + TimerRegion region; + bool print; }; diff --git a/share/lib/DPUtils.cpp b/share/lib/DPUtils.cpp index 174399b22..9aa7771a3 100644 --- a/share/lib/DPUtils.cpp +++ b/share/lib/DPUtils.cpp @@ -20,11 +20,11 @@ using namespace std; // cl::Hidden); string FileMappingPath = ""; -cl::opt DP_MEMORY_PROFILING_SKIP_FUNCTION_ARGUMENTS( - "memory-profiling-skip-function-arguments", cl::init(false), - cl::desc("disable the memory profiling for allocations which belong to " - "function arguments"), - cl::Hidden); +cl::opt + DP_MEMORY_PROFILING_SKIP_FUNCTION_ARGUMENTS("memory-profiling-skip-function-arguments", cl::init(false), + cl::desc("disable the memory profiling for allocations which belong to " + "function arguments"), + cl::Hidden); namespace dputil { @@ -46,7 +46,6 @@ int32_t getFileID(string fileMapping, string fullPathName) { { return 0; } - int tempfid = 1; fstream fileMappingFile; @@ -200,16 +199,14 @@ void determineFileID(Function &F, int32_t &fileID) { File = Loc->getFilename(); Dir = Loc->getDirectory(); - char *absolutePathFileName = - realpath((Dir.str() + "/" + File.str()).c_str(), NULL); + char *absolutePathFileName = realpath((Dir.str() + "/" + File.str()).c_str(), NULL); if (absolutePathFileName == NULL) { absolutePathFileName = realpath(File.data(), NULL); } if (absolutePathFileName) { - fileID = dputil::getFileID(FileMappingPath, - string(absolutePathFileName)); + fileID = dputil::getFileID(FileMappingPath, string(absolutePathFileName)); delete[] absolutePathFileName; } break; @@ -364,8 +361,7 @@ string VariableNameFinder::getVarName(Value const *V) { } if (const GEPOperator *gepo = dyn_cast(V)) { - if (const GlobalVariable *gv = - dyn_cast(gepo->getPointerOperand())) { + if (const GlobalVariable *gv = dyn_cast(gepo->getPointerOperand())) { string r = gv->getGlobalIdentifier(); Type *st = gepo->getSourceElementType(); if (StructType *ct = dyn_cast(st)) { diff --git a/test/do_all/calls/LULESH_proxy/src/code.cpp b/test/do_all/calls/LULESH_proxy/src/code.cpp index 658821937..14d1ceace 100644 --- a/test/do_all/calls/LULESH_proxy/src/code.cpp +++ b/test/do_all/calls/LULESH_proxy/src/code.cpp @@ -11,8 +11,8 @@ class Domain { double *arr_fz; public: - void setPointers(double *arg_arr_x, double *arg_arr_y, double *arg_arr_z, - double *arg_fx, double *arg_fy, double *arg_fz) { + void setPointers(double *arg_arr_x, double *arg_arr_y, double *arg_arr_z, double *arg_fx, double *arg_fy, + double *arg_fz) { arr_x = arg_arr_x; arr_y = arg_arr_y; arr_z = arg_arr_z; @@ -34,11 +34,8 @@ class Domain { double &fz(int idx) { return arr_fz[idx]; } }; -static inline void CollectDomainNodesToElemNodes(Domain domain, - const short *elemToNode, - double elemX[8], - double elemY[8], - double elemZ[8]) { +static inline void CollectDomainNodesToElemNodes(Domain domain, const short *elemToNode, double elemX[8], + double elemY[8], double elemZ[8]) { short nd0i = elemToNode[0]; short nd1i = elemToNode[1]; short nd2i = elemToNode[2]; @@ -76,10 +73,7 @@ static inline void CollectDomainNodesToElemNodes(Domain domain, elemZ[7] = domain.z(nd7i); } -static inline void CalcElemShapeFunctionDerivatives(double const x[], - double const y[], - double const z[], - double b[][8], +static inline void CalcElemShapeFunctionDerivatives(double const x[], double const y[], double const z[], double b[][8], double *const volume) { const double x0 = x[0]; const double x1 = x[1]; @@ -166,13 +160,12 @@ static inline void CalcElemShapeFunctionDerivatives(double const x[], *volume = double(8.) * (fjxet * cjxet + fjyet * cjyet + fjzet * cjzet); } -static inline void SumElemFaceNormal( - double *normalX0, double *normalY0, double *normalZ0, double *normalX1, - double *normalY1, double *normalZ1, double *normalX2, double *normalY2, - double *normalZ2, double *normalX3, double *normalY3, double *normalZ3, - const double x0, const double y0, const double z0, const double x1, - const double y1, const double z1, const double x2, const double y2, - const double z2, const double x3, const double y3, const double z3) { +static inline void SumElemFaceNormal(double *normalX0, double *normalY0, double *normalZ0, double *normalX1, + double *normalY1, double *normalZ1, double *normalX2, double *normalY2, + double *normalZ2, double *normalX3, double *normalY3, double *normalZ3, + const double x0, const double y0, const double z0, const double x1, + const double y1, const double z1, const double x2, const double y2, + const double z2, const double x3, const double y3, const double z3) { double bisectX0 = double(0.5) * (x3 + x2 - x1 - x0); double bisectY0 = double(0.5) * (y3 + y2 - y1 - y0); double bisectZ0 = double(0.5) * (z3 + z2 - z1 - z0); @@ -199,8 +192,7 @@ static inline void SumElemFaceNormal( *normalZ3 += areaZ; } -static inline void CalcElemNodeNormals(double pfx[8], double pfy[8], - double pfz[8], const double x[8], +static inline void CalcElemNodeNormals(double pfx[8], double pfy[8], double pfz[8], const double x[8], const double y[8], const double z[8]) { for (int i = 0; i < 8; ++i) { pfx[i] = double(0.0); @@ -208,41 +200,27 @@ static inline void CalcElemNodeNormals(double pfx[8], double pfy[8], pfz[i] = double(0.0); } /* evaluate face one: nodes 0, 1, 2, 3 */ - SumElemFaceNormal(&pfx[0], &pfy[0], &pfz[0], &pfx[1], &pfy[1], &pfz[1], - &pfx[2], &pfy[2], &pfz[2], &pfx[3], &pfy[3], &pfz[3], x[0], - y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], x[3], y[3], - z[3]); + SumElemFaceNormal(&pfx[0], &pfy[0], &pfz[0], &pfx[1], &pfy[1], &pfz[1], &pfx[2], &pfy[2], &pfz[2], &pfx[3], &pfy[3], + &pfz[3], x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], x[3], y[3], z[3]); /* evaluate face two: nodes 0, 4, 5, 1 */ - SumElemFaceNormal(&pfx[0], &pfy[0], &pfz[0], &pfx[4], &pfy[4], &pfz[4], - &pfx[5], &pfy[5], &pfz[5], &pfx[1], &pfy[1], &pfz[1], x[0], - y[0], z[0], x[4], y[4], z[4], x[5], y[5], z[5], x[1], y[1], - z[1]); + SumElemFaceNormal(&pfx[0], &pfy[0], &pfz[0], &pfx[4], &pfy[4], &pfz[4], &pfx[5], &pfy[5], &pfz[5], &pfx[1], &pfy[1], + &pfz[1], x[0], y[0], z[0], x[4], y[4], z[4], x[5], y[5], z[5], x[1], y[1], z[1]); /* evaluate face three: nodes 1, 5, 6, 2 */ - SumElemFaceNormal(&pfx[1], &pfy[1], &pfz[1], &pfx[5], &pfy[5], &pfz[5], - &pfx[6], &pfy[6], &pfz[6], &pfx[2], &pfy[2], &pfz[2], x[1], - y[1], z[1], x[5], y[5], z[5], x[6], y[6], z[6], x[2], y[2], - z[2]); + SumElemFaceNormal(&pfx[1], &pfy[1], &pfz[1], &pfx[5], &pfy[5], &pfz[5], &pfx[6], &pfy[6], &pfz[6], &pfx[2], &pfy[2], + &pfz[2], x[1], y[1], z[1], x[5], y[5], z[5], x[6], y[6], z[6], x[2], y[2], z[2]); /* evaluate face four: nodes 2, 6, 7, 3 */ - SumElemFaceNormal(&pfx[2], &pfy[2], &pfz[2], &pfx[6], &pfy[6], &pfz[6], - &pfx[7], &pfy[7], &pfz[7], &pfx[3], &pfy[3], &pfz[3], x[2], - y[2], z[2], x[6], y[6], z[6], x[7], y[7], z[7], x[3], y[3], - z[3]); + SumElemFaceNormal(&pfx[2], &pfy[2], &pfz[2], &pfx[6], &pfy[6], &pfz[6], &pfx[7], &pfy[7], &pfz[7], &pfx[3], &pfy[3], + &pfz[3], x[2], y[2], z[2], x[6], y[6], z[6], x[7], y[7], z[7], x[3], y[3], z[3]); /* evaluate face five: nodes 3, 7, 4, 0 */ - SumElemFaceNormal(&pfx[3], &pfy[3], &pfz[3], &pfx[7], &pfy[7], &pfz[7], - &pfx[4], &pfy[4], &pfz[4], &pfx[0], &pfy[0], &pfz[0], x[3], - y[3], z[3], x[7], y[7], z[7], x[4], y[4], z[4], x[0], y[0], - z[0]); + SumElemFaceNormal(&pfx[3], &pfy[3], &pfz[3], &pfx[7], &pfy[7], &pfz[7], &pfx[4], &pfy[4], &pfz[4], &pfx[0], &pfy[0], + &pfz[0], x[3], y[3], z[3], x[7], y[7], z[7], x[4], y[4], z[4], x[0], y[0], z[0]); /* evaluate face six: nodes 4, 7, 6, 5 */ - SumElemFaceNormal(&pfx[4], &pfy[4], &pfz[4], &pfx[7], &pfy[7], &pfz[7], - &pfx[6], &pfy[6], &pfz[6], &pfx[5], &pfy[5], &pfz[5], x[4], - y[4], z[4], x[7], y[7], z[7], x[6], y[6], z[6], x[5], y[5], - z[5]); + SumElemFaceNormal(&pfx[4], &pfy[4], &pfz[4], &pfx[7], &pfy[7], &pfz[7], &pfx[6], &pfy[6], &pfz[6], &pfx[5], &pfy[5], + &pfz[5], x[4], y[4], z[4], x[7], y[7], z[7], x[6], y[6], z[6], x[5], y[5], z[5]); } -static inline void -SumElemStressesToNodeForces(const double B[][8], const double stress_xx, - const double stress_yy, const double stress_zz, - double fx[], double fy[], double fz[]) { +static inline void SumElemStressesToNodeForces(const double B[][8], const double stress_xx, const double stress_yy, + const double stress_zz, double fx[], double fy[], double fz[]) { for (int i = 0; i < 8; i++) { fx[i] = -(stress_xx * B[0][i]); fy[i] = -(stress_yy * B[1][i]); @@ -277,16 +255,14 @@ int main(int argc, const char *argv[]) { short elemToNode[8] = {4, 3, 2, 1, 5, 6, 7, 0}; // get nodal coordinates from global arrays and copy into local arrays. - CollectDomainNodesToElemNodes(domain, elemToNode, x_local, y_local, - z_local); + CollectDomainNodesToElemNodes(domain, elemToNode, x_local, y_local, z_local); // Volume calculation involves extra work for numerical consistency CalcElemShapeFunctionDerivatives(x_local, y_local, z_local, B, &volumes[k]); CalcElemNodeNormals(B[0], B[1], B[2], x_local, y_local, z_local); - SumElemStressesToNodeForces(B, sigxx, sigyy, sigzz, fx_local, fy_local, - fz_local); + SumElemStressesToNodeForces(B, sigxx, sigyy, sigzz, fx_local, fy_local, fz_local); // copy nodal force contributions to global force arrray. for (int lnode = 0; lnode < 8; ++lnode) { diff --git a/test/do_all/calls/above_nesting_level_3/__init__.py b/test/do_all/calls/above_nesting_level_3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/do_all/calls/above_nesting_level_3/src/Makefile b/test/do_all/calls/above_nesting_level_3/src/Makefile new file mode 100644 index 000000000..a64882be3 --- /dev/null +++ b/test/do_all/calls/above_nesting_level_3/src/Makefile @@ -0,0 +1,17 @@ +all: clean prog + +prog: code.o + $(CXX) -o prog code.o $(CXXFLAGS) + +code.o: + $(CXX) -c -S -emit-llvm -o code.ll code.cpp $(CXXFLAGS) + rm -rf .discopop + $(CXX) -c -o code.o code.cpp $(CXXFLAGS) + +clean: + rm -rf .discopop + rm -rf src/.discopop + find . -not -name code.cpp -not -name Makefile -not -path **/FileMapping.txt -delete + +veryclean: clean + rm -f FileMapping.txt diff --git a/test/do_all/calls/above_nesting_level_3/src/code.cpp b/test/do_all/calls/above_nesting_level_3/src/code.cpp new file mode 100644 index 000000000..37cc38427 --- /dev/null +++ b/test/do_all/calls/above_nesting_level_3/src/code.cpp @@ -0,0 +1,30 @@ +#include +#include + +int allowing_doall(double tmp[], int i) { + int sum = 0; + for (int n = 0; n < i; n++) { + sum = tmp[i]; + } + return sum; +} + +int main(int argc, const char *argv[]) { + static int n = 4000; + double *x = (double *)malloc(n * sizeof(double)); + // Initialize x, y + // DOALL + for (int i = 0; i < n; i++) { + x[i] = 1.0; + } + for (int k = 0; k < 20; k++) { + for (int j = 0; j < 20; j++) { + for (int i = 0; i < n / (20 * 20); ++i) { + int sum = allowing_doall(x + k * (n / 20) + j * (n / (20 * 20)) + i, (n / (20 * 20)) - i); + } + } + } + + free(x); + return 0; +} diff --git a/test/do_all/calls/above_nesting_level_3/test.py b/test/do_all/calls/above_nesting_level_3/test.py new file mode 100644 index 000000000..999c59d34 --- /dev/null +++ b/test/do_all/calls/above_nesting_level_3/test.py @@ -0,0 +1,69 @@ +import os +import pathlib +import unittest + +import jsonpickle + +from discopop_library.result_classes.DetectionResult import DetectionResult +from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd +from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation +from discopop_library.ConfigProvider.config_provider import run as run_config_provider +from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments + + +class TestMethods(unittest.TestCase): + def test(self): + current_dir = pathlib.Path(__file__).parent.resolve() + dp_build_dir = run_config_provider( + ConfigProviderArguments( + return_dp_build_dir=True, + return_dp_source_dir=False, + return_llvm_bin_dir=False, + return_version_string=False, + ) + ) + + env_vars = dict(os.environ) + + src_dir = os.path.join(current_dir, "src") + + # create FileMapping + cmd = os.path.join(dp_build_dir, "scripts", "dp-fmap") + run_cmd(cmd, src_dir, env_vars) + + # build + env_vars["CC"] = os.path.join(dp_build_dir, "scripts", "CC_wrapper.sh") + env_vars["CXX"] = os.path.join(dp_build_dir, "scripts", "CXX_wrapper.sh") + cmd = "make" + run_cmd(cmd, src_dir, env_vars) + # execute instrumented program + cmd = "./prog" + run_cmd(cmd, src_dir, env_vars) + # execute DiscoPoP analysis + cwd = os.path.join(src_dir, ".discopop") + cmd = "discopop_explorer --enable-patterns doall,reduction" + run_cmd(cmd, cwd, env_vars) + # validate results + try: + self.validate_results(current_dir, src_dir) + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + except Exception as ex: + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + raise ex + + def validate_results(self, test_dir, src_dir): + """Check that exactly one do-all is suggested""" + test_output_file = os.path.join(src_dir, ".discopop", "explorer", "detection_result_dump.json") + # load detection results + with open(test_output_file, "r") as f: + tmp_str = f.read() + test_output: DetectionResult = jsonpickle.decode(tmp_str) + + for pattern_type in test_output.patterns.__dict__: + amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type]) + if pattern_type == "do_all": + self.assertEqual(amount_of_identified_patterns, 5) + else: + self.assertEqual(amount_of_identified_patterns, 0) diff --git a/test/do_all/calls/allowing_2/__init__.py b/test/do_all/calls/allowing_2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/do_all/calls/allowing_2/src/Makefile b/test/do_all/calls/allowing_2/src/Makefile new file mode 100644 index 000000000..a64882be3 --- /dev/null +++ b/test/do_all/calls/allowing_2/src/Makefile @@ -0,0 +1,17 @@ +all: clean prog + +prog: code.o + $(CXX) -o prog code.o $(CXXFLAGS) + +code.o: + $(CXX) -c -S -emit-llvm -o code.ll code.cpp $(CXXFLAGS) + rm -rf .discopop + $(CXX) -c -o code.o code.cpp $(CXXFLAGS) + +clean: + rm -rf .discopop + rm -rf src/.discopop + find . -not -name code.cpp -not -name Makefile -not -path **/FileMapping.txt -delete + +veryclean: clean + rm -f FileMapping.txt diff --git a/test/do_all/calls/allowing_2/src/code.cpp b/test/do_all/calls/allowing_2/src/code.cpp new file mode 100644 index 000000000..46df5a80a --- /dev/null +++ b/test/do_all/calls/allowing_2/src/code.cpp @@ -0,0 +1,23 @@ +#include +#include + +int allowing_doall(double tmp[], int i) { + int sum = 0; + for (int n = 0; n < i; n++) { + sum = tmp[i]; + } + return sum; +} + +int main(int argc, const char *argv[]) { + static int n = 1000; + double *x = (double *)malloc(n * sizeof(double)); + // Initialize x, y + // DOALL + for (int i = 0; i < n; ++i) { + x[i] = 1.0; + int sum = allowing_doall(x + i, n - i); + } + free(x); + return 0; +} diff --git a/test/do_all/calls/allowing_2/test.py b/test/do_all/calls/allowing_2/test.py new file mode 100644 index 000000000..1419ca8e3 --- /dev/null +++ b/test/do_all/calls/allowing_2/test.py @@ -0,0 +1,69 @@ +import os +import pathlib +import unittest + +import jsonpickle + +from discopop_library.result_classes.DetectionResult import DetectionResult +from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd +from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation +from discopop_library.ConfigProvider.config_provider import run as run_config_provider +from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments + + +class TestMethods(unittest.TestCase): + def test(self): + current_dir = pathlib.Path(__file__).parent.resolve() + dp_build_dir = run_config_provider( + ConfigProviderArguments( + return_dp_build_dir=True, + return_dp_source_dir=False, + return_llvm_bin_dir=False, + return_version_string=False, + ) + ) + + env_vars = dict(os.environ) + + src_dir = os.path.join(current_dir, "src") + + # create FileMapping + cmd = os.path.join(dp_build_dir, "scripts", "dp-fmap") + run_cmd(cmd, src_dir, env_vars) + + # build + env_vars["CC"] = os.path.join(dp_build_dir, "scripts", "CC_wrapper.sh") + env_vars["CXX"] = os.path.join(dp_build_dir, "scripts", "CXX_wrapper.sh") + cmd = "make" + run_cmd(cmd, src_dir, env_vars) + # execute instrumented program + cmd = "./prog" + run_cmd(cmd, src_dir, env_vars) + # execute DiscoPoP analysis + cwd = os.path.join(src_dir, ".discopop") + cmd = "discopop_explorer --enable-patterns doall,reduction" + run_cmd(cmd, cwd, env_vars) + # validate results + try: + self.validate_results(current_dir, src_dir) + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + except Exception as ex: + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + raise ex + + def validate_results(self, test_dir, src_dir): + """Check that exactly one do-all is suggested""" + test_output_file = os.path.join(src_dir, ".discopop", "explorer", "detection_result_dump.json") + # load detection results + with open(test_output_file, "r") as f: + tmp_str = f.read() + test_output: DetectionResult = jsonpickle.decode(tmp_str) + + for pattern_type in test_output.patterns.__dict__: + amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type]) + if pattern_type == "do_all": + self.assertEqual(amount_of_identified_patterns, 2) + else: + self.assertEqual(amount_of_identified_patterns, 0) diff --git a/test/do_all/negative/nested/OMPSCR/c_Mandelbrot/src/code.cpp b/test/do_all/negative/nested/OMPSCR/c_Mandelbrot/src/code.cpp index 76abd260f..006b01bae 100644 --- a/test/do_all/negative/nested/OMPSCR/c_Mandelbrot/src/code.cpp +++ b/test/do_all/negative/nested/OMPSCR/c_Mandelbrot/src/code.cpp @@ -27,12 +27,10 @@ COMMENTS TO: sande@csi.ull.es DESCRIPTION: This program computes an estimation to the Mandelbrot Set area using MonteCarlo sampling. - The best known estimate so far is 1.50659177 +- 0.00000008. - COMMENTS: The Mandelbrot set is a fractal that is defined as the -set of points c in the complex plane for which the sequence z_{n+1} = z_n^2 + c - with z_0 = 0 does not tend to infinity. - The area of the Mandelbrot set is an open question that has -been discussed in the recent past. It is not easy to obtain an accurate + The best known estimate so far +is 1.50659177 +- 0.00000008. COMMENTS: The Mandelbrot set is a fractal that is defined as the set of points c +in the complex plane for which the sequence z_{n+1} = z_n^2 + c with z_0 = 0 does not tend to infinity. The area of the +Mandelbrot set is an open question that has been discussed in the recent past. It is not easy to obtain an accurate analytical estimate, and therefore statistical methods have been used. The program explores the rectangle ranging over (-2.0, 0.5) in the real axis and (0.0, 1.125) in the imaginary axis. This rectangle covers the top half of the diff --git a/test/reduction_pattern/positive/nested/OMPSCR/c_Mandelbrot/src/code.cpp b/test/reduction_pattern/positive/nested/OMPSCR/c_Mandelbrot/src/code.cpp index 76abd260f..006b01bae 100644 --- a/test/reduction_pattern/positive/nested/OMPSCR/c_Mandelbrot/src/code.cpp +++ b/test/reduction_pattern/positive/nested/OMPSCR/c_Mandelbrot/src/code.cpp @@ -27,12 +27,10 @@ COMMENTS TO: sande@csi.ull.es DESCRIPTION: This program computes an estimation to the Mandelbrot Set area using MonteCarlo sampling. - The best known estimate so far is 1.50659177 +- 0.00000008. - COMMENTS: The Mandelbrot set is a fractal that is defined as the -set of points c in the complex plane for which the sequence z_{n+1} = z_n^2 + c - with z_0 = 0 does not tend to infinity. - The area of the Mandelbrot set is an open question that has -been discussed in the recent past. It is not easy to obtain an accurate + The best known estimate so far +is 1.50659177 +- 0.00000008. COMMENTS: The Mandelbrot set is a fractal that is defined as the set of points c +in the complex plane for which the sequence z_{n+1} = z_n^2 + c with z_0 = 0 does not tend to infinity. The area of the +Mandelbrot set is an open question that has been discussed in the recent past. It is not easy to obtain an accurate analytical estimate, and therefore statistical methods have been used. The program explores the rectangle ranging over (-2.0, 0.5) in the real axis and (0.0, 1.125) in the imaginary axis. This rectangle covers the top half of the diff --git a/test/unit_tests/loops/loop_counter/test_loop_counter.cpp b/test/unit_tests/loops/loop_counter/test_loop_counter.cpp index 39d31995f..993695ef0 100644 --- a/test/unit_tests/loops/loop_counter/test_loop_counter.cpp +++ b/test/unit_tests/loops/loop_counter/test_loop_counter.cpp @@ -4,41 +4,41 @@ // Tests for old version (i.e., capturing functionality) -class LoopCounterTest : public ::testing::Test { }; +class LoopCounterTest : public ::testing::Test {}; TEST_F(LoopCounterTest, testInit) { - const auto lc = __dp::LoopCounter{}; + const auto lc = __dp::LoopCounter{}; - const auto loop_counters = lc.get_loop_counters(); - EXPECT_EQ(loop_counters.size(), 0); + const auto loop_counters = lc.get_loop_counters(); + EXPECT_EQ(loop_counters.size(), 0); } TEST_F(LoopCounterTest, testIncreaseLoopCounter) { - auto lc = __dp::LoopCounter{}; - - lc.incr_loop_counter(0); - lc.incr_loop_counter(1); - lc.incr_loop_counter(0); - - const auto loop_counters = lc.get_loop_counters(); - EXPECT_EQ(loop_counters.size(), 2); - EXPECT_EQ(loop_counters[0], 2); - EXPECT_EQ(loop_counters[1], 1); - - lc.incr_loop_counter(4); - lc.incr_loop_counter(3); - lc.incr_loop_counter(9); - - const auto loop_counters2 = lc.get_loop_counters(); - EXPECT_EQ(loop_counters2.size(), 10); - EXPECT_EQ(loop_counters2[0], 2); - EXPECT_EQ(loop_counters2[1], 1); - EXPECT_EQ(loop_counters2[2], 0); - EXPECT_EQ(loop_counters2[3], 1); - EXPECT_EQ(loop_counters2[4], 1); - EXPECT_EQ(loop_counters2[5], 0); - EXPECT_EQ(loop_counters2[6], 0); - EXPECT_EQ(loop_counters2[7], 0); - EXPECT_EQ(loop_counters2[8], 0); - EXPECT_EQ(loop_counters2[9], 1); + auto lc = __dp::LoopCounter{}; + + lc.incr_loop_counter(0); + lc.incr_loop_counter(1); + lc.incr_loop_counter(0); + + const auto loop_counters = lc.get_loop_counters(); + EXPECT_EQ(loop_counters.size(), 2); + EXPECT_EQ(loop_counters[0], 2); + EXPECT_EQ(loop_counters[1], 1); + + lc.incr_loop_counter(4); + lc.incr_loop_counter(3); + lc.incr_loop_counter(9); + + const auto loop_counters2 = lc.get_loop_counters(); + EXPECT_EQ(loop_counters2.size(), 10); + EXPECT_EQ(loop_counters2[0], 2); + EXPECT_EQ(loop_counters2[1], 1); + EXPECT_EQ(loop_counters2[2], 0); + EXPECT_EQ(loop_counters2[3], 1); + EXPECT_EQ(loop_counters2[4], 1); + EXPECT_EQ(loop_counters2[5], 0); + EXPECT_EQ(loop_counters2[6], 0); + EXPECT_EQ(loop_counters2[7], 0); + EXPECT_EQ(loop_counters2[8], 0); + EXPECT_EQ(loop_counters2[9], 1); } diff --git a/test/unit_tests/loops/loop_info/test_loop_info.cpp b/test/unit_tests/loops/loop_info/test_loop_info.cpp index 29b5a423d..c4471b945 100644 --- a/test/unit_tests/loops/loop_info/test_loop_info.cpp +++ b/test/unit_tests/loops/loop_info/test_loop_info.cpp @@ -4,48 +4,48 @@ // Tests for old version (i.e., capturing functionality) -class LoopInfoTest : public ::testing::Test { }; +class LoopInfoTest : public ::testing::Test {}; TEST_F(LoopInfoTest, testZeroInitialization) { - const auto li = __dp::loop_info_t{}; + const auto li = __dp::loop_info_t{}; - ASSERT_EQ(li.line_nr_, 0); - ASSERT_EQ(li.loop_id_, 0); - ASSERT_EQ(li.file_id_, 0); + ASSERT_EQ(li.line_nr_, 0); + ASSERT_EQ(li.loop_id_, 0); + ASSERT_EQ(li.file_id_, 0); } TEST_F(LoopInfoTest, testInitialization) { - const auto li = __dp::loop_info_t{1, 2, 3}; + const auto li = __dp::loop_info_t{1, 2, 3}; - ASSERT_EQ(li.line_nr_, 1); - ASSERT_EQ(li.loop_id_, 2); - ASSERT_EQ(li.file_id_, 3); + ASSERT_EQ(li.line_nr_, 1); + ASSERT_EQ(li.loop_id_, 2); + ASSERT_EQ(li.file_id_, 3); } TEST_F(LoopInfoTest, testInitializationWithNegativeValues) { - const auto li = __dp::loop_info_t{-1, -2, -3}; + const auto li = __dp::loop_info_t{-1, -2, -3}; - ASSERT_EQ(li.line_nr_, -1); - ASSERT_EQ(li.loop_id_, -2); - ASSERT_EQ(li.file_id_, -3); + ASSERT_EQ(li.line_nr_, -1); + ASSERT_EQ(li.loop_id_, -2); + ASSERT_EQ(li.file_id_, -3); } TEST_F(LoopInfoTest, testEquality) { - const auto li1 = __dp::loop_info_t{1, 2, 3}; - const auto li2 = __dp::loop_info_t{1, 2, 3}; - const auto li3 = __dp::loop_info_t{1, 2, 4}; - const auto li4 = __dp::loop_info_t{1, 3, 3}; - const auto li5 = __dp::loop_info_t{2, 2, 3}; - - ASSERT_EQ(li1, li1); - - ASSERT_EQ(li1, li2); - ASSERT_NE(li1, li3); - ASSERT_NE(li1, li4); - ASSERT_NE(li1, li5); - - ASSERT_EQ(li2, li1); - ASSERT_NE(li3, li1); - ASSERT_NE(li4, li1); - ASSERT_NE(li5, li1); + const auto li1 = __dp::loop_info_t{1, 2, 3}; + const auto li2 = __dp::loop_info_t{1, 2, 3}; + const auto li3 = __dp::loop_info_t{1, 2, 4}; + const auto li4 = __dp::loop_info_t{1, 3, 3}; + const auto li5 = __dp::loop_info_t{2, 2, 3}; + + ASSERT_EQ(li1, li1); + + ASSERT_EQ(li1, li2); + ASSERT_NE(li1, li3); + ASSERT_NE(li1, li4); + ASSERT_NE(li1, li5); + + ASSERT_EQ(li2, li1); + ASSERT_NE(li3, li1); + ASSERT_NE(li4, li1); + ASSERT_NE(li5, li1); } diff --git a/test/unit_tests/loops/loop_manager/test_loop_manager.cpp b/test/unit_tests/loops/loop_manager/test_loop_manager.cpp index 3dee98170..db6734885 100644 --- a/test/unit_tests/loops/loop_manager/test_loop_manager.cpp +++ b/test/unit_tests/loops/loop_manager/test_loop_manager.cpp @@ -4,296 +4,296 @@ // Tests for old version (i.e., capturing functionality) -class LoopManagerTest : public ::testing::Test { }; +class LoopManagerTest : public ::testing::Test {}; TEST_F(LoopManagerTest, testInitialization) { - auto lm = __dp::LoopManager(); - ASSERT_TRUE(lm.empty()); + auto lm = __dp::LoopManager(); + ASSERT_TRUE(lm.empty()); - for (auto i = 0; i < 10; i++) { - for (auto j = 1; j < 1024; j *= 2) { - ASSERT_NO_THROW(lm.clean_function_exit(i, j)); - } + for (auto i = 0; i < 10; i++) { + for (auto j = 1; j < 1024; j *= 2) { + ASSERT_NO_THROW(lm.clean_function_exit(i, j)); } + } - for (auto i = 0; i < 100; i++) { - ASSERT_TRUE(lm.is_new_loop(i)); - } + for (auto i = 0; i < 100; i++) { + ASSERT_TRUE(lm.is_new_loop(i)); + } - for (auto i = 0; i < 100; i++) { - ASSERT_TRUE(lm.is_single_exit(i)); - } + for (auto i = 0; i < 100; i++) { + ASSERT_TRUE(lm.is_single_exit(i)); + } - const auto lid = (LID)0; - ASSERT_EQ(lm.update_lid(lid), 0xFF00000000000000LL); + const auto lid = (LID)0; + ASSERT_EQ(lm.update_lid(lid), 0xFF00000000000000LL); } TEST_F(LoopManagerTest, testCreateNewLoop) { - auto lm = __dp::LoopManager(); + auto lm = __dp::LoopManager(); + + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 3, 0); - lm.create_new_loop(2, 2, 1); - lm.create_new_loop(1, 3, 0); + lm.create_new_loop(1, 3, 0); + lm.create_new_loop(2, 2, 1); + lm.create_new_loop(1, 3, 0); - ASSERT_EQ(table.size(), 3); - ASSERT_EQ(loops.size(), 2); + ASSERT_EQ(table.size(), 3); + ASSERT_EQ(loops.size(), 2); - ASSERT_FALSE(lm.empty()); + ASSERT_FALSE(lm.empty()); } TEST_F(LoopManagerTest, testIsNewLoop) { - auto lm = __dp::LoopManager(); - - lm.create_new_loop(1, 3, 0); - lm.create_new_loop(2, 2, 1); - lm.create_new_loop(1, 3, 0); - - ASSERT_TRUE(lm.is_new_loop(1)); - ASSERT_TRUE(lm.is_new_loop(2)); - ASSERT_FALSE(lm.is_new_loop(3)); + auto lm = __dp::LoopManager(); + + lm.create_new_loop(1, 3, 0); + lm.create_new_loop(2, 2, 1); + lm.create_new_loop(1, 3, 0); + + ASSERT_TRUE(lm.is_new_loop(1)); + ASSERT_TRUE(lm.is_new_loop(2)); + ASSERT_FALSE(lm.is_new_loop(3)); } TEST_F(LoopManagerTest, testIterateLoop) { - auto lm = __dp::LoopManager(); + auto lm = __dp::LoopManager(); + + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 3, 0); - lm.create_new_loop(2, 2, 1); - lm.create_new_loop(1, 3, 0); + lm.create_new_loop(1, 3, 0); + lm.create_new_loop(2, 2, 1); + lm.create_new_loop(1, 3, 0); - lm.iterate_loop(1); - lm.iterate_loop(2); - lm.iterate_loop(1); + lm.iterate_loop(1); + lm.iterate_loop(2); + lm.iterate_loop(1); - ASSERT_EQ(table.size(), 3); - ASSERT_EQ(loops.size(), 2); + ASSERT_EQ(table.size(), 3); + ASSERT_EQ(loops.size(), 2); - ASSERT_EQ(table.top().get_count(), 3); - ASSERT_EQ(table.topMinusN(1).get_count(), 0); - ASSERT_EQ(table.topMinusN(2).get_count(), 0); + ASSERT_EQ(table.top().get_count(), 3); + ASSERT_EQ(table.topMinusN(1).get_count(), 0); + ASSERT_EQ(table.topMinusN(2).get_count(), 0); } TEST_F(LoopManagerTest, testCleanFunctionExit) { - auto lm = __dp::LoopManager(); + auto lm = __dp::LoopManager(); - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 3, 0); - lm.create_new_loop(2, 2, 1); - lm.create_new_loop(1, 3, 0); + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); - lm.clean_function_exit(0, 0); + lm.create_new_loop(1, 3, 0); + lm.create_new_loop(2, 2, 1); + lm.create_new_loop(1, 3, 0); - ASSERT_EQ(table.size(), 3); - ASSERT_EQ(loops.size(), 2); + lm.clean_function_exit(0, 0); - lm.clean_function_exit(2, 0); + ASSERT_EQ(table.size(), 3); + ASSERT_EQ(loops.size(), 2); - ASSERT_EQ(table.size(), 3); - ASSERT_EQ(loops.size(), 2); + lm.clean_function_exit(2, 0); - lm.clean_function_exit(1, 12); + ASSERT_EQ(table.size(), 3); + ASSERT_EQ(loops.size(), 2); - ASSERT_EQ(table.size(), 2); - ASSERT_EQ(loops.size(), 2); + lm.clean_function_exit(1, 12); - const auto it = loops.find(0); - ASSERT_NE(it, loops.end()); + ASSERT_EQ(table.size(), 2); + ASSERT_EQ(loops.size(), 2); - const auto loop = it->second; + const auto it = loops.find(0); + ASSERT_NE(it, loops.end()); - ASSERT_EQ(loop->end, 12); - ASSERT_EQ(loop->maxIterationCount, 0); - ASSERT_EQ(loop->nEntered, 1); - ASSERT_EQ(loop->total, 0); + const auto loop = it->second; + + ASSERT_EQ(loop->end, 12); + ASSERT_EQ(loop->maxIterationCount, 0); + ASSERT_EQ(loop->nEntered, 1); + ASSERT_EQ(loop->total, 0); } TEST_F(LoopManagerTest, testUpdateLid) { - auto lm = __dp::LoopManager(); - - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 2, 0); - lm.create_new_loop(4, 5, 0); - lm.create_new_loop(7, 8, 0); - lm.create_new_loop(10, 11, 0); - lm.create_new_loop(13, 14, 0); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = table.update_lid(lid_1); - const auto expected_lid_2 = table.update_lid(lid_2); - const auto expected_lid_3 = table.update_lid(lid_3); - const auto expected_lid_4 = table.update_lid(lid_4); - const auto expected_lid_5 = table.update_lid(lid_5); - const auto expected_lid_6 = table.update_lid(lid_6); - const auto expected_lid_7 = table.update_lid(lid_7); - const auto expected_lid_8 = table.update_lid(lid_8); - - ASSERT_EQ(expected_lid_1, lm.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lm.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lm.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lm.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lm.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lm.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lm.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lm.update_lid(lid_8)); + auto lm = __dp::LoopManager(); + + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); + + lm.create_new_loop(1, 2, 0); + lm.create_new_loop(4, 5, 0); + lm.create_new_loop(7, 8, 0); + lm.create_new_loop(10, 11, 0); + lm.create_new_loop(13, 14, 0); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = table.update_lid(lid_1); + const auto expected_lid_2 = table.update_lid(lid_2); + const auto expected_lid_3 = table.update_lid(lid_3); + const auto expected_lid_4 = table.update_lid(lid_4); + const auto expected_lid_5 = table.update_lid(lid_5); + const auto expected_lid_6 = table.update_lid(lid_6); + const auto expected_lid_7 = table.update_lid(lid_7); + const auto expected_lid_8 = table.update_lid(lid_8); + + ASSERT_EQ(expected_lid_1, lm.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lm.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lm.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lm.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lm.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lm.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lm.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lm.update_lid(lid_8)); } TEST_F(LoopManagerTest, testExitLoop) { - auto lm = __dp::LoopManager(); - - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 2, 3); - lm.create_new_loop(4, 5, 6); - lm.create_new_loop(7, 8, 9); - lm.create_new_loop(10, 11, 12); - lm.create_new_loop(13, 14, 15); - - lm.iterate_loop(1); - lm.iterate_loop(4); - lm.iterate_loop(7); - lm.iterate_loop(10); - lm.iterate_loop(13); - - lm.exit_loop(15); - lm.exit_loop(12); - lm.exit_loop(9); - - ASSERT_EQ(table.size(), 2); - ASSERT_EQ(loops.size(), 5); - - const auto loop_3 = *loops.find(3)->second; - const auto loop_6 = *loops.find(6)->second; - const auto loop_9 = *loops.find(9)->second; - const auto loop_12 = *loops.find(12)->second; - const auto loop_15 = *loops.find(15)->second; - - ASSERT_EQ(loop_3.end, 0); - ASSERT_EQ(loop_6.end, 0); - ASSERT_EQ(loop_9.end, 9); - ASSERT_EQ(loop_12.end, 12); - ASSERT_EQ(loop_15.end, 15); - - ASSERT_EQ(loop_3.maxIterationCount, 0); - ASSERT_EQ(loop_6.maxIterationCount, 0); - ASSERT_EQ(loop_9.maxIterationCount, 0); - ASSERT_EQ(loop_12.maxIterationCount, 0); - ASSERT_EQ(loop_15.maxIterationCount, 5); - - ASSERT_EQ(loop_3.nEntered, 0); - ASSERT_EQ(loop_6.nEntered, 0); - ASSERT_EQ(loop_9.nEntered, 1); - ASSERT_EQ(loop_12.nEntered, 1); - ASSERT_EQ(loop_15.nEntered, 1); - - ASSERT_EQ(loop_3.total, 0); - ASSERT_EQ(loop_6.total, 0); - ASSERT_EQ(loop_9.total, 0); - ASSERT_EQ(loop_12.total, 0); - ASSERT_EQ(loop_15.total, 5); + auto lm = __dp::LoopManager(); + + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); + + lm.create_new_loop(1, 2, 3); + lm.create_new_loop(4, 5, 6); + lm.create_new_loop(7, 8, 9); + lm.create_new_loop(10, 11, 12); + lm.create_new_loop(13, 14, 15); + + lm.iterate_loop(1); + lm.iterate_loop(4); + lm.iterate_loop(7); + lm.iterate_loop(10); + lm.iterate_loop(13); + + lm.exit_loop(15); + lm.exit_loop(12); + lm.exit_loop(9); + + ASSERT_EQ(table.size(), 2); + ASSERT_EQ(loops.size(), 5); + + const auto loop_3 = *loops.find(3)->second; + const auto loop_6 = *loops.find(6)->second; + const auto loop_9 = *loops.find(9)->second; + const auto loop_12 = *loops.find(12)->second; + const auto loop_15 = *loops.find(15)->second; + + ASSERT_EQ(loop_3.end, 0); + ASSERT_EQ(loop_6.end, 0); + ASSERT_EQ(loop_9.end, 9); + ASSERT_EQ(loop_12.end, 12); + ASSERT_EQ(loop_15.end, 15); + + ASSERT_EQ(loop_3.maxIterationCount, 0); + ASSERT_EQ(loop_6.maxIterationCount, 0); + ASSERT_EQ(loop_9.maxIterationCount, 0); + ASSERT_EQ(loop_12.maxIterationCount, 0); + ASSERT_EQ(loop_15.maxIterationCount, 5); + + ASSERT_EQ(loop_3.nEntered, 0); + ASSERT_EQ(loop_6.nEntered, 0); + ASSERT_EQ(loop_9.nEntered, 1); + ASSERT_EQ(loop_12.nEntered, 1); + ASSERT_EQ(loop_15.nEntered, 1); + + ASSERT_EQ(loop_3.total, 0); + ASSERT_EQ(loop_6.total, 0); + ASSERT_EQ(loop_9.total, 0); + ASSERT_EQ(loop_12.total, 0); + ASSERT_EQ(loop_15.total, 5); } TEST_F(LoopManagerTest, testIsSingleExit) { - auto lm = __dp::LoopManager(); + auto lm = __dp::LoopManager(); - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); - lm.create_new_loop(1, 2, 3); - lm.create_new_loop(4, 5, 6); - lm.create_new_loop(7, 8, 9); - lm.create_new_loop(10, 11, 12); - lm.create_new_loop(13, 14, 15); + lm.create_new_loop(1, 2, 3); + lm.create_new_loop(4, 5, 6); + lm.create_new_loop(7, 8, 9); + lm.create_new_loop(10, 11, 12); + lm.create_new_loop(13, 14, 15); - lm.iterate_loop(1); - lm.iterate_loop(4); - lm.iterate_loop(7); - lm.iterate_loop(10); - lm.iterate_loop(13); + lm.iterate_loop(1); + lm.iterate_loop(4); + lm.iterate_loop(7); + lm.iterate_loop(10); + lm.iterate_loop(13); - ASSERT_FALSE(lm.empty()); + ASSERT_FALSE(lm.empty()); - for (auto i = 0; i < 20; i++) { - ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); - } + for (auto i = 0; i < 20; i++) { + ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); + } - lm.exit_loop(15); - ASSERT_FALSE(lm.empty()); + lm.exit_loop(15); + ASSERT_FALSE(lm.empty()); - lm.exit_loop(12); - ASSERT_FALSE(lm.empty()); - - lm.exit_loop(9); - ASSERT_FALSE(lm.empty()); + lm.exit_loop(12); + ASSERT_FALSE(lm.empty()); - for (auto i = 0; i < 20; i++) { - ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); - } + lm.exit_loop(9); + ASSERT_FALSE(lm.empty()); - lm.exit_loop(3); - ASSERT_FALSE(lm.empty()); + for (auto i = 0; i < 20; i++) { + ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); + } - for (auto i = 0; i < 20; i++) { - ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); - } + lm.exit_loop(3); + ASSERT_FALSE(lm.empty()); + + for (auto i = 0; i < 20; i++) { + ASSERT_EQ(table.is_single_exit(i), lm.is_single_exit(i)); + } } TEST_F(LoopManagerTest, testCorrectFuncLevel) { - auto lm = __dp::LoopManager(); - - const auto& table = lm.get_stack(); - const auto& loops = lm.get_loops(); - - lm.create_new_loop(1, 2, 3); - lm.create_new_loop(4, 5, 6); - lm.create_new_loop(7, 8, 9); - lm.create_new_loop(10, 11, 12); - lm.create_new_loop(13, 14, 15); - - lm.iterate_loop(1); - lm.iterate_loop(4); - lm.iterate_loop(7); - lm.iterate_loop(10); - lm.iterate_loop(13); - - lm.correct_func_level(103); - - const auto& loop_3 = table.topMinusN(4); - const auto& loop_6 = table.topMinusN(3); - const auto& loop_9 = table.topMinusN(2); - const auto& loop_12 = table.topMinusN(1); - const auto& loop_15 = table.topMinusN(0); - - ASSERT_EQ(loop_3.funcLevel, 1); - ASSERT_EQ(loop_6.funcLevel, 4); - ASSERT_EQ(loop_9.funcLevel, 7); - ASSERT_EQ(loop_12.funcLevel, 10); - ASSERT_EQ(loop_15.funcLevel, 103); - - lm.exit_loop(15); - - lm.correct_func_level(104); - - ASSERT_EQ(loop_3.funcLevel, 1); - ASSERT_EQ(loop_6.funcLevel, 4); - ASSERT_EQ(loop_9.funcLevel, 7); - ASSERT_EQ(loop_12.funcLevel, 104); - ASSERT_EQ(loop_15.funcLevel, 103); + auto lm = __dp::LoopManager(); + + const auto &table = lm.get_stack(); + const auto &loops = lm.get_loops(); + + lm.create_new_loop(1, 2, 3); + lm.create_new_loop(4, 5, 6); + lm.create_new_loop(7, 8, 9); + lm.create_new_loop(10, 11, 12); + lm.create_new_loop(13, 14, 15); + + lm.iterate_loop(1); + lm.iterate_loop(4); + lm.iterate_loop(7); + lm.iterate_loop(10); + lm.iterate_loop(13); + + lm.correct_func_level(103); + + const auto &loop_3 = table.topMinusN(4); + const auto &loop_6 = table.topMinusN(3); + const auto &loop_9 = table.topMinusN(2); + const auto &loop_12 = table.topMinusN(1); + const auto &loop_15 = table.topMinusN(0); + + ASSERT_EQ(loop_3.funcLevel, 1); + ASSERT_EQ(loop_6.funcLevel, 4); + ASSERT_EQ(loop_9.funcLevel, 7); + ASSERT_EQ(loop_12.funcLevel, 10); + ASSERT_EQ(loop_15.funcLevel, 103); + + lm.exit_loop(15); + + lm.correct_func_level(104); + + ASSERT_EQ(loop_3.funcLevel, 1); + ASSERT_EQ(loop_6.funcLevel, 4); + ASSERT_EQ(loop_9.funcLevel, 7); + ASSERT_EQ(loop_12.funcLevel, 104); + ASSERT_EQ(loop_15.funcLevel, 103); } diff --git a/test/unit_tests/loops/loop_record/test_loop_record.cpp b/test/unit_tests/loops/loop_record/test_loop_record.cpp index 962ffc078..1fc4340cc 100644 --- a/test/unit_tests/loops/loop_record/test_loop_record.cpp +++ b/test/unit_tests/loops/loop_record/test_loop_record.cpp @@ -4,60 +4,60 @@ // Tests for old version (i.e., capturing functionality) -class LoopRecordTest : public ::testing::Test { }; +class LoopRecordTest : public ::testing::Test {}; TEST_F(LoopRecordTest, testInitialization) { - const auto lr = __dp::LoopRecord{1, 2, 3}; + const auto lr = __dp::LoopRecord{1, 2, 3}; - ASSERT_EQ(lr.end, 1); - ASSERT_EQ(lr.total, 2); - ASSERT_EQ(lr.nEntered, 3); - ASSERT_EQ(lr.maxIterationCount, 0); + ASSERT_EQ(lr.end, 1); + ASSERT_EQ(lr.total, 2); + ASSERT_EQ(lr.nEntered, 3); + ASSERT_EQ(lr.maxIterationCount, 0); } TEST_F(LoopRecordTest, testNegativeInitialization) { - const auto lr = __dp::LoopRecord{-1, -2, -3}; + const auto lr = __dp::LoopRecord{-1, -2, -3}; - ASSERT_EQ(lr.end, -1); - ASSERT_EQ(lr.total, -2); - ASSERT_EQ(lr.nEntered, -3); - ASSERT_EQ(lr.maxIterationCount, 0); + ASSERT_EQ(lr.end, -1); + ASSERT_EQ(lr.total, -2); + ASSERT_EQ(lr.nEntered, -3); + ASSERT_EQ(lr.maxIterationCount, 0); } TEST_F(LoopRecordTest, testLongInitialization) { - const auto lr = __dp::LoopRecord{4'000'000'000LL, 1'000'000'000LL, 2'000'000'000LL}; + const auto lr = __dp::LoopRecord{4'000'000'000LL, 1'000'000'000LL, 2'000'000'000LL}; - ASSERT_EQ(lr.end, 4'000'000'000LL); - ASSERT_EQ(lr.total, 1'000'000'000LL); - ASSERT_EQ(lr.nEntered, 2'000'000'000LL); - ASSERT_EQ(lr.maxIterationCount, 0); + ASSERT_EQ(lr.end, 4'000'000'000LL); + ASSERT_EQ(lr.total, 1'000'000'000LL); + ASSERT_EQ(lr.nEntered, 2'000'000'000LL); + ASSERT_EQ(lr.maxIterationCount, 0); } TEST_F(LoopRecordTest, testLongNegativeInitialization) { - const auto lr = __dp::LoopRecord{-4'000'000'000LL, -1'000'000'000LL, -2'000'000'000LL}; + const auto lr = __dp::LoopRecord{-4'000'000'000LL, -1'000'000'000LL, -2'000'000'000LL}; - ASSERT_EQ(lr.end, -4'000'000'000LL); - ASSERT_EQ(lr.total, -1'000'000'000LL); - ASSERT_EQ(lr.nEntered, -2'000'000'000LL); - ASSERT_EQ(lr.maxIterationCount, 0); + ASSERT_EQ(lr.end, -4'000'000'000LL); + ASSERT_EQ(lr.total, -1'000'000'000LL); + ASSERT_EQ(lr.nEntered, -2'000'000'000LL); + ASSERT_EQ(lr.maxIterationCount, 0); } TEST_F(LoopRecordTest, testEquality) { - const auto lr1 = __dp::LoopRecord{1, 2, 3}; - const auto lr2 = __dp::LoopRecord{1, 2, 3}; - const auto lr3 = __dp::LoopRecord{1, 2, 4}; - const auto lr4 = __dp::LoopRecord{1, 3, 3}; - const auto lr5 = __dp::LoopRecord{2, 2, 3}; - - ASSERT_EQ(lr1, lr1); - - ASSERT_EQ(lr1, lr2); - ASSERT_NE(lr1, lr3); - ASSERT_NE(lr1, lr4); - ASSERT_NE(lr1, lr5); - - ASSERT_EQ(lr2, lr1); - ASSERT_NE(lr3, lr1); - ASSERT_NE(lr4, lr1); - ASSERT_NE(lr5, lr1); + const auto lr1 = __dp::LoopRecord{1, 2, 3}; + const auto lr2 = __dp::LoopRecord{1, 2, 3}; + const auto lr3 = __dp::LoopRecord{1, 2, 4}; + const auto lr4 = __dp::LoopRecord{1, 3, 3}; + const auto lr5 = __dp::LoopRecord{2, 2, 3}; + + ASSERT_EQ(lr1, lr1); + + ASSERT_EQ(lr1, lr2); + ASSERT_NE(lr1, lr3); + ASSERT_NE(lr1, lr4); + ASSERT_NE(lr1, lr5); + + ASSERT_EQ(lr2, lr1); + ASSERT_NE(lr3, lr1); + ASSERT_NE(lr4, lr1); + ASSERT_NE(lr5, lr1); } diff --git a/test/unit_tests/loops/loop_table/test_loop_table.cpp b/test/unit_tests/loops/loop_table/test_loop_table.cpp index ad7693f45..e4fec01c0 100644 --- a/test/unit_tests/loops/loop_table/test_loop_table.cpp +++ b/test/unit_tests/loops/loop_table/test_loop_table.cpp @@ -4,442 +4,440 @@ // Tests for old version (i.e., capturing functionality) -class LoopTableTest : public ::testing::Test { }; +class LoopTableTest : public ::testing::Test {}; TEST_F(LoopTableTest, testInitialization) { - const auto lt = __dp::LoopTable{}; + const auto lt = __dp::LoopTable{}; - ASSERT_EQ(lt.size(), 0); - ASSERT_TRUE(lt.empty()); + ASSERT_EQ(lt.size(), 0); + ASSERT_TRUE(lt.empty()); - for (auto lid = 0; lid < 10; ++lid) { - ASSERT_TRUE(lt.is_single_exit(lid)); - } + for (auto lid = 0; lid < 10; ++lid) { + ASSERT_TRUE(lt.is_single_exit(lid)); + } - ASSERT_NO_THROW(lt.debug_output()); + ASSERT_NO_THROW(lt.debug_output()); } TEST_F(LoopTableTest, testPushBack) { - auto lt = __dp::LoopTable{}; - - lt.push(__dp::LoopTableEntry{1, 2, 3, 0}); - ASSERT_EQ(lt.size(), 1); - ASSERT_FALSE(lt.empty()); - for (auto lid = 0; lid < 10 && lid != 2; ++lid) { - ASSERT_TRUE(lt.is_single_exit(lid)); - } - ASSERT_FALSE(lt.is_single_exit(2)); - - lt.push(__dp::LoopTableEntry{4, 5, 6, 0}); - ASSERT_EQ(lt.size(), 2); - ASSERT_FALSE(lt.empty()); - for (auto lid = 0; lid < 10 && lid != 5; ++lid) { - ASSERT_TRUE(lt.is_single_exit(lid)); - } - ASSERT_FALSE(lt.is_single_exit(5)); - - ASSERT_NO_THROW(lt.debug_output()); + auto lt = __dp::LoopTable{}; + + lt.push(__dp::LoopTableEntry{1, 2, 3, 0}); + ASSERT_EQ(lt.size(), 1); + ASSERT_FALSE(lt.empty()); + for (auto lid = 0; lid < 10 && lid != 2; ++lid) { + ASSERT_TRUE(lt.is_single_exit(lid)); + } + ASSERT_FALSE(lt.is_single_exit(2)); + + lt.push(__dp::LoopTableEntry{4, 5, 6, 0}); + ASSERT_EQ(lt.size(), 2); + ASSERT_FALSE(lt.empty()); + for (auto lid = 0; lid < 10 && lid != 5; ++lid) { + ASSERT_TRUE(lt.is_single_exit(lid)); + } + ASSERT_FALSE(lt.is_single_exit(5)); + + ASSERT_NO_THROW(lt.debug_output()); } TEST_F(LoopTableTest, testGetters) { - auto lt = __dp::LoopTable{}; + auto lt = __dp::LoopTable{}; - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - lt.push(first_entry); - lt.push(second_entry); + lt.push(first_entry); + lt.push(second_entry); - ASSERT_NO_THROW(lt.debug_output()); + ASSERT_NO_THROW(lt.debug_output()); - const auto top_entry_from_lt = lt.top(); - ASSERT_EQ(top_entry_from_lt, second_entry); + const auto top_entry_from_lt = lt.top(); + ASSERT_EQ(top_entry_from_lt, second_entry); - const auto first_entry_from_lt = lt.first(); - ASSERT_EQ(first_entry_from_lt, first_entry); + const auto first_entry_from_lt = lt.first(); + ASSERT_EQ(first_entry_from_lt, first_entry); - const auto top_minus_0_entry_from_lt = lt.topMinusN(0); - ASSERT_EQ(top_minus_0_entry_from_lt, second_entry); + const auto top_minus_0_entry_from_lt = lt.topMinusN(0); + ASSERT_EQ(top_minus_0_entry_from_lt, second_entry); - const auto top_minus_1_entry_from_lt = lt.topMinusN(1); - ASSERT_EQ(top_minus_1_entry_from_lt, first_entry); + const auto top_minus_1_entry_from_lt = lt.topMinusN(1); + ASSERT_EQ(top_minus_1_entry_from_lt, first_entry); - ASSERT_EQ(lt.size(), 2); - ASSERT_FALSE(lt.empty()); + ASSERT_EQ(lt.size(), 2); + ASSERT_FALSE(lt.empty()); - lt.pop(); + lt.pop(); - const auto top_entry_from_lt_after_pop = lt.top(); - ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); + const auto top_entry_from_lt_after_pop = lt.top(); + ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); - const auto first_entry_from_lt_after_pop = lt.first(); - ASSERT_EQ(first_entry_from_lt_after_pop, first_entry); + const auto first_entry_from_lt_after_pop = lt.first(); + ASSERT_EQ(first_entry_from_lt_after_pop, first_entry); - const auto top_minus_0_entry_from_lt_after_pop = lt.topMinusN(0); - ASSERT_EQ(top_minus_0_entry_from_lt_after_pop, first_entry); + const auto top_minus_0_entry_from_lt_after_pop = lt.topMinusN(0); + ASSERT_EQ(top_minus_0_entry_from_lt_after_pop, first_entry); - ASSERT_EQ(lt.size(), 1); - ASSERT_FALSE(lt.empty()); + ASSERT_EQ(lt.size(), 1); + ASSERT_FALSE(lt.empty()); - ASSERT_NO_THROW(lt.debug_output()); + ASSERT_NO_THROW(lt.debug_output()); - lt.pop(); + lt.pop(); - ASSERT_EQ(lt.size(), 0); - ASSERT_TRUE(lt.empty()); + ASSERT_EQ(lt.size(), 0); + ASSERT_TRUE(lt.empty()); } TEST_F(LoopTableTest, testCorrectFunctionLevel) { - auto lt = __dp::LoopTable{}; + auto lt = __dp::LoopTable{}; - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - lt.push(first_entry); - lt.push(second_entry); + lt.push(first_entry); + lt.push(second_entry); - lt.correct_func_level(7); + lt.correct_func_level(7); - const auto top_entry_from_lt = lt.top(); - ASSERT_EQ(top_entry_from_lt, __dp::LoopTableEntry(7, 5, 6, 0)); + const auto top_entry_from_lt = lt.top(); + ASSERT_EQ(top_entry_from_lt, __dp::LoopTableEntry(7, 5, 6, 0)); - lt.pop(); + lt.pop(); - const auto top_entry_from_lt_after_pop = lt.top(); - ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); + const auto top_entry_from_lt_after_pop = lt.top(); + ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); - lt.pop(); + lt.pop(); - ASSERT_TRUE(lt.empty()); + ASSERT_TRUE(lt.empty()); - lt.push(first_entry); - lt.push(second_entry); + lt.push(first_entry); + lt.push(second_entry); - lt.correct_func_level(4); + lt.correct_func_level(4); - const auto top_entry_from_lt_2 = lt.top(); - ASSERT_EQ(top_entry_from_lt_2, second_entry); + const auto top_entry_from_lt_2 = lt.top(); + ASSERT_EQ(top_entry_from_lt_2, second_entry); - lt.pop(); + lt.pop(); - const auto top_entry_from_lt_after_pop_2 = lt.top(); - ASSERT_EQ(top_entry_from_lt_after_pop_2, first_entry); + const auto top_entry_from_lt_after_pop_2 = lt.top(); + ASSERT_EQ(top_entry_from_lt_after_pop_2, first_entry); - lt.pop(); + lt.pop(); - ASSERT_TRUE(lt.empty()); + ASSERT_TRUE(lt.empty()); } TEST_F(LoopTableTest, testIncrementTopCount) { - auto lt = __dp::LoopTable{}; + auto lt = __dp::LoopTable{}; - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - lt.push(first_entry); - lt.push(second_entry); + lt.push(first_entry); + lt.push(second_entry); - lt.increment_top_count(); + lt.increment_top_count(); - const auto top_entry_from_lt = lt.top(); - ASSERT_EQ(top_entry_from_lt, __dp::LoopTableEntry(4, 5, 7, 0)); + const auto top_entry_from_lt = lt.top(); + ASSERT_EQ(top_entry_from_lt, __dp::LoopTableEntry(4, 5, 7, 0)); - lt.pop(); + lt.pop(); - const auto top_entry_from_lt_after_pop = lt.top(); - ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); + const auto top_entry_from_lt_after_pop = lt.top(); + ASSERT_EQ(top_entry_from_lt_after_pop, first_entry); - lt.pop(); + lt.pop(); - ASSERT_TRUE(lt.empty()); + ASSERT_TRUE(lt.empty()); - lt.push(first_entry); - lt.push(second_entry); + lt.push(first_entry); + lt.push(second_entry); - const auto top_entry_from_lt_2 = lt.top(); - ASSERT_EQ(top_entry_from_lt_2, second_entry); + const auto top_entry_from_lt_2 = lt.top(); + ASSERT_EQ(top_entry_from_lt_2, second_entry); - lt.pop(); + lt.pop(); - lt.increment_top_count(); + lt.increment_top_count(); - const auto top_entry_from_lt_after_pop_2 = lt.top(); - ASSERT_EQ(top_entry_from_lt_after_pop_2, __dp::LoopTableEntry(1, 2, 4, 0)); + const auto top_entry_from_lt_after_pop_2 = lt.top(); + ASSERT_EQ(top_entry_from_lt_after_pop_2, __dp::LoopTableEntry(1, 2, 4, 0)); - lt.pop(); + lt.pop(); - ASSERT_TRUE(lt.empty()); + ASSERT_TRUE(lt.empty()); } TEST_F(LoopTableTest, testUpdateLidSize0) { - auto lt = __dp::LoopTable{}; - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b1111'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'1111'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b1111'1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b1111'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'1111'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } TEST_F(LoopTableTest, testUpdateLidSize1) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - - lt.push(first_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + + lt.push(first_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } TEST_F(LoopTableTest, testUpdateLidSize2) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - - lt.push(first_entry); - lt.push(second_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'0110'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + + lt.push(first_entry); + lt.push(second_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'0110'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } TEST_F(LoopTableTest, testUpdateLidSize3) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; - - lt.push(first_entry); - lt.push(second_entry); - lt.push(third_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'1001'1111'0110'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; + + lt.push(first_entry); + lt.push(second_entry); + lt.push(third_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1000'1001'1000'0110'1000'0011'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'1001'1111'0110'1111'0011'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } TEST_F(LoopTableTest, testUpdateLidSize4) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; - const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; - - lt.push(first_entry); - lt.push(second_entry); - lt.push(third_entry); - lt.push(fourth_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'1100'1111'1001'1111'0110'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; + const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; + + lt.push(first_entry); + lt.push(second_entry); + lt.push(third_entry); + lt.push(fourth_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1000'1100'1000'1001'1000'0110'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'1100'1111'1001'1111'0110'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } TEST_F(LoopTableTest, testUpdateLidSize5) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; - const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; - const auto fifth_entry = __dp::LoopTableEntry{13, 14, 15, 0}; - - lt.push(first_entry); - lt.push(second_entry); - lt.push(third_entry); - lt.push(fourth_entry); - lt.push(fifth_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; + const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; + const auto fifth_entry = __dp::LoopTableEntry{13, 14, 15, 0}; + + lt.push(first_entry); + lt.push(second_entry); + lt.push(third_entry); + lt.push(fourth_entry); + lt.push(fifth_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } - TEST_F(LoopTableTest, testUpdateLidSize6) { - auto lt = __dp::LoopTable{}; - - const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; - const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; - const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; - const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; - const auto fifth_entry = __dp::LoopTableEntry{13, 14, 15, 0}; - const auto sixth_entry = __dp::LoopTableEntry{16, 17, 18, 0}; - - lt.push(first_entry); - lt.push(second_entry); - lt.push(third_entry); - lt.push(fourth_entry); - lt.push(fifth_entry); - lt.push(sixth_entry); - - const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_2 = 0b1111'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto expected_lid_3 = 0b0000'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto expected_lid_4 = 0b0000'1111'1001'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto expected_lid_5 = 0b1111'0010'1111'0010'1111'1111'1111'1100'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); - ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); - ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); - ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); - ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); - ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); - ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); - ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); + auto lt = __dp::LoopTable{}; + + const auto first_entry = __dp::LoopTableEntry{1, 2, 3, 0}; + const auto second_entry = __dp::LoopTableEntry{4, 5, 6, 0}; + const auto third_entry = __dp::LoopTableEntry{7, 8, 9, 0}; + const auto fourth_entry = __dp::LoopTableEntry{10, 11, 12, 0}; + const auto fifth_entry = __dp::LoopTableEntry{13, 14, 15, 0}; + const auto sixth_entry = __dp::LoopTableEntry{16, 17, 18, 0}; + + lt.push(first_entry); + lt.push(second_entry); + lt.push(third_entry); + lt.push(fourth_entry); + lt.push(fifth_entry); + lt.push(sixth_entry); + + const auto lid_1 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_2 = 0b1111'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto expected_lid_3 = 0b0000'0010'1001'0010'1000'1111'1000'1100'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto expected_lid_4 = 0b0000'1111'1001'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto expected_lid_5 = 0b1111'0010'1111'0010'1111'1111'1111'1100'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto expected_lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto expected_lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto expected_lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + ASSERT_EQ(expected_lid_1, lt.update_lid(lid_1)); + ASSERT_EQ(expected_lid_2, lt.update_lid(lid_2)); + ASSERT_EQ(expected_lid_3, lt.update_lid(lid_3)); + ASSERT_EQ(expected_lid_4, lt.update_lid(lid_4)); + ASSERT_EQ(expected_lid_5, lt.update_lid(lid_5)); + ASSERT_EQ(expected_lid_6, lt.update_lid(lid_6)); + ASSERT_EQ(expected_lid_7, lt.update_lid(lid_7)); + ASSERT_EQ(expected_lid_8, lt.update_lid(lid_8)); } - diff --git a/test/unit_tests/loops/loop_table_entry/test_loop_table_entry.cpp b/test/unit_tests/loops/loop_table_entry/test_loop_table_entry.cpp index b047ba5d0..bac284826 100644 --- a/test/unit_tests/loops/loop_table_entry/test_loop_table_entry.cpp +++ b/test/unit_tests/loops/loop_table_entry/test_loop_table_entry.cpp @@ -4,63 +4,63 @@ // Tests for old version (i.e., capturing functionality) -class LoopTableEntryTest : public ::testing::Test { }; +class LoopTableEntryTest : public ::testing::Test {}; TEST_F(LoopTableEntryTest, testInitialization) { - const auto lte = __dp::LoopTableEntry{1, 2, 3, 4}; + const auto lte = __dp::LoopTableEntry{1, 2, 3, 4}; - ASSERT_EQ(lte.funcLevel, 1); - ASSERT_EQ(lte.loopID, 2); - ASSERT_EQ(lte.get_count(), 3); - ASSERT_EQ(lte.begin, 4); + ASSERT_EQ(lte.funcLevel, 1); + ASSERT_EQ(lte.loopID, 2); + ASSERT_EQ(lte.get_count(), 3); + ASSERT_EQ(lte.begin, 4); } TEST_F(LoopTableEntryTest, testNegativeInitialization) { - const auto lte = __dp::LoopTableEntry{-1, -2, -3, -4}; + const auto lte = __dp::LoopTableEntry{-1, -2, -3, -4}; - ASSERT_EQ(lte.funcLevel, -1); - ASSERT_EQ(lte.loopID, -2); - ASSERT_EQ(lte.get_count(), -3); - ASSERT_EQ(lte.begin, -4); + ASSERT_EQ(lte.funcLevel, -1); + ASSERT_EQ(lte.loopID, -2); + ASSERT_EQ(lte.get_count(), -3); + ASSERT_EQ(lte.begin, -4); } TEST_F(LoopTableEntryTest, testLongInitialization) { - const auto lte = __dp::LoopTableEntry{1'000'000'000, 1'500'000'000, 2'000'000'000, 4'000'000'000LL}; + const auto lte = __dp::LoopTableEntry{1'000'000'000, 1'500'000'000, 2'000'000'000, 4'000'000'000LL}; - ASSERT_EQ(lte.funcLevel, 1'000'000'000); - ASSERT_EQ(lte.loopID, 1'500'000'000); - ASSERT_EQ(lte.get_count(), 2'000'000'000); - ASSERT_EQ(lte.begin, 4'000'000'000LL); + ASSERT_EQ(lte.funcLevel, 1'000'000'000); + ASSERT_EQ(lte.loopID, 1'500'000'000); + ASSERT_EQ(lte.get_count(), 2'000'000'000); + ASSERT_EQ(lte.begin, 4'000'000'000LL); } TEST_F(LoopTableEntryTest, testNegativeLongInitialization) { - const auto lte = __dp::LoopTableEntry{-1'000'000'000, -1'500'000'000, -2'000'000'000, -4'000'000'000LL}; + const auto lte = __dp::LoopTableEntry{-1'000'000'000, -1'500'000'000, -2'000'000'000, -4'000'000'000LL}; - ASSERT_EQ(lte.funcLevel, -1'000'000'000); - ASSERT_EQ(lte.loopID, -1'500'000'000); - ASSERT_EQ(lte.get_count(), -2'000'000'000); - ASSERT_EQ(lte.begin, -4'000'000'000LL); + ASSERT_EQ(lte.funcLevel, -1'000'000'000); + ASSERT_EQ(lte.loopID, -1'500'000'000); + ASSERT_EQ(lte.get_count(), -2'000'000'000); + ASSERT_EQ(lte.begin, -4'000'000'000LL); } TEST_F(LoopTableEntryTest, testEquality) { - const auto lte1 = __dp::LoopTableEntry{1, 2, 3, 4}; - const auto lte2 = __dp::LoopTableEntry{1, 2, 3, 4}; - const auto lte3 = __dp::LoopTableEntry{1, 2, 3, 5}; - const auto lte4 = __dp::LoopTableEntry{1, 2, 4, 4}; - const auto lte5 = __dp::LoopTableEntry{1, 3, 3, 4}; - const auto lte6 = __dp::LoopTableEntry{2, 2, 3, 4}; + const auto lte1 = __dp::LoopTableEntry{1, 2, 3, 4}; + const auto lte2 = __dp::LoopTableEntry{1, 2, 3, 4}; + const auto lte3 = __dp::LoopTableEntry{1, 2, 3, 5}; + const auto lte4 = __dp::LoopTableEntry{1, 2, 4, 4}; + const auto lte5 = __dp::LoopTableEntry{1, 3, 3, 4}; + const auto lte6 = __dp::LoopTableEntry{2, 2, 3, 4}; - ASSERT_EQ(lte1, lte1); + ASSERT_EQ(lte1, lte1); - ASSERT_EQ(lte1, lte2); - ASSERT_NE(lte1, lte3); - ASSERT_NE(lte1, lte4); - ASSERT_NE(lte1, lte5); - ASSERT_NE(lte1, lte6); - - ASSERT_EQ(lte2, lte1); - ASSERT_NE(lte3, lte1); - ASSERT_NE(lte4, lte1); - ASSERT_NE(lte5, lte1); - ASSERT_NE(lte6, lte1); + ASSERT_EQ(lte1, lte2); + ASSERT_NE(lte1, lte3); + ASSERT_NE(lte1, lte4); + ASSERT_NE(lte1, lte5); + ASSERT_NE(lte1, lte6); + + ASSERT_EQ(lte2, lte1); + ASSERT_NE(lte3, lte1); + ASSERT_NE(lte4, lte1); + ASSERT_NE(lte5, lte1); + ASSERT_NE(lte6, lte1); } diff --git a/test/unit_tests/loops/makros/test_makros.cpp b/test/unit_tests/loops/makros/test_makros.cpp index 163096e15..7752648c0 100644 --- a/test/unit_tests/loops/makros/test_makros.cpp +++ b/test/unit_tests/loops/makros/test_makros.cpp @@ -4,207 +4,207 @@ // Tests for old version (i.e., capturing functionality) -class MakrosTest : public ::testing::Test { }; +class MakrosTest : public ::testing::Test {}; TEST_F(MakrosTest, testGetLoopId) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0010LL; - const auto expected_lid_2 = 0b1111'0010LL; - const auto expected_lid_3 = 0b0000'0010LL; - const auto expected_lid_4 = 0b0000'1111LL; - const auto expected_lid_5 = 0b1111'0010LL; - const auto expected_lid_6 = 0b0000'1111LL; - const auto expected_lid_7 = 0b1111'1111LL; - const auto expected_lid_8 = 0b1111'1111LL; - - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_1), expected_lid_1); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_2), expected_lid_2); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_3), expected_lid_3); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_4), expected_lid_4); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_5), expected_lid_5); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_6), expected_lid_6); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_7), expected_lid_7); - ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0010LL; + const auto expected_lid_2 = 0b1111'0010LL; + const auto expected_lid_3 = 0b0000'0010LL; + const auto expected_lid_4 = 0b0000'1111LL; + const auto expected_lid_5 = 0b1111'0010LL; + const auto expected_lid_6 = 0b0000'1111LL; + const auto expected_lid_7 = 0b1111'1111LL; + const auto expected_lid_8 = 0b1111'1111LL; + + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_1), expected_lid_1); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_2), expected_lid_2); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_3), expected_lid_3); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_4), expected_lid_4); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_5), expected_lid_5); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_6), expected_lid_6); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_7), expected_lid_7); + ASSERT_EQ(unpackLIDMetadata_getLoopID(lid_8), expected_lid_8); } TEST_F(MakrosTest, testGetLoopIteration0) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'1111LL; - const auto expected_lid_2 = 0b0000'1111LL; - const auto expected_lid_3 = 0b0000'1111LL; - const auto expected_lid_4 = 0b0000'1111LL; - const auto expected_lid_5 = 0b0111'1111LL; - const auto expected_lid_6 = 0b0111'1111LL; - const auto expected_lid_7 = 0b0111'1111LL; - const auto expected_lid_8 = 0b0111'1111LL; - - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_1), expected_lid_1); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_2), expected_lid_2); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_3), expected_lid_3); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_4), expected_lid_4); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_5), expected_lid_5); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_6), expected_lid_6); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_7), expected_lid_7); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'1111LL; + const auto expected_lid_2 = 0b0000'1111LL; + const auto expected_lid_3 = 0b0000'1111LL; + const auto expected_lid_4 = 0b0000'1111LL; + const auto expected_lid_5 = 0b0111'1111LL; + const auto expected_lid_6 = 0b0111'1111LL; + const auto expected_lid_7 = 0b0111'1111LL; + const auto expected_lid_8 = 0b0111'1111LL; + + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_1), expected_lid_1); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_2), expected_lid_2); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_3), expected_lid_3); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_4), expected_lid_4); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_5), expected_lid_5); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_6), expected_lid_6); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_7), expected_lid_7); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_0(lid_8), expected_lid_8); } TEST_F(MakrosTest, testGetLoopIteration1) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'1100LL; - const auto expected_lid_2 = 0b0000'1100LL; - const auto expected_lid_3 = 0b0000'1100LL; - const auto expected_lid_4 = 0b0000'1111LL; - const auto expected_lid_5 = 0b0111'1100LL; - const auto expected_lid_6 = 0b0111'1111LL; - const auto expected_lid_7 = 0b0111'1111LL; - const auto expected_lid_8 = 0b0111'1111LL; - - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_1), expected_lid_1); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_2), expected_lid_2); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_3), expected_lid_3); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_4), expected_lid_4); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_5), expected_lid_5); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_6), expected_lid_6); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_7), expected_lid_7); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'1100LL; + const auto expected_lid_2 = 0b0000'1100LL; + const auto expected_lid_3 = 0b0000'1100LL; + const auto expected_lid_4 = 0b0000'1111LL; + const auto expected_lid_5 = 0b0111'1100LL; + const auto expected_lid_6 = 0b0111'1111LL; + const auto expected_lid_7 = 0b0111'1111LL; + const auto expected_lid_8 = 0b0111'1111LL; + + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_1), expected_lid_1); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_2), expected_lid_2); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_3), expected_lid_3); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_4), expected_lid_4); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_5), expected_lid_5); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_6), expected_lid_6); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_7), expected_lid_7); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_1(lid_8), expected_lid_8); } TEST_F(MakrosTest, testGetLoopIteration2) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'1001LL; - const auto expected_lid_2 = 0b0000'1001LL; - const auto expected_lid_3 = 0b0000'1001LL; - const auto expected_lid_4 = 0b0000'1111LL; - const auto expected_lid_5 = 0b0111'1001LL; - const auto expected_lid_6 = 0b0111'1111LL; - const auto expected_lid_7 = 0b0111'1111LL; - const auto expected_lid_8 = 0b0111'1111LL; - - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_1), expected_lid_1); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_2), expected_lid_2); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_3), expected_lid_3); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_4), expected_lid_4); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_5), expected_lid_5); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_6), expected_lid_6); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_7), expected_lid_7); - ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'1001LL; + const auto expected_lid_2 = 0b0000'1001LL; + const auto expected_lid_3 = 0b0000'1001LL; + const auto expected_lid_4 = 0b0000'1111LL; + const auto expected_lid_5 = 0b0111'1001LL; + const auto expected_lid_6 = 0b0111'1111LL; + const auto expected_lid_7 = 0b0111'1111LL; + const auto expected_lid_8 = 0b0111'1111LL; + + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_1), expected_lid_1); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_2), expected_lid_2); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_3), expected_lid_3); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_4), expected_lid_4); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_5), expected_lid_5); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_6), expected_lid_6); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_7), expected_lid_7); + ASSERT_EQ(unpackLIDMetadata_getLoopIteration_2(lid_8), expected_lid_8); } TEST_F(MakrosTest, testValidity0) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0001LL; - const auto expected_lid_2 = 0b0000'0001LL; - const auto expected_lid_3 = 0b0000'0001LL; - const auto expected_lid_4 = 0b0000'0001LL; - const auto expected_lid_5 = 0b0000'0001LL; - const auto expected_lid_6 = 0b0000'0001LL; - const auto expected_lid_7 = 0b0000'0001LL; - const auto expected_lid_8 = 0b0000'0001LL; - - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_1), expected_lid_1); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_2), expected_lid_2); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_3), expected_lid_3); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_4), expected_lid_4); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_5), expected_lid_5); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_6), expected_lid_6); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_7), expected_lid_7); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0001LL; + const auto expected_lid_2 = 0b0000'0001LL; + const auto expected_lid_3 = 0b0000'0001LL; + const auto expected_lid_4 = 0b0000'0001LL; + const auto expected_lid_5 = 0b0000'0001LL; + const auto expected_lid_6 = 0b0000'0001LL; + const auto expected_lid_7 = 0b0000'0001LL; + const auto expected_lid_8 = 0b0000'0001LL; + + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_1), expected_lid_1); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_2), expected_lid_2); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_3), expected_lid_3); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_4), expected_lid_4); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_5), expected_lid_5); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_6), expected_lid_6); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_7), expected_lid_7); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_8), expected_lid_8); } TEST_F(MakrosTest, testValidity1) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0001LL; - const auto expected_lid_2 = 0b0000'0001LL; - const auto expected_lid_3 = 0b0000'0001LL; - const auto expected_lid_4 = 0b0000'0001LL; - const auto expected_lid_5 = 0b0000'0001LL; - const auto expected_lid_6 = 0b0000'0001LL; - const auto expected_lid_7 = 0b0000'0001LL; - const auto expected_lid_8 = 0b0000'0001LL; - - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_1), expected_lid_1); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_2), expected_lid_2); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_3), expected_lid_3); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_4), expected_lid_4); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_5), expected_lid_5); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_6), expected_lid_6); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_7), expected_lid_7); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0001LL; + const auto expected_lid_2 = 0b0000'0001LL; + const auto expected_lid_3 = 0b0000'0001LL; + const auto expected_lid_4 = 0b0000'0001LL; + const auto expected_lid_5 = 0b0000'0001LL; + const auto expected_lid_6 = 0b0000'0001LL; + const auto expected_lid_7 = 0b0000'0001LL; + const auto expected_lid_8 = 0b0000'0001LL; + + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_1), expected_lid_1); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_2), expected_lid_2); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_3), expected_lid_3); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_4), expected_lid_4); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_5), expected_lid_5); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_6), expected_lid_6); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_7), expected_lid_7); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_0(lid_8), expected_lid_8); } TEST_F(MakrosTest, testValidity2) { - const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; - const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; - const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; - const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; - const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; - const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; - - const auto expected_lid_1 = 0b0000'0001LL; - const auto expected_lid_2 = 0b0000'0001LL; - const auto expected_lid_3 = 0b0000'0001LL; - const auto expected_lid_4 = 0b0000'0001LL; - const auto expected_lid_5 = 0b0000'0001LL; - const auto expected_lid_6 = 0b0000'0001LL; - const auto expected_lid_7 = 0b0000'0001LL; - const auto expected_lid_8 = 0b0000'0001LL; - - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_1), expected_lid_1); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_2), expected_lid_2); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_3), expected_lid_3); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_4), expected_lid_4); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_5), expected_lid_5); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_6), expected_lid_6); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_7), expected_lid_7); - ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_8), expected_lid_8); + const auto lid_1 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_2 = 0b1111'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'0000LL; + const auto lid_3 = 0b0000'0010'1000'1111'1000'1100'1000'1001'0000'0000'0000'0000'0000'0000'0000'1111LL; + const auto lid_4 = 0b0000'1111'1000'1111'1000'1111'1000'1111'0000'1111'0000'1111'0000'1111'0000'1111LL; + const auto lid_5 = 0b1111'0010'1111'1111'1111'1100'1111'1001'1111'0000'1111'0000'1111'0000'1111'0000LL; + const auto lid_6 = 0b0000'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + const auto lid_7 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'0000LL; + const auto lid_8 = 0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111LL; + + const auto expected_lid_1 = 0b0000'0001LL; + const auto expected_lid_2 = 0b0000'0001LL; + const auto expected_lid_3 = 0b0000'0001LL; + const auto expected_lid_4 = 0b0000'0001LL; + const auto expected_lid_5 = 0b0000'0001LL; + const auto expected_lid_6 = 0b0000'0001LL; + const auto expected_lid_7 = 0b0000'0001LL; + const auto expected_lid_8 = 0b0000'0001LL; + + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_1), expected_lid_1); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_2), expected_lid_2); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_3), expected_lid_3); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_4), expected_lid_4); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_5), expected_lid_5); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_6), expected_lid_6); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_7), expected_lid_7); + ASSERT_EQ(checkLIDMetadata_getLoopIterationValidity_2(lid_8), expected_lid_8); } diff --git a/test/unit_tests/loops/var_counter/test_var_counter.cpp b/test/unit_tests/loops/var_counter/test_var_counter.cpp index 5fa72c816..c745feb19 100644 --- a/test/unit_tests/loops/var_counter/test_var_counter.cpp +++ b/test/unit_tests/loops/var_counter/test_var_counter.cpp @@ -4,54 +4,54 @@ // Tests for old version (i.e., capturing functionality) -class VarCounterTest : public ::testing::Test { }; +class VarCounterTest : public ::testing::Test {}; TEST_F(VarCounterTest, testZeroInitialization) { - const auto vc = __dp::VarCounter{}; + const auto vc = __dp::VarCounter{}; - ASSERT_EQ(vc.counters_[0], 0); - ASSERT_EQ(vc.counters_[1], 0); - ASSERT_EQ(vc.mem_addr_, 0); - ASSERT_TRUE(vc.valid_); + ASSERT_EQ(vc.counters_[0], 0); + ASSERT_EQ(vc.counters_[1], 0); + ASSERT_EQ(vc.mem_addr_, 0); + ASSERT_TRUE(vc.valid_); } TEST_F(VarCounterTest, testInitialization) { - const auto vc = __dp::VarCounter{1, 2, 3, false}; + const auto vc = __dp::VarCounter{1, 2, 3, false}; - ASSERT_EQ(vc.counters_[0], 1); - ASSERT_EQ(vc.counters_[1], 2); - ASSERT_EQ(vc.mem_addr_, 3); - ASSERT_FALSE(vc.valid_); + ASSERT_EQ(vc.counters_[0], 1); + ASSERT_EQ(vc.counters_[1], 2); + ASSERT_EQ(vc.mem_addr_, 3); + ASSERT_FALSE(vc.valid_); } TEST_F(VarCounterTest, testNegativeInitialization) { - const auto vc = __dp::VarCounter{1, 2, -3, false}; + const auto vc = __dp::VarCounter{1, 2, -3, false}; - ASSERT_EQ(vc.counters_[0], 1); - ASSERT_EQ(vc.counters_[1], 2); - ASSERT_EQ(vc.mem_addr_, -3); - ASSERT_FALSE(vc.valid_); + ASSERT_EQ(vc.counters_[0], 1); + ASSERT_EQ(vc.counters_[1], 2); + ASSERT_EQ(vc.mem_addr_, -3); + ASSERT_FALSE(vc.valid_); } TEST_F(VarCounterTest, testEquality) { - const auto vc1 = __dp::VarCounter{1, 2, 3, false}; - const auto vc2 = __dp::VarCounter{1, 2, 3, false}; - const auto vc3 = __dp::VarCounter{1, 2, 4, false}; - const auto vc4 = __dp::VarCounter{1, 3, 3, false}; - const auto vc5 = __dp::VarCounter{2, 2, 3, false}; - const auto vc6 = __dp::VarCounter{1, 2, 3, true}; - - ASSERT_EQ(vc1, vc1); - - ASSERT_EQ(vc1, vc2); - ASSERT_NE(vc1, vc3); - ASSERT_NE(vc1, vc4); - ASSERT_NE(vc1, vc5); - ASSERT_NE(vc1, vc6); - - ASSERT_EQ(vc2, vc1); - ASSERT_NE(vc3, vc1); - ASSERT_NE(vc4, vc1); - ASSERT_NE(vc5, vc1); - ASSERT_NE(vc6, vc1); + const auto vc1 = __dp::VarCounter{1, 2, 3, false}; + const auto vc2 = __dp::VarCounter{1, 2, 3, false}; + const auto vc3 = __dp::VarCounter{1, 2, 4, false}; + const auto vc4 = __dp::VarCounter{1, 3, 3, false}; + const auto vc5 = __dp::VarCounter{2, 2, 3, false}; + const auto vc6 = __dp::VarCounter{1, 2, 3, true}; + + ASSERT_EQ(vc1, vc1); + + ASSERT_EQ(vc1, vc2); + ASSERT_NE(vc1, vc3); + ASSERT_NE(vc1, vc4); + ASSERT_NE(vc1, vc5); + ASSERT_NE(vc1, vc6); + + ASSERT_EQ(vc2, vc1); + ASSERT_NE(vc3, vc1); + ASSERT_NE(vc4, vc1); + ASSERT_NE(vc5, vc1); + ASSERT_NE(vc6, vc1); } diff --git a/test/unit_tests/loops/var_info/test_var_info.cpp b/test/unit_tests/loops/var_info/test_var_info.cpp index 05f42296a..ec80fa4a4 100644 --- a/test/unit_tests/loops/var_info/test_var_info.cpp +++ b/test/unit_tests/loops/var_info/test_var_info.cpp @@ -4,69 +4,69 @@ // Tests for old version (i.e., capturing functionality) -class VarInfoTest : public ::testing::Test { }; +class VarInfoTest : public ::testing::Test {}; TEST_F(VarInfoTest, testZeroInitialization) { - const auto vi = __dp::var_info_t{}; + const auto vi = __dp::var_info_t{}; - ASSERT_TRUE(vi.var_name_.empty()); - ASSERT_EQ(vi.file_id_, 0); - ASSERT_EQ(vi.instr_id_, 0); - ASSERT_EQ(vi.loop_line_nr_, 0); - ASSERT_EQ(vi.instr_line_, 0); - ASSERT_EQ(vi.operation_, 0); + ASSERT_TRUE(vi.var_name_.empty()); + ASSERT_EQ(vi.file_id_, 0); + ASSERT_EQ(vi.instr_id_, 0); + ASSERT_EQ(vi.loop_line_nr_, 0); + ASSERT_EQ(vi.instr_line_, 0); + ASSERT_EQ(vi.operation_, 0); } TEST_F(VarInfoTest, testInitialization) { - const auto vi = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; + const auto vi = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; - ASSERT_EQ(vi.var_name_, "var"); - ASSERT_EQ(vi.file_id_, 1); - ASSERT_EQ(vi.instr_id_, 2); - ASSERT_EQ(vi.loop_line_nr_, 3); - ASSERT_EQ(vi.instr_line_, 4); - ASSERT_EQ(vi.operation_, 'a'); + ASSERT_EQ(vi.var_name_, "var"); + ASSERT_EQ(vi.file_id_, 1); + ASSERT_EQ(vi.instr_id_, 2); + ASSERT_EQ(vi.loop_line_nr_, 3); + ASSERT_EQ(vi.instr_line_, 4); + ASSERT_EQ(vi.operation_, 'a'); } TEST_F(VarInfoTest, testNegativeInitialization) { - const auto vi = __dp::var_info_t{"negative", -1, -2, -3, -4, 'n'}; + const auto vi = __dp::var_info_t{"negative", -1, -2, -3, -4, 'n'}; - ASSERT_EQ(vi.var_name_, "negative"); - ASSERT_EQ(vi.file_id_, -1); - ASSERT_EQ(vi.instr_id_, -2); - ASSERT_EQ(vi.loop_line_nr_, -3); - ASSERT_EQ(vi.instr_line_, -4); - ASSERT_EQ(vi.operation_, 'n'); + ASSERT_EQ(vi.var_name_, "negative"); + ASSERT_EQ(vi.file_id_, -1); + ASSERT_EQ(vi.instr_id_, -2); + ASSERT_EQ(vi.loop_line_nr_, -3); + ASSERT_EQ(vi.instr_line_, -4); + ASSERT_EQ(vi.operation_, 'n'); } TEST_F(VarInfoTest, testEquality) { - const auto vi1 = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; - const auto vi2 = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; - const auto vi3 = __dp::var_info_t{"var", 1, 2, 3, 4, 'b'}; - const auto vi4 = __dp::var_info_t{"var", 1, 2, 3, 5, 'a'}; - const auto vi5 = __dp::var_info_t{"var", 1, 2, 4, 4, 'a'}; - const auto vi6 = __dp::var_info_t{"var", 1, 3, 3, 4, 'a'}; - const auto vi7 = __dp::var_info_t{"var", 2, 2, 3, 4, 'a'}; - const auto vi8 = __dp::var_info_t{"var", 1, 2, 3, 4, 'c'}; - const auto vi9 = __dp::var_info_t{"VAR", 1, 2, 3, 4, 'c'}; + const auto vi1 = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; + const auto vi2 = __dp::var_info_t{"var", 1, 2, 3, 4, 'a'}; + const auto vi3 = __dp::var_info_t{"var", 1, 2, 3, 4, 'b'}; + const auto vi4 = __dp::var_info_t{"var", 1, 2, 3, 5, 'a'}; + const auto vi5 = __dp::var_info_t{"var", 1, 2, 4, 4, 'a'}; + const auto vi6 = __dp::var_info_t{"var", 1, 3, 3, 4, 'a'}; + const auto vi7 = __dp::var_info_t{"var", 2, 2, 3, 4, 'a'}; + const auto vi8 = __dp::var_info_t{"var", 1, 2, 3, 4, 'c'}; + const auto vi9 = __dp::var_info_t{"VAR", 1, 2, 3, 4, 'c'}; - ASSERT_EQ(vi1, vi1); + ASSERT_EQ(vi1, vi1); - ASSERT_EQ(vi1, vi2); - ASSERT_NE(vi1, vi3); - ASSERT_NE(vi1, vi4); - ASSERT_NE(vi1, vi5); - ASSERT_NE(vi1, vi6); - ASSERT_NE(vi1, vi7); - ASSERT_NE(vi1, vi8); - ASSERT_NE(vi1, vi9); - - ASSERT_EQ(vi2, vi1); - ASSERT_NE(vi3, vi1); - ASSERT_NE(vi4, vi1); - ASSERT_NE(vi5, vi1); - ASSERT_NE(vi6, vi1); - ASSERT_NE(vi7, vi1); - ASSERT_NE(vi8, vi1); - ASSERT_NE(vi9, vi1); + ASSERT_EQ(vi1, vi2); + ASSERT_NE(vi1, vi3); + ASSERT_NE(vi1, vi4); + ASSERT_NE(vi1, vi5); + ASSERT_NE(vi1, vi6); + ASSERT_NE(vi1, vi7); + ASSERT_NE(vi1, vi8); + ASSERT_NE(vi1, vi9); + + ASSERT_EQ(vi2, vi1); + ASSERT_NE(vi3, vi1); + ASSERT_NE(vi4, vi1); + ASSERT_NE(vi5, vi1); + ASSERT_NE(vi6, vi1); + ASSERT_NE(vi7, vi1); + ASSERT_NE(vi8, vi1); + ASSERT_NE(vi9, vi1); } diff --git a/test/unit_tests/memory/memory_manager/test_memory_manager.cpp b/test/unit_tests/memory/memory_manager/test_memory_manager.cpp index 8aeec70b5..8b916f567 100644 --- a/test/unit_tests/memory/memory_manager/test_memory_manager.cpp +++ b/test/unit_tests/memory/memory_manager/test_memory_manager.cpp @@ -7,995 +7,995 @@ // Tests for old version (i.e., capturing functionality) -class MemoryManagerTest : public ::testing::Test { }; +class MemoryManagerTest : public ::testing::Test {}; TEST_F(MemoryManagerTest, testConstructor) { - auto mm = __dp::MemoryManager{}; + auto mm = __dp::MemoryManager{}; - ASSERT_EQ(mm.get_smallest_allocated_addr(), std::numeric_limits::max()); - ASSERT_EQ(mm.get_largest_allocated_addr(), std::numeric_limits::min()); + ASSERT_EQ(mm.get_smallest_allocated_addr(), std::numeric_limits::max()); + ASSERT_EQ(mm.get_largest_allocated_addr(), std::numeric_limits::min()); - for (auto i = 1; i < 1024; i++) { - ASSERT_EQ(mm.get_next_free_memory_region_id(), i); - } + for (auto i = 1; i < 1024; i++) { + ASSERT_EQ(mm.get_next_free_memory_region_id(), i); + } - ASSERT_EQ(mm.get_smallest_allocated_addr(), std::numeric_limits::max()); - ASSERT_EQ(mm.get_largest_allocated_addr(), std::numeric_limits::min()); + ASSERT_EQ(mm.get_smallest_allocated_addr(), std::numeric_limits::max()); + ASSERT_EQ(mm.get_largest_allocated_addr(), std::numeric_limits::min()); } TEST_F(MemoryManagerTest, testStack) { - auto mm = __dp::MemoryManager{}; - - mm.enter_new_function(); - mm.update_stack_addresses(0x1000, 0x2000); - mm.enter_new_function(); - mm.update_stack_addresses(0x3000, 0x4000); - mm.enter_new_function(); - mm.update_stack_addresses(0x5000, 0x6000); - - auto addr = mm.pop_last_stack_address(); - ASSERT_EQ(addr.first, 0x5000); - ASSERT_EQ(addr.second, 0x6000); - - addr = mm.pop_last_stack_address(); - ASSERT_EQ(addr.first, 0x3000); - ASSERT_EQ(addr.second, 0x4000); - - addr = mm.pop_last_stack_address(); - ASSERT_EQ(addr.first, 0x1000); - ASSERT_EQ(addr.second, 0x2000); + auto mm = __dp::MemoryManager{}; + + mm.enter_new_function(); + mm.update_stack_addresses(0x1000, 0x2000); + mm.enter_new_function(); + mm.update_stack_addresses(0x3000, 0x4000); + mm.enter_new_function(); + mm.update_stack_addresses(0x5000, 0x6000); + + auto addr = mm.pop_last_stack_address(); + ASSERT_EQ(addr.first, 0x5000); + ASSERT_EQ(addr.second, 0x6000); + + addr = mm.pop_last_stack_address(); + ASSERT_EQ(addr.first, 0x3000); + ASSERT_EQ(addr.second, 0x4000); + + addr = mm.pop_last_stack_address(); + ASSERT_EQ(addr.first, 0x1000); + ASSERT_EQ(addr.second, 0x2000); } TEST_F(MemoryManagerTest, testUpdateStackAddresses) { - auto mm = __dp::MemoryManager{}; + auto mm = __dp::MemoryManager{}; - mm.enter_new_function(); - mm.update_stack_addresses(0x2000, 0x3000); - mm.update_stack_addresses(0x1000, 0x4000); + mm.enter_new_function(); + mm.update_stack_addresses(0x2000, 0x3000); + mm.update_stack_addresses(0x1000, 0x4000); - auto addr = mm.pop_last_stack_address(); - ASSERT_EQ(addr.first, 0x1000); - ASSERT_EQ(addr.second, 0x4000); + auto addr = mm.pop_last_stack_address(); + ASSERT_EQ(addr.first, 0x1000); + ASSERT_EQ(addr.second, 0x4000); } TEST_F(MemoryManagerTest, testIsStackAccess) { - auto mm = __dp::MemoryManager{}; - - mm.enter_new_function(); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - mm.update_stack_addresses(0x1000, 0x2000); - mm.enter_new_function(); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - mm.update_stack_addresses(0x3000, 0x4000); - mm.enter_new_function(); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - mm.update_stack_addresses(0x5000, 0x6000); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_TRUE(mm.is_stack_access(0x5000)); - ASSERT_TRUE(mm.is_stack_access(0x5500)); - ASSERT_TRUE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - auto addr = mm.pop_last_stack_address(); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_TRUE(mm.is_stack_access(0x3000)); - ASSERT_TRUE(mm.is_stack_access(0x3500)); - ASSERT_TRUE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - addr = mm.pop_last_stack_address(); - - ASSERT_TRUE(mm.is_stack_access(0x1000)); - ASSERT_TRUE(mm.is_stack_access(0x1500)); - ASSERT_TRUE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); - - addr = mm.pop_last_stack_address(); - - ASSERT_FALSE(mm.is_stack_access(0x1000)); - ASSERT_FALSE(mm.is_stack_access(0x1500)); - ASSERT_FALSE(mm.is_stack_access(0x2000)); - ASSERT_FALSE(mm.is_stack_access(0x2500)); - ASSERT_FALSE(mm.is_stack_access(0x3000)); - ASSERT_FALSE(mm.is_stack_access(0x3500)); - ASSERT_FALSE(mm.is_stack_access(0x4000)); - ASSERT_FALSE(mm.is_stack_access(0x4500)); - ASSERT_FALSE(mm.is_stack_access(0x5000)); - ASSERT_FALSE(mm.is_stack_access(0x5500)); - ASSERT_FALSE(mm.is_stack_access(0x6000)); - ASSERT_FALSE(mm.is_stack_access(0x6500)); + auto mm = __dp::MemoryManager{}; + + mm.enter_new_function(); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + mm.update_stack_addresses(0x1000, 0x2000); + mm.enter_new_function(); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + mm.update_stack_addresses(0x3000, 0x4000); + mm.enter_new_function(); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + mm.update_stack_addresses(0x5000, 0x6000); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_TRUE(mm.is_stack_access(0x5000)); + ASSERT_TRUE(mm.is_stack_access(0x5500)); + ASSERT_TRUE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + auto addr = mm.pop_last_stack_address(); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_TRUE(mm.is_stack_access(0x3000)); + ASSERT_TRUE(mm.is_stack_access(0x3500)); + ASSERT_TRUE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + addr = mm.pop_last_stack_address(); + + ASSERT_TRUE(mm.is_stack_access(0x1000)); + ASSERT_TRUE(mm.is_stack_access(0x1500)); + ASSERT_TRUE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); + + addr = mm.pop_last_stack_address(); + + ASSERT_FALSE(mm.is_stack_access(0x1000)); + ASSERT_FALSE(mm.is_stack_access(0x1500)); + ASSERT_FALSE(mm.is_stack_access(0x2000)); + ASSERT_FALSE(mm.is_stack_access(0x2500)); + ASSERT_FALSE(mm.is_stack_access(0x3000)); + ASSERT_FALSE(mm.is_stack_access(0x3500)); + ASSERT_FALSE(mm.is_stack_access(0x4000)); + ASSERT_FALSE(mm.is_stack_access(0x4500)); + ASSERT_FALSE(mm.is_stack_access(0x5000)); + ASSERT_FALSE(mm.is_stack_access(0x5500)); + ASSERT_FALSE(mm.is_stack_access(0x6000)); + ASSERT_FALSE(mm.is_stack_access(0x6500)); } TEST_F(MemoryManagerTest, testScoping) { - auto manager = __dp::MemoryManager{}; + auto manager = __dp::MemoryManager{}; - manager.enterScope("First scope", 0); - const auto first_scope = manager.getCurrentScope(); - manager.leaveScope("Already gone", 0); + manager.enterScope("First scope", 0); + const auto first_scope = manager.getCurrentScope(); + manager.leaveScope("Already gone", 0); - ASSERT_EQ(first_scope.get_id(), 1); - ASSERT_TRUE(first_scope.get_first_read().empty()); - ASSERT_TRUE(first_scope.get_first_write().empty()); + ASSERT_EQ(first_scope.get_id(), 1); + ASSERT_TRUE(first_scope.get_first_read().empty()); + ASSERT_TRUE(first_scope.get_first_write().empty()); - manager.enterScope("Hello", 1); - manager.enterScope(" ", 20); - manager.enterScope("world", 10); - manager.enterScope("!\n", 1); + manager.enterScope("Hello", 1); + manager.enterScope(" ", 20); + manager.enterScope("world", 10); + manager.enterScope("!\n", 1); - for (auto i = 0; i < 4; i++) { - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 5 - i); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + for (auto i = 0; i < 4; i++) { + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 5 - i); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - const auto scope_again = manager.getCurrentScope(); - ASSERT_EQ(scope_again.get_id(), 5 - i); - ASSERT_TRUE(scope_again.get_first_read().empty()); - ASSERT_TRUE(scope_again.get_first_write().empty()); + const auto scope_again = manager.getCurrentScope(); + ASSERT_EQ(scope_again.get_id(), 5 - i); + ASSERT_TRUE(scope_again.get_first_read().empty()); + ASSERT_TRUE(scope_again.get_first_write().empty()); - manager.leaveScope("leave!", 55); - } + manager.leaveScope("leave!", 55); + } - manager.enterScope("New version", 2); - manager.enterScope("...\n", 5); + manager.enterScope("New version", 2); + manager.enterScope("...\n", 5); - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 7); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 7); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - manager.leaveScope("Leave.", 4); + manager.leaveScope("Leave.", 4); - const auto last_scope = manager.getCurrentScope(); - ASSERT_EQ(last_scope.get_id(), 6); - ASSERT_TRUE(last_scope.get_first_read().empty()); - ASSERT_TRUE(last_scope.get_first_write().empty()); + const auto last_scope = manager.getCurrentScope(); + ASSERT_EQ(last_scope.get_id(), 6); + ASSERT_TRUE(last_scope.get_first_read().empty()); + ASSERT_TRUE(last_scope.get_first_write().empty()); - manager.leaveScope("Leave the last time", 0); + manager.leaveScope("Leave the last time", 0); } TEST_F(MemoryManagerTest, testRegisterRead) { - auto manager = __dp::MemoryManager{}; + auto manager = __dp::MemoryManager{}; + + manager.enterScope("First", 1); - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackRead(24, 2, ""); - manager.registerStackRead(32, 1, ""); + manager.enterScope("Second", 2); + manager.registerStackRead(24, 2, ""); + manager.registerStackRead(32, 1, ""); - manager.enterScope("Third", 3); - manager.registerStackRead(1024, 0, ""); + manager.enterScope("Third", 3); + manager.registerStackRead(1024, 0, ""); - manager.enterScope("Fourth", 4); + manager.enterScope("Fourth", 4); - const auto scope4 = manager.getCurrentScope(); + const auto scope4 = manager.getCurrentScope(); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.leaveScope("Fourth", 4); + manager.leaveScope("Fourth", 4); - manager.registerStackRead(52, 0, ""); + manager.registerStackRead(52, 0, ""); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - - ASSERT_TRUE(scope3.get_first_write().empty()); - ASSERT_EQ(reads3.size(), 2); - ASSERT_NE(reads3.find(52), reads3.end()); - ASSERT_NE(reads3.find(1024), reads3.end()); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); - manager.leaveScope("Third", 3); + ASSERT_TRUE(scope3.get_first_write().empty()); + ASSERT_EQ(reads3.size(), 2); + ASSERT_NE(reads3.find(52), reads3.end()); + ASSERT_NE(reads3.find(1024), reads3.end()); - manager.registerStackRead(24, 2, ""); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - - ASSERT_TRUE(scope2.get_first_write().empty()); - ASSERT_EQ(reads2.size(), 2); - ASSERT_NE(reads2.find(24), reads3.end()); - ASSERT_NE(reads2.find(32), reads3.end()); + manager.registerStackRead(24, 2, ""); - manager.leaveScope("Second", 2); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + ASSERT_TRUE(scope2.get_first_write().empty()); + ASSERT_EQ(reads2.size(), 2); + ASSERT_NE(reads2.find(24), reads3.end()); + ASSERT_NE(reads2.find(32), reads3.end()); - manager.leaveScope("First", 1); + manager.leaveScope("Second", 2); + + const auto scope1 = manager.getCurrentScope(); + + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); + + manager.leaveScope("First", 1); } TEST_F(MemoryManagerTest, testRegisterWrite) { - auto manager = __dp::MemoryManager{}; + auto manager = __dp::MemoryManager{}; + + manager.enterScope("First", 1); + + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackWrite(32, 1, ""); + + manager.enterScope("Third", 3); + manager.registerStackWrite(1024, 0, ""); + + manager.enterScope("Fourth", 4); - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackWrite(32, 1, ""); + const auto scope4 = manager.getCurrentScope(); - manager.enterScope("Third", 3); - manager.registerStackWrite(1024, 0, ""); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.enterScope("Fourth", 4); + manager.leaveScope("Fourth", 4); - const auto scope4 = manager.getCurrentScope(); + manager.registerStackWrite(52, 0, ""); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + const auto scope3 = manager.getCurrentScope(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Fourth", 4); + ASSERT_TRUE(scope3.get_first_read().empty()); + ASSERT_EQ(writes3.size(), 2); + ASSERT_NE(writes3.find(52), writes3.end()); + ASSERT_NE(writes3.find(1024), writes3.end()); - manager.registerStackWrite(52, 0, ""); + manager.leaveScope("Third", 3); - const auto scope3 = manager.getCurrentScope(); - const auto writes3 = scope3.get_first_write(); - - ASSERT_TRUE(scope3.get_first_read().empty()); - ASSERT_EQ(writes3.size(), 2); - ASSERT_NE(writes3.find(52), writes3.end()); - ASSERT_NE(writes3.find(1024), writes3.end()); + manager.registerStackWrite(24, 2, ""); - manager.leaveScope("Third", 3); + const auto scope2 = manager.getCurrentScope(); + const auto writes2 = scope2.get_first_write(); - manager.registerStackWrite(24, 2, ""); + ASSERT_TRUE(scope2.get_first_read().empty()); + ASSERT_EQ(writes2.size(), 2); + ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_NE(writes2.find(32), writes2.end()); - const auto scope2 = manager.getCurrentScope(); - const auto writes2 = scope2.get_first_write(); - - ASSERT_TRUE(scope2.get_first_read().empty()); - ASSERT_EQ(writes2.size(), 2); - ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_NE(writes2.find(32), writes2.end()); + manager.leaveScope("Second", 2); - manager.leaveScope("Second", 2); + const auto scope1 = manager.getCurrentScope(); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); } -TEST_F(MemoryManagerTest, testRegister) { - auto manager = __dp::MemoryManager{}; +TEST_F(MemoryManagerTest, testRegister) { + auto manager = __dp::MemoryManager{}; - manager.enterScope("First", 1); + manager.enterScope("First", 1); - manager.registerStackRead(32, 0, ""); - manager.registerStackRead(24, 1, ""); + manager.registerStackRead(32, 0, ""); + manager.registerStackRead(24, 1, ""); - manager.enterScope("Second", 2); + manager.enterScope("Second", 2); - manager.registerStackRead(32, 3, ""); - manager.registerStackWrite(24, 4, ""); + manager.registerStackRead(32, 3, ""); + manager.registerStackWrite(24, 4, ""); - manager.enterScope("Third", 3); + manager.enterScope("Third", 3); - manager.registerStackRead(24, 5, ""); - manager.registerStackWrite(24, 6, ""); + manager.registerStackRead(24, 5, ""); + manager.registerStackWrite(24, 6, ""); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - const auto writes3 = scope3.get_first_write(); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Third", 3); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - const auto writes2 = scope2.get_first_write(); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); + const auto writes2 = scope2.get_first_write(); - manager.leaveScope("Second", 2); + manager.leaveScope("Second", 2); - const auto scope1 = manager.getCurrentScope(); - const auto reads1 = scope1.get_first_read(); - const auto writes1 = scope1.get_first_write(); + const auto scope1 = manager.getCurrentScope(); + const auto reads1 = scope1.get_first_read(); + const auto writes1 = scope1.get_first_write(); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); - ASSERT_TRUE(writes1.empty()); - ASSERT_EQ(reads1.size(), 2); - ASSERT_NE(reads1.find(24), reads1.end()); - ASSERT_NE(reads1.find(32), reads1.end()); + ASSERT_TRUE(writes1.empty()); + ASSERT_EQ(reads1.size(), 2); + ASSERT_NE(reads1.find(24), reads1.end()); + ASSERT_NE(reads1.find(32), reads1.end()); - ASSERT_EQ(reads2.size(), 1); - ASSERT_EQ(writes2.size(), 1); - ASSERT_NE(reads2.find(32), reads2.end()); - ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_EQ(reads2.size(), 1); + ASSERT_EQ(writes2.size(), 1); + ASSERT_NE(reads2.find(32), reads2.end()); + ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_TRUE(writes3.empty()); - ASSERT_EQ(reads3.size(), 1); - ASSERT_NE(reads3.find(24), reads3.end()); + ASSERT_TRUE(writes3.empty()); + ASSERT_EQ(reads3.size(), 1); + ASSERT_NE(reads3.find(24), reads3.end()); } TEST_F(MemoryManagerTest, testFirstWritten) { - auto manager = __dp::MemoryManager{}; - - manager.enterScope("First", 1); - manager.registerStackRead(24, 0, ""); - manager.registerStackWrite(24, 1, ""); - manager.registerStackWrite(12, 2, ""); - manager.registerStackRead(12, 3, ""); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackRead(24, 3, ""); - manager.registerStackRead(12, 0, ""); - manager.registerStackWrite(12, 1, ""); - - manager.enterScope("Third", 3); - manager.registerStackRead(32, 4, ""); - manager.registerStackWrite(36, 5, ""); - manager.registerStackRead(40, 6, ""); - - ASSERT_TRUE(manager.isFirstWrittenInScope(36, true)); - ASSERT_TRUE(manager.isFirstWrittenInScope(1012, true)); - ASSERT_TRUE(manager.isFirstWrittenInScope(1024, true)); - - ASSERT_FALSE(manager.isFirstWrittenInScope(12, true)); - ASSERT_FALSE(manager.isFirstWrittenInScope(24, true)); - ASSERT_FALSE(manager.isFirstWrittenInScope(32, true)); - ASSERT_FALSE(manager.isFirstWrittenInScope(32, false)); - ASSERT_FALSE(manager.isFirstWrittenInScope(40, true)); - ASSERT_FALSE(manager.isFirstWrittenInScope(40, false)); - ASSERT_FALSE(manager.isFirstWrittenInScope(1012, false)); - ASSERT_FALSE(manager.isFirstWrittenInScope(1024, false)); + auto manager = __dp::MemoryManager{}; + + manager.enterScope("First", 1); + manager.registerStackRead(24, 0, ""); + manager.registerStackWrite(24, 1, ""); + manager.registerStackWrite(12, 2, ""); + manager.registerStackRead(12, 3, ""); + + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackRead(24, 3, ""); + manager.registerStackRead(12, 0, ""); + manager.registerStackWrite(12, 1, ""); + + manager.enterScope("Third", 3); + manager.registerStackRead(32, 4, ""); + manager.registerStackWrite(36, 5, ""); + manager.registerStackRead(40, 6, ""); + + ASSERT_TRUE(manager.isFirstWrittenInScope(36, true)); + ASSERT_TRUE(manager.isFirstWrittenInScope(1012, true)); + ASSERT_TRUE(manager.isFirstWrittenInScope(1024, true)); + + ASSERT_FALSE(manager.isFirstWrittenInScope(12, true)); + ASSERT_FALSE(manager.isFirstWrittenInScope(24, true)); + ASSERT_FALSE(manager.isFirstWrittenInScope(32, true)); + ASSERT_FALSE(manager.isFirstWrittenInScope(32, false)); + ASSERT_FALSE(manager.isFirstWrittenInScope(40, true)); + ASSERT_FALSE(manager.isFirstWrittenInScope(40, false)); + ASSERT_FALSE(manager.isFirstWrittenInScope(1012, false)); + ASSERT_FALSE(manager.isFirstWrittenInScope(1024, false)); } TEST_F(MemoryManagerTest, testPositiveChange) { - auto scope = __dp::MemoryManager{}; + auto scope = __dp::MemoryManager{}; - scope.enterScope("First", 1); - scope.registerStackRead(24, 0, ""); - scope.registerStackRead(64, 1, ""); + scope.enterScope("First", 1); + scope.registerStackRead(24, 0, ""); + scope.registerStackRead(64, 1, ""); - scope.enterScope("Second", 2); - scope.registerStackWrite(32, 2, ""); + scope.enterScope("Second", 2); + scope.registerStackWrite(32, 2, ""); - scope.enterScope("Third", 3); - scope.registerStackWrite(64, 3, ""); + scope.enterScope("Third", 3); + scope.registerStackWrite(64, 3, ""); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("Third", 3); + scope.leaveScope("Third", 3); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("Second", 2); + scope.leaveScope("Second", 2); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("First", 1); + scope.leaveScope("First", 1); - // TODO(Lukas): Currently, there is no active scope. - // Think about your error handling. + // TODO(Lukas): Currently, there is no active scope. + // Think about your error handling. - // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.enterScope("Forth", 4); + scope.enterScope("Forth", 4); - scope.registerStackRead(24, 4, ""); + scope.registerStackRead(24, 4, ""); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.enterScope("Fifth", 5); + scope.enterScope("Fifth", 5); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); } TEST_F(MemoryManagerTest, testAllocateDummyRegion) { - auto manager = __dp::MemoryManager{}; + auto manager = __dp::MemoryManager{}; - ASSERT_EQ(manager.get_number_allocations(), 0); + ASSERT_EQ(manager.get_number_allocations(), 0); - manager.allocate_dummy_region(); + manager.allocate_dummy_region(); - ASSERT_EQ(manager.get_number_allocations(), 1); + ASSERT_EQ(manager.get_number_allocations(), 1); - manager.allocate_dummy_region(); + manager.allocate_dummy_region(); - ASSERT_EQ(manager.get_number_allocations(), 2); + ASSERT_EQ(manager.get_number_allocations(), 2); - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 2); + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 2); - for (const auto& allocation : allocations) { - ASSERT_EQ(std::get<0>(allocation), 0); - ASSERT_EQ(std::get<1>(allocation), "%%dummy%%"); - ASSERT_EQ(std::get<2>(allocation), 0); - ASSERT_EQ(std::get<3>(allocation), 0); - ASSERT_EQ(std::get<4>(allocation), 0); - ASSERT_EQ(std::get<5>(allocation), 0); - } + for (const auto &allocation : allocations) { + ASSERT_EQ(std::get<0>(allocation), 0); + ASSERT_EQ(std::get<1>(allocation), "%%dummy%%"); + ASSERT_EQ(std::get<2>(allocation), 0); + ASSERT_EQ(std::get<3>(allocation), 0); + ASSERT_EQ(std::get<4>(allocation), 0); + ASSERT_EQ(std::get<5>(allocation), 0); + } } TEST_F(MemoryManagerTest, testAllocateRegion1) { - auto manager = __dp::MemoryManager{}; - - const auto lid = 43; - const auto start_address = 0x2000'0000'0000'0000LL; - const auto end_address = 0x2000'0000'0000'1000LL; - const auto num_bytes = 0x1000LL; - const auto num_elements = 0x100LL; - - manager.allocate_memory(lid, start_address, end_address, num_bytes, num_elements); - - for (auto i = start_address; i <= end_address; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 1); - ASSERT_EQ(manager.get_number_allocations(), 1); - - const auto& allocation = allocations[0]; - ASSERT_EQ(std::get<0>(allocation), lid); - ASSERT_EQ(std::get<1>(allocation), "1"); - ASSERT_EQ(std::get<2>(allocation), start_address); - ASSERT_EQ(std::get<3>(allocation), end_address); - ASSERT_EQ(std::get<4>(allocation), num_bytes); - ASSERT_EQ(std::get<5>(allocation), num_elements); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 2); + auto manager = __dp::MemoryManager{}; + + const auto lid = 43; + const auto start_address = 0x2000'0000'0000'0000LL; + const auto end_address = 0x2000'0000'0000'1000LL; + const auto num_bytes = 0x1000LL; + const auto num_elements = 0x100LL; + + manager.allocate_memory(lid, start_address, end_address, num_bytes, num_elements); + + for (auto i = start_address; i <= end_address; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 1); + ASSERT_EQ(manager.get_number_allocations(), 1); + + const auto &allocation = allocations[0]; + ASSERT_EQ(std::get<0>(allocation), lid); + ASSERT_EQ(std::get<1>(allocation), "1"); + ASSERT_EQ(std::get<2>(allocation), start_address); + ASSERT_EQ(std::get<3>(allocation), end_address); + ASSERT_EQ(std::get<4>(allocation), num_bytes); + ASSERT_EQ(std::get<5>(allocation), num_elements); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 2); } TEST_F(MemoryManagerTest, testAllocateRegion2) { - auto manager = __dp::MemoryManager{}; - - const auto lid_1 = 43; - const auto start_address_1 = 0x2000'0000'0000'0000LL; - const auto end_address_1 = 0x2000'0000'0000'1000LL; - const auto num_bytes_1 = 0x1000LL; - const auto num_elements_1 = 0x100LL; - - manager.allocate_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); - - const auto lid_2 = 44; - const auto start_address_2 = 0x3000'0000'0000'0000LL; - const auto end_address_2 = 0x3000'0000'0000'5000LL; - const auto num_bytes_2 = 0x5000LL; - const auto num_elements_2 = 0x400LL; - - manager.allocate_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); - - for (auto i = start_address_1; i <= end_address_1; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - for (auto i = start_address_2; i <= end_address_2; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 2); - ASSERT_EQ(manager.get_number_allocations(), 2); - - const auto& allocation_1 = allocations[0]; - ASSERT_EQ(std::get<0>(allocation_1), lid_1); - ASSERT_EQ(std::get<1>(allocation_1), "1"); - ASSERT_EQ(std::get<2>(allocation_1), start_address_1); - ASSERT_EQ(std::get<3>(allocation_1), end_address_1); - ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); - ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); - - const auto& allocation_2 = allocations[1]; - ASSERT_EQ(std::get<0>(allocation_2), lid_2); - ASSERT_EQ(std::get<1>(allocation_2), "2"); - ASSERT_EQ(std::get<2>(allocation_2), start_address_2); - ASSERT_EQ(std::get<3>(allocation_2), end_address_2); - ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); - ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); + auto manager = __dp::MemoryManager{}; + + const auto lid_1 = 43; + const auto start_address_1 = 0x2000'0000'0000'0000LL; + const auto end_address_1 = 0x2000'0000'0000'1000LL; + const auto num_bytes_1 = 0x1000LL; + const auto num_elements_1 = 0x100LL; + + manager.allocate_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); + + const auto lid_2 = 44; + const auto start_address_2 = 0x3000'0000'0000'0000LL; + const auto end_address_2 = 0x3000'0000'0000'5000LL; + const auto num_bytes_2 = 0x5000LL; + const auto num_elements_2 = 0x400LL; + + manager.allocate_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); + + for (auto i = start_address_1; i <= end_address_1; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + for (auto i = start_address_2; i <= end_address_2; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 2); + ASSERT_EQ(manager.get_number_allocations(), 2); + + const auto &allocation_1 = allocations[0]; + ASSERT_EQ(std::get<0>(allocation_1), lid_1); + ASSERT_EQ(std::get<1>(allocation_1), "1"); + ASSERT_EQ(std::get<2>(allocation_1), start_address_1); + ASSERT_EQ(std::get<3>(allocation_1), end_address_1); + ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); + ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); + + const auto &allocation_2 = allocations[1]; + ASSERT_EQ(std::get<0>(allocation_2), lid_2); + ASSERT_EQ(std::get<1>(allocation_2), "2"); + ASSERT_EQ(std::get<2>(allocation_2), start_address_2); + ASSERT_EQ(std::get<3>(allocation_2), end_address_2); + ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); + ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); } TEST_F(MemoryManagerTest, testAllocateStackRegion1) { - auto manager = __dp::MemoryManager{}; - - manager.enter_new_function(); - - const auto lid = 43; - const auto start_address = 0x2000'0000'0000'0000LL; - const auto end_address = 0x2000'0000'0000'1000LL; - const auto num_bytes = 0x1000LL; - const auto num_elements = 0x100LL; - - manager.allocate_stack_memory(lid, start_address, end_address, num_bytes, num_elements); - - for (auto i = start_address; i <= end_address; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 1); - ASSERT_EQ(manager.get_number_allocations(), 1); - - const auto& allocation = allocations[0]; - ASSERT_EQ(std::get<0>(allocation), lid); - ASSERT_EQ(std::get<1>(allocation), "1"); - ASSERT_EQ(std::get<2>(allocation), start_address); - ASSERT_EQ(std::get<3>(allocation), end_address); - ASSERT_EQ(std::get<4>(allocation), num_bytes); - ASSERT_EQ(std::get<5>(allocation), num_elements); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 2); - - const auto stack_addresses = manager.pop_last_stack_address(); - ASSERT_EQ(stack_addresses.first, start_address); - ASSERT_EQ(stack_addresses.second, end_address); + auto manager = __dp::MemoryManager{}; + + manager.enter_new_function(); + + const auto lid = 43; + const auto start_address = 0x2000'0000'0000'0000LL; + const auto end_address = 0x2000'0000'0000'1000LL; + const auto num_bytes = 0x1000LL; + const auto num_elements = 0x100LL; + + manager.allocate_stack_memory(lid, start_address, end_address, num_bytes, num_elements); + + for (auto i = start_address; i <= end_address; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 1); + ASSERT_EQ(manager.get_number_allocations(), 1); + + const auto &allocation = allocations[0]; + ASSERT_EQ(std::get<0>(allocation), lid); + ASSERT_EQ(std::get<1>(allocation), "1"); + ASSERT_EQ(std::get<2>(allocation), start_address); + ASSERT_EQ(std::get<3>(allocation), end_address); + ASSERT_EQ(std::get<4>(allocation), num_bytes); + ASSERT_EQ(std::get<5>(allocation), num_elements); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 2); + + const auto stack_addresses = manager.pop_last_stack_address(); + ASSERT_EQ(stack_addresses.first, start_address); + ASSERT_EQ(stack_addresses.second, end_address); } TEST_F(MemoryManagerTest, testAllocateStackRegion2) { - auto manager = __dp::MemoryManager{}; - - manager.enter_new_function(); - - const auto lid_1 = 43; - const auto start_address_1 = 0x2000'0000'0000'0000LL; - const auto end_address_1 = 0x2000'0000'0000'1000LL; - const auto num_bytes_1 = 0x1000LL; - const auto num_elements_1 = 0x100LL; - - manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); - - const auto lid_2 = 44; - const auto start_address_2 = 0x3000'0000'0000'0000LL; - const auto end_address_2 = 0x3000'0000'0000'5000LL; - const auto num_bytes_2 = 0x5000LL; - const auto num_elements_2 = 0x400LL; - - manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); - - for (auto i = start_address_1; i <= end_address_1; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - for (auto i = start_address_2; i <= end_address_2; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 2); - ASSERT_EQ(manager.get_number_allocations(), 2); - - const auto& allocation_1 = allocations[0]; - ASSERT_EQ(std::get<0>(allocation_1), lid_1); - ASSERT_EQ(std::get<1>(allocation_1), "1"); - ASSERT_EQ(std::get<2>(allocation_1), start_address_1); - ASSERT_EQ(std::get<3>(allocation_1), end_address_1); - ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); - ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); - - const auto& allocation_2 = allocations[1]; - ASSERT_EQ(std::get<0>(allocation_2), lid_2); - ASSERT_EQ(std::get<1>(allocation_2), "2"); - ASSERT_EQ(std::get<2>(allocation_2), start_address_2); - ASSERT_EQ(std::get<3>(allocation_2), end_address_2); - ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); - ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); - - const auto stack_addresses = manager.pop_last_stack_address(); - ASSERT_EQ(stack_addresses.first, start_address_1); - ASSERT_EQ(stack_addresses.second, end_address_2); + auto manager = __dp::MemoryManager{}; + + manager.enter_new_function(); + + const auto lid_1 = 43; + const auto start_address_1 = 0x2000'0000'0000'0000LL; + const auto end_address_1 = 0x2000'0000'0000'1000LL; + const auto num_bytes_1 = 0x1000LL; + const auto num_elements_1 = 0x100LL; + + manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); + + const auto lid_2 = 44; + const auto start_address_2 = 0x3000'0000'0000'0000LL; + const auto end_address_2 = 0x3000'0000'0000'5000LL; + const auto num_bytes_2 = 0x5000LL; + const auto num_elements_2 = 0x400LL; + + manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); + + for (auto i = start_address_1; i <= end_address_1; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + for (auto i = start_address_2; i <= end_address_2; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 2); + ASSERT_EQ(manager.get_number_allocations(), 2); + + const auto &allocation_1 = allocations[0]; + ASSERT_EQ(std::get<0>(allocation_1), lid_1); + ASSERT_EQ(std::get<1>(allocation_1), "1"); + ASSERT_EQ(std::get<2>(allocation_1), start_address_1); + ASSERT_EQ(std::get<3>(allocation_1), end_address_1); + ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); + ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); + + const auto &allocation_2 = allocations[1]; + ASSERT_EQ(std::get<0>(allocation_2), lid_2); + ASSERT_EQ(std::get<1>(allocation_2), "2"); + ASSERT_EQ(std::get<2>(allocation_2), start_address_2); + ASSERT_EQ(std::get<3>(allocation_2), end_address_2); + ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); + ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); + + const auto stack_addresses = manager.pop_last_stack_address(); + ASSERT_EQ(stack_addresses.first, start_address_1); + ASSERT_EQ(stack_addresses.second, end_address_2); } TEST_F(MemoryManagerTest, testAllocateStackRegion3) { - auto manager = __dp::MemoryManager{}; - - manager.enter_new_function(); - - const auto lid_1 = 43; - const auto start_address_1 = 0x2000'0000'0000'0000LL; - const auto end_address_1 = 0x2000'0000'0000'1000LL; - const auto num_bytes_1 = 0x1000LL; - const auto num_elements_1 = 0x100LL; - - manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); - - manager.enter_new_function(); - - const auto lid_2 = 44; - const auto start_address_2 = 0x3000'0000'0000'0000LL; - const auto end_address_2 = 0x3000'0000'0000'5000LL; - const auto num_bytes_2 = 0x5000LL; - const auto num_elements_2 = 0x400LL; - - manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); - - for (auto i = start_address_1; i <= end_address_1; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - for (auto i = start_address_2; i <= end_address_2; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 2); - ASSERT_EQ(manager.get_number_allocations(), 2); - - const auto& allocation_1 = allocations[0]; - ASSERT_EQ(std::get<0>(allocation_1), lid_1); - ASSERT_EQ(std::get<1>(allocation_1), "1"); - ASSERT_EQ(std::get<2>(allocation_1), start_address_1); - ASSERT_EQ(std::get<3>(allocation_1), end_address_1); - ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); - ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); - - const auto& allocation_2 = allocations[1]; - ASSERT_EQ(std::get<0>(allocation_2), lid_2); - ASSERT_EQ(std::get<1>(allocation_2), "2"); - ASSERT_EQ(std::get<2>(allocation_2), start_address_2); - ASSERT_EQ(std::get<3>(allocation_2), end_address_2); - ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); - ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); - - const auto stack_addresses = manager.pop_last_stack_address(); - ASSERT_EQ(stack_addresses.first, start_address_2); - ASSERT_EQ(stack_addresses.second, end_address_2); + auto manager = __dp::MemoryManager{}; + + manager.enter_new_function(); + + const auto lid_1 = 43; + const auto start_address_1 = 0x2000'0000'0000'0000LL; + const auto end_address_1 = 0x2000'0000'0000'1000LL; + const auto num_bytes_1 = 0x1000LL; + const auto num_elements_1 = 0x100LL; + + manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); + + manager.enter_new_function(); + + const auto lid_2 = 44; + const auto start_address_2 = 0x3000'0000'0000'0000LL; + const auto end_address_2 = 0x3000'0000'0000'5000LL; + const auto num_bytes_2 = 0x5000LL; + const auto num_elements_2 = 0x400LL; + + manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); + + for (auto i = start_address_1; i <= end_address_1; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + for (auto i = start_address_2; i <= end_address_2; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_1); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 2); + ASSERT_EQ(manager.get_number_allocations(), 2); + + const auto &allocation_1 = allocations[0]; + ASSERT_EQ(std::get<0>(allocation_1), lid_1); + ASSERT_EQ(std::get<1>(allocation_1), "1"); + ASSERT_EQ(std::get<2>(allocation_1), start_address_1); + ASSERT_EQ(std::get<3>(allocation_1), end_address_1); + ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); + ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); + + const auto &allocation_2 = allocations[1]; + ASSERT_EQ(std::get<0>(allocation_2), lid_2); + ASSERT_EQ(std::get<1>(allocation_2), "2"); + ASSERT_EQ(std::get<2>(allocation_2), start_address_2); + ASSERT_EQ(std::get<3>(allocation_2), end_address_2); + ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); + ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 3); + + const auto stack_addresses = manager.pop_last_stack_address(); + ASSERT_EQ(stack_addresses.first, start_address_2); + ASSERT_EQ(stack_addresses.second, end_address_2); } TEST_F(MemoryManagerTest, testAllocate1) { - auto manager = __dp::MemoryManager{}; - - manager.enter_new_function(); - - const auto lid_1 = 43; - const auto start_address_1 = 0x2000'0000'0000'0000LL; - const auto end_address_1 = 0x2000'0000'0000'1000LL; - const auto num_bytes_1 = 0x1000LL; - const auto num_elements_1 = 0x100LL; - - manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); - - const auto lid_2 = 44; - const auto start_address_2 = 0x3000'0000'0000'0000LL; - const auto end_address_2 = 0x3000'0000'0000'5000LL; - const auto num_bytes_2 = 0x5000LL; - const auto num_elements_2 = 0x400LL; - - manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); - - const auto lid_3 = 45; - const auto start_address_3 = 0x1000'0000'0000'0000LL; - const auto end_address_3 = 0x1000'0000'0000'2000LL; - const auto num_bytes_3 = 0x2000LL; - const auto num_elements_3 = 0x2000LL; - - manager.allocate_memory(lid_3, start_address_3, end_address_3, num_bytes_3, num_elements_3); - - for (auto i = start_address_1; i <= end_address_1; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - for (auto i = start_address_2; i <= end_address_2; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); - } - - for (auto i = start_address_3; i <= end_address_3; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "3"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_3); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 3); - ASSERT_EQ(manager.get_number_allocations(), 3); - - const auto& allocation_1 = allocations[0]; - ASSERT_EQ(std::get<0>(allocation_1), lid_1); - ASSERT_EQ(std::get<1>(allocation_1), "1"); - ASSERT_EQ(std::get<2>(allocation_1), start_address_1); - ASSERT_EQ(std::get<3>(allocation_1), end_address_1); - ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); - ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); - - const auto& allocation_2 = allocations[1]; - ASSERT_EQ(std::get<0>(allocation_2), lid_2); - ASSERT_EQ(std::get<1>(allocation_2), "2"); - ASSERT_EQ(std::get<2>(allocation_2), start_address_2); - ASSERT_EQ(std::get<3>(allocation_2), end_address_2); - ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); - ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); - - const auto& allocation_3 = allocations[2]; - ASSERT_EQ(std::get<0>(allocation_3), lid_3); - ASSERT_EQ(std::get<1>(allocation_3), "3"); - ASSERT_EQ(std::get<2>(allocation_3), start_address_3); - ASSERT_EQ(std::get<3>(allocation_3), end_address_3); - ASSERT_EQ(std::get<4>(allocation_3), num_bytes_3); - ASSERT_EQ(std::get<5>(allocation_3), num_elements_3); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 4); - - const auto stack_addresses = manager.pop_last_stack_address(); - ASSERT_EQ(stack_addresses.first, start_address_1); - ASSERT_EQ(stack_addresses.second, end_address_2); + auto manager = __dp::MemoryManager{}; + + manager.enter_new_function(); + + const auto lid_1 = 43; + const auto start_address_1 = 0x2000'0000'0000'0000LL; + const auto end_address_1 = 0x2000'0000'0000'1000LL; + const auto num_bytes_1 = 0x1000LL; + const auto num_elements_1 = 0x100LL; + + manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); + + const auto lid_2 = 44; + const auto start_address_2 = 0x3000'0000'0000'0000LL; + const auto end_address_2 = 0x3000'0000'0000'5000LL; + const auto num_bytes_2 = 0x5000LL; + const auto num_elements_2 = 0x400LL; + + manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); + + const auto lid_3 = 45; + const auto start_address_3 = 0x1000'0000'0000'0000LL; + const auto end_address_3 = 0x1000'0000'0000'2000LL; + const auto num_bytes_3 = 0x2000LL; + const auto num_elements_3 = 0x2000LL; + + manager.allocate_memory(lid_3, start_address_3, end_address_3, num_bytes_3, num_elements_3); + + for (auto i = start_address_1; i <= end_address_1; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + for (auto i = start_address_2; i <= end_address_2; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); + } + + for (auto i = start_address_3; i <= end_address_3; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "3"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_3); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_2); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 3); + ASSERT_EQ(manager.get_number_allocations(), 3); + + const auto &allocation_1 = allocations[0]; + ASSERT_EQ(std::get<0>(allocation_1), lid_1); + ASSERT_EQ(std::get<1>(allocation_1), "1"); + ASSERT_EQ(std::get<2>(allocation_1), start_address_1); + ASSERT_EQ(std::get<3>(allocation_1), end_address_1); + ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); + ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); + + const auto &allocation_2 = allocations[1]; + ASSERT_EQ(std::get<0>(allocation_2), lid_2); + ASSERT_EQ(std::get<1>(allocation_2), "2"); + ASSERT_EQ(std::get<2>(allocation_2), start_address_2); + ASSERT_EQ(std::get<3>(allocation_2), end_address_2); + ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); + ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); + + const auto &allocation_3 = allocations[2]; + ASSERT_EQ(std::get<0>(allocation_3), lid_3); + ASSERT_EQ(std::get<1>(allocation_3), "3"); + ASSERT_EQ(std::get<2>(allocation_3), start_address_3); + ASSERT_EQ(std::get<3>(allocation_3), end_address_3); + ASSERT_EQ(std::get<4>(allocation_3), num_bytes_3); + ASSERT_EQ(std::get<5>(allocation_3), num_elements_3); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 4); + + const auto stack_addresses = manager.pop_last_stack_address(); + ASSERT_EQ(stack_addresses.first, start_address_1); + ASSERT_EQ(stack_addresses.second, end_address_2); } TEST_F(MemoryManagerTest, testAllocate2) { - auto manager = __dp::MemoryManager{}; - - manager.enter_new_function(); - - const auto lid_1 = 43; - const auto start_address_1 = 0x2000'0000'0000'0000LL; - const auto end_address_1 = 0x2000'0000'0000'1000LL; - const auto num_bytes_1 = 0x1000LL; - const auto num_elements_1 = 0x100LL; - - manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); - - const auto lid_2 = 44; - const auto start_address_2 = 0x3000'0000'0000'0000LL; - const auto end_address_2 = 0x3000'0000'0000'5000LL; - const auto num_bytes_2 = 0x5000LL; - const auto num_elements_2 = 0x400LL; - - manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); - - const auto lid_3 = 45; - const auto start_address_3 = 0x1000'0000'0000'0000LL; - const auto end_address_3 = 0x1000'0000'0000'2000LL; - const auto num_bytes_3 = 0x2000LL; - const auto num_elements_3 = 0x2000LL; - - manager.allocate_memory(lid_3, start_address_3, end_address_3, num_bytes_3, num_elements_3); - - const auto lid_4 = 46; - const auto start_address_4 = 0x5000'0000'0000'0000LL; - const auto end_address_4 = 0x5000'0000'0000'0200LL; - const auto num_bytes_4 = 0x200LL; - const auto num_elements_4 = 0x2LL; - - manager.allocate_memory(lid_4, start_address_4, end_address_4, num_bytes_4, num_elements_4); - - for (auto i = start_address_1; i <= end_address_1; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); - } - - for (auto i = start_address_2; i <= end_address_2; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); - } - - for (auto i = start_address_3; i <= end_address_3; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "3"); - } - - for (auto i = start_address_4; i <= end_address_4; i++) { - ASSERT_EQ(manager.get_memory_region_id(i, ""), "4"); - } - - ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - - ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_3); - ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_4); - - const auto& allocations = manager.get_allocated_memory_regions(); - ASSERT_EQ(allocations.size(), 4); - ASSERT_EQ(manager.get_number_allocations(), 4); - - const auto& allocation_1 = allocations[0]; - ASSERT_EQ(std::get<0>(allocation_1), lid_1); - ASSERT_EQ(std::get<1>(allocation_1), "1"); - ASSERT_EQ(std::get<2>(allocation_1), start_address_1); - ASSERT_EQ(std::get<3>(allocation_1), end_address_1); - ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); - ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); - - const auto& allocation_2 = allocations[1]; - ASSERT_EQ(std::get<0>(allocation_2), lid_2); - ASSERT_EQ(std::get<1>(allocation_2), "2"); - ASSERT_EQ(std::get<2>(allocation_2), start_address_2); - ASSERT_EQ(std::get<3>(allocation_2), end_address_2); - ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); - ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); - - const auto& allocation_3 = allocations[2]; - ASSERT_EQ(std::get<0>(allocation_3), lid_3); - ASSERT_EQ(std::get<1>(allocation_3), "3"); - ASSERT_EQ(std::get<2>(allocation_3), start_address_3); - ASSERT_EQ(std::get<3>(allocation_3), end_address_3); - ASSERT_EQ(std::get<4>(allocation_3), num_bytes_3); - ASSERT_EQ(std::get<5>(allocation_3), num_elements_3); - - const auto& allocation_4 = allocations[3]; - ASSERT_EQ(std::get<0>(allocation_4), lid_4); - ASSERT_EQ(std::get<1>(allocation_4), "4"); - ASSERT_EQ(std::get<2>(allocation_4), start_address_4); - ASSERT_EQ(std::get<3>(allocation_4), end_address_4); - ASSERT_EQ(std::get<4>(allocation_4), num_bytes_4); - ASSERT_EQ(std::get<5>(allocation_4), num_elements_4); - - ASSERT_EQ(manager.get_next_free_memory_region_id(), 5); - - const auto stack_addresses = manager.pop_last_stack_address(); - ASSERT_EQ(stack_addresses.first, start_address_1); - ASSERT_EQ(stack_addresses.second, end_address_2); + auto manager = __dp::MemoryManager{}; + + manager.enter_new_function(); + + const auto lid_1 = 43; + const auto start_address_1 = 0x2000'0000'0000'0000LL; + const auto end_address_1 = 0x2000'0000'0000'1000LL; + const auto num_bytes_1 = 0x1000LL; + const auto num_elements_1 = 0x100LL; + + manager.allocate_stack_memory(lid_1, start_address_1, end_address_1, num_bytes_1, num_elements_1); + + const auto lid_2 = 44; + const auto start_address_2 = 0x3000'0000'0000'0000LL; + const auto end_address_2 = 0x3000'0000'0000'5000LL; + const auto num_bytes_2 = 0x5000LL; + const auto num_elements_2 = 0x400LL; + + manager.allocate_stack_memory(lid_2, start_address_2, end_address_2, num_bytes_2, num_elements_2); + + const auto lid_3 = 45; + const auto start_address_3 = 0x1000'0000'0000'0000LL; + const auto end_address_3 = 0x1000'0000'0000'2000LL; + const auto num_bytes_3 = 0x2000LL; + const auto num_elements_3 = 0x2000LL; + + manager.allocate_memory(lid_3, start_address_3, end_address_3, num_bytes_3, num_elements_3); + + const auto lid_4 = 46; + const auto start_address_4 = 0x5000'0000'0000'0000LL; + const auto end_address_4 = 0x5000'0000'0000'0200LL; + const auto num_bytes_4 = 0x200LL; + const auto num_elements_4 = 0x2LL; + + manager.allocate_memory(lid_4, start_address_4, end_address_4, num_bytes_4, num_elements_4); + + for (auto i = start_address_1; i <= end_address_1; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "1"); + } + + for (auto i = start_address_2; i <= end_address_2; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "2"); + } + + for (auto i = start_address_3; i <= end_address_3; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "3"); + } + + for (auto i = start_address_4; i <= end_address_4; i++) { + ASSERT_EQ(manager.get_memory_region_id(i, ""), "4"); + } + + ASSERT_EQ(manager.get_memory_region_id(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x1242'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x5300'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(manager.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + + ASSERT_EQ(manager.get_smallest_allocated_addr(), start_address_3); + ASSERT_EQ(manager.get_largest_allocated_addr(), end_address_4); + + const auto &allocations = manager.get_allocated_memory_regions(); + ASSERT_EQ(allocations.size(), 4); + ASSERT_EQ(manager.get_number_allocations(), 4); + + const auto &allocation_1 = allocations[0]; + ASSERT_EQ(std::get<0>(allocation_1), lid_1); + ASSERT_EQ(std::get<1>(allocation_1), "1"); + ASSERT_EQ(std::get<2>(allocation_1), start_address_1); + ASSERT_EQ(std::get<3>(allocation_1), end_address_1); + ASSERT_EQ(std::get<4>(allocation_1), num_bytes_1); + ASSERT_EQ(std::get<5>(allocation_1), num_elements_1); + + const auto &allocation_2 = allocations[1]; + ASSERT_EQ(std::get<0>(allocation_2), lid_2); + ASSERT_EQ(std::get<1>(allocation_2), "2"); + ASSERT_EQ(std::get<2>(allocation_2), start_address_2); + ASSERT_EQ(std::get<3>(allocation_2), end_address_2); + ASSERT_EQ(std::get<4>(allocation_2), num_bytes_2); + ASSERT_EQ(std::get<5>(allocation_2), num_elements_2); + + const auto &allocation_3 = allocations[2]; + ASSERT_EQ(std::get<0>(allocation_3), lid_3); + ASSERT_EQ(std::get<1>(allocation_3), "3"); + ASSERT_EQ(std::get<2>(allocation_3), start_address_3); + ASSERT_EQ(std::get<3>(allocation_3), end_address_3); + ASSERT_EQ(std::get<4>(allocation_3), num_bytes_3); + ASSERT_EQ(std::get<5>(allocation_3), num_elements_3); + + const auto &allocation_4 = allocations[3]; + ASSERT_EQ(std::get<0>(allocation_4), lid_4); + ASSERT_EQ(std::get<1>(allocation_4), "4"); + ASSERT_EQ(std::get<2>(allocation_4), start_address_4); + ASSERT_EQ(std::get<3>(allocation_4), end_address_4); + ASSERT_EQ(std::get<4>(allocation_4), num_bytes_4); + ASSERT_EQ(std::get<5>(allocation_4), num_elements_4); + + ASSERT_EQ(manager.get_next_free_memory_region_id(), 5); + + const auto stack_addresses = manager.pop_last_stack_address(); + ASSERT_EQ(stack_addresses.first, start_address_1); + ASSERT_EQ(stack_addresses.second, end_address_2); } diff --git a/test/unit_tests/memory/memory_region_tree/test_memory_region_tree.cpp b/test/unit_tests/memory/memory_region_tree/test_memory_region_tree.cpp index e16e70617..415dca00f 100644 --- a/test/unit_tests/memory/memory_region_tree/test_memory_region_tree.cpp +++ b/test/unit_tests/memory/memory_region_tree/test_memory_region_tree.cpp @@ -5,683 +5,683 @@ #include #include -class MemoryRegionTreeTest : public ::testing::Test { }; +class MemoryRegionTreeTest : public ::testing::Test {}; TEST_F(MemoryRegionTreeTest, testConstructor) { - const auto tree = __dp::MemoryRegionTree{}; + const auto tree = __dp::MemoryRegionTree{}; - const auto* root = tree.get_root(); + const auto *root = tree.get_root(); - ASSERT_EQ(root->get_first_addr(), 0x0000000000000000LL); - ASSERT_EQ(root->get_last_addr(), 0x7FFFFFFFFFFFFFFFLL); - ASSERT_EQ(root->get_memory_region_id(), 0); + ASSERT_EQ(root->get_first_addr(), 0x0000000000000000LL); + ASSERT_EQ(root->get_last_addr(), 0x7FFFFFFFFFFFFFFFLL); + ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion1) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1234; + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1234; - tree.allocate_region(start_addr, end_addr, memory_region_id); + tree.allocate_region(start_addr, end_addr, memory_region_id); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), memory_region_id); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), memory_region_id); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion2) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x0FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x2345; + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x0FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x2345; - tree.allocate_region(start_addr, end_addr, memory_region_id); + tree.allocate_region(start_addr, end_addr, memory_region_id); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 1; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 1; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } - auto child = root->get_child(0); - - ASSERT_EQ(child->get_memory_region_id(), memory_region_id); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(child->get_child(i), nullptr); - } + auto child = root->get_child(0); + + ASSERT_EQ(child->get_memory_region_id(), memory_region_id); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(child->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion3) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x1000000000000000LL; - const auto end_addr = 0x3FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x2345; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - auto* root = tree.get_root(); - - ASSERT_EQ(root->get_child(0), nullptr); - ASSERT_NE(root->get_child(1), nullptr); - ASSERT_NE(root->get_child(2), nullptr); - ASSERT_NE(root->get_child(3), nullptr); - ASSERT_EQ(root->get_child(4), nullptr); - ASSERT_EQ(root->get_child(5), nullptr); - ASSERT_EQ(root->get_child(6), nullptr); - ASSERT_EQ(root->get_child(7), nullptr); - ASSERT_EQ(root->get_child(8), nullptr); - ASSERT_EQ(root->get_child(9), nullptr); - ASSERT_EQ(root->get_child(10), nullptr); - ASSERT_EQ(root->get_child(11), nullptr); - ASSERT_EQ(root->get_child(12), nullptr); - ASSERT_EQ(root->get_child(13), nullptr); - ASSERT_EQ(root->get_child(14), nullptr); - ASSERT_EQ(root->get_child(15), nullptr); - - auto* child1 = root->get_child(1); - auto* child2 = root->get_child(2); - auto* child3 = root->get_child(3); - - ASSERT_EQ(child1->get_memory_region_id(), memory_region_id); - ASSERT_EQ(child2->get_memory_region_id(), memory_region_id); - ASSERT_EQ(child3->get_memory_region_id(), memory_region_id); - - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(child1->get_child(i), nullptr); - ASSERT_EQ(child2->get_child(i), nullptr); - ASSERT_EQ(child3->get_child(i), nullptr); - } + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x1000000000000000LL; + const auto end_addr = 0x3FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x2345; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_child(0), nullptr); + ASSERT_NE(root->get_child(1), nullptr); + ASSERT_NE(root->get_child(2), nullptr); + ASSERT_NE(root->get_child(3), nullptr); + ASSERT_EQ(root->get_child(4), nullptr); + ASSERT_EQ(root->get_child(5), nullptr); + ASSERT_EQ(root->get_child(6), nullptr); + ASSERT_EQ(root->get_child(7), nullptr); + ASSERT_EQ(root->get_child(8), nullptr); + ASSERT_EQ(root->get_child(9), nullptr); + ASSERT_EQ(root->get_child(10), nullptr); + ASSERT_EQ(root->get_child(11), nullptr); + ASSERT_EQ(root->get_child(12), nullptr); + ASSERT_EQ(root->get_child(13), nullptr); + ASSERT_EQ(root->get_child(14), nullptr); + ASSERT_EQ(root->get_child(15), nullptr); + + auto *child1 = root->get_child(1); + auto *child2 = root->get_child(2); + auto *child3 = root->get_child(3); + + ASSERT_EQ(child1->get_memory_region_id(), memory_region_id); + ASSERT_EQ(child2->get_memory_region_id(), memory_region_id); + ASSERT_EQ(child3->get_memory_region_id(), memory_region_id); + + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(child1->get_child(i), nullptr); + ASSERT_EQ(child2->get_child(i), nullptr); + ASSERT_EQ(child3->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion4) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x1000000000000000LL; - const auto end_addr = 0x2CFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1111; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - auto* root = tree.get_root(); - - ASSERT_EQ(root->get_child(0), nullptr); - ASSERT_NE(root->get_child(1), nullptr); - ASSERT_NE(root->get_child(2), nullptr); - ASSERT_EQ(root->get_child(3), nullptr); - ASSERT_EQ(root->get_child(4), nullptr); - ASSERT_EQ(root->get_child(5), nullptr); - ASSERT_EQ(root->get_child(6), nullptr); - ASSERT_EQ(root->get_child(7), nullptr); - ASSERT_EQ(root->get_child(8), nullptr); - ASSERT_EQ(root->get_child(9), nullptr); - ASSERT_EQ(root->get_child(10), nullptr); - ASSERT_EQ(root->get_child(11), nullptr); - ASSERT_EQ(root->get_child(12), nullptr); - ASSERT_EQ(root->get_child(13), nullptr); - ASSERT_EQ(root->get_child(14), nullptr); - ASSERT_EQ(root->get_child(15), nullptr); - - auto* child1 = root->get_child(1); - auto* child2 = root->get_child(2); - - ASSERT_EQ(child1->get_memory_region_id(), memory_region_id); - ASSERT_EQ(child2->get_memory_region_id(), 0); - - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(child1->get_child(i), nullptr); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x1000000000000000LL; + const auto end_addr = 0x2CFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1111; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_child(0), nullptr); + ASSERT_NE(root->get_child(1), nullptr); + ASSERT_NE(root->get_child(2), nullptr); + ASSERT_EQ(root->get_child(3), nullptr); + ASSERT_EQ(root->get_child(4), nullptr); + ASSERT_EQ(root->get_child(5), nullptr); + ASSERT_EQ(root->get_child(6), nullptr); + ASSERT_EQ(root->get_child(7), nullptr); + ASSERT_EQ(root->get_child(8), nullptr); + ASSERT_EQ(root->get_child(9), nullptr); + ASSERT_EQ(root->get_child(10), nullptr); + ASSERT_EQ(root->get_child(11), nullptr); + ASSERT_EQ(root->get_child(12), nullptr); + ASSERT_EQ(root->get_child(13), nullptr); + ASSERT_EQ(root->get_child(14), nullptr); + ASSERT_EQ(root->get_child(15), nullptr); + + auto *child1 = root->get_child(1); + auto *child2 = root->get_child(2); + + ASSERT_EQ(child1->get_memory_region_id(), memory_region_id); + ASSERT_EQ(child2->get_memory_region_id(), 0); + + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(child1->get_child(i), nullptr); + } + + for (auto i = 0; i < 13; i++) { + ASSERT_NE(child2->get_child(i), nullptr); + for (auto *gc : child2->get_child(i)->get_children()) { + ASSERT_EQ(gc, nullptr); } - for (auto i = 0; i < 13; i++) { - ASSERT_NE(child2->get_child(i), nullptr); - for (auto* gc : child2->get_child(i)->get_children()) { - ASSERT_EQ(gc, nullptr); - } + ASSERT_EQ(child2->get_child(i)->get_memory_region_id(), memory_region_id); + } - ASSERT_EQ(child2->get_child(i)->get_memory_region_id(), memory_region_id); - } - - for (auto i = 13; i < 16; i++) { - ASSERT_EQ(child2->get_child(i), nullptr); - } + for (auto i = 13; i < 16; i++) { + ASSERT_EQ(child2->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion5) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x13542698001FAB52LL; - const auto end_addr = 0x13542698001FAB52LL; - const auto memory_region_id = 0x1111; + const auto start_addr = 0x13542698001FAB52LL; + const auto end_addr = 0x13542698001FAB52LL; + const auto memory_region_id = 0x1111; - tree.allocate_region(start_addr, end_addr, memory_region_id); + tree.allocate_region(start_addr, end_addr, memory_region_id); - auto* node = tree.get_root(); + auto *node = tree.get_root(); - while (true) { - const auto node_start = node->get_first_addr(); - const auto node_end = node->get_last_addr(); + while (true) { + const auto node_start = node->get_first_addr(); + const auto node_end = node->get_last_addr(); - if (node_start == start_addr && node_end == end_addr) { - ASSERT_EQ(node->get_memory_region_id(), memory_region_id); - ASSERT_EQ(node_start, start_addr); - ASSERT_EQ(node_end, end_addr); + if (node_start == start_addr && node_end == end_addr) { + ASSERT_EQ(node->get_memory_region_id(), memory_region_id); + ASSERT_EQ(node_start, start_addr); + ASSERT_EQ(node_end, end_addr); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(node->get_child(i), nullptr); - } - break; - } + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(node->get_child(i), nullptr); + } + break; + } - auto counter = 0; - __dp::MRTNode* new_node = nullptr; + auto counter = 0; + __dp::MRTNode *new_node = nullptr; - for (auto i = 0; i < 16; i++) { - auto* child = node->get_child(i); - if (child != nullptr) { - new_node = child; - counter++; - } - } + for (auto i = 0; i < 16; i++) { + auto *child = node->get_child(i); + if (child != nullptr) { + new_node = child; + counter++; + } + } - node = new_node; + node = new_node; - ASSERT_EQ(counter, 1); - } + ASSERT_EQ(counter, 1); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion6) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x5000000000000000LL; - const auto end_addr_2 = 0x5FFFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - auto* root = tree.get_root(); - - ASSERT_EQ(root->get_child(0), nullptr); - ASSERT_NE(root->get_child(1), nullptr); - ASSERT_EQ(root->get_child(2), nullptr); - ASSERT_EQ(root->get_child(3), nullptr); - ASSERT_EQ(root->get_child(4), nullptr); - ASSERT_NE(root->get_child(5), nullptr); - ASSERT_EQ(root->get_child(6), nullptr); - ASSERT_EQ(root->get_child(7), nullptr); - ASSERT_EQ(root->get_child(8), nullptr); - ASSERT_EQ(root->get_child(9), nullptr); - ASSERT_EQ(root->get_child(10), nullptr); - ASSERT_EQ(root->get_child(11), nullptr); - ASSERT_EQ(root->get_child(12), nullptr); - ASSERT_EQ(root->get_child(13), nullptr); - ASSERT_EQ(root->get_child(14), nullptr); - ASSERT_EQ(root->get_child(15), nullptr); - - auto* child1 = root->get_child(1); - auto* child5 = root->get_child(5); - - ASSERT_EQ(child1->get_memory_region_id(), memory_region_id_1); - ASSERT_EQ(child5->get_memory_region_id(), memory_region_id_2); - - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(child1->get_child(i), nullptr); - ASSERT_EQ(child5->get_child(i), nullptr); - } + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x5000000000000000LL; + const auto end_addr_2 = 0x5FFFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_child(0), nullptr); + ASSERT_NE(root->get_child(1), nullptr); + ASSERT_EQ(root->get_child(2), nullptr); + ASSERT_EQ(root->get_child(3), nullptr); + ASSERT_EQ(root->get_child(4), nullptr); + ASSERT_NE(root->get_child(5), nullptr); + ASSERT_EQ(root->get_child(6), nullptr); + ASSERT_EQ(root->get_child(7), nullptr); + ASSERT_EQ(root->get_child(8), nullptr); + ASSERT_EQ(root->get_child(9), nullptr); + ASSERT_EQ(root->get_child(10), nullptr); + ASSERT_EQ(root->get_child(11), nullptr); + ASSERT_EQ(root->get_child(12), nullptr); + ASSERT_EQ(root->get_child(13), nullptr); + ASSERT_EQ(root->get_child(14), nullptr); + ASSERT_EQ(root->get_child(15), nullptr); + + auto *child1 = root->get_child(1); + auto *child5 = root->get_child(5); + + ASSERT_EQ(child1->get_memory_region_id(), memory_region_id_1); + ASSERT_EQ(child5->get_memory_region_id(), memory_region_id_2); + + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(child1->get_child(i), nullptr); + ASSERT_EQ(child5->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testAllocateRegion7) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x5300000000000000LL; - const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - auto* root = tree.get_root(); - - ASSERT_EQ(root->get_child(0), nullptr); - ASSERT_NE(root->get_child(1), nullptr); - ASSERT_EQ(root->get_child(2), nullptr); - ASSERT_EQ(root->get_child(3), nullptr); - ASSERT_EQ(root->get_child(4), nullptr); - ASSERT_NE(root->get_child(5), nullptr); - ASSERT_EQ(root->get_child(6), nullptr); - ASSERT_EQ(root->get_child(7), nullptr); - ASSERT_EQ(root->get_child(8), nullptr); - ASSERT_EQ(root->get_child(9), nullptr); - ASSERT_EQ(root->get_child(10), nullptr); - ASSERT_EQ(root->get_child(11), nullptr); - ASSERT_EQ(root->get_child(12), nullptr); - ASSERT_EQ(root->get_child(13), nullptr); - ASSERT_EQ(root->get_child(14), nullptr); - ASSERT_EQ(root->get_child(15), nullptr); - - auto* child1 = root->get_child(1); - ASSERT_EQ(child1->get_memory_region_id(), memory_region_id_1); - - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(child1->get_child(i), nullptr); - } - - auto* child5 = root->get_child(5); - ASSERT_EQ(child5->get_memory_region_id(), 0); - - for (auto i = 0; i < 16; i++) { - if (i == 3) { - ASSERT_NE(child5->get_child(i), nullptr); - ASSERT_EQ(child5->get_child(i)->get_memory_region_id(), memory_region_id_2); - - for (auto j = 0; j < 16; j++) { - ASSERT_EQ(child5->get_child(i)->get_child(j), nullptr); - } - } else { - ASSERT_EQ(child5->get_child(i), nullptr); - } + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x5300000000000000LL; + const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_child(0), nullptr); + ASSERT_NE(root->get_child(1), nullptr); + ASSERT_EQ(root->get_child(2), nullptr); + ASSERT_EQ(root->get_child(3), nullptr); + ASSERT_EQ(root->get_child(4), nullptr); + ASSERT_NE(root->get_child(5), nullptr); + ASSERT_EQ(root->get_child(6), nullptr); + ASSERT_EQ(root->get_child(7), nullptr); + ASSERT_EQ(root->get_child(8), nullptr); + ASSERT_EQ(root->get_child(9), nullptr); + ASSERT_EQ(root->get_child(10), nullptr); + ASSERT_EQ(root->get_child(11), nullptr); + ASSERT_EQ(root->get_child(12), nullptr); + ASSERT_EQ(root->get_child(13), nullptr); + ASSERT_EQ(root->get_child(14), nullptr); + ASSERT_EQ(root->get_child(15), nullptr); + + auto *child1 = root->get_child(1); + ASSERT_EQ(child1->get_memory_region_id(), memory_region_id_1); + + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(child1->get_child(i), nullptr); + } + + auto *child5 = root->get_child(5); + ASSERT_EQ(child5->get_memory_region_id(), 0); + + for (auto i = 0; i < 16; i++) { + if (i == 3) { + ASSERT_NE(child5->get_child(i), nullptr); + ASSERT_EQ(child5->get_child(i)->get_memory_region_id(), memory_region_id_2); + + for (auto j = 0; j < 16; j++) { + ASSERT_EQ(child5->get_child(i)->get_child(j), nullptr); + } + } else { + ASSERT_EQ(child5->get_child(i), nullptr); } + } } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionId1) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1234; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - ASSERT_EQ(tree.get_memory_region_id(0x0000000000000000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x7FFFFFFFFFFFFFFFLL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x5687140000000000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x3FF0000000000000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x1000000000000000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x5000000000000000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x4FFFFFFFFFFFFFFFLL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x622516846acd64b6LL), memory_region_id); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1234; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + ASSERT_EQ(tree.get_memory_region_id(0x0000000000000000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x7FFFFFFFFFFFFFFFLL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x5687140000000000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x3FF0000000000000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x1000000000000000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x5000000000000000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x4FFFFFFFFFFFFFFFLL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x622516846acd64b6LL), memory_region_id); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionId2) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1234; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - ASSERT_EQ(tree.get_memory_region_id(0x8000000000000000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xFFFFFFFFFFFFFFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xA687140000000000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xCFF0000000000000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x9000000000000000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xE000000000000000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xDFFFFFFFFFFFFFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0xF22516846acd64b6LL), 0xFFFF'FFFFU); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1234; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + ASSERT_EQ(tree.get_memory_region_id(0x8000000000000000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xFFFFFFFFFFFFFFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xA687140000000000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xCFF0000000000000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x9000000000000000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xE000000000000000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xDFFFFFFFFFFFFFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0xF22516846acd64b6LL), 0xFFFF'FFFFU); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionId3) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x1000'0000'0000'0000LL; - const auto end_addr = 0x2000'0000'0000'0000LL; - const auto memory_region_id = 12; - - tree.allocate_region(start_addr, end_addr, 12); - - ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), memory_region_id); - ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x8225'1684'6ac4'd4b6LL), 0xFFFF'FFFFU); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x1000'0000'0000'0000LL; + const auto end_addr = 0x2000'0000'0000'0000LL; + const auto memory_region_id = 12; + + tree.allocate_region(start_addr, end_addr, 12); + + ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), memory_region_id); + ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x8225'1684'6ac4'd4b6LL), 0xFFFF'FFFFU); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionId4) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x2000000000000000LL; - const auto end_addr_2 = 0x2FFFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id_1); - ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id_1); - ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), memory_region_id_2); - ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x2225'1684'6ac4'd4b6LL), memory_region_id_2); - ASSERT_EQ(tree.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL), memory_region_id_2); - ASSERT_EQ(tree.get_memory_region_id(0x3000'0000'0000'0000LL), 0xFFFF'FFFFU); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x2000000000000000LL; + const auto end_addr_2 = 0x2FFFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id_1); + ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id_1); + ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), memory_region_id_2); + ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x2225'1684'6ac4'd4b6LL), memory_region_id_2); + ASSERT_EQ(tree.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL), memory_region_id_2); + ASSERT_EQ(tree.get_memory_region_id(0x3000'0000'0000'0000LL), 0xFFFF'FFFFU); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionId5) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x5300000000000000LL; - const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id_1); - ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id_1); - ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x2225'1684'6ac4'd4b6LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x3000'0000'0000'0000LL), 0xFFFF'FFFFU); - ASSERT_EQ(tree.get_memory_region_id(0x5300'0000'0000'0000LL), memory_region_id_2); - ASSERT_EQ(tree.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL), memory_region_id_2); - ASSERT_EQ(tree.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL), memory_region_id_2); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x5300000000000000LL; + const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + ASSERT_EQ(tree.get_memory_region_id(0x0000'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1000'0000'0000'0000LL), memory_region_id_1); + ASSERT_EQ(tree.get_memory_region_id(0x5687'1400'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x3FF0'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x1242'0000'0000'0000LL), memory_region_id_1); + ASSERT_EQ(tree.get_memory_region_id(0x2000'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x4FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x2225'1684'6ac4'd4b6LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x2FFF'FFFF'FFFF'FFFFLL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x3000'0000'0000'0000LL), 0xFFFF'FFFFU); + ASSERT_EQ(tree.get_memory_region_id(0x5300'0000'0000'0000LL), memory_region_id_2); + ASSERT_EQ(tree.get_memory_region_id(0x530F'FFFF'FFFF'FFFFLL), memory_region_id_2); + ASSERT_EQ(tree.get_memory_region_id(0x53FF'FFFF'FFFF'FFFFLL), memory_region_id_2); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionIdStr1) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1234; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - ASSERT_EQ(tree.get_memory_region_id_string(0x0000000000000000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x7FFFFFFFFFFFFFFFLL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x5687140000000000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0000000000000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x1000000000000000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x5000000000000000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x4FFFFFFFFFFFFFFFLL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x622516846acd64b6LL, "fallback"), std::to_string(memory_region_id)); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1234; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + ASSERT_EQ(tree.get_memory_region_id_string(0x0000000000000000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x7FFFFFFFFFFFFFFFLL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x5687140000000000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0000000000000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x1000000000000000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x5000000000000000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x4FFFFFFFFFFFFFFFLL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x622516846acd64b6LL, "fallback"), std::to_string(memory_region_id)); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionIdStr2) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x0000000000000000LL; - const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; - const auto memory_region_id = 0x1234; - - tree.allocate_region(start_addr, end_addr, memory_region_id); - - ASSERT_EQ(tree.get_memory_region_id_string(0x8000000000000000LL, "fallback1"), std::string("fallback1")); - ASSERT_EQ(tree.get_memory_region_id_string(0xFFFFFFFFFFFFFFFFLL, "fallback2"), std::string("fallback2")); - ASSERT_EQ(tree.get_memory_region_id_string(0xA687140000000000LL, "fallback3"), std::string("fallback3")); - ASSERT_EQ(tree.get_memory_region_id_string(0xCFF0000000000000LL, "fallback4"), std::string("fallback4")); - ASSERT_EQ(tree.get_memory_region_id_string(0x9000000000000000LL, "fallback5"), std::string("fallback5")); - ASSERT_EQ(tree.get_memory_region_id_string(0xE000000000000000LL, "fallback6"), std::string("fallback6")); - ASSERT_EQ(tree.get_memory_region_id_string(0xDFFFFFFFFFFFFFFFLL, "fallback7"), std::string("fallback7")); - ASSERT_EQ(tree.get_memory_region_id_string(0xF22516846acd64b6LL, "fallback8"), std::string("fallback8")); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x0000000000000000LL; + const auto end_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto memory_region_id = 0x1234; + + tree.allocate_region(start_addr, end_addr, memory_region_id); + + ASSERT_EQ(tree.get_memory_region_id_string(0x8000000000000000LL, "fallback1"), std::string("fallback1")); + ASSERT_EQ(tree.get_memory_region_id_string(0xFFFFFFFFFFFFFFFFLL, "fallback2"), std::string("fallback2")); + ASSERT_EQ(tree.get_memory_region_id_string(0xA687140000000000LL, "fallback3"), std::string("fallback3")); + ASSERT_EQ(tree.get_memory_region_id_string(0xCFF0000000000000LL, "fallback4"), std::string("fallback4")); + ASSERT_EQ(tree.get_memory_region_id_string(0x9000000000000000LL, "fallback5"), std::string("fallback5")); + ASSERT_EQ(tree.get_memory_region_id_string(0xE000000000000000LL, "fallback6"), std::string("fallback6")); + ASSERT_EQ(tree.get_memory_region_id_string(0xDFFFFFFFFFFFFFFFLL, "fallback7"), std::string("fallback7")); + ASSERT_EQ(tree.get_memory_region_id_string(0xF22516846acd64b6LL, "fallback8"), std::string("fallback8")); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionIdStr3) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x1000'0000'0000'0000LL; - const auto end_addr = 0x2000'0000'0000'0000LL; - const auto memory_region_id = 12; - - tree.allocate_region(start_addr, end_addr, 12); - - ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); - ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x8225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr = 0x1000'0000'0000'0000LL; + const auto end_addr = 0x2000'0000'0000'0000LL; + const auto memory_region_id = 12; + + tree.allocate_region(start_addr, end_addr, 12); + + ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id)); + ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x8225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionIdStr4) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x2000000000000000LL; - const auto end_addr_2 = 0x2FFFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); - ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); - ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_2)); - ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x2225'1684'6ac4'd4b6LL, "fallback"), std::to_string(memory_region_id_2)); - ASSERT_EQ(tree.get_memory_region_id_string(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); - ASSERT_EQ(tree.get_memory_region_id_string(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x2000000000000000LL; + const auto end_addr_2 = 0x2FFFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); + ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); + ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_2)); + ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x2225'1684'6ac4'd4b6LL, "fallback"), std::to_string(memory_region_id_2)); + ASSERT_EQ(tree.get_memory_region_id_string(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); + ASSERT_EQ(tree.get_memory_region_id_string(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); } TEST_F(MemoryRegionTreeTest, testGetMemoryRegionIdStr5) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x5300000000000000LL; - const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); - ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); - ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); - ASSERT_EQ(tree.get_memory_region_id_string(0x5300'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_2)); - ASSERT_EQ(tree.get_memory_region_id_string(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); - ASSERT_EQ(tree.get_memory_region_id_string(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x5300000000000000LL; + const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + ASSERT_EQ(tree.get_memory_region_id_string(0x0000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1000'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); + ASSERT_EQ(tree.get_memory_region_id_string(0x5687'1400'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x3FF0'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x1242'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_1)); + ASSERT_EQ(tree.get_memory_region_id_string(0x2000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x4FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x2225'1684'6ac4'd4b6LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x2FFF'FFFF'FFFF'FFFFLL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x3000'0000'0000'0000LL, "fallback"), std::string("fallback")); + ASSERT_EQ(tree.get_memory_region_id_string(0x5300'0000'0000'0000LL, "fallback"), std::to_string(memory_region_id_2)); + ASSERT_EQ(tree.get_memory_region_id_string(0x530F'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); + ASSERT_EQ(tree.get_memory_region_id_string(0x53FF'FFFF'FFFF'FFFFLL, "fallback"), std::to_string(memory_region_id_2)); } TEST_F(MemoryRegionTreeTest, testFreeRegion1) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr = 0x0000000000000000LL; + auto tree = __dp::MemoryRegionTree{}; - tree.free_region(start_addr); + const auto start_addr = 0x0000000000000000LL; - auto* root = tree.get_root(); + tree.free_region(start_addr); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testFreeRegion2) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x7FFFFFFFFFFFFFFFLL; + const auto start_addr = 0x7FFFFFFFFFFFFFFFLL; - tree.free_region(start_addr); + tree.free_region(start_addr); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testFreeRegion3) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x9472dcab36975afaLL; + const auto start_addr = 0x9472dcab36975afaLL; - tree.free_region(start_addr); + tree.free_region(start_addr); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testFreeRegion4) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x1000'0000'0000'0000LL; - const auto end_addr = 0x1FFF'FFFF'FFFF'FFFFLL; - const auto memory_region_id = 0x1111; + const auto start_addr = 0x1000'0000'0000'0000LL; + const auto end_addr = 0x1FFF'FFFF'FFFF'FFFFLL; + const auto memory_region_id = 0x1111; - tree.allocate_region(start_addr, end_addr, memory_region_id); + tree.allocate_region(start_addr, end_addr, memory_region_id); - tree.free_region(start_addr); + tree.free_region(start_addr); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } TEST_F(MemoryRegionTreeTest, testFreeRegion5) { - auto tree = __dp::MemoryRegionTree{}; + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr = 0x0000'0000'0000'0000LL; - const auto end_addr = 0x7FFF'FFFF'FFFF'FFFFLL; - const auto memory_region_id = 0x1111; + const auto start_addr = 0x0000'0000'0000'0000LL; + const auto end_addr = 0x7FFF'FFFF'FFFF'FFFFLL; + const auto memory_region_id = 0x1111; - tree.allocate_region(start_addr, end_addr, memory_region_id); + tree.allocate_region(start_addr, end_addr, memory_region_id); - tree.free_region(start_addr); + tree.free_region(start_addr); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } -TEST_F(MemoryRegionTreeTest, testFreeRegion6) { - auto tree = __dp::MemoryRegionTree{}; - - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; - - const auto start_addr_2 = 0x5300000000000000LL; - const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; - - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - - tree.free_region(start_addr_1); - - auto* root = tree.get_root(); - - ASSERT_EQ(root->get_child(0), nullptr); - ASSERT_EQ(root->get_child(1), nullptr); - ASSERT_EQ(root->get_child(2), nullptr); - ASSERT_EQ(root->get_child(3), nullptr); - ASSERT_EQ(root->get_child(4), nullptr); - ASSERT_NE(root->get_child(5), nullptr); - ASSERT_EQ(root->get_child(6), nullptr); - ASSERT_EQ(root->get_child(7), nullptr); - ASSERT_EQ(root->get_child(8), nullptr); - ASSERT_EQ(root->get_child(9), nullptr); - ASSERT_EQ(root->get_child(10), nullptr); - ASSERT_EQ(root->get_child(11), nullptr); - ASSERT_EQ(root->get_child(12), nullptr); - ASSERT_EQ(root->get_child(13), nullptr); - ASSERT_EQ(root->get_child(14), nullptr); - ASSERT_EQ(root->get_child(15), nullptr); - - auto* child5 = root->get_child(5); - ASSERT_EQ(child5->get_memory_region_id(), 0); - - for (auto i = 0; i < 16; i++) { - if (i == 3) { - ASSERT_NE(child5->get_child(i), nullptr); - ASSERT_EQ(child5->get_child(i)->get_memory_region_id(), memory_region_id_2); - - for (auto j = 0; j < 16; j++) { - ASSERT_EQ(child5->get_child(i)->get_child(j), nullptr); - } - } else { - ASSERT_EQ(child5->get_child(i), nullptr); - } +TEST_F(MemoryRegionTreeTest, testFreeRegion6) { + auto tree = __dp::MemoryRegionTree{}; + + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; + + const auto start_addr_2 = 0x5300000000000000LL; + const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; + + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + + tree.free_region(start_addr_1); + + auto *root = tree.get_root(); + + ASSERT_EQ(root->get_child(0), nullptr); + ASSERT_EQ(root->get_child(1), nullptr); + ASSERT_EQ(root->get_child(2), nullptr); + ASSERT_EQ(root->get_child(3), nullptr); + ASSERT_EQ(root->get_child(4), nullptr); + ASSERT_NE(root->get_child(5), nullptr); + ASSERT_EQ(root->get_child(6), nullptr); + ASSERT_EQ(root->get_child(7), nullptr); + ASSERT_EQ(root->get_child(8), nullptr); + ASSERT_EQ(root->get_child(9), nullptr); + ASSERT_EQ(root->get_child(10), nullptr); + ASSERT_EQ(root->get_child(11), nullptr); + ASSERT_EQ(root->get_child(12), nullptr); + ASSERT_EQ(root->get_child(13), nullptr); + ASSERT_EQ(root->get_child(14), nullptr); + ASSERT_EQ(root->get_child(15), nullptr); + + auto *child5 = root->get_child(5); + ASSERT_EQ(child5->get_memory_region_id(), 0); + + for (auto i = 0; i < 16; i++) { + if (i == 3) { + ASSERT_NE(child5->get_child(i), nullptr); + ASSERT_EQ(child5->get_child(i)->get_memory_region_id(), memory_region_id_2); + + for (auto j = 0; j < 16; j++) { + ASSERT_EQ(child5->get_child(i)->get_child(j), nullptr); + } + } else { + ASSERT_EQ(child5->get_child(i), nullptr); } + } } -TEST_F(MemoryRegionTreeTest, testFreeRegion7) { - auto tree = __dp::MemoryRegionTree{}; +TEST_F(MemoryRegionTreeTest, testFreeRegion7) { + auto tree = __dp::MemoryRegionTree{}; - const auto start_addr_1 = 0x1000000000000000LL; - const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; - const auto memory_region_id_1 = 0x1111; + const auto start_addr_1 = 0x1000000000000000LL; + const auto end_addr_1 = 0x1FFFFFFFFFFFFFFFLL; + const auto memory_region_id_1 = 0x1111; - const auto start_addr_2 = 0x5300000000000000LL; - const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; - const auto memory_region_id_2 = 0x2222; + const auto start_addr_2 = 0x5300000000000000LL; + const auto end_addr_2 = 0x53FFFFFFFFFFFFFFLL; + const auto memory_region_id_2 = 0x2222; - tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); - tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); + tree.allocate_region(start_addr_1, end_addr_1, memory_region_id_1); + tree.allocate_region(start_addr_2, end_addr_2, memory_region_id_2); - tree.free_region(start_addr_1); - tree.free_region(start_addr_2); + tree.free_region(start_addr_1); + tree.free_region(start_addr_2); - auto* root = tree.get_root(); + auto *root = tree.get_root(); - ASSERT_EQ(root->get_memory_region_id(), 0); - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(root->get_child(i), nullptr); - } + ASSERT_EQ(root->get_memory_region_id(), 0); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(root->get_child(i), nullptr); + } } diff --git a/test/unit_tests/memory/mrtnode/test_mrtnode.cpp b/test/unit_tests/memory/mrtnode/test_mrtnode.cpp index d8feeb41a..597684727 100644 --- a/test/unit_tests/memory/mrtnode/test_mrtnode.cpp +++ b/test/unit_tests/memory/mrtnode/test_mrtnode.cpp @@ -5,118 +5,122 @@ #include #include -class MRTNodeTest : public ::testing::Test { }; +class MRTNodeTest : public ::testing::Test {}; TEST_F(MRTNodeTest, testConstructor) { - const auto start_addr = 0x1234567890ABCDEFLL; - const auto end_addr = 0x2234567890ABCDEFLL; - const auto level = 0x1234; - - const auto node = __dp::MRTNode(start_addr, end_addr, level); - - ASSERT_EQ(node.get_first_addr(), start_addr); - ASSERT_EQ(node.get_last_addr(), end_addr); - ASSERT_EQ(node.get_level(), level); - ASSERT_EQ(node.get_memory_region_id(), 0); - - for (auto i = 0; i < 16; i++) { - ASSERT_EQ(node.get_child(i), nullptr); - } - - for (const auto* child : node.get_children()) { - ASSERT_EQ(child, nullptr); - } -} + const auto start_addr = 0x1234567890ABCDEFLL; + const auto end_addr = 0x2234567890ABCDEFLL; + const auto level = 0x1234; -TEST_F(MRTNodeTest, testGetChildIndex) { - const auto start_addr = 0x1200000000000000LL; - const auto end_addr = 0x12FFFFFFFFFFFFFFLL; - - const auto level = 2; + const auto node = __dp::MRTNode(start_addr, end_addr, level); - const auto node = __dp::MRTNode(start_addr, end_addr, level); + ASSERT_EQ(node.get_first_addr(), start_addr); + ASSERT_EQ(node.get_last_addr(), end_addr); + ASSERT_EQ(node.get_level(), level); + ASSERT_EQ(node.get_memory_region_id(), 0); - const auto base_addr = 0x010000000000000LL; - for (auto i = 0; i < 16; i++) { - const auto inquiry_addr = start_addr + (base_addr * i); - const auto calculated_index = node.get_child_index(inquiry_addr); + for (auto i = 0; i < 16; i++) { + ASSERT_EQ(node.get_child(i), nullptr); + } - ASSERT_EQ(calculated_index, i); - } + for (const auto *child : node.get_children()) { + ASSERT_EQ(child, nullptr); + } +} - ASSERT_EQ(node.get_child_index(start_addr - 1), -1); - ASSERT_EQ(node.get_child_index(end_addr + 1), -1); - ASSERT_EQ(node.get_child_index(0x1100000000000000LL), -1); - ASSERT_EQ(node.get_child_index(0x1400000000000000LL), -1); - ASSERT_EQ(node.get_child_index(0x1863453534300000LL), -1); - ASSERT_EQ(node.get_child_index(0x0000000000000000LL), -1); - ASSERT_EQ(node.get_child_index(0x1000000000000000LL), -1); - ASSERT_EQ(node.get_child_index(0x2000000000000000LL), -1); - ASSERT_EQ(node.get_child_index(0xEFFFFFFFFFFFFFFFLL), -1); +TEST_F(MRTNodeTest, testGetChildIndex) { + const auto start_addr = 0x1200000000000000LL; + const auto end_addr = 0x12FFFFFFFFFFFFFFLL; + + const auto level = 2; + + const auto node = __dp::MRTNode(start_addr, end_addr, level); + + const auto base_addr = 0x010000000000000LL; + for (auto i = 0; i < 16; i++) { + const auto inquiry_addr = start_addr + (base_addr * i); + const auto calculated_index = node.get_child_index(inquiry_addr); + + ASSERT_EQ(calculated_index, i); + } + + ASSERT_EQ(node.get_child_index(start_addr - 1), -1); + ASSERT_EQ(node.get_child_index(end_addr + 1), -1); + ASSERT_EQ(node.get_child_index(0x1100000000000000LL), -1); + ASSERT_EQ(node.get_child_index(0x1400000000000000LL), -1); + ASSERT_EQ(node.get_child_index(0x1863453534300000LL), -1); + ASSERT_EQ(node.get_child_index(0x0000000000000000LL), -1); + ASSERT_EQ(node.get_child_index(0x1000000000000000LL), -1); + ASSERT_EQ(node.get_child_index(0x2000000000000000LL), -1); + ASSERT_EQ(node.get_child_index(0xEFFFFFFFFFFFFFFFLL), -1); } TEST_F(MRTNodeTest, testAddChild0) { - const auto start_addr = 0x1000000000000000LL; - const auto end_addr = 0x1FFFFFFFFFFFFFFFLL; + const auto start_addr = 0x1000000000000000LL; + const auto end_addr = 0x1FFFFFFFFFFFFFFFLL; - const auto level = 1; + const auto level = 1; - auto node = __dp::MRTNode(start_addr, end_addr, level); + auto node = __dp::MRTNode(start_addr, end_addr, level); - node.add_child(0); + node.add_child(0); - for (auto i = 0; i < 16; i++) { - if (i == 0) { - ASSERT_NE(node.get_child(i), nullptr); - ASSERT_EQ(node.get_child(i)->get_first_addr(), 0x1000000000000000LL) << std::hex << node.get_child(i)->get_first_addr(); - ASSERT_EQ(node.get_child(i)->get_last_addr(), 0x10FFFFFFFFFFFFFFLL) << std::hex << node.get_child(i)->get_last_addr(); - ASSERT_EQ(node.get_child(i)->get_level(), 2); + for (auto i = 0; i < 16; i++) { + if (i == 0) { + ASSERT_NE(node.get_child(i), nullptr); + ASSERT_EQ(node.get_child(i)->get_first_addr(), 0x1000000000000000LL) + << std::hex << node.get_child(i)->get_first_addr(); + ASSERT_EQ(node.get_child(i)->get_last_addr(), 0x10FFFFFFFFFFFFFFLL) + << std::hex << node.get_child(i)->get_last_addr(); + ASSERT_EQ(node.get_child(i)->get_level(), 2); - for (auto j = 0; j < 16; j++) { - ASSERT_EQ(node.get_child(i)->get_child(j), nullptr); - } - } else { - ASSERT_EQ(node.get_child(i), nullptr); - } + for (auto j = 0; j < 16; j++) { + ASSERT_EQ(node.get_child(i)->get_child(j), nullptr); + } + } else { + ASSERT_EQ(node.get_child(i), nullptr); } + } } TEST_F(MRTNodeTest, testAddChild1) { - const auto start_addr = 0x2E00000000000000LL; - const auto end_addr = 0x2EFFFFFFFFFFFFFFLL; + const auto start_addr = 0x2E00000000000000LL; + const auto end_addr = 0x2EFFFFFFFFFFFFFFLL; - const auto level = 2; + const auto level = 2; - auto node = __dp::MRTNode(start_addr, end_addr, level); + auto node = __dp::MRTNode(start_addr, end_addr, level); - node.add_child(3); + node.add_child(3); - for (auto i = 0; i < 16; i++) { - if (i == 3) { - ASSERT_NE(node.get_child(i), nullptr); - ASSERT_EQ(node.get_child(i)->get_first_addr(), 0x2E30000000000000LL) << std::hex << node.get_child(i)->get_first_addr(); - ASSERT_EQ(node.get_child(i)->get_last_addr(), 0x2E3FFFFFFFFFFFFFLL) << std::hex << node.get_child(i)->get_last_addr(); - ASSERT_EQ(node.get_child(i)->get_level(), 3); + for (auto i = 0; i < 16; i++) { + if (i == 3) { + ASSERT_NE(node.get_child(i), nullptr); + ASSERT_EQ(node.get_child(i)->get_first_addr(), 0x2E30000000000000LL) + << std::hex << node.get_child(i)->get_first_addr(); + ASSERT_EQ(node.get_child(i)->get_last_addr(), 0x2E3FFFFFFFFFFFFFLL) + << std::hex << node.get_child(i)->get_last_addr(); + ASSERT_EQ(node.get_child(i)->get_level(), 3); - for (auto j = 0; j < 16; j++) { - ASSERT_EQ(node.get_child(i)->get_child(j), nullptr); - } - } else { - ASSERT_EQ(node.get_child(i), nullptr); - } + for (auto j = 0; j < 16; j++) { + ASSERT_EQ(node.get_child(i)->get_child(j), nullptr); + } + } else { + ASSERT_EQ(node.get_child(i), nullptr); } + } } TEST_F(MRTNodeTest, testSetMemoryRegionId) { - const auto start_addr = 0x1000000000000000LL; - const auto end_addr = 0x1FFFFFFFFFFFFFFFLL; + const auto start_addr = 0x1000000000000000LL; + const auto end_addr = 0x1FFFFFFFFFFFFFFFLL; - const auto level = 1; + const auto level = 1; - auto node = __dp::MRTNode(start_addr, end_addr, level); + auto node = __dp::MRTNode(start_addr, end_addr, level); - const auto memory_region_id = 0x1234; - node.set_memory_region_id(memory_region_id); + const auto memory_region_id = 0x1234; + node.set_memory_region_id(memory_region_id); - ASSERT_EQ(node.get_memory_region_id(), memory_region_id); + ASSERT_EQ(node.get_memory_region_id(), memory_region_id); } diff --git a/test/unit_tests/memory/perfect_shadow/test_perfect_shadow.cpp b/test/unit_tests/memory/perfect_shadow/test_perfect_shadow.cpp index 8e7c85a3b..2a3564c0a 100644 --- a/test/unit_tests/memory/perfect_shadow/test_perfect_shadow.cpp +++ b/test/unit_tests/memory/perfect_shadow/test_perfect_shadow.cpp @@ -7,646 +7,646 @@ // Tests for old version (i.e., capturing functionality) -class PerfectShadowTest : public ::testing::Test { }; +class PerfectShadowTest : public ::testing::Test {}; TEST_F(PerfectShadowTest, testConstructor) { - const auto shadow = __dp::PerfectShadow{}; + const auto shadow = __dp::PerfectShadow{}; - const auto* reads = shadow.getSigRead(); - ASSERT_NE(reads, nullptr); - ASSERT_TRUE(reads->empty()); + const auto *reads = shadow.getSigRead(); + ASSERT_NE(reads, nullptr); + ASSERT_TRUE(reads->empty()); - const auto* writes = shadow.getSigWrite(); - ASSERT_NE(writes, nullptr); - ASSERT_TRUE(writes->empty()); + const auto *writes = shadow.getSigWrite(); + ASSERT_NE(writes, nullptr); + ASSERT_TRUE(writes->empty()); } TEST_F(PerfectShadowTest, testGet) { - auto shadow = __dp::PerfectShadow{}; + auto shadow = __dp::PerfectShadow{}; - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInWrite(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInWrite(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInWrite(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInWrite(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 0); - } + ASSERT_EQ(val, 0); + } - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 0); - } + ASSERT_EQ(val, 0); + } } TEST_F(PerfectShadowTest, testInsert) { - auto shadow = __dp::PerfectShadow{}; + auto shadow = __dp::PerfectShadow{}; - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - for (const auto address : addresses) { - const auto old_val = shadow.insertToRead(address, 1); - ASSERT_EQ(old_val, 0); - } + for (const auto address : addresses) { + const auto old_val = shadow.insertToRead(address, 1); + ASSERT_EQ(old_val, 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 1); - } + ASSERT_EQ(val, 1); + } - for (const auto address : addresses) { - const auto old_val = shadow.insertToRead(address, 14); - ASSERT_EQ(old_val, 1); - } + for (const auto address : addresses) { + const auto old_val = shadow.insertToRead(address, 14); + ASSERT_EQ(old_val, 1); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 14); - } + ASSERT_EQ(val, 14); + } - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 14); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 14); + } - for (const auto address : addresses) { - const auto old_val = shadow.insertToWrite(address, 4); - ASSERT_EQ(old_val, 0); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto old_val = shadow.insertToWrite(address, 4); + ASSERT_EQ(old_val, 0); + } - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - ASSERT_EQ(val, 14); - } + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + const auto addr = iterator->first; + const auto val = iterator->second; - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(val, 14); + } - ASSERT_EQ(val, 4); - } + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 4); + } } TEST_F(PerfectShadowTest, testUpdate) { - auto shadow = __dp::PerfectShadow{}; + auto shadow = __dp::PerfectShadow{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + for (const auto address : addresses) { + std::ignore = shadow.insertToRead(address, 1); + std::ignore = shadow.insertToWrite(address, 12); + } - for (const auto address : addresses) { - std::ignore = shadow.insertToRead(address, 1); - std::ignore = shadow.insertToWrite(address, 12); - } + for (const auto address : addresses) { + shadow.updateInRead(address, 14); + } - for (const auto address : addresses) { - shadow.updateInRead(address, 14); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - ASSERT_EQ(val, 14); - } + const auto addr = iterator->first; + const auto val = iterator->second; - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + ASSERT_EQ(val, 14); + } - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); - ASSERT_EQ(val, 12); - } + const auto addr = iterator->first; + const auto val = iterator->second; - for (const auto address : addresses) { - shadow.updateInWrite(address, 27); - } - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + ASSERT_EQ(val, 12); + } - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + shadow.updateInWrite(address, 27); + } - ASSERT_EQ(val, 14); - } + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + const auto addr = iterator->first; + const auto val = iterator->second; - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(val, 14); + } - ASSERT_EQ(val, 27); - } + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 27); + } } TEST_F(PerfectShadowTest, testRemove) { - auto shadow = __dp::PerfectShadow{}; - - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); - - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - - for (const auto address : addresses) { - std::ignore = shadow.insertToRead(address, 1); - std::ignore = shadow.insertToWrite(address, 12); - } - - for (const auto address : addresses) { - shadow.removeFromRead(address); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0); - } - - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 12); - } - - for (const auto address : addresses) { - shadow.removeFromWrite(address); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0); - } - - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0 ); - } + auto shadow = __dp::PerfectShadow{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); + + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + + for (const auto address : addresses) { + std::ignore = shadow.insertToRead(address, 1); + std::ignore = shadow.insertToWrite(address, 12); + } + + for (const auto address : addresses) { + shadow.removeFromRead(address); + } + + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); + + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } + + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 12); + } + + for (const auto address : addresses) { + shadow.removeFromWrite(address); + } + + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); + + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } + + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } } TEST_F(PerfectShadowTest, testAddressesInRange) { - auto shadow = __dp::PerfectShadow{}; - - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); - - const auto addresses_read = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - const auto addresses_write = std::vector{4, 6, 8, 12, 16, 20, 48, 56, 1001, 1002, 1003, 1005}; - - for (const auto address : addresses_read) { - std::ignore = shadow.insertToRead(address, 1); - } - - for (const auto address : addresses_write) { - std::ignore = shadow.insertToWrite(address, 1); - } - - const auto addresses_in_range_1 = shadow.getAddrsInRange(7, 14); - ASSERT_EQ(addresses_in_range_1.size(), 2); - ASSERT_TRUE(addresses_in_range_1.find(8) != addresses_in_range_1.end()); - ASSERT_TRUE(addresses_in_range_1.find(12) != addresses_in_range_1.end()); - - const auto addresses_in_range_2 = shadow.getAddrsInRange(1000, 1004); - ASSERT_EQ(addresses_in_range_2.size(), 5); - ASSERT_TRUE(addresses_in_range_2.find(1000) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1001) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1002) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1003) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1004) != addresses_in_range_2.end()); - - for (const auto address : addresses_read) { - shadow.removeFromRead(address); - } - - const auto addresses_in_range_3 = shadow.getAddrsInRange(7, 14); - ASSERT_EQ(addresses_in_range_3.size(), 2); - ASSERT_TRUE(addresses_in_range_3.find(8) != addresses_in_range_3.end()); - ASSERT_TRUE(addresses_in_range_3.find(12) != addresses_in_range_3.end()); + auto shadow = __dp::PerfectShadow{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); + + const auto addresses_read = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses_write = std::vector{4, 6, 8, 12, 16, 20, 48, 56, 1001, 1002, 1003, 1005}; + + for (const auto address : addresses_read) { + std::ignore = shadow.insertToRead(address, 1); + } + + for (const auto address : addresses_write) { + std::ignore = shadow.insertToWrite(address, 1); + } + + const auto addresses_in_range_1 = shadow.getAddrsInRange(7, 14); + ASSERT_EQ(addresses_in_range_1.size(), 2); + ASSERT_TRUE(addresses_in_range_1.find(8) != addresses_in_range_1.end()); + ASSERT_TRUE(addresses_in_range_1.find(12) != addresses_in_range_1.end()); + + const auto addresses_in_range_2 = shadow.getAddrsInRange(1000, 1004); + ASSERT_EQ(addresses_in_range_2.size(), 5); + ASSERT_TRUE(addresses_in_range_2.find(1000) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1001) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1002) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1003) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1004) != addresses_in_range_2.end()); + + for (const auto address : addresses_read) { + shadow.removeFromRead(address); + } + + const auto addresses_in_range_3 = shadow.getAddrsInRange(7, 14); + ASSERT_EQ(addresses_in_range_3.size(), 2); + ASSERT_TRUE(addresses_in_range_3.find(8) != addresses_in_range_3.end()); + ASSERT_TRUE(addresses_in_range_3.find(12) != addresses_in_range_3.end()); } // Tests for new version (i.e., reproducing functionality) -class PerfectShadow2Test : public ::testing::Test { }; +class PerfectShadow2Test : public ::testing::Test {}; TEST_F(PerfectShadow2Test, testConstructor) { - const auto shadow = __dp::PerfectShadow2{}; + const auto shadow = __dp::PerfectShadow2{}; - const auto* reads = shadow.getSigRead(); - ASSERT_NE(reads, nullptr); - ASSERT_TRUE(reads->empty()); + const auto *reads = shadow.getSigRead(); + ASSERT_NE(reads, nullptr); + ASSERT_TRUE(reads->empty()); - const auto* writes = shadow.getSigWrite(); - ASSERT_NE(writes, nullptr); - ASSERT_TRUE(writes->empty()); + const auto *writes = shadow.getSigWrite(); + ASSERT_NE(writes, nullptr); + ASSERT_TRUE(writes->empty()); } TEST_F(PerfectShadow2Test, testGet) { - auto shadow = __dp::PerfectShadow2{}; + auto shadow = __dp::PerfectShadow2{}; - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInWrite(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInWrite(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInWrite(address), 0); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInWrite(address), 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 0); - } + ASSERT_EQ(val, 0); + } - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 0); - } + ASSERT_EQ(val, 0); + } } TEST_F(PerfectShadow2Test, testInsert) { - auto shadow = __dp::PerfectShadow2{}; + auto shadow = __dp::PerfectShadow2{}; - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - for (const auto address : addresses) { - const auto old_val = shadow.insertToRead(address, 1); - ASSERT_EQ(old_val, 0); - } + for (const auto address : addresses) { + const auto old_val = shadow.insertToRead(address, 1); + ASSERT_EQ(old_val, 0); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 1); - } + ASSERT_EQ(val, 1); + } - for (const auto address : addresses) { - const auto old_val = shadow.insertToRead(address, 14); - ASSERT_EQ(old_val, 1); - } + for (const auto address : addresses) { + const auto old_val = shadow.insertToRead(address, 14); + ASSERT_EQ(old_val, 1); + } - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_TRUE(writes->empty()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_TRUE(writes->empty()); - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - const auto addr = iterator->first; - const auto val = iterator->second; + const auto addr = iterator->first; + const auto val = iterator->second; - ASSERT_EQ(val, 14); - } + ASSERT_EQ(val, 14); + } - for (const auto address : addresses) { - ASSERT_EQ(shadow.testInRead(address), 14); - } + for (const auto address : addresses) { + ASSERT_EQ(shadow.testInRead(address), 14); + } - for (const auto address : addresses) { - const auto old_val = shadow.insertToWrite(address, 4); - ASSERT_EQ(old_val, 0); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + for (const auto address : addresses) { + const auto old_val = shadow.insertToWrite(address, 4); + ASSERT_EQ(old_val, 0); + } - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - ASSERT_EQ(val, 14); - } + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + const auto addr = iterator->first; + const auto val = iterator->second; - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(val, 14); + } - ASSERT_EQ(val, 4); - } + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 4); + } } TEST_F(PerfectShadow2Test, testUpdate) { - auto shadow = __dp::PerfectShadow2{}; + auto shadow = __dp::PerfectShadow2{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + for (const auto address : addresses) { + std::ignore = shadow.insertToRead(address, 1); + std::ignore = shadow.insertToWrite(address, 12); + } - for (const auto address : addresses) { - std::ignore = shadow.insertToRead(address, 1); - std::ignore = shadow.insertToWrite(address, 12); - } + for (const auto address : addresses) { + shadow.updateInRead(address, 14); + } - for (const auto address : addresses) { - shadow.updateInRead(address, 14); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - ASSERT_EQ(val, 14); - } + const auto addr = iterator->first; + const auto val = iterator->second; - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + ASSERT_EQ(val, 14); + } - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); - ASSERT_EQ(val, 12); - } + const auto addr = iterator->first; + const auto val = iterator->second; - for (const auto address : addresses) { - shadow.updateInWrite(address, 27); - } - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); + ASSERT_EQ(val, 12); + } - const auto addr = iterator->first; - const auto val = iterator->second; + for (const auto address : addresses) { + shadow.updateInWrite(address, 27); + } - ASSERT_EQ(val, 14); - } + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); + const auto addr = iterator->first; + const auto val = iterator->second; - const auto addr = iterator->first; - const auto val = iterator->second; + ASSERT_EQ(val, 14); + } - ASSERT_EQ(val, 27); - } + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 27); + } } TEST_F(PerfectShadow2Test, testRemove) { - auto shadow = __dp::PerfectShadow2{}; - - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); - - const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - - for (const auto address : addresses) { - std::ignore = shadow.insertToRead(address, 1); - std::ignore = shadow.insertToWrite(address, 12); - } - - for (const auto address : addresses) { - shadow.removeFromRead(address); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0); - } - - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 12); - } - - for (const auto address : addresses) { - shadow.removeFromWrite(address); - } - - ASSERT_EQ(reads->size(), addresses.size()); - ASSERT_EQ(writes->size(), addresses.size()); - - for (const auto address : addresses) { - const auto iterator = reads->find(address); - ASSERT_NE(iterator, reads->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0); - } - - for (const auto address : addresses) { - const auto iterator = writes->find(address); - ASSERT_NE(iterator, writes->end()); - - const auto addr = iterator->first; - const auto val = iterator->second; - - ASSERT_EQ(val, 0 ); - } + auto shadow = __dp::PerfectShadow2{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); + + const auto addresses = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + + for (const auto address : addresses) { + std::ignore = shadow.insertToRead(address, 1); + std::ignore = shadow.insertToWrite(address, 12); + } + + for (const auto address : addresses) { + shadow.removeFromRead(address); + } + + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); + + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } + + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 12); + } + + for (const auto address : addresses) { + shadow.removeFromWrite(address); + } + + ASSERT_EQ(reads->size(), addresses.size()); + ASSERT_EQ(writes->size(), addresses.size()); + + for (const auto address : addresses) { + const auto iterator = reads->find(address); + ASSERT_NE(iterator, reads->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } + + for (const auto address : addresses) { + const auto iterator = writes->find(address); + ASSERT_NE(iterator, writes->end()); + + const auto addr = iterator->first; + const auto val = iterator->second; + + ASSERT_EQ(val, 0); + } } TEST_F(PerfectShadow2Test, testAddressesInRange) { - auto shadow = __dp::PerfectShadow2{}; - - const auto* reads = shadow.getSigRead(); - const auto* writes = shadow.getSigWrite(); - - const auto addresses_read = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; - const auto addresses_write = std::vector{4, 6, 8, 12, 16, 20, 48, 56, 1001, 1002, 1003, 1005}; - - for (const auto address : addresses_read) { - std::ignore = shadow.insertToRead(address, 1); - } - - for (const auto address : addresses_write) { - std::ignore = shadow.insertToWrite(address, 1); - } - - const auto addresses_in_range_1 = shadow.getAddrsInRange(7, 14); - ASSERT_EQ(addresses_in_range_1.size(), 2); - ASSERT_TRUE(addresses_in_range_1.find(8) != addresses_in_range_1.end()); - ASSERT_TRUE(addresses_in_range_1.find(12) != addresses_in_range_1.end()); - - const auto addresses_in_range_2 = shadow.getAddrsInRange(1000, 1004); - ASSERT_EQ(addresses_in_range_2.size(), 5); - ASSERT_TRUE(addresses_in_range_2.find(1000) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1001) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1002) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1003) != addresses_in_range_2.end()); - ASSERT_TRUE(addresses_in_range_2.find(1004) != addresses_in_range_2.end()); - - for (const auto address : addresses_read) { - shadow.removeFromRead(address); - } - - const auto addresses_in_range_3 = shadow.getAddrsInRange(7, 14); - ASSERT_EQ(addresses_in_range_3.size(), 2); - ASSERT_TRUE(addresses_in_range_3.find(8) != addresses_in_range_3.end()); - ASSERT_TRUE(addresses_in_range_3.find(12) != addresses_in_range_3.end()); + auto shadow = __dp::PerfectShadow2{}; + + const auto *reads = shadow.getSigRead(); + const auto *writes = shadow.getSigWrite(); + + const auto addresses_read = std::vector{0, 4, 5, 12, 16, 20, 24, 28, 1000, 1004, 1008}; + const auto addresses_write = std::vector{4, 6, 8, 12, 16, 20, 48, 56, 1001, 1002, 1003, 1005}; + + for (const auto address : addresses_read) { + std::ignore = shadow.insertToRead(address, 1); + } + + for (const auto address : addresses_write) { + std::ignore = shadow.insertToWrite(address, 1); + } + + const auto addresses_in_range_1 = shadow.getAddrsInRange(7, 14); + ASSERT_EQ(addresses_in_range_1.size(), 2); + ASSERT_TRUE(addresses_in_range_1.find(8) != addresses_in_range_1.end()); + ASSERT_TRUE(addresses_in_range_1.find(12) != addresses_in_range_1.end()); + + const auto addresses_in_range_2 = shadow.getAddrsInRange(1000, 1004); + ASSERT_EQ(addresses_in_range_2.size(), 5); + ASSERT_TRUE(addresses_in_range_2.find(1000) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1001) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1002) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1003) != addresses_in_range_2.end()); + ASSERT_TRUE(addresses_in_range_2.find(1004) != addresses_in_range_2.end()); + + for (const auto address : addresses_read) { + shadow.removeFromRead(address); + } + + const auto addresses_in_range_3 = shadow.getAddrsInRange(7, 14); + ASSERT_EQ(addresses_in_range_3.size(), 2); + ASSERT_TRUE(addresses_in_range_3.find(8) != addresses_in_range_3.end()); + ASSERT_TRUE(addresses_in_range_3.find(12) != addresses_in_range_3.end()); } diff --git a/test/unit_tests/memory/scope/test_scope.cpp b/test/unit_tests/memory/scope/test_scope.cpp index 31d422833..c4b310abd 100644 --- a/test/unit_tests/memory/scope/test_scope.cpp +++ b/test/unit_tests/memory/scope/test_scope.cpp @@ -4,955 +4,954 @@ // Tests for old version (i.e., capturing functionality) -class ScopeTest : public ::testing::Test { }; +class ScopeTest : public ::testing::Test {}; -class ScopeManagerTest : public ::testing::Test { }; +class ScopeManagerTest : public ::testing::Test {}; TEST_F(ScopeTest, testConstructor) { - const auto scope_1 = __dp::Scope(4); - ASSERT_EQ(scope_1.get_id(), 4); + const auto scope_1 = __dp::Scope(4); + ASSERT_EQ(scope_1.get_id(), 4); - ASSERT_TRUE(scope_1.get_first_read().empty()); - ASSERT_TRUE(scope_1.get_first_write().empty()); + ASSERT_TRUE(scope_1.get_first_read().empty()); + ASSERT_TRUE(scope_1.get_first_write().empty()); - const auto scope_2 = __dp::Scope(9); - ASSERT_EQ(scope_2.get_id(), 9); + const auto scope_2 = __dp::Scope(9); + ASSERT_EQ(scope_2.get_id(), 9); - ASSERT_TRUE(scope_2.get_first_read().empty()); - ASSERT_TRUE(scope_2.get_first_write().empty()); + ASSERT_TRUE(scope_2.get_first_read().empty()); + ASSERT_TRUE(scope_2.get_first_write().empty()); } TEST_F(ScopeTest, testRegisterRead) { - auto scope = __dp::Scope(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); + auto scope = __dp::Scope(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); - scope.registerStackRead(24, 0, ""); - scope.registerStackRead(32, 1, ""); + scope.registerStackRead(24, 0, ""); + scope.registerStackRead(32, 1, ""); - ASSERT_TRUE(writes.empty()); - ASSERT_EQ(reads.size(), 2); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); + ASSERT_TRUE(writes.empty()); + ASSERT_EQ(reads.size(), 2); - scope.registerStackRead(72, 1, ""); - scope.registerStackRead(24, 6, ""); - scope.registerStackRead(32, 1, ""); + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); - ASSERT_TRUE(writes.empty()); - ASSERT_EQ(reads.size(), 3); + scope.registerStackRead(72, 1, ""); + scope.registerStackRead(24, 6, ""); + scope.registerStackRead(32, 1, ""); - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); - ASSERT_NE(reads.find(72), reads.end()); + ASSERT_TRUE(writes.empty()); + ASSERT_EQ(reads.size(), 3); + + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); + ASSERT_NE(reads.find(72), reads.end()); } TEST_F(ScopeTest, testRegisterWrite) { - auto scope = __dp::Scope(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); + auto scope = __dp::Scope(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); + + scope.registerStackWrite(1024, 0, ""); + scope.registerStackWrite(1032, 1, ""); - scope.registerStackWrite(1024, 0, ""); - scope.registerStackWrite(1032, 1, ""); + ASSERT_TRUE(reads.empty()); + ASSERT_EQ(writes.size(), 2); - ASSERT_TRUE(reads.empty()); - ASSERT_EQ(writes.size(), 2); - - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); - scope.registerStackWrite(1072, 1, ""); - scope.registerStackWrite(1024, 6, ""); - scope.registerStackWrite(1032, 1, ""); + scope.registerStackWrite(1072, 1, ""); + scope.registerStackWrite(1024, 6, ""); + scope.registerStackWrite(1032, 1, ""); - ASSERT_TRUE(reads.empty()); - ASSERT_EQ(writes.size(), 3); + ASSERT_TRUE(reads.empty()); + ASSERT_EQ(writes.size(), 3); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); - ASSERT_NE(writes.find(1072), writes.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); + ASSERT_NE(writes.find(1072), writes.end()); } TEST_F(ScopeTest, testRegister) { - auto scope = __dp::Scope(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); - - scope.registerStackRead(24, 0, ""); - scope.registerStackWrite(1024, 0, ""); - scope.registerStackWrite(1032, 1, ""); - - ASSERT_EQ(reads.size(), 1); - ASSERT_EQ(writes.size(), 2); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); - - scope.registerStackRead(32, 1, ""); - scope.registerStackRead(1024, 5, ""); - scope.registerStackWrite(1876, 0, ""); - scope.registerStackWrite(24, 0, ""); - - ASSERT_EQ(reads.size(), 2); - ASSERT_EQ(writes.size(), 3); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1876), writes.end()); + auto scope = __dp::Scope(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); + + scope.registerStackRead(24, 0, ""); + scope.registerStackWrite(1024, 0, ""); + scope.registerStackWrite(1032, 1, ""); + + ASSERT_EQ(reads.size(), 1); + ASSERT_EQ(writes.size(), 2); + + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); + + scope.registerStackRead(32, 1, ""); + scope.registerStackRead(1024, 5, ""); + scope.registerStackWrite(1876, 0, ""); + scope.registerStackWrite(24, 0, ""); + + ASSERT_EQ(reads.size(), 2); + ASSERT_EQ(writes.size(), 3); + + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1876), writes.end()); } TEST_F(ScopeTest, testCopy1) { - const auto scope_1 = __dp::Scope(4); - const auto scope_2 = __dp::Scope(scope_1); - - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_TRUE(scope_1.get_first_read().empty()); - ASSERT_TRUE(scope_1.get_first_write().empty()); - ASSERT_TRUE(scope_2.get_first_read().empty()); - ASSERT_TRUE(scope_2.get_first_write().empty()); + const auto scope_1 = __dp::Scope(4); + const auto scope_2 = __dp::Scope(scope_1); + + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_TRUE(scope_1.get_first_read().empty()); + ASSERT_TRUE(scope_1.get_first_write().empty()); + ASSERT_TRUE(scope_2.get_first_read().empty()); + ASSERT_TRUE(scope_2.get_first_write().empty()); } TEST_F(ScopeTest, testCopy2) { - auto scope_1 = __dp::Scope(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); + auto scope_1 = __dp::Scope(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); - const auto scope_2 = __dp::Scope(scope_1); + const auto scope_2 = __dp::Scope(scope_1); - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); } TEST_F(ScopeTest, testCopy3) { - auto scope_1 = __dp::Scope(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); - - auto scope_2 = __dp::Scope(scope_1); - auto scope_3 = __dp::Scope(scope_1); - - scope_2.registerStackRead(72, 1, ""); - scope_2.registerStackRead(24, 6, ""); - scope_2.registerStackRead(32, 1, ""); - - scope_2.registerStackWrite(1072, 1, ""); - scope_2.registerStackWrite(1024, 6, ""); - scope_2.registerStackWrite(1032, 1, ""); - - ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); + auto scope_1 = __dp::Scope(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); + + auto scope_2 = __dp::Scope(scope_1); + auto scope_3 = __dp::Scope(scope_1); + + scope_2.registerStackRead(72, 1, ""); + scope_2.registerStackRead(24, 6, ""); + scope_2.registerStackRead(32, 1, ""); + + scope_2.registerStackWrite(1072, 1, ""); + scope_2.registerStackWrite(1024, 6, ""); + scope_2.registerStackWrite(1032, 1, ""); + + ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); } TEST_F(ScopeTest, testCopy4) { - auto scope_1 = __dp::Scope(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); + auto scope_1 = __dp::Scope(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); - auto scope_2 = __dp::Scope(scope_1); - auto scope_3 = __dp::Scope(scope_1); + auto scope_2 = __dp::Scope(scope_1); + auto scope_3 = __dp::Scope(scope_1); - scope_2.registerStackRead(72, 1, ""); - scope_2.registerStackRead(24, 6, ""); - scope_2.registerStackRead(32, 1, ""); + scope_2.registerStackRead(72, 1, ""); + scope_2.registerStackRead(24, 6, ""); + scope_2.registerStackRead(32, 1, ""); - scope_2.registerStackWrite(1072, 1, ""); - scope_2.registerStackWrite(1024, 6, ""); - scope_2.registerStackWrite(1032, 1, ""); + scope_2.registerStackWrite(1072, 1, ""); + scope_2.registerStackWrite(1024, 6, ""); + scope_2.registerStackWrite(1032, 1, ""); - scope_2 = scope_3; + scope_2 = scope_3; - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); - ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); } TEST_F(ScopeManagerTest, testScoping) { - auto manager = __dp::ScopeManager{}; + auto manager = __dp::ScopeManager{}; - manager.enterScope("First scope", 0); - const auto first_scope = manager.getCurrentScope(); - manager.leaveScope("Already gone", 0); + manager.enterScope("First scope", 0); + const auto first_scope = manager.getCurrentScope(); + manager.leaveScope("Already gone", 0); - ASSERT_EQ(first_scope.get_id(), 1); - ASSERT_TRUE(first_scope.get_first_read().empty()); - ASSERT_TRUE(first_scope.get_first_write().empty()); + ASSERT_EQ(first_scope.get_id(), 1); + ASSERT_TRUE(first_scope.get_first_read().empty()); + ASSERT_TRUE(first_scope.get_first_write().empty()); - manager.enterScope("Hello", 1); - manager.enterScope(" ", 20); - manager.enterScope("world", 10); - manager.enterScope("!\n", 1); + manager.enterScope("Hello", 1); + manager.enterScope(" ", 20); + manager.enterScope("world", 10); + manager.enterScope("!\n", 1); - for (auto i = 0; i < 4; i++) { - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 5 - i); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + for (auto i = 0; i < 4; i++) { + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 5 - i); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - const auto scope_again = manager.getCurrentScope(); - ASSERT_EQ(scope_again.get_id(), 5 - i); - ASSERT_TRUE(scope_again.get_first_read().empty()); - ASSERT_TRUE(scope_again.get_first_write().empty()); + const auto scope_again = manager.getCurrentScope(); + ASSERT_EQ(scope_again.get_id(), 5 - i); + ASSERT_TRUE(scope_again.get_first_read().empty()); + ASSERT_TRUE(scope_again.get_first_write().empty()); - manager.leaveScope("leave!", 55); - } + manager.leaveScope("leave!", 55); + } - manager.enterScope("New version", 2); - manager.enterScope("...\n", 5); + manager.enterScope("New version", 2); + manager.enterScope("...\n", 5); - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 7); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 7); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - manager.leaveScope("Leave.", 4); + manager.leaveScope("Leave.", 4); - const auto last_scope = manager.getCurrentScope(); - ASSERT_EQ(last_scope.get_id(), 6); - ASSERT_TRUE(last_scope.get_first_read().empty()); - ASSERT_TRUE(last_scope.get_first_write().empty()); + const auto last_scope = manager.getCurrentScope(); + ASSERT_EQ(last_scope.get_id(), 6); + ASSERT_TRUE(last_scope.get_first_read().empty()); + ASSERT_TRUE(last_scope.get_first_write().empty()); - manager.leaveScope("Leave the last time", 0); + manager.leaveScope("Leave the last time", 0); } TEST_F(ScopeManagerTest, testRegisterRead) { - auto manager = __dp::ScopeManager{}; + auto manager = __dp::ScopeManager{}; + + manager.enterScope("First", 1); - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackRead(24, 2, ""); - manager.registerStackRead(32, 1, ""); + manager.enterScope("Second", 2); + manager.registerStackRead(24, 2, ""); + manager.registerStackRead(32, 1, ""); - manager.enterScope("Third", 3); - manager.registerStackRead(1024, 0, ""); + manager.enterScope("Third", 3); + manager.registerStackRead(1024, 0, ""); - manager.enterScope("Fourth", 4); + manager.enterScope("Fourth", 4); - const auto scope4 = manager.getCurrentScope(); + const auto scope4 = manager.getCurrentScope(); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.leaveScope("Fourth", 4); + manager.leaveScope("Fourth", 4); - manager.registerStackRead(52, 0, ""); + manager.registerStackRead(52, 0, ""); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - - ASSERT_TRUE(scope3.get_first_write().empty()); - ASSERT_EQ(reads3.size(), 2); - ASSERT_NE(reads3.find(52), reads3.end()); - ASSERT_NE(reads3.find(1024), reads3.end()); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); - manager.leaveScope("Third", 3); + ASSERT_TRUE(scope3.get_first_write().empty()); + ASSERT_EQ(reads3.size(), 2); + ASSERT_NE(reads3.find(52), reads3.end()); + ASSERT_NE(reads3.find(1024), reads3.end()); - manager.registerStackRead(24, 2, ""); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - - ASSERT_TRUE(scope2.get_first_write().empty()); - ASSERT_EQ(reads2.size(), 2); - ASSERT_NE(reads2.find(24), reads3.end()); - ASSERT_NE(reads2.find(32), reads3.end()); + manager.registerStackRead(24, 2, ""); - manager.leaveScope("Second", 2); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + ASSERT_TRUE(scope2.get_first_write().empty()); + ASSERT_EQ(reads2.size(), 2); + ASSERT_NE(reads2.find(24), reads3.end()); + ASSERT_NE(reads2.find(32), reads3.end()); - manager.leaveScope("First", 1); + manager.leaveScope("Second", 2); + + const auto scope1 = manager.getCurrentScope(); + + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); + + manager.leaveScope("First", 1); } TEST_F(ScopeManagerTest, testRegisterWrite) { - auto manager = __dp::ScopeManager{}; + auto manager = __dp::ScopeManager{}; + + manager.enterScope("First", 1); - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackWrite(32, 1, ""); + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackWrite(32, 1, ""); - manager.enterScope("Third", 3); - manager.registerStackWrite(1024, 0, ""); + manager.enterScope("Third", 3); + manager.registerStackWrite(1024, 0, ""); - manager.enterScope("Fourth", 4); + manager.enterScope("Fourth", 4); - const auto scope4 = manager.getCurrentScope(); + const auto scope4 = manager.getCurrentScope(); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.leaveScope("Fourth", 4); + manager.leaveScope("Fourth", 4); - manager.registerStackWrite(52, 0, ""); + manager.registerStackWrite(52, 0, ""); - const auto scope3 = manager.getCurrentScope(); - const auto writes3 = scope3.get_first_write(); - - ASSERT_TRUE(scope3.get_first_read().empty()); - ASSERT_EQ(writes3.size(), 2); - ASSERT_NE(writes3.find(52), writes3.end()); - ASSERT_NE(writes3.find(1024), writes3.end()); + const auto scope3 = manager.getCurrentScope(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Third", 3); + ASSERT_TRUE(scope3.get_first_read().empty()); + ASSERT_EQ(writes3.size(), 2); + ASSERT_NE(writes3.find(52), writes3.end()); + ASSERT_NE(writes3.find(1024), writes3.end()); - manager.registerStackWrite(24, 2, ""); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto writes2 = scope2.get_first_write(); - - ASSERT_TRUE(scope2.get_first_read().empty()); - ASSERT_EQ(writes2.size(), 2); - ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_NE(writes2.find(32), writes2.end()); + manager.registerStackWrite(24, 2, ""); - manager.leaveScope("Second", 2); + const auto scope2 = manager.getCurrentScope(); + const auto writes2 = scope2.get_first_write(); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + ASSERT_TRUE(scope2.get_first_read().empty()); + ASSERT_EQ(writes2.size(), 2); + ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_NE(writes2.find(32), writes2.end()); - manager.leaveScope("First", 1); + manager.leaveScope("Second", 2); + + const auto scope1 = manager.getCurrentScope(); + + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); + + manager.leaveScope("First", 1); } -TEST_F(ScopeManagerTest, testRegister) { - auto manager = __dp::ScopeManager{}; +TEST_F(ScopeManagerTest, testRegister) { + auto manager = __dp::ScopeManager{}; - manager.enterScope("First", 1); + manager.enterScope("First", 1); - manager.registerStackRead(32, 0, ""); - manager.registerStackRead(24, 1, ""); + manager.registerStackRead(32, 0, ""); + manager.registerStackRead(24, 1, ""); - manager.enterScope("Second", 2); + manager.enterScope("Second", 2); - manager.registerStackRead(32, 3, ""); - manager.registerStackWrite(24, 4, ""); + manager.registerStackRead(32, 3, ""); + manager.registerStackWrite(24, 4, ""); - manager.enterScope("Third", 3); + manager.enterScope("Third", 3); - manager.registerStackRead(24, 5, ""); - manager.registerStackWrite(24, 6, ""); + manager.registerStackRead(24, 5, ""); + manager.registerStackWrite(24, 6, ""); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - const auto writes3 = scope3.get_first_write(); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Third", 3); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - const auto writes2 = scope2.get_first_write(); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); + const auto writes2 = scope2.get_first_write(); - manager.leaveScope("Second", 2); + manager.leaveScope("Second", 2); - const auto scope1 = manager.getCurrentScope(); - const auto reads1 = scope1.get_first_read(); - const auto writes1 = scope1.get_first_write(); + const auto scope1 = manager.getCurrentScope(); + const auto reads1 = scope1.get_first_read(); + const auto writes1 = scope1.get_first_write(); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); - ASSERT_TRUE(writes1.empty()); - ASSERT_EQ(reads1.size(), 2); - ASSERT_NE(reads1.find(24), reads1.end()); - ASSERT_NE(reads1.find(32), reads1.end()); + ASSERT_TRUE(writes1.empty()); + ASSERT_EQ(reads1.size(), 2); + ASSERT_NE(reads1.find(24), reads1.end()); + ASSERT_NE(reads1.find(32), reads1.end()); - ASSERT_EQ(reads2.size(), 1); - ASSERT_EQ(writes2.size(), 1); - ASSERT_NE(reads2.find(32), reads2.end()); - ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_EQ(reads2.size(), 1); + ASSERT_EQ(writes2.size(), 1); + ASSERT_NE(reads2.find(32), reads2.end()); + ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_TRUE(writes3.empty()); - ASSERT_EQ(reads3.size(), 1); - ASSERT_NE(reads3.find(24), reads3.end()); + ASSERT_TRUE(writes3.empty()); + ASSERT_EQ(reads3.size(), 1); + ASSERT_NE(reads3.find(24), reads3.end()); } TEST_F(ScopeManagerTest, testFirstWritten) { - auto manager = __dp::ScopeManager{}; - - manager.enterScope("First", 1); - manager.registerStackRead(24, 0, ""); - manager.registerStackWrite(24, 1, ""); - manager.registerStackWrite(12, 2, ""); - manager.registerStackRead(12, 3, ""); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackRead(24, 3, ""); - manager.registerStackRead(12, 0, ""); - manager.registerStackWrite(12, 1, ""); - - manager.enterScope("Third", 3); - manager.registerStackRead(32, 4, ""); - manager.registerStackWrite(36, 5, ""); - manager.registerStackRead(40, 6, ""); - - ASSERT_TRUE(manager.isOwnedByScope(36, true)); - ASSERT_TRUE(manager.isOwnedByScope(1012, true)); - ASSERT_TRUE(manager.isOwnedByScope(1024, true)); - - ASSERT_FALSE(manager.isOwnedByScope(12, true)); - ASSERT_FALSE(manager.isOwnedByScope(24, true)); - ASSERT_FALSE(manager.isOwnedByScope(32, true)); - ASSERT_FALSE(manager.isOwnedByScope(32, false)); - ASSERT_FALSE(manager.isOwnedByScope(40, true)); - ASSERT_FALSE(manager.isOwnedByScope(40, false)); - ASSERT_FALSE(manager.isOwnedByScope(1012, false)); - ASSERT_FALSE(manager.isOwnedByScope(1024, false)); + auto manager = __dp::ScopeManager{}; + + manager.enterScope("First", 1); + manager.registerStackRead(24, 0, ""); + manager.registerStackWrite(24, 1, ""); + manager.registerStackWrite(12, 2, ""); + manager.registerStackRead(12, 3, ""); + + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackRead(24, 3, ""); + manager.registerStackRead(12, 0, ""); + manager.registerStackWrite(12, 1, ""); + + manager.enterScope("Third", 3); + manager.registerStackRead(32, 4, ""); + manager.registerStackWrite(36, 5, ""); + manager.registerStackRead(40, 6, ""); + + ASSERT_TRUE(manager.isOwnedByScope(36, true)); + ASSERT_TRUE(manager.isOwnedByScope(1012, true)); + ASSERT_TRUE(manager.isOwnedByScope(1024, true)); + + ASSERT_FALSE(manager.isOwnedByScope(12, true)); + ASSERT_FALSE(manager.isOwnedByScope(24, true)); + ASSERT_FALSE(manager.isOwnedByScope(32, true)); + ASSERT_FALSE(manager.isOwnedByScope(32, false)); + ASSERT_FALSE(manager.isOwnedByScope(40, true)); + ASSERT_FALSE(manager.isOwnedByScope(40, false)); + ASSERT_FALSE(manager.isOwnedByScope(1012, false)); + ASSERT_FALSE(manager.isOwnedByScope(1024, false)); } TEST_F(ScopeManagerTest, testPositiveChange) { - auto scope = __dp::ScopeManager{}; + auto scope = __dp::ScopeManager{}; - scope.enterScope("First", 1); - scope.registerStackRead(24, 0, ""); - scope.registerStackRead(64, 1, ""); + scope.enterScope("First", 1); + scope.registerStackRead(24, 0, ""); + scope.registerStackRead(64, 1, ""); - scope.enterScope("Second", 2); - scope.registerStackWrite(32, 2, ""); + scope.enterScope("Second", 2); + scope.registerStackWrite(32, 2, ""); - scope.enterScope("Third", 3); - scope.registerStackWrite(64, 3, ""); + scope.enterScope("Third", 3); + scope.registerStackWrite(64, 3, ""); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("Third", 3); + scope.leaveScope("Third", 3); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("Second", 2); + scope.leaveScope("Second", 2); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.leaveScope("First", 1); + scope.leaveScope("First", 1); - // TODO(Lukas): Currently, there is no active scope. - // Think about your error handling. + // TODO(Lukas): Currently, there is no active scope. + // Think about your error handling. - // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.enterScope("Forth", 4); + scope.enterScope("Forth", 4); - scope.registerStackRead(24, 4, ""); + scope.registerStackRead(24, 4, ""); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - scope.enterScope("Fifth", 5); + scope.enterScope("Fifth", 5); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); } // Tests for new version (i.e., reproducing functionality) -class Scope2Test : public ::testing::Test { }; +class Scope2Test : public ::testing::Test {}; -class ScopeManager2Test : public ::testing::Test { }; +class ScopeManager2Test : public ::testing::Test {}; TEST_F(Scope2Test, testConstructor) { - const auto scope_1 = __dp::Scope2(4); - ASSERT_EQ(scope_1.get_id(), 4); + const auto scope_1 = __dp::Scope2(4); + ASSERT_EQ(scope_1.get_id(), 4); - ASSERT_TRUE(scope_1.get_first_read().empty()); - ASSERT_TRUE(scope_1.get_first_write().empty()); + ASSERT_TRUE(scope_1.get_first_read().empty()); + ASSERT_TRUE(scope_1.get_first_write().empty()); - const auto scope_2 = __dp::Scope2(9); - ASSERT_EQ(scope_2.get_id(), 9); + const auto scope_2 = __dp::Scope2(9); + ASSERT_EQ(scope_2.get_id(), 9); - ASSERT_TRUE(scope_2.get_first_read().empty()); - ASSERT_TRUE(scope_2.get_first_write().empty()); + ASSERT_TRUE(scope_2.get_first_read().empty()); + ASSERT_TRUE(scope_2.get_first_write().empty()); } TEST_F(Scope2Test, testRegisterRead) { - auto scope = __dp::Scope2(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); + auto scope = __dp::Scope2(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); + + scope.registerStackRead(24, 0, ""); + scope.registerStackRead(32, 1, ""); - scope.registerStackRead(24, 0, ""); - scope.registerStackRead(32, 1, ""); + ASSERT_TRUE(writes.empty()); + ASSERT_EQ(reads.size(), 2); - ASSERT_TRUE(writes.empty()); - ASSERT_EQ(reads.size(), 2); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); - scope.registerStackRead(72, 1, ""); - scope.registerStackRead(24, 6, ""); - scope.registerStackRead(32, 1, ""); + scope.registerStackRead(72, 1, ""); + scope.registerStackRead(24, 6, ""); + scope.registerStackRead(32, 1, ""); - ASSERT_TRUE(writes.empty()); - ASSERT_EQ(reads.size(), 3); + ASSERT_TRUE(writes.empty()); + ASSERT_EQ(reads.size(), 3); - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); - ASSERT_NE(reads.find(72), reads.end()); + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); + ASSERT_NE(reads.find(72), reads.end()); } TEST_F(Scope2Test, testRegisterWrite) { - auto scope = __dp::Scope2(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); + auto scope = __dp::Scope2(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); - scope.registerStackWrite(1024, 0, ""); - scope.registerStackWrite(1032, 1, ""); + scope.registerStackWrite(1024, 0, ""); + scope.registerStackWrite(1032, 1, ""); - ASSERT_TRUE(reads.empty()); - ASSERT_EQ(writes.size(), 2); - - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); + ASSERT_TRUE(reads.empty()); + ASSERT_EQ(writes.size(), 2); - scope.registerStackWrite(1072, 1, ""); - scope.registerStackWrite(1024, 6, ""); - scope.registerStackWrite(1032, 1, ""); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); - ASSERT_TRUE(reads.empty()); - ASSERT_EQ(writes.size(), 3); + scope.registerStackWrite(1072, 1, ""); + scope.registerStackWrite(1024, 6, ""); + scope.registerStackWrite(1032, 1, ""); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); - ASSERT_NE(writes.find(1072), writes.end()); + ASSERT_TRUE(reads.empty()); + ASSERT_EQ(writes.size(), 3); + + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); + ASSERT_NE(writes.find(1072), writes.end()); } TEST_F(Scope2Test, testRegister) { - auto scope = __dp::Scope2(3); - const auto& reads = scope.get_first_read(); - const auto& writes = scope.get_first_write(); - - scope.registerStackRead(24, 0, ""); - scope.registerStackWrite(1024, 0, ""); - scope.registerStackWrite(1032, 1, ""); - - ASSERT_EQ(reads.size(), 1); - ASSERT_EQ(writes.size(), 2); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1032), writes.end()); - - scope.registerStackRead(32, 1, ""); - scope.registerStackRead(1024, 5, ""); - scope.registerStackWrite(1876, 0, ""); - scope.registerStackWrite(24, 0, ""); - - ASSERT_EQ(reads.size(), 2); - ASSERT_EQ(writes.size(), 3); - - ASSERT_NE(reads.find(24), reads.end()); - ASSERT_NE(reads.find(32), reads.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1024), writes.end()); - ASSERT_NE(writes.find(1876), writes.end()); + auto scope = __dp::Scope2(3); + const auto &reads = scope.get_first_read(); + const auto &writes = scope.get_first_write(); + + scope.registerStackRead(24, 0, ""); + scope.registerStackWrite(1024, 0, ""); + scope.registerStackWrite(1032, 1, ""); + + ASSERT_EQ(reads.size(), 1); + ASSERT_EQ(writes.size(), 2); + + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1032), writes.end()); + + scope.registerStackRead(32, 1, ""); + scope.registerStackRead(1024, 5, ""); + scope.registerStackWrite(1876, 0, ""); + scope.registerStackWrite(24, 0, ""); + + ASSERT_EQ(reads.size(), 2); + ASSERT_EQ(writes.size(), 3); + + ASSERT_NE(reads.find(24), reads.end()); + ASSERT_NE(reads.find(32), reads.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1024), writes.end()); + ASSERT_NE(writes.find(1876), writes.end()); } TEST_F(Scope2Test, testCopy1) { - const auto scope_1 = __dp::Scope2(4); - const auto scope_2 = __dp::Scope2(scope_1); - - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_TRUE(scope_1.get_first_read().empty()); - ASSERT_TRUE(scope_1.get_first_write().empty()); - ASSERT_TRUE(scope_2.get_first_read().empty()); - ASSERT_TRUE(scope_2.get_first_write().empty()); + const auto scope_1 = __dp::Scope2(4); + const auto scope_2 = __dp::Scope2(scope_1); + + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_TRUE(scope_1.get_first_read().empty()); + ASSERT_TRUE(scope_1.get_first_write().empty()); + ASSERT_TRUE(scope_2.get_first_read().empty()); + ASSERT_TRUE(scope_2.get_first_write().empty()); } TEST_F(Scope2Test, testCopy2) { - auto scope_1 = __dp::Scope2(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); + auto scope_1 = __dp::Scope2(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); - const auto scope_2 = __dp::Scope2(scope_1); + const auto scope_2 = __dp::Scope2(scope_1); - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); } TEST_F(Scope2Test, testCopy3) { - auto scope_1 = __dp::Scope2(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); - - auto scope_2 = __dp::Scope2(scope_1); - auto scope_3 = __dp::Scope2(scope_1); - - scope_2.registerStackRead(72, 1, ""); - scope_2.registerStackRead(24, 6, ""); - scope_2.registerStackRead(32, 1, ""); - - scope_2.registerStackWrite(1072, 1, ""); - scope_2.registerStackWrite(1024, 6, ""); - scope_2.registerStackWrite(1032, 1, ""); - - ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); + auto scope_1 = __dp::Scope2(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); + + auto scope_2 = __dp::Scope2(scope_1); + auto scope_3 = __dp::Scope2(scope_1); + + scope_2.registerStackRead(72, 1, ""); + scope_2.registerStackRead(24, 6, ""); + scope_2.registerStackRead(32, 1, ""); + + scope_2.registerStackWrite(1072, 1, ""); + scope_2.registerStackWrite(1024, 6, ""); + scope_2.registerStackWrite(1032, 1, ""); + + ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); } TEST_F(Scope2Test, testCopy4) { - auto scope_1 = __dp::Scope2(4); - scope_1.registerStackRead(24, 0, ""); - scope_1.registerStackRead(32, 1, ""); - scope_1.registerStackWrite(1024, 0, ""); - scope_1.registerStackWrite(1032, 1, ""); + auto scope_1 = __dp::Scope2(4); + scope_1.registerStackRead(24, 0, ""); + scope_1.registerStackRead(32, 1, ""); + scope_1.registerStackWrite(1024, 0, ""); + scope_1.registerStackWrite(1032, 1, ""); - auto scope_2 = __dp::Scope2(scope_1); - auto scope_3 = __dp::Scope2(scope_1); + auto scope_2 = __dp::Scope2(scope_1); + auto scope_3 = __dp::Scope2(scope_1); - scope_2.registerStackRead(72, 1, ""); - scope_2.registerStackRead(24, 6, ""); - scope_2.registerStackRead(32, 1, ""); + scope_2.registerStackRead(72, 1, ""); + scope_2.registerStackRead(24, 6, ""); + scope_2.registerStackRead(32, 1, ""); - scope_2.registerStackWrite(1072, 1, ""); - scope_2.registerStackWrite(1024, 6, ""); - scope_2.registerStackWrite(1032, 1, ""); + scope_2.registerStackWrite(1072, 1, ""); + scope_2.registerStackWrite(1024, 6, ""); + scope_2.registerStackWrite(1032, 1, ""); - scope_2 = scope_3; + scope_2 = scope_3; - ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_2.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_2.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_2.get_first_write()); - ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); - ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); - ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); + ASSERT_EQ(scope_1.get_id(), scope_3.get_id()); + ASSERT_EQ(scope_1.get_first_read(), scope_3.get_first_read()); + ASSERT_EQ(scope_1.get_first_write(), scope_3.get_first_write()); } - TEST_F(ScopeManager2Test, testScoping) { - auto manager = __dp::ScopeManager2{}; + auto manager = __dp::ScopeManager2{}; - manager.enterScope("First scope", 0); - const auto first_scope = manager.getCurrentScope(); - manager.leaveScope("Already gone", 0); + manager.enterScope("First scope", 0); + const auto first_scope = manager.getCurrentScope(); + manager.leaveScope("Already gone", 0); - ASSERT_EQ(first_scope.get_id(), 1); - ASSERT_TRUE(first_scope.get_first_read().empty()); - ASSERT_TRUE(first_scope.get_first_write().empty()); + ASSERT_EQ(first_scope.get_id(), 1); + ASSERT_TRUE(first_scope.get_first_read().empty()); + ASSERT_TRUE(first_scope.get_first_write().empty()); - manager.enterScope("Hello", 1); - manager.enterScope(" ", 20); - manager.enterScope("world", 10); - manager.enterScope("!\n", 1); + manager.enterScope("Hello", 1); + manager.enterScope(" ", 20); + manager.enterScope("world", 10); + manager.enterScope("!\n", 1); - for (auto i = 0; i < 4; i++) { - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 5 - i); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + for (auto i = 0; i < 4; i++) { + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 5 - i); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - const auto scope_again = manager.getCurrentScope(); - ASSERT_EQ(scope_again.get_id(), 5 - i); - ASSERT_TRUE(scope_again.get_first_read().empty()); - ASSERT_TRUE(scope_again.get_first_write().empty()); + const auto scope_again = manager.getCurrentScope(); + ASSERT_EQ(scope_again.get_id(), 5 - i); + ASSERT_TRUE(scope_again.get_first_read().empty()); + ASSERT_TRUE(scope_again.get_first_write().empty()); - manager.leaveScope("leave!", 55); - } + manager.leaveScope("leave!", 55); + } - manager.enterScope("New version", 2); - manager.enterScope("...\n", 5); + manager.enterScope("New version", 2); + manager.enterScope("...\n", 5); - const auto scope = manager.getCurrentScope(); - ASSERT_EQ(scope.get_id(), 7); - ASSERT_TRUE(scope.get_first_read().empty()); - ASSERT_TRUE(scope.get_first_write().empty()); + const auto scope = manager.getCurrentScope(); + ASSERT_EQ(scope.get_id(), 7); + ASSERT_TRUE(scope.get_first_read().empty()); + ASSERT_TRUE(scope.get_first_write().empty()); - manager.leaveScope("Leave.", 4); + manager.leaveScope("Leave.", 4); - const auto last_scope = manager.getCurrentScope(); - ASSERT_EQ(last_scope.get_id(), 6); - ASSERT_TRUE(last_scope.get_first_read().empty()); - ASSERT_TRUE(last_scope.get_first_write().empty()); + const auto last_scope = manager.getCurrentScope(); + ASSERT_EQ(last_scope.get_id(), 6); + ASSERT_TRUE(last_scope.get_first_read().empty()); + ASSERT_TRUE(last_scope.get_first_write().empty()); - manager.leaveScope("Leave the last time", 0); + manager.leaveScope("Leave the last time", 0); } TEST_F(ScopeManager2Test, testRegisterRead) { - auto manager = __dp::ScopeManager2{}; + auto manager = __dp::ScopeManager2{}; - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackRead(24, 2, ""); - manager.registerStackRead(32, 1, ""); + manager.enterScope("First", 1); - manager.enterScope("Third", 3); - manager.registerStackRead(1024, 0, ""); + manager.enterScope("Second", 2); + manager.registerStackRead(24, 2, ""); + manager.registerStackRead(32, 1, ""); - manager.enterScope("Fourth", 4); + manager.enterScope("Third", 3); + manager.registerStackRead(1024, 0, ""); - const auto scope4 = manager.getCurrentScope(); + manager.enterScope("Fourth", 4); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + const auto scope4 = manager.getCurrentScope(); - manager.leaveScope("Fourth", 4); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.registerStackRead(52, 0, ""); + manager.leaveScope("Fourth", 4); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - - ASSERT_TRUE(scope3.get_first_write().empty()); - ASSERT_EQ(reads3.size(), 2); - ASSERT_NE(reads3.find(52), reads3.end()); - ASSERT_NE(reads3.find(1024), reads3.end()); + manager.registerStackRead(52, 0, ""); - manager.leaveScope("Third", 3); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); - manager.registerStackRead(24, 2, ""); + ASSERT_TRUE(scope3.get_first_write().empty()); + ASSERT_EQ(reads3.size(), 2); + ASSERT_NE(reads3.find(52), reads3.end()); + ASSERT_NE(reads3.find(1024), reads3.end()); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - - ASSERT_TRUE(scope2.get_first_write().empty()); - ASSERT_EQ(reads2.size(), 2); - ASSERT_NE(reads2.find(24), reads3.end()); - ASSERT_NE(reads2.find(32), reads3.end()); + manager.leaveScope("Third", 3); - manager.leaveScope("Second", 2); + manager.registerStackRead(24, 2, ""); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); - manager.leaveScope("First", 1); + ASSERT_TRUE(scope2.get_first_write().empty()); + ASSERT_EQ(reads2.size(), 2); + ASSERT_NE(reads2.find(24), reads3.end()); + ASSERT_NE(reads2.find(32), reads3.end()); + + manager.leaveScope("Second", 2); + + const auto scope1 = manager.getCurrentScope(); + + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); + + manager.leaveScope("First", 1); } TEST_F(ScopeManager2Test, testRegisterWrite) { - auto manager = __dp::ScopeManager2{}; + auto manager = __dp::ScopeManager2{}; + + manager.enterScope("First", 1); + + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackWrite(32, 1, ""); + + manager.enterScope("Third", 3); + manager.registerStackWrite(1024, 0, ""); + + manager.enterScope("Fourth", 4); - manager.enterScope("First", 1); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackWrite(32, 1, ""); + const auto scope4 = manager.getCurrentScope(); - manager.enterScope("Third", 3); - manager.registerStackWrite(1024, 0, ""); + ASSERT_TRUE(scope4.get_first_read().empty()); + ASSERT_TRUE(scope4.get_first_write().empty()); - manager.enterScope("Fourth", 4); + manager.leaveScope("Fourth", 4); - const auto scope4 = manager.getCurrentScope(); + manager.registerStackWrite(52, 0, ""); - ASSERT_TRUE(scope4.get_first_read().empty()); - ASSERT_TRUE(scope4.get_first_write().empty()); + const auto scope3 = manager.getCurrentScope(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Fourth", 4); + ASSERT_TRUE(scope3.get_first_read().empty()); + ASSERT_EQ(writes3.size(), 2); + ASSERT_NE(writes3.find(52), writes3.end()); + ASSERT_NE(writes3.find(1024), writes3.end()); - manager.registerStackWrite(52, 0, ""); + manager.leaveScope("Third", 3); - const auto scope3 = manager.getCurrentScope(); - const auto writes3 = scope3.get_first_write(); - - ASSERT_TRUE(scope3.get_first_read().empty()); - ASSERT_EQ(writes3.size(), 2); - ASSERT_NE(writes3.find(52), writes3.end()); - ASSERT_NE(writes3.find(1024), writes3.end()); + manager.registerStackWrite(24, 2, ""); - manager.leaveScope("Third", 3); + const auto scope2 = manager.getCurrentScope(); + const auto writes2 = scope2.get_first_write(); - manager.registerStackWrite(24, 2, ""); + ASSERT_TRUE(scope2.get_first_read().empty()); + ASSERT_EQ(writes2.size(), 2); + ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_NE(writes2.find(32), writes2.end()); - const auto scope2 = manager.getCurrentScope(); - const auto writes2 = scope2.get_first_write(); - - ASSERT_TRUE(scope2.get_first_read().empty()); - ASSERT_EQ(writes2.size(), 2); - ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_NE(writes2.find(32), writes2.end()); + manager.leaveScope("Second", 2); - manager.leaveScope("Second", 2); + const auto scope1 = manager.getCurrentScope(); - const auto scope1 = manager.getCurrentScope(); - - ASSERT_TRUE(scope1.get_first_read().empty()); - ASSERT_TRUE(scope1.get_first_write().empty()); + ASSERT_TRUE(scope1.get_first_read().empty()); + ASSERT_TRUE(scope1.get_first_write().empty()); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); } -TEST_F(ScopeManager2Test, testRegister) { - auto manager = __dp::ScopeManager2{}; +TEST_F(ScopeManager2Test, testRegister) { + auto manager = __dp::ScopeManager2{}; - manager.enterScope("First", 1); + manager.enterScope("First", 1); - manager.registerStackRead(32, 0, ""); - manager.registerStackRead(24, 1, ""); + manager.registerStackRead(32, 0, ""); + manager.registerStackRead(24, 1, ""); - manager.enterScope("Second", 2); + manager.enterScope("Second", 2); - manager.registerStackRead(32, 3, ""); - manager.registerStackWrite(24, 4, ""); + manager.registerStackRead(32, 3, ""); + manager.registerStackWrite(24, 4, ""); - manager.enterScope("Third", 3); + manager.enterScope("Third", 3); - manager.registerStackRead(24, 5, ""); - manager.registerStackWrite(24, 6, ""); + manager.registerStackRead(24, 5, ""); + manager.registerStackWrite(24, 6, ""); - const auto scope3 = manager.getCurrentScope(); - const auto reads3 = scope3.get_first_read(); - const auto writes3 = scope3.get_first_write(); + const auto scope3 = manager.getCurrentScope(); + const auto reads3 = scope3.get_first_read(); + const auto writes3 = scope3.get_first_write(); - manager.leaveScope("Third", 3); + manager.leaveScope("Third", 3); - const auto scope2 = manager.getCurrentScope(); - const auto reads2 = scope2.get_first_read(); - const auto writes2 = scope2.get_first_write(); + const auto scope2 = manager.getCurrentScope(); + const auto reads2 = scope2.get_first_read(); + const auto writes2 = scope2.get_first_write(); - manager.leaveScope("Second", 2); + manager.leaveScope("Second", 2); - const auto scope1 = manager.getCurrentScope(); - const auto reads1 = scope1.get_first_read(); - const auto writes1 = scope1.get_first_write(); + const auto scope1 = manager.getCurrentScope(); + const auto reads1 = scope1.get_first_read(); + const auto writes1 = scope1.get_first_write(); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); - ASSERT_TRUE(writes1.empty()); - ASSERT_EQ(reads1.size(), 2); - ASSERT_NE(reads1.find(24), reads1.end()); - ASSERT_NE(reads1.find(32), reads1.end()); + ASSERT_TRUE(writes1.empty()); + ASSERT_EQ(reads1.size(), 2); + ASSERT_NE(reads1.find(24), reads1.end()); + ASSERT_NE(reads1.find(32), reads1.end()); - ASSERT_EQ(reads2.size(), 1); - ASSERT_EQ(writes2.size(), 1); - ASSERT_NE(reads2.find(32), reads2.end()); - ASSERT_NE(writes2.find(24), writes2.end()); + ASSERT_EQ(reads2.size(), 1); + ASSERT_EQ(writes2.size(), 1); + ASSERT_NE(reads2.find(32), reads2.end()); + ASSERT_NE(writes2.find(24), writes2.end()); - ASSERT_TRUE(writes3.empty()); - ASSERT_EQ(reads3.size(), 1); - ASSERT_NE(reads3.find(24), reads3.end()); + ASSERT_TRUE(writes3.empty()); + ASSERT_EQ(reads3.size(), 1); + ASSERT_NE(reads3.find(24), reads3.end()); } TEST_F(ScopeManager2Test, testFirstWritten) { - auto manager = __dp::ScopeManager2{}; - - manager.enterScope("First", 1); - manager.registerStackRead(24, 0, ""); - manager.registerStackWrite(24, 1, ""); - manager.registerStackWrite(12, 2, ""); - manager.registerStackRead(12, 3, ""); - - manager.enterScope("Second", 2); - manager.registerStackWrite(24, 2, ""); - manager.registerStackRead(24, 3, ""); - manager.registerStackRead(12, 0, ""); - manager.registerStackWrite(12, 1, ""); - - manager.enterScope("Third", 3); - manager.registerStackRead(32, 4, ""); - manager.registerStackWrite(36, 5, ""); - manager.registerStackRead(40, 6, ""); - - ASSERT_TRUE(manager.isOwnedByScope(36, true)); - ASSERT_TRUE(manager.isOwnedByScope(1012, true)); - ASSERT_TRUE(manager.isOwnedByScope(1024, true)); - - ASSERT_FALSE(manager.isOwnedByScope(12, true)); - ASSERT_FALSE(manager.isOwnedByScope(24, true)); - ASSERT_FALSE(manager.isOwnedByScope(32, true)); - ASSERT_FALSE(manager.isOwnedByScope(32, false)); - ASSERT_FALSE(manager.isOwnedByScope(40, true)); - ASSERT_FALSE(manager.isOwnedByScope(40, false)); - ASSERT_FALSE(manager.isOwnedByScope(1012, false)); - ASSERT_FALSE(manager.isOwnedByScope(1024, false)); + auto manager = __dp::ScopeManager2{}; + + manager.enterScope("First", 1); + manager.registerStackRead(24, 0, ""); + manager.registerStackWrite(24, 1, ""); + manager.registerStackWrite(12, 2, ""); + manager.registerStackRead(12, 3, ""); + + manager.enterScope("Second", 2); + manager.registerStackWrite(24, 2, ""); + manager.registerStackRead(24, 3, ""); + manager.registerStackRead(12, 0, ""); + manager.registerStackWrite(12, 1, ""); + + manager.enterScope("Third", 3); + manager.registerStackRead(32, 4, ""); + manager.registerStackWrite(36, 5, ""); + manager.registerStackRead(40, 6, ""); + + ASSERT_TRUE(manager.isOwnedByScope(36, true)); + ASSERT_TRUE(manager.isOwnedByScope(1012, true)); + ASSERT_TRUE(manager.isOwnedByScope(1024, true)); + + ASSERT_FALSE(manager.isOwnedByScope(12, true)); + ASSERT_FALSE(manager.isOwnedByScope(24, true)); + ASSERT_FALSE(manager.isOwnedByScope(32, true)); + ASSERT_FALSE(manager.isOwnedByScope(32, false)); + ASSERT_FALSE(manager.isOwnedByScope(40, true)); + ASSERT_FALSE(manager.isOwnedByScope(40, false)); + ASSERT_FALSE(manager.isOwnedByScope(1012, false)); + ASSERT_FALSE(manager.isOwnedByScope(1024, false)); } TEST_F(ScopeManager2Test, testPositiveChange) { - auto manager = __dp::ScopeManager2{}; + auto manager = __dp::ScopeManager2{}; - manager.enterScope("First", 1); - manager.registerStackRead(24, 0, ""); - manager.registerStackRead(64, 1, ""); + manager.enterScope("First", 1); + manager.registerStackRead(24, 0, ""); + manager.registerStackRead(64, 1, ""); - manager.enterScope("Second", 2); - manager.registerStackWrite(32, 2, ""); + manager.enterScope("Second", 2); + manager.registerStackWrite(32, 2, ""); - manager.enterScope("Third", 3); - manager.registerStackWrite(64, 3, ""); + manager.enterScope("Third", 3); + manager.registerStackWrite(64, 3, ""); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); - manager.leaveScope("Third", 3); + manager.leaveScope("Third", 3); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); - manager.leaveScope("Second", 2); + manager.leaveScope("Second", 2); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); - manager.leaveScope("First", 1); + manager.leaveScope("First", 1); - // These do not work anymore - // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); - // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); + // These do not work anymore + // ASSERT_TRUE(scope.positiveScopeChangeOccuredSinceLastAccess(12)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(24)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(32)); + // ASSERT_FALSE(scope.positiveScopeChangeOccuredSinceLastAccess(64)); - manager.enterScope("Forth", 4); + manager.enterScope("Forth", 4); - manager.registerStackRead(24, 4, ""); + manager.registerStackRead(24, 4, ""); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_FALSE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); - manager.enterScope("Fifth", 5); + manager.enterScope("Fifth", 5); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); - ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(12)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(24)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(32)); + ASSERT_TRUE(manager.positiveScopeChangeOccuredSinceLastAccess(64)); } diff --git a/test/unit_tests/tests.cpp b/test/unit_tests/tests.cpp index d48025d90..8338d27a8 100644 --- a/test/unit_tests/tests.cpp +++ b/test/unit_tests/tests.cpp @@ -1,8 +1,8 @@ #include -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - const auto tests_return_code = RUN_ALL_TESTS(); +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + const auto tests_return_code = RUN_ALL_TESTS(); - return tests_return_code; + return tests_return_code; }