changeset 244:861b2bbafe0a before_aarch_setjmp

fix ParseCbC
author matac
date Fri, 11 Aug 2023 17:38:36 +0900
parents a916df8444bf
children b3a488e1e1b4
files clang/lib/Parse/ParseCbC.cpp llvm/lib/Passes/PassBuilderPipelines.cpp
diffstat 2 files changed, 28 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/clang/lib/Parse/ParseCbC.cpp	Fri Aug 11 15:57:02 2023 +0900
+++ b/clang/lib/Parse/ParseCbC.cpp	Fri Aug 11 17:38:36 2023 +0900
@@ -288,7 +288,7 @@
   ParsedType CastTy;
   DeclSpec void_DS(AttrFactory);
   setTST(&void_DS, DeclSpec::TST_void);
-  Declarator DeclaratorInfo(void_DS, DeclaratorContext::TypeName);
+  Declarator DeclaratorInfo(void_DS, ParsedAttributesView::none(), DeclaratorContext::TypeName);
   DeclSpec star_DS(AttrFactory);
   star_DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy());
   DeclaratorInfo.ExtendWithDeclSpec(star_DS);
@@ -366,7 +366,9 @@
   DSp = &DS;
 
   setTST(&DS, valueType, Name, TQ);
-  ParsingDeclarator D(*this, DS, static_cast<DeclaratorContext>(DeclaratorContext::Block));
+  ParsedAttributes LocalAttrs(AttrFactory);
+  // LocalAttrs.takeAllFrom(Attrs);
+  ParsingDeclarator D(*this, DS, LocalAttrs, static_cast<DeclaratorContext>(DeclaratorContext::Block));
   D.SetIdentifier(II, Loc);
     
   if (array) {
@@ -549,7 +551,7 @@
   InnerScope.Exit();
   IfScope.Exit();
   StmtResult ElseStmt;
-  IfRes = Actions.ActOnIfStmt(Loc, false, Loc, CondExp.get(), Cond, Loc, ThenStmt.get(),Loc, ElseStmt.get());
+  IfRes = Actions.ActOnIfStmt(Loc, IfStatementKind::Ordinary, Loc, CondExp.get(), Cond, Loc, ThenStmt.get(),Loc, ElseStmt.get());
   return IfRes;
 }
 
@@ -609,7 +611,7 @@
   DeclResult TagOrTempResult = true;
   bool Owned = false;
   bool IsDependent = false;
-  ParsedAttributesWithRange attrs(AttrFactory);
+  ParsedAttributes attrs(AttrFactory);
   MultiTemplateParamsArg TParams;
       
   TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, Sema::TUK_Definition, Loc,
@@ -641,7 +643,9 @@
   ParsingDeclSpec PDS(*this);
   setTST(&PDS, T);
   SourceLocation CommaLoc;
-  ParsingFieldDeclarator DeclaratorInfo(*this, PDS);
+  ParsedAttributes LocalAttrs(AttrFactory);
+  // LocalAttrs.takeAllFrom(Attrs);
+  ParsingFieldDeclarator DeclaratorInfo(*this, PDS, LocalAttrs);
   DeclaratorInfo.D.setCommaLoc(CommaLoc);
   DeclaratorInfo.D.SetRangeEnd(Loc);
   DeclSpec DS(AttrFactory);
@@ -717,7 +721,9 @@
   SourceLocation Loc = Tok.getLocation();
   ParsingDeclSpec PDS(*this);
   setTST(&PDS, DeclSpec::TST___code);
-  ParsingDeclarator D(*this, PDS, static_cast<DeclaratorContext>(DeclaratorContext::File));
+  ParsedAttributes LocalAttrs(AttrFactory);
+  // LocalAttrs.takeAllFrom(Attrs);
+  ParsingDeclarator D(*this, PDS, LocalAttrs, static_cast<DeclaratorContext>(DeclaratorContext::File));
   D.SetIdentifier(csName, Loc);
   ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope);
   bool IsAmbiguous = false;
@@ -776,7 +782,7 @@
   IdentifierInfo *structName = CreateIdentifierInfo(__CBC_STRUCT_NAME, Loc);
   setTST(&envDS, DeclSpec::TST_struct, structName);
 
-  Declarator envDInfo(envDS, DeclaratorContext::TypeName);
+  Declarator envDInfo(envDS, ParsedAttributesView::none(), DeclaratorContext::TypeName);
   envDInfo.SetRangeEnd(Loc);
   DeclSpec starDS(AttrFactory);
   starDS.Finish(Actions, Policy);
@@ -823,7 +829,7 @@
   DeclSpec ljDS(AttrFactory);
   setTST(&ljDS, DeclSpec::TST_struct, structName);
 
-  Declarator ljD(ljDS, DeclaratorContext::TypeName);
+  Declarator ljD(ljDS, ParsedAttributesView::none(), DeclaratorContext::TypeName);
   ljD.SetRangeEnd(Loc);
   DeclSpec starDS2(AttrFactory);
   starDS2.Finish(Actions, Policy);
@@ -920,7 +926,7 @@
   SourceLocation Loc = Tok.getLocation();
   DeclSpec DS(AttrFactory);
   setTST(&DS, T);
-  Declarator ParamDeclarator(DS, DeclaratorContext::Prototype);
+  Declarator ParamDeclarator(DS, ParsedAttributesView::none(), DeclaratorContext::Prototype);
   ParamDeclarator.SetIdentifier(II, Loc);
   for(int i = 0;i<pointerNum; i++){
     DeclSpec pointerDS(AttrFactory);
@@ -955,7 +961,7 @@
   }
 
   if (T == DeclSpec::TST_struct) {
-    ParsedAttributesWithRange attrs(AttrFactory);
+    ParsedAttributes attrs(AttrFactory);
     DeclResult TagOrTempResult = true;
     bool Owned = false;
     bool IsDependent = false;
@@ -1023,7 +1029,7 @@
 ///       jump-statement:
 /// [CbC]   'goto' codeSegment ';'
 ///
-StmtResult Parser::ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts) {
+StmtResult Parser::ParseCbCGotoStatement(ParsedAttributes &Attrs,StmtVector &Stmts) {
   assert(Tok.is(tok::kw_goto) && "Not a goto stmt!");
   StmtVector CompoundedStmts;
 
@@ -1075,74 +1081,6 @@
   return false;
 }
 
-bool Parser::NeedPrototypeDeclaration(Token IITok){
-#if 0
-  // if we allo unprototyped code segment
-  LookupResult LR(Actions, IITok.getIdentifierInfo(), IITok.getLocation(), Actions.LookupOrdinaryName);
-  CXXScopeSpec SS;
-  Actions.LookupParsedName(LR, getCurScope(), &SS, !(Actions.getCurMethodDecl()));
-
-  return (LR.getResultKind() == LookupResult::NotFound);
-#endif
-  return false;
-}
-
-/// CreatePrototypeDeclaration - Create prototype declaration by it's definition.
-void Parser::CreatePrototypeDeclaration(){
-  // move to the top level scope
-  Scope *SavedScope = getCurScope();
-  DeclContext *SavedContext = Actions.CurContext;
-  sema::FunctionScopeInfo *SavedFSI = Actions.FunctionScopes.pop_back_val();
-  Actions.CurContext = static_cast<DeclContext *>(Actions.Context.getTranslationUnitDecl());
-  Scope *TopScope = getCurScope();
-  while(TopScope->getParent() != NULL)
-    TopScope = TopScope->getParent();
-  Actions.CurScope = TopScope;
-  
-  Token Next = NextToken();
-  Token CachedTokens[3] = {Next, PP.LookAhead(1)};
-  Token SavedToken = Tok;
-  Token IITok = Tok.is(tok::identifier) ? Tok : Next;
-  PP.ClearCache();
-  PP.ProtoParsing = true;
-  ProtoParsing = true;
-  
-  const DirectoryLookup *CurDir = nullptr;
-  FileID FID = PP.getSourceManager().createFileID(PP.getCurrentFileLexer()->getFileEntry(), IITok.getLocation(), SrcMgr::C_User);
-  PP.EnterSourceFile(FID,CurDir,IITok.getLocation());
-  ConsumeToken();
-
-  if(SearchCodeSegmentDeclaration(IITok.getIdentifierInfo()->getName().str())){
-    DeclGroupPtrTy ProtoDecl;
-    ParseTopLevelDecl(ProtoDecl);
-    // add declaration to AST.
-    if(ProtoDecl)
-      (&Actions.getASTConsumer())->HandleTopLevelDecl(ProtoDecl.get());
-    // File Closing
-    Token T;
-    PP.HandleEndOfFile(T, false);
-
-    // recover tokens.
-    Tok = SavedToken;
-    PP.RestoreTokens(CachedTokens, 2);
-    
-  }
-  else {
-    // recover tokens.
-    CachedTokens[2] = Tok;
-    Tok = SavedToken;
-    PP.RestoreTokens(CachedTokens, 3);
-  }
-
-  // move to the previous scope.
-  Actions.CurScope = SavedScope;
-  Actions.CurContext = SavedContext;
-  Actions.FunctionScopes.push_back(SavedFSI);
-  
-  ProtoParsing = false;
-  PP.ProtoParsing = false;
-}
-
 static bool HasFlagsSet(Parser::SkipUntilFlags L, Parser::SkipUntilFlags R) {
   return (static_cast<unsigned>(L) & static_cast<unsigned>(R)) != 0;
 }
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp	Fri Aug 11 15:57:02 2023 +0900
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp	Fri Aug 11 17:38:36 2023 +0900
@@ -675,7 +675,18 @@
   MPM.addPass(PGOInstrumentationGen(IsCS));
 
 #ifndef noCbC
+  FunctionPassManager FPM;
+  FPM.addPass(SROAPass());
+  FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
+  FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
+      true)));                    // Merge & remove basic blocks.
+  FPM.addPass(InstCombinePass()); // Combine silly sequences.
   FPM.addPass(TailCallElimPass());
+  invokePeepholeEPCallbacks(FPM, Level);
+
+  // Add the core optimizing pipeline.
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM),
+                                                PTO.EagerlyInvalidateAnalyses));
 #endif
 
   if (EnablePostPGOLoopRotation) {