003 File Manager
Current Path:
/usr/src/contrib/llvm-project/clang/lib/CodeGen
usr
/
src
/
contrib
/
llvm-project
/
clang
/
lib
/
CodeGen
/
📁
..
📄
ABIInfo.h
(5.01 KB)
📄
Address.h
(3.28 KB)
📄
BackendUtil.cpp
(67.92 KB)
📄
CGAtomic.cpp
(85.95 KB)
📄
CGBlocks.cpp
(111.14 KB)
📄
CGBlocks.h
(8.94 KB)
📄
CGBuilder.h
(13.78 KB)
📄
CGBuiltin.cpp
(695.8 KB)
📄
CGCUDANV.cpp
(35.16 KB)
📄
CGCUDARuntime.cpp
(1.53 KB)
📄
CGCUDARuntime.h
(3.4 KB)
📄
CGCXX.cpp
(11.8 KB)
📄
CGCXXABI.cpp
(12.47 KB)
📄
CGCXXABI.h
(27.9 KB)
📄
CGCall.cpp
(197.3 KB)
📄
CGCall.h
(11.62 KB)
📄
CGClass.cpp
(113.54 KB)
📄
CGCleanup.cpp
(46.97 KB)
📄
CGCleanup.h
(19.28 KB)
📄
CGCoroutine.cpp
(27.82 KB)
📄
CGDebugInfo.cpp
(191.42 KB)
📄
CGDebugInfo.h
(34.73 KB)
📄
CGDecl.cpp
(97.98 KB)
📄
CGDeclCXX.cpp
(34.73 KB)
📄
CGException.cpp
(80.38 KB)
📄
CGExpr.cpp
(209.78 KB)
📄
CGExprAgg.cpp
(77.04 KB)
📄
CGExprCXX.cpp
(90.39 KB)
📄
CGExprComplex.cpp
(44.9 KB)
📄
CGExprConstant.cpp
(86.17 KB)
📄
CGExprScalar.cpp
(196.29 KB)
📄
CGGPUBuiltin.cpp
(6.17 KB)
📄
CGLoopInfo.cpp
(29.17 KB)
📄
CGLoopInfo.h
(10.5 KB)
📄
CGNonTrivialStruct.cpp
(41.4 KB)
📄
CGObjC.cpp
(142.79 KB)
📄
CGObjCGNU.cpp
(168.38 KB)
📄
CGObjCMac.cpp
(304.84 KB)
📄
CGObjCRuntime.cpp
(14.68 KB)
📄
CGObjCRuntime.h
(14.81 KB)
📄
CGOpenCLRuntime.cpp
(7.08 KB)
📄
CGOpenCLRuntime.h
(3.44 KB)
📄
CGOpenMPRuntime.cpp
(501.86 KB)
📄
CGOpenMPRuntime.h
(111.87 KB)
📄
CGOpenMPRuntimeNVPTX.cpp
(215.42 KB)
📄
CGOpenMPRuntimeNVPTX.h
(22.59 KB)
📄
CGRecordLayout.h
(7.84 KB)
📄
CGRecordLayoutBuilder.cpp
(38.24 KB)
📄
CGStmt.cpp
(92.92 KB)
📄
CGStmtOpenMP.cpp
(278.04 KB)
📄
CGVTT.cpp
(6.81 KB)
📄
CGVTables.cpp
(55.02 KB)
📄
CGVTables.h
(6.38 KB)
📄
CGValue.h
(21.24 KB)
📄
CodeGenABITypes.cpp
(5 KB)
📄
CodeGenAction.cpp
(46.2 KB)
📄
CodeGenFunction.cpp
(95.34 KB)
📄
CodeGenFunction.h
(200.94 KB)
📄
CodeGenModule.cpp
(228.13 KB)
📄
CodeGenModule.h
(60.91 KB)
📄
CodeGenPGO.cpp
(36.17 KB)
📄
CodeGenPGO.h
(4.36 KB)
📄
CodeGenTBAA.cpp
(16.92 KB)
📄
CodeGenTBAA.h
(9.19 KB)
📄
CodeGenTypeCache.h
(3.28 KB)
📄
CodeGenTypes.cpp
(32.35 KB)
📄
CodeGenTypes.h
(13.42 KB)
📄
ConstantEmitter.h
(6.65 KB)
📄
ConstantInitBuilder.cpp
(10.29 KB)
📄
CoverageMappingGen.cpp
(54.64 KB)
📄
CoverageMappingGen.h
(4.04 KB)
📄
EHScopeStack.h
(14.38 KB)
📄
ItaniumCXXABI.cpp
(176.66 KB)
📄
MacroPPCallbacks.cpp
(6.41 KB)
📄
MacroPPCallbacks.h
(4.54 KB)
📄
MicrosoftCXXABI.cpp
(175.41 KB)
📄
ModuleBuilder.cpp
(11.79 KB)
📄
ObjectFilePCHContainerOperations.cpp
(12.93 KB)
📄
PatternInit.cpp
(4.1 KB)
📄
PatternInit.h
(722 B)
📄
SanitizerMetadata.cpp
(4.21 KB)
📄
SanitizerMetadata.h
(1.63 KB)
📄
SwiftCallingConv.cpp
(29.76 KB)
📄
TargetInfo.cpp
(403.11 KB)
📄
TargetInfo.h
(15.43 KB)
📄
VarBypassDetector.cpp
(5.1 KB)
📄
VarBypassDetector.h
(2.29 KB)
Editing: VarBypassDetector.cpp
//===--- VarBypassDetector.h - Bypass jumps detector --------------*- C++ -*-=// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "VarBypassDetector.h" #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" #include "clang/AST/Stmt.h" using namespace clang; using namespace CodeGen; /// Clear the object and pre-process for the given statement, usually function /// body statement. void VarBypassDetector::Init(const Stmt *Body) { FromScopes.clear(); ToScopes.clear(); Bypasses.clear(); Scopes = {{~0U, nullptr}}; unsigned ParentScope = 0; AlwaysBypassed = !BuildScopeInformation(Body, ParentScope); if (!AlwaysBypassed) Detect(); } /// Build scope information for a declaration that is part of a DeclStmt. /// Returns false if we failed to build scope information and can't tell for /// which vars are being bypassed. bool VarBypassDetector::BuildScopeInformation(const Decl *D, unsigned &ParentScope) { const VarDecl *VD = dyn_cast<VarDecl>(D); if (VD && VD->hasLocalStorage()) { Scopes.push_back({ParentScope, VD}); ParentScope = Scopes.size() - 1; } if (const VarDecl *VD = dyn_cast<VarDecl>(D)) if (const Expr *Init = VD->getInit()) return BuildScopeInformation(Init, ParentScope); return true; } /// Walk through the statements, adding any labels or gotos to /// LabelAndGotoScopes and recursively walking the AST as needed. /// Returns false if we failed to build scope information and can't tell for /// which vars are being bypassed. bool VarBypassDetector::BuildScopeInformation(const Stmt *S, unsigned &origParentScope) { // If this is a statement, rather than an expression, scopes within it don't // propagate out into the enclosing scope. Otherwise we have to worry about // block literals, which have the lifetime of their enclosing statement. unsigned independentParentScope = origParentScope; unsigned &ParentScope = ((isa<Expr>(S) && !isa<StmtExpr>(S)) ? origParentScope : independentParentScope); unsigned StmtsToSkip = 0u; switch (S->getStmtClass()) { case Stmt::IndirectGotoStmtClass: return false; case Stmt::SwitchStmtClass: if (const Stmt *Init = cast<SwitchStmt>(S)->getInit()) { if (!BuildScopeInformation(Init, ParentScope)) return false; ++StmtsToSkip; } if (const VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) { if (!BuildScopeInformation(Var, ParentScope)) return false; ++StmtsToSkip; } LLVM_FALLTHROUGH; case Stmt::GotoStmtClass: FromScopes.push_back({S, ParentScope}); break; case Stmt::DeclStmtClass: { const DeclStmt *DS = cast<DeclStmt>(S); for (auto *I : DS->decls()) if (!BuildScopeInformation(I, origParentScope)) return false; return true; } case Stmt::CaseStmtClass: case Stmt::DefaultStmtClass: case Stmt::LabelStmtClass: llvm_unreachable("the loop below handles labels and cases"); break; default: break; } for (const Stmt *SubStmt : S->children()) { if (!SubStmt) continue; if (StmtsToSkip) { --StmtsToSkip; continue; } // Cases, labels, and defaults aren't "scope parents". It's also // important to handle these iteratively instead of recursively in // order to avoid blowing out the stack. while (true) { const Stmt *Next; if (const SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt)) Next = SC->getSubStmt(); else if (const LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt)) Next = LS->getSubStmt(); else break; ToScopes[SubStmt] = ParentScope; SubStmt = Next; } // Recursively walk the AST. if (!BuildScopeInformation(SubStmt, ParentScope)) return false; } return true; } /// Checks each jump and stores each variable declaration they bypass. void VarBypassDetector::Detect() { for (const auto &S : FromScopes) { const Stmt *St = S.first; unsigned from = S.second; if (const GotoStmt *GS = dyn_cast<GotoStmt>(St)) { if (const LabelStmt *LS = GS->getLabel()->getStmt()) Detect(from, ToScopes[LS]); } else if (const SwitchStmt *SS = dyn_cast<SwitchStmt>(St)) { for (const SwitchCase *SC = SS->getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) { Detect(from, ToScopes[SC]); } } else { llvm_unreachable("goto or switch was expected"); } } } /// Checks the jump and stores each variable declaration it bypasses. void VarBypassDetector::Detect(unsigned From, unsigned To) { while (From != To) { if (From < To) { assert(Scopes[To].first < To); const auto &ScopeTo = Scopes[To]; To = ScopeTo.first; Bypasses.insert(ScopeTo.second); } else { assert(Scopes[From].first < From); From = Scopes[From].first; } } }
Upload File
Create Folder