Mercurial > hg > CbC > CbC_llvm
changeset 240:ca573705d418
merge
line wrap: on
line diff
--- a/clang/include/clang/AST/ASTContext.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/AST/ASTContext.h Fri Jul 28 20:50:09 2023 +0900 @@ -1105,6 +1105,9 @@ // Builtin Types. CanQualType VoidTy; +#ifndef noCbC + CanQualType __CodeTy; +#endif CanQualType BoolTy; CanQualType CharTy; CanQualType WCharTy; // [C++ 3.9.1p5].
--- a/clang/include/clang/AST/BuiltinTypes.def Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/AST/BuiltinTypes.def Fri Jul 28 20:50:09 2023 +0900 @@ -57,6 +57,10 @@ // void BUILTIN_TYPE(Void, VoidTy) +#ifndef noCbC +BUILTIN_TYPE(__Code, __CodeTy) +#endif + //===- Unsigned Types -----------------------------------------------------===// // 'bool' in C++, '_Bool' in C99
--- a/clang/include/clang/AST/CanonicalType.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/AST/CanonicalType.h Fri Jul 28 20:50:09 2023 +0900 @@ -282,6 +282,9 @@ LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isRealType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isArithmeticType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isVoidType) +#ifndef noCbC + LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, is__CodeType) +#endif LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isDerivedType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isScalarType) LLVM_CLANG_CANPROXY_SIMPLE_ACCESSOR(bool, isAggregateType)
--- a/clang/include/clang/AST/Type.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/AST/Type.h Fri Jul 28 20:50:09 2023 +0900 @@ -2138,6 +2138,10 @@ bool isFundamentalType() const; bool isCompoundType() const; +#ifndef noCbC + bool is__CodeType() const; // for CbC +#endif + // Type Predicates: Check to see if this type is structurally the specified // type, ignoring typedefs and qualifiers. bool isFunctionType() const; @@ -7178,9 +7182,21 @@ } inline bool Type::isVoidType() const { +#ifndef noCbC + if (dyn_cast<BuiltinType>(CanonicalType)) + return isSpecificBuiltinType(BuiltinType::Void) || isSpecificBuiltinType(BuiltinType::__Code); +#endif return isSpecificBuiltinType(BuiltinType::Void); } +#ifndef noCbC +inline bool Type::is__CodeType() const { + if (dyn_cast<BuiltinType>(CanonicalType)) + return isSpecificBuiltinType(BuiltinType::__Code); + return false; +} +#endif + inline bool Type::isHalfType() const { // FIXME: Should we allow complex __fp16? Probably not. return isSpecificBuiltinType(BuiltinType::Half); @@ -7266,8 +7282,14 @@ inline bool Type::isScalarType() const { if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) +#ifndef noCbC return BT->getKind() > BuiltinType::Void && - BT->getKind() <= BuiltinType::NullPtr; + BT->getKind() <= BuiltinType::NullPtr && + BT->getKind() != BuiltinType::__Code; +#else + return BT->getKind() > BuiltinType::Void && + BT->getKind() <= BuiltinType::NullPtr; +#endif if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) // Enums are scalar types, but only if they are defined. Incomplete enums // are not treated as scalar types.
--- a/clang/include/clang/Basic/LangOptions.def Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Basic/LangOptions.def Fri Jul 28 20:50:09 2023 +0900 @@ -412,6 +412,9 @@ BENIGN_LANGOPT(AllowEditorPlaceholders, 1, 0, "allow editor placeholders in source") +#ifndef noCbC +LANGOPT(HasCodeSegment , 1, 0, "CbC") +#endif ENUM_LANGOPT(ClangABICompat, ClangABI, 4, ClangABI::Latest, "version of Clang that we should attempt to be ABI-compatible "
--- a/clang/include/clang/Basic/Specifiers.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Basic/Specifiers.h Fri Jul 28 20:50:09 2023 +0900 @@ -91,6 +91,9 @@ TST_auto_type, // __auto_type extension TST_unknown_anytype, // __unknown_anytype extension TST_atomic, // C11 _Atomic +#ifndef noCbC + TST___code, +#endif #define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image types #include "clang/Basic/OpenCLImageTypes.def" TST_error // erroneous type
--- a/clang/include/clang/Basic/TokenKinds.def Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Basic/TokenKinds.def Fri Jul 28 20:50:09 2023 +0900 @@ -330,6 +330,11 @@ KEYWORD(__objc_yes , KEYALL) KEYWORD(__objc_no , KEYALL) +#ifndef noCbC // CbC Keywords. +KEYWORD(__code , KEYALL) +KEYWORD(_CbC_return , KEYALL) +KEYWORD(_CbC_environment , KEYALL) +#endif // C++ 2.11p1: Keywords. KEYWORD(asm , KEYCXX|KEYGNU)
--- a/clang/include/clang/Lex/Lexer.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Lex/Lexer.h Fri Jul 28 20:50:09 2023 +0900 @@ -201,6 +201,9 @@ private: /// Lex - Return the next token in the file. If this is the end of file, it /// return the tok::eof token. This implicitly involves the preprocessor. +#ifndef noCbC + bool Lex(Token &Result, bool ProtoParsing = false); +#else bool Lex(Token &Result); /// Called when the preprocessor is in 'dependency scanning lexing mode'. @@ -219,6 +222,7 @@ /// \returns the buffer pointer at the beginning of the token. const char *convertDependencyDirectiveToken( const dependency_directives_scan::Token &DDTok, Token &Result); +#endif public: /// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma. @@ -605,7 +609,11 @@ /// LexTokenInternal - Internal interface to lex a preprocessing token. Called /// by Lex. /// +#ifndef noCbC + bool LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine, bool ignoreInclude = false); +#else bool LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine); +#endif bool CheckUnicodeWhitespace(Token &Result, uint32_t C, const char *CurPtr);
--- a/clang/include/clang/Lex/Preprocessor.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Lex/Preprocessor.h Fri Jul 28 20:50:09 2023 +0900 @@ -2685,6 +2685,16 @@ static void processPathForFileMacro(SmallVectorImpl<char> &Path, const LangOptions &LangOpts, const TargetInfo &TI); +#ifndef noCbC + bool IncludeHeader(Token Tok, const char* Name); + Token ReadFromString(const char *src , SourceLocation Loc) ; + unsigned int SavedDepth; + Token SavedToken; + bool SavedTokenFlag; + void ClearCache(); + void RestoreTokens(Token *Toks, unsigned NumToks); + bool ProtoParsing = false; +#endif private: void emitMacroDeprecationWarning(const Token &Identifier) const;
--- a/clang/include/clang/Parse/Parser.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Parse/Parser.h Fri Jul 28 20:50:09 2023 +0900 @@ -2082,6 +2082,13 @@ /// A SmallVector of types. typedef SmallVector<ParsedType, 12> TypeVector; +#ifndef noCbC // for CbC + StmtVector* Stmtsp; + const char* curFuncName; + unsigned int UniqueId; + bool ProtoParsing = false; +#endif + StmtResult ParseStatement(SourceLocation *TrailingElseLoc = nullptr, ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt); @@ -2117,6 +2124,10 @@ StmtResult ParseDoStatement(); StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); StmtResult ParseGotoStatement(); +#ifndef noCbC + StmtResult ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts); + void CompileFromString(const char *str, StmtVector &CompoundStmts); +#endif StmtResult ParseContinueStatement(); StmtResult ParseBreakStatement(); StmtResult ParseReturnStatement(); @@ -2455,9 +2466,70 @@ void ParseStructDeclaration( ParsingDeclSpec &DS, llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback); +#ifndef noCbC + void CreateRetCS(IdentifierInfo* csName); + void Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS); + IdentifierInfo* CreateIdentifierInfo(const char* Name, SourceLocation Loc); + IdentifierInfo* CreateAnonIdentifierInfo(const char* Name, SourceLocation Loc); + Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name); + ExprResult LookupNameAndBuildExpr(IdentifierInfo *II = 0, bool IsAddressOfOperand = false); + ExprResult LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow); + StmtResult CreateSjForContinuationWithTheEnv(); + StmtResult CreateAssignmentStmt(IdentifierInfo* LHSII = 0, IdentifierInfo* RHSII = 0, bool LHSisM +mberAccess = false, + bool RHShasAmp = false, IdentifierInfo* extraLHSII = 0, Identifie +Info* extraRHSII = 0); + StmtResult CreateDeclStmt(IdentifierInfo *II = 0, bool isRetCS = false, bool copyType = false, in + array = 0, DeclSpec::TST valueType = DeclSpec::TST_int, IdentifierInfo* Name = 0, DeclSpec::TQ TQ + DeclSpec::TQ_unspecified); + IdentifierInfo* CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc); + ParmVarDecl* CreateParam(IdentifierInfo *II = 0, int pointerNum = 0, DeclSpec::TST T = DeclSpec::TST_int); + Decl* HandleDeclAndChangeDeclType(Declarator &D); + void setTST(DeclSpec *DS = 0, DeclSpec::TST T = DeclSpec::TST_int, IdentifierInfo *Name = 0, DeclSpec::TQ TQ = DeclSpec::TQ_unspecified); + void CheckTheSjHeader(); + ExprResult IIToExpr(IdentifierInfo *II, tok::TokenKind Kind); + ExprResult AnonToExpr(IdentifierInfo *II, tok::TokenKind Kind); + StmtResult CreateComplexStmtRet(IdentifierInfo *II, bool IsAddressOfOperand); + ExprResult Prepare__retForGotoWithTheEnvExpr(); + ExprResult Prepare__envForGotoWithTheEnvExpr(); + bool isVoidFunction(); + bool SearchCodeSegmentDeclaration(std::string Name); + void CreatePrototypeDeclaration(); + bool SkipAnyUntil(tok::TokenKind T, SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); + bool NeedPrototypeDeclaration(Token IITok); +#endif bool isDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, bool DisambiguatingWithExpression = false); +#ifndef noCbC + void CreateRetCS(IdentifierInfo* csName); + void Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS); + IdentifierInfo* CreateIdentifierInfo(const char* Name, SourceLocation Loc); + IdentifierInfo* CreateAnonIdentifierInfo(const char* Name, SourceLocation Loc); + Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name); + ExprResult LookupNameAndBuildExpr(IdentifierInfo *II = 0, bool IsAddressOfOperand = false); + ExprResult LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow); + StmtResult CreateSjForContinuationWithTheEnv(); + StmtResult CreateAssignmentStmt(IdentifierInfo* LHSII = 0, IdentifierInfo* RHSII = 0, bool LHSisMemberAccess = false, + bool RHShasAmp = false, IdentifierInfo* extraLHSII = 0, IdentifierInfo* extraRHSII = 0); + StmtResult CreateDeclStmt(IdentifierInfo *II = 0, bool isRetCS = false, bool copyType = false, int array = 0, DeclSpec::TST valueType = DeclSpec::TST_int, IdentifierInfo* Name = 0, DeclSpec::TQ TQ = DeclSpec::TQ_unspecified); + IdentifierInfo* CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc); + ParmVarDecl* CreateParam(IdentifierInfo *II = 0, int pointerNum = 0, DeclSpec::TST T = DeclSpec::TST_int); + Decl* HandleDeclAndChangeDeclType(Declarator &D); + void setTST(DeclSpec *DS = 0, DeclSpec::TST T = DeclSpec::TST_int, IdentifierInfo *Name = 0, DeclSpec::TQ TQ = DeclSpec::TQ_unspecified); + void CheckTheSjHeader(); + ExprResult IIToExpr(IdentifierInfo *II, tok::TokenKind Kind); + ExprResult AnonToExpr(IdentifierInfo *II, tok::TokenKind Kind); + StmtResult CreateComplexStmtRet(IdentifierInfo *II, bool IsAddressOfOperand); + ExprResult Prepare__retForGotoWithTheEnvExpr(); + ExprResult Prepare__envForGotoWithTheEnvExpr(); + bool isVoidFunction(); + bool SearchCodeSegmentDeclaration(std::string Name); + void CreatePrototypeDeclaration(); + bool SkipAnyUntil(tok::TokenKind T, SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); + bool NeedPrototypeDeclaration(Token IITok); +#endif + bool isTypeSpecifierQualifier(); /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
--- a/clang/include/clang/Sema/DeclSpec.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Sema/DeclSpec.h Fri Jul 28 20:50:09 2023 +0900 @@ -305,6 +305,10 @@ #include "clang/Basic/OpenCLImageTypes.def" static const TST TST_error = clang::TST_error; +#ifndef noCbC + static const TST TST___code = clang::TST___code; +#endif + // type-qualifiers enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ. TQ_unspecified = 0,
--- a/clang/include/clang/Serialization/ASTBitCodes.h Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/include/clang/Serialization/ASTBitCodes.h Fri Jul 28 20:50:09 2023 +0900 @@ -1076,6 +1076,10 @@ /// \brief The '__ibm128' type PREDEF_TYPE_IBM128_ID = 74, +#ifndef noCbC + /// \brief The __code type. + PREDEF_TYPE___CODE_ID = 81, +#endif /// OpenCL image types with auto numeration #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
--- a/clang/lib/AST/ASTContext.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/ASTContext.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1298,6 +1298,11 @@ // C99 6.2.5p19. InitBuiltinType(VoidTy, BuiltinType::Void); +#ifndef noCbC + // CbC + InitBuiltinType(__CodeTy, BuiltinType::__Code); +#endif + // C99 6.2.5p2. InitBuiltinType(BoolTy, BuiltinType::Bool); // C99 6.2.5p3. @@ -2075,6 +2080,9 @@ default: llvm_unreachable("Unknown builtin type!"); case BuiltinType::Void: // GCC extension: alignof(void) = 8 bits. +#ifndef noCbC + case BuiltinType::__Code: +#endif Width = 0; Align = 8; break; @@ -7985,6 +7993,9 @@ BuiltinType::Kind kind = BT->getKind(); switch (kind) { case BuiltinType::Void: return 'v'; +#ifndef noCbC + case BuiltinType::__Code: return 'v'; +#endif case BuiltinType::Bool: return 'B'; case BuiltinType::Char8: case BuiltinType::Char_U:
--- a/clang/lib/AST/ExprConstant.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/ExprConstant.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -11270,6 +11270,9 @@ case BuiltinType::ID: break; #include "clang/AST/BuiltinTypes.def" case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif return GCCTypeClass::Void; case BuiltinType::Bool:
--- a/clang/lib/AST/FormatString.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/FormatString.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -487,6 +487,9 @@ case BuiltinType::UChar: case BuiltinType::Char_S: case BuiltinType::SChar: +#ifndef noCbC + case BuiltinType::__Code: +#endif return Match; default: break;
--- a/clang/lib/AST/ItaniumMangle.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/ItaniumMangle.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -2938,6 +2938,9 @@ std::string type_name; switch (T->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif Out << 'v'; break; case BuiltinType::Bool:
--- a/clang/lib/AST/MicrosoftMangle.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/MicrosoftMangle.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -2337,6 +2337,9 @@ // ::= _Z # __float80 (Digital Mars) switch (T->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif Out << 'X'; break; case BuiltinType::SChar:
--- a/clang/lib/AST/NSAPI.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/NSAPI.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -422,6 +422,9 @@ return NSAPI::NSNumberWithBool; case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif case BuiltinType::WChar_U: case BuiltinType::WChar_S: case BuiltinType::Char8:
--- a/clang/lib/AST/Type.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/Type.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -2948,6 +2948,10 @@ switch (getKind()) { case Void: return "void"; +#ifndef noCbC + case __Code: + return "__code"; +#endif case Bool: return Policy.Bool ? "bool" : "_Bool"; case Char_S: @@ -4219,6 +4223,9 @@ return ResultIfUnknown; case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel:
--- a/clang/lib/AST/TypeLoc.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/AST/TypeLoc.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -334,6 +334,10 @@ switch (getTypePtr()->getKind()) { case BuiltinType::Void: return TST_void; +#ifndef noCbC + case BuiltinType::__Code: + return TST___code; +#endif case BuiltinType::Bool: return TST_bool; case BuiltinType::Char_U:
--- a/clang/lib/CodeGen/BackendUtil.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/BackendUtil.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -488,6 +488,10 @@ Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64; Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments; Options.MCOptions.ABIName = TargetOpts.ABI; +#ifndef noCbC + Options.HasCodeSegment = LangOpts.HasCodeSegment; + Options.GuaranteedTailCallOpt = LangOpts.HasCodeSegment; +#endif for (const auto &Entry : HSOpts.UserEntries) if (!Entry.IsFramework && (Entry.Group == frontend::IncludeDirGroup::Quoted ||
--- a/clang/lib/CodeGen/CGCall.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/CGCall.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -771,6 +771,13 @@ unsigned CC = ClangCallConvToLLVMCallConv(info.getCC()); +#ifndef noCbC + // if the function is a code segment , set fastcall calling convention. + if(resultType.getTypePtr()->is__CodeType()){ + CC = llvm::CallingConv::Fast; + } +#endif + // Construct the function info. We co-allocate the ArgInfos. FI = CGFunctionInfo::create(CC, instanceMethod, chainCall, info, paramInfos, resultType, argTypes, required); @@ -1644,7 +1651,14 @@ case ABIArgInfo::Indirect: case ABIArgInfo::Ignore: +#ifndef noCbC + if (FI.getReturnType().getTypePtr()->is__CodeType()) + resultType = llvm::Type::get__CodeTy(getLLVMContext()); + else + resultType = llvm::Type::getVoidTy(getLLVMContext()); +#else resultType = llvm::Type::getVoidTy(getLLVMContext()); +#endif break; case ABIArgInfo::CoerceAndExpand: @@ -1834,6 +1848,11 @@ FpKind = "all"; break; } +#ifndef noCbC + if (getLangOpts().HasCodeSegment) { + FpKind = "none"; + } +#endif FuncAttrs.addAttribute("frame-pointer", FpKind); if (CodeGenOpts.LessPreciseFPMAD) @@ -5225,6 +5244,12 @@ IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg; } +#ifndef noCbC +/* + terminates local variable pointer life time here. + cf. CodeGenFunction::PopCleanupBlock at clang/lib/CodeGen/CGCleanup.cpp +*/ +#endif // 2. Prepare the function pointer. // If the callee is a bitcast of a non-variadic function to have a @@ -5442,6 +5467,12 @@ Call->setTailCallKind(llvm::CallInst::TCK_NoTail); else if (IsMustTail) Call->setTailCallKind(llvm::CallInst::TCK_MustTail); +#ifndef noCbC + if (! CallInfo.isVariadic() && ! IsMustTail) { + if (this->FnRetTy.getTypePtr()->is__CodeType() && CallInfo.getReturnType().getTypePtr()->is__CodeType()) + Call->setTailCallKind(llvm::CallInst::TCK_Tail); + } +#endif } // Add metadata for calls to MSAllocator functions
--- a/clang/lib/CodeGen/CGCleanup.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/CGCleanup.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -584,6 +584,9 @@ } // Ask the cleanup to emit itself. +#ifndef noCbC + if (!CGF.FnRetTy.getTypePtr()->is__CodeType()) // in __code cleanup is done just before tail call (goto) +#endif Fn->Emit(CGF, flags); assert(CGF.HaveInsertPoint() && "cleanup ended with no insertion point?");
--- a/clang/lib/CodeGen/CGDebugInfo.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/CGDebugInfo.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -655,6 +655,9 @@ case BuiltinType::NullPtr: return DBuilder.createNullPtrType(); case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif return nullptr; case BuiltinType::ObjCClass: if (!ClassTy)
--- a/clang/lib/CodeGen/CodeGenTypes.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/CodeGenTypes.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -458,6 +458,9 @@ case Type::Builtin: { switch (cast<BuiltinType>(Ty)->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel:
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -3214,6 +3214,9 @@ // Types added here must also be added to EmitFundamentalRTTIDescriptors. switch (Ty->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif case BuiltinType::NullPtr: case BuiltinType::Bool: case BuiltinType::WChar_S:
--- a/clang/lib/CodeGen/TargetInfo.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/CodeGen/TargetInfo.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -2860,7 +2860,11 @@ if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) { BuiltinType::Kind k = BT->getKind(); - if (k == BuiltinType::Void) { +#ifndef noCbC + if (k == BuiltinType::Void || k == BuiltinType::__Code) { +#else + if (k == BuiltinType::Void) { +#endif Current = NoClass; } else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) { Lo = Integer;
--- a/clang/lib/Driver/Types.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Driver/Types.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -355,6 +355,9 @@ .Case("cppm", TY_CXXModule) .Case("cxxm", TY_CXXModule) .Case("hlsl", TY_HLSL) +#ifndef noCbC + .Case("cbc", TY_C) +#endif .Default(TY_INVALID); }
--- a/clang/lib/Frontend/CompilerInvocation.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Frontend/CompilerInvocation.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -2864,6 +2864,9 @@ .Case("objective-c++", Language::ObjCXX) .Case("renderscript", Language::RenderScript) .Case("hlsl", Language::HLSL) +#ifndef noCbC + .Case("cbc", Language::C) +#endif .Default(Language::Unknown); // "objc[++]-cpp-output" is an acceptable synonym for
--- a/clang/lib/Frontend/FrontendOptions.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Frontend/FrontendOptions.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -34,5 +34,8 @@ .Case("hip", Language::HIP) .Cases("ll", "bc", Language::LLVM_IR) .Case("hlsl", Language::HLSL) +#ifndef noCbC + .Case("cbc", Language::C) +#endif .Default(Language::Unknown); }
--- a/clang/lib/Index/USRGeneration.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Index/USRGeneration.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -661,6 +661,9 @@ unsigned char c = '\0'; switch (BT->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif c = 'v'; break; case BuiltinType::Bool: c = 'b'; break;
--- a/clang/lib/Lex/Lexer.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Lex/Lexer.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -50,6 +50,10 @@ using namespace clang; +#ifndef noCbC +#include <string.h> +#endif + //===----------------------------------------------------------------------===// // Token Class Implementation //===----------------------------------------------------------------------===//
--- a/clang/lib/Lex/PPDirectives.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Lex/PPDirectives.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -49,6 +49,9 @@ #include <new> #include <string> #include <utility> +#ifndef noCbC +#include <string> +#endif using namespace clang;
--- a/clang/lib/Lex/PPLexerChange.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Lex/PPLexerChange.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -505,6 +505,25 @@ FileType, ExitedFID, Loc); } +#ifndef noCbC + if (SavedTokenFlag && IncludeMacroStack.size() == SavedDepth){ // dead code? + Result = SavedToken; + SavedTokenFlag = false; + if (CurLexer->ParsingPreprocessorDirective) { + // Done parsing the "line". + CurLexer->ParsingPreprocessorDirective = false; + + // Restore comment saving mode, in case it was disabled for directive. + CurLexer->resetExtendedTokenMode(); + + // Since we consumed a newline, we are back at the start of a line. + CurLexer->IsAtStartOfLine = true; + CurLexer->IsAtPhysicalStartOfLine = true; + } + return true; + } +#endif + // Restore conditional stack as well as the recorded // \#pragma clang assume_nonnull from the preamble right after exiting // from the predefines file.
--- a/clang/lib/Lex/Preprocessor.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Lex/Preprocessor.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -154,6 +154,11 @@ !this->PPOpts->ImplicitPCHInclude.empty()) SkippingUntilPCHThroughHeader = true; +#ifndef noCbC + SavedDepth = 0; + SavedTokenFlag = false; +#endif + if (this->PPOpts->GeneratePreamble) PreambleConditionalStack.startRecording(); @@ -1476,3 +1481,31 @@ Record = new PreprocessingRecord(getSourceManager()); addPPCallbacks(std::unique_ptr<PPCallbacks>(Record)); } + +#ifndef noCbC + +Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) { + // Push the ( "string" ) tokens into the token stream. + MacroInfo *MI = AllocateMacroInfo(Loc); + Token Tok; + std::unique_ptr<Lexer> lx(new Lexer(CurLexer->getFileID(),getSourceManager().getBufferOrFake(CurLexer->getFileID(), Loc),*this)); + lx->InitLexer(src,src,src + strlen(src)); + lx->Lex(Tok); + CurLexer.swap(lx); + int i = 0; + while (Tok.getKind() != tok::TokenKind::eof) { + Tok.setLocation(Loc); + MI->AddTokenToBody(Tok); + Lex(Tok); i++; + } + Tok.setLocation(Loc); + MI->AddTokenToBody(Tok); i++; + MI->DefinitionLength = i; + CurLexer = std::move(lx); + CurPPLexer = CurLexer.get(); + EnterMacro(Tok, Loc, MI , 0 ); + CurTokenLexer->MacroDefLength = i; + return Tok; +} + +#endif
--- a/clang/lib/Parse/CMakeLists.txt Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/CMakeLists.txt Fri Jul 28 20:50:09 2023 +0900 @@ -21,6 +21,7 @@ ParseStmtAsm.cpp ParseTemplate.cpp ParseTentative.cpp + ParseCbC.cpp Parser.cpp LINK_LIBS
--- a/clang/lib/Parse/ParseDecl.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/ParseDecl.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -4055,6 +4055,15 @@ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID, Policy); break; +#ifndef noCbC + case tok::kw___code: { + LangOptions* LOP; + LOP = const_cast<LangOptions*>(&getLangOpts()); + LOP->HasCodeSegment = 1; + isInvalid = DS.SetTypeSpecType(DeclSpec::TST___code, Loc, PrevSpec, DiagID, Policy); + break; + } +#endif case tok::kw_char: isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID, Policy); @@ -5213,6 +5222,9 @@ case tok::kw__Complex: case tok::kw__Imaginary: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw_char: case tok::kw_wchar_t: case tok::kw_char8_t: @@ -5297,6 +5309,9 @@ case tok::kw__Complex: case tok::kw__Imaginary: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw_char: case tok::kw_wchar_t: case tok::kw_char8_t: @@ -5476,6 +5491,9 @@ case tok::kw__Complex: case tok::kw__Imaginary: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw_char: case tok::kw_wchar_t: case tok::kw_char8_t: @@ -7715,6 +7733,9 @@ case tok::kw_signed: case tok::kw_unsigned: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw_char: case tok::kw_int: case tok::kw_float: @@ -7751,6 +7772,9 @@ case tok::kw_signed: case tok::kw_unsigned: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw_char: case tok::kw_int: case tok::kw_float:
--- a/clang/lib/Parse/ParseExpr.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/ParseExpr.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1765,6 +1765,14 @@ goto ParseIdentifier; } goto ExpectedExpression; +#ifndef noCbC + case tok::kw__CbC_return: + Res = Prepare__retForGotoWithTheEnvExpr(); + break; + case tok::kw__CbC_environment: + Res = Prepare__envForGotoWithTheEnvExpr(); + break; +#endif case tok::l_square: if (getLangOpts().CPlusPlus11) { if (getLangOpts().ObjC) { @@ -3442,6 +3450,14 @@ if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); Expr = ParseBraceInitializer(); + } +#ifndef noCbC + else if (Tok.is(tok::kw__CbC_return)){ + Expr = Prepare__retForGotoWithTheEnvExpr(); + } + else if (Tok.is(tok::kw__CbC_environment)){ + Expr = Prepare__envForGotoWithTheEnvExpr(); +#endif } else Expr = ParseAssignmentExpression();
--- a/clang/lib/Parse/ParseStmt.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/ParseStmt.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -311,6 +311,16 @@ return ParseForStatement(TrailingElseLoc); case tok::kw_goto: // C99 6.8.6.1: goto-statement +#ifndef noCbC + { + Token Next = NextToken(); + if (!(Next.is(tok::identifier) && PP.LookAhead(1).is(tok::semi)) && // C: 'goto' identifier ';' + Next.isNot(tok::star)) { // C: 'goto' '*' expression ';' + SemiError = "goto code segment"; + return ParseCbCGotoStatement(Attrs, Stmts); // CbC: goto codesegment statement + } + } +#endif Res = ParseGotoStatement(); SemiError = "goto"; break;
--- a/clang/lib/Parse/ParseTentative.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/ParseTentative.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1669,6 +1669,9 @@ case tok::kw___float128: case tok::kw___ibm128: case tok::kw_void: +#ifndef noCbC + case tok::kw___code: +#endif case tok::annot_decltype: #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: #include "clang/Basic/OpenCLImageTypes.def" @@ -1788,6 +1791,9 @@ case tok::kw___ibm128: case tok::kw_void: case tok::kw___unknown_anytype: +#ifndef noCbC + case tok::kw___code: +#endif case tok::kw___auto_type: #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: #include "clang/Basic/OpenCLImageTypes.def"
--- a/clang/lib/Parse/Parser.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Parse/Parser.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -68,6 +68,9 @@ PP.addCommentHandler(CommentSemaHandler.get()); PP.setCodeCompletionHandler(*this); +#ifndef noCbC + UniqueId = 0; // for CreateUniqueIdentifier() +#endif } DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) { @@ -1435,6 +1438,12 @@ if (LateParsedAttrs) ParseLexedAttributeList(*LateParsedAttrs, Res, false, true); +#ifndef noCbC + curFuncName = "__cbc_"; + if (D.getIdentifier()) { + curFuncName = D.getIdentifier()->getName().data(); + } +#endif return ParseFunctionStatementBody(Res, BodyScope); }
--- a/clang/lib/Sema/DeclSpec.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Sema/DeclSpec.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -374,6 +374,9 @@ case TST_void: case TST_wchar: case TST_BFloat16: +#ifndef noCbC + case TST___code: +#endif #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t: #include "clang/Basic/OpenCLImageTypes.def" return false; @@ -593,6 +596,9 @@ return #ImgType "_t"; #include "clang/Basic/OpenCLImageTypes.def" case DeclSpec::TST_error: return "(error)"; +#ifndef noCbC + case DeclSpec::TST___code: return "__code"; +#endif } llvm_unreachable("Unknown typespec!"); }
--- a/clang/lib/Sema/SemaCodeComplete.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Sema/SemaCodeComplete.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -844,6 +844,9 @@ case Type::Builtin: switch (cast<BuiltinType>(T)->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif return STC_Void; case BuiltinType::NullPtr:
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -917,6 +917,9 @@ #include "clang/Basic/OpenCLImageTypes.def" case TST_unknown_anytype: case TST_error: +#ifndef noCbC + case TST___code: +#endif break; }
--- a/clang/lib/Sema/SemaType.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Sema/SemaType.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1284,6 +1284,11 @@ case DeclSpec::TST_void: Result = Context.VoidTy; break; +#ifndef noCbC + case DeclSpec::TST___code: + Result = Context.__CodeTy; + break; +#endif case DeclSpec::TST_char: if (DS.getTypeSpecSign() == TypeSpecifierSign::Unspecified) Result = Context.CharTy;
--- a/clang/lib/Serialization/ASTCommon.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Serialization/ASTCommon.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -259,6 +259,11 @@ case BuiltinType::OMPArraySection: ID = PREDEF_TYPE_OMP_ARRAY_SECTION; break; +#ifndef noCbC + case BuiltinType::__Code: + ID = PREDEF_TYPE___CODE_ID; + break; +#endif case BuiltinType::OMPArrayShaping: ID = PREDEF_TYPE_OMP_ARRAY_SHAPING; break;
--- a/clang/lib/Serialization/ASTReader.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/lib/Serialization/ASTReader.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -6852,6 +6852,11 @@ case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; +#ifndef noCbC + case PREDEF_TYPE___CODE_ID: + T = Context.__CodeTy; + break; +#endif case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break;
--- a/clang/tools/libclang/CIndex.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/clang/tools/libclang/CIndex.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1609,6 +1609,9 @@ switch (TL.getTypePtr()->getKind()) { case BuiltinType::Void: +#ifndef noCbC + case BuiltinType::__Code: +#endif case BuiltinType::NullPtr: case BuiltinType::Dependent: #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
--- a/llvm/include/llvm/CodeGen/TargetPassConfig.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/CodeGen/TargetPassConfig.h Fri Jul 28 20:50:09 2023 +0900 @@ -156,6 +156,9 @@ void setInitialized() { Initialized = true; } CodeGenOpt::Level getOptLevel() const; +#ifndef noCbC + unsigned hasCodeSegment(); +#endif /// Returns true if one of the `-start-after`, `-start-before`, `-stop-after` /// or `-stop-before` options is set.
--- a/llvm/include/llvm/IR/IRBuilder.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/IR/IRBuilder.h Fri Jul 28 20:50:09 2023 +0900 @@ -552,6 +552,11 @@ PointerType *getPtrTy(unsigned AddrSpace = 0) { return PointerType::get(Context, AddrSpace); } +#ifndef noCbC + Type *get__CodeTy() { + return Type::get__CodeTy(Context); + } +#endif /// Fetch the type representing a pointer to an 8-bit integer value. PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
--- a/llvm/include/llvm/IR/Type.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/IR/Type.h Fri Jul 28 20:50:09 2023 +0900 @@ -68,6 +68,9 @@ TokenTyID, ///< Tokens // Derived types... see DerivedTypes.h file. +#ifndef noCbC + __CodeTyID, ///< CbC Code Gear type +#endif IntegerTyID, ///< Arbitrary bit width integers FunctionTyID, ///< Functions PointerTyID, ///< Pointers @@ -135,8 +138,14 @@ /// elements defined above. TypeID getTypeID() const { return ID; } - /// Return true if this is 'void'. - bool isVoidTy() const { return getTypeID() == VoidTyID; } +#ifndef noCbC + bool isVoidTy() const { return (getTypeID() == VoidTyID || getTypeID() == __CodeTyID); } + /// is__CodeTy - Return true if this is '__code'. + bool is__CodeTy() const { return getTypeID() == __CodeTyID; } +#else + /// Return true if this is 'void'. + bool isVoidTy() const { return getTypeID() == VoidTyID; } +#endif /// Return true if this is 'half', a 16-bit IEEE fp type. bool isHalfTy() const { return getTypeID() == HalfTyID; } @@ -246,7 +255,11 @@ /// Return true if the type is "first class", meaning it is a valid type for a /// Value. bool isFirstClassType() const { - return getTypeID() != FunctionTyID && getTypeID() != VoidTyID; +#ifndef noCbC + return getTypeID() != FunctionTyID && getTypeID() != VoidTyID && getTypeID() != __CodeTyID; +#else + return getTypeID() != FunctionTyID && getTypeID() != VoidTyID; +#endif } /// Return true if the type is a valid type for a register in codegen. This @@ -431,6 +444,9 @@ static Type *getX86_MMXTy(LLVMContext &C); static Type *getX86_AMXTy(LLVMContext &C); static Type *getTokenTy(LLVMContext &C); +#ifndef noCbC + static Type *get__CodeTy(LLVMContext &C); // for CbC project +#endif static IntegerType *getIntNTy(LLVMContext &C, unsigned N); static IntegerType *getInt1Ty(LLVMContext &C); static IntegerType *getInt8Ty(LLVMContext &C);
--- a/llvm/include/llvm/LinkAllPasses.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/LinkAllPasses.h Fri Jul 28 20:50:09 2023 +0900 @@ -159,7 +159,11 @@ (void) llvm::createStripNonDebugSymbolsPass(); (void) llvm::createStripDeadDebugInfoPass(); (void) llvm::createStripDeadPrototypesPass(); +#ifndef noCbC + (void) llvm::createTailCallEliminationPass(false); +#else (void) llvm::createTailCallEliminationPass(); +#endif (void)llvm::createTLSVariableHoistPass(); (void) llvm::createJumpThreadingPass(); (void) llvm::createDFAJumpThreadingPass();
--- a/llvm/include/llvm/Target/TargetOptions.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/Target/TargetOptions.h Fri Jul 28 20:50:09 2023 +0900 @@ -397,6 +397,9 @@ /// via the llvm.fma.* intrinsic) will always be honored, regardless of /// the value of this option. FPOpFusion::FPOpFusionMode AllowFPOpFusion = FPOpFusion::Standard; +#ifndef noCbC + unsigned HasCodeSegment : 1; +#endif /// ThreadModel - This flag specifies the type of threading model to assume /// for things like atomics
--- a/llvm/include/llvm/Transforms/Scalar.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/include/llvm/Transforms/Scalar.h Fri Jul 28 20:50:09 2023 +0900 @@ -111,7 +111,11 @@ // // SROA - Replace aggregates or pieces of aggregates with scalar SSA values. // -FunctionPass *createSROAPass(); +#ifndef noCbC +FunctionPass *createSROAPass(bool isOnlyForCbC = false); +#else + FunctionPass *createSROAPass(); +#endif //===----------------------------------------------------------------------===// // @@ -283,7 +287,11 @@ // TailCallElimination - This pass eliminates call instructions to the current // function which occur immediately before return instructions. // -FunctionPass *createTailCallEliminationPass(); +#ifndef noCbC +FunctionPass *createTailCallEliminationPass(bool isOnlyForCbC); +#else + FunctionPass *createTailCallEliminationPass(); +#endif //===----------------------------------------------------------------------===// //
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -939,6 +939,9 @@ switch (T->getTypeID()) { case Type::VoidTyID: Code = bitc::TYPE_CODE_VOID; break; +#ifndef noCbC + case Type::__CodeTyID: Code = bitc::TYPE_CODE_VOID; break; +#endif case Type::HalfTyID: Code = bitc::TYPE_CODE_HALF; break; case Type::BFloatTyID: Code = bitc::TYPE_CODE_BFLOAT; break; case Type::FloatTyID: Code = bitc::TYPE_CODE_FLOAT; break;
--- a/llvm/lib/CodeGen/Analysis.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/CodeGen/Analysis.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -524,6 +524,11 @@ const Instruction *Term = ExitBB->getTerminator(); const ReturnInst *Ret = dyn_cast<ReturnInst>(Term); +#ifndef noCbC + if (Call.getType()->is__CodeTy()) + return true; +#endif + // The block must end in a return statement or unreachable. // // FIXME: Decline tailcall if it's not guaranteed and if the block ends in
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -7914,6 +7914,16 @@ .setIsPreallocated( CB.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0) .setCFIType(CFIType); +#ifndef noCbC + // if code segment's tail call flag was changed false , we report it on error. + if (RetTy->is__CodeTy() && !isTailCall ) { + if (CB.getCaller()->getReturnType()->is__CodeTy()) { + // LLVMContext &Ctx = *DAG.getContext(); + //- Ctx.emitError(&CB, "tail call failed on __code"); + errs() << "tail call failed on __code " + CB.getCaller()->getName() ; + } + } +#endif std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB); if (Result.first.getNode()) {
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1536,6 +1536,9 @@ // If the call was emitted as a tail call, we're done with the block. // We also need to delete any previously emitted instructions. if (HadTailCall) { +#ifndef noCbC + if (Fn.getReturnType()->is__CodeTy()) break; +#endif // noCbC FastIS->removeDeadCode(SavedInsertPt, FuncInfo->MBB->end()); --BI; break;
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -645,6 +645,12 @@ return TM->getOptLevel(); } +#ifndef noCbC +unsigned TargetPassConfig::hasCodeSegment() { + return TM->Options.HasCodeSegment; +} +#endif + /// Insert InsertedPassID pass after TargetPassID. void TargetPassConfig::insertPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID) { @@ -993,7 +999,9 @@ /// Add pass to prepare the LLVM IR for code generation. This should be done /// before exception handling preparation passes. void TargetPassConfig::addCodeGenPrepare() { +#ifdef noCbC if (getOptLevel() != CodeGenOpt::None && !DisableCGP) +#endif addPass(createCodeGenPreparePass()); }
--- a/llvm/lib/CodeGen/ValueTypes.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/CodeGen/ValueTypes.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -548,6 +548,9 @@ if (HandleUnknown) return MVT(MVT::Other); llvm_unreachable("Unknown type!"); case Type::VoidTyID: +#ifndef noCbC + case Type::__CodeTyID: +#endif return MVT::isVoid; case Type::IntegerTyID: return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -82,6 +82,9 @@ static char getTypeID(Type *Ty) { switch (Ty->getTypeID()) { case Type::VoidTyID: return 'V'; +#ifndef noCbC + case Type::__CodeTyID: return 'V'; +#endif case Type::IntegerTyID: switch (cast<IntegerType>(Ty)->getBitWidth()) { case 1: return 'o'; @@ -133,6 +136,9 @@ static ffi_type *ffiTypeFor(Type *Ty) { switch (Ty->getTypeID()) { case Type::VoidTyID: return &ffi_type_void; +#ifndef noCbC + case Type::__CodeTyID: return &ffi_type_void; +#endif case Type::IntegerTyID: switch (cast<IntegerType>(Ty)->getBitWidth()) { case 8: return &ffi_type_sint8; @@ -242,7 +248,11 @@ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, args.data()) == FFI_OK) { SmallVector<uint8_t, 128> ret; +#ifndef noCbC + if (RetTy->getTypeID() != Type::VoidTyID && RetTy->getTypeID() != Type::__CodeTyID) +#else if (RetTy->getTypeID() != Type::VoidTyID) +#endif ret.resize(TD.getTypeStoreSize(RetTy)); ffi_call(&cif, Fn, ret.data(), values.data()); switch (RetTy->getTypeID()) {
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -590,6 +590,9 @@ return rv; } case Type::VoidTyID: +#ifndef noCbC + case Type::__CodeTyID: +#endif rv.IntVal = APInt(32, ((int(*)())(intptr_t)FPtr)()); return rv; case Type::FloatTyID:
--- a/llvm/lib/IR/AsmWriter.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/IR/AsmWriter.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -537,6 +537,9 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) { switch (Ty->getTypeID()) { case Type::VoidTyID: OS << "void"; return; +#ifndef noCbC + case Type::__CodeTyID: OS << "void"; return; +#endif case Type::HalfTyID: OS << "half"; return; case Type::BFloatTyID: OS << "bfloat"; return; case Type::FloatTyID: OS << "float"; return;
--- a/llvm/lib/IR/Core.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/IR/Core.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -490,6 +490,9 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { switch (unwrap(Ty)->getTypeID()) { case Type::VoidTyID: +#ifndef noCbC + case Type::__CodeTyID: +#endif return LLVMVoidTypeKind; case Type::HalfTyID: return LLVMHalfTypeKind;
--- a/llvm/lib/IR/LLVMContextImpl.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/IR/LLVMContextImpl.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -45,7 +45,11 @@ MetadataTy(C, Type::MetadataTyID), TokenTy(C, Type::TokenTyID), X86_FP80Ty(C, Type::X86_FP80TyID), FP128Ty(C, Type::FP128TyID), PPC_FP128Ty(C, Type::PPC_FP128TyID), X86_MMXTy(C, Type::X86_MMXTyID), +#ifndef noCbC + X86_AMXTy(C, Type::X86_AMXTyID), __CodeTy(C, Type::__CodeTyID), Int1Ty(C, 1), Int8Ty(C, 8), +#else X86_AMXTy(C, Type::X86_AMXTyID), Int1Ty(C, 1), Int8Ty(C, 8), +#endif Int16Ty(C, 16), Int32Ty(C, 32), Int64Ty(C, 64), Int128Ty(C, 128) { if (OpaquePointersCL.getNumOccurrences()) { OpaquePointers = OpaquePointersCL;
--- a/llvm/lib/IR/LLVMContextImpl.h Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/IR/LLVMContextImpl.h Fri Jul 28 20:50:09 2023 +0900 @@ -1465,6 +1465,9 @@ Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy, TokenTy; Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy; +#ifndef noCbC + Type __CodeTy; +#endif IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; std::unique_ptr<ConstantTokenNone> TheNoneToken;
--- a/llvm/lib/IR/Type.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/IR/Type.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -49,6 +49,9 @@ case X86_MMXTyID : return getX86_MMXTy(C); case X86_AMXTyID : return getX86_AMXTy(C); case TokenTyID : return getTokenTy(C); +#ifndef noCbC + case __CodeTyID : return get__CodeTy(C); +#endif default: return nullptr; } @@ -232,6 +235,9 @@ Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; } Type *Type::getX86_MMXTy(LLVMContext &C) { return &C.pImpl->X86_MMXTy; } Type *Type::getX86_AMXTy(LLVMContext &C) { return &C.pImpl->X86_AMXTy; } +#ifndef noCbC +Type *Type::get__CodeTy(LLVMContext &C) { return &C.pImpl->__CodeTy; } +#endif IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; } IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -254,6 +254,13 @@ // Form SSA out of local memory accesses after breaking apart aggregates into // scalars. +#ifndef noCbC + FPM.addPass(SROAPass()); + FPM.addPass(TailCallElimPass()); +#else + if (Level.getSpeedupLevel() > 1) + FPM.addPass(TailCallElimPass()); +#endif FPM.addPass(SROAPass()); // Catch trivial redundancies @@ -667,6 +674,10 @@ // Perform PGO instrumentation. MPM.addPass(PGOInstrumentationGen(IsCS)); +#ifndef noCbC + FPM.addPass(TailCallElimPass()); +#endif + if (EnablePostPGOLoopRotation) { // Disable header duplication in loop rotation at -Oz. MPM.addPass(createModuleToFunctionPassAdaptor(
--- a/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -333,6 +333,9 @@ case Type::X86_AMXTyID: case Type::TokenTyID: case Type::TypedPointerTyID: +#ifndef noCbC + case Type::__CodeTyID: +#endif return 0; }
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -339,7 +339,11 @@ bool isABI = (STI.getSmVersion() >= 20); +#ifndef noCbC + if (Ty->getTypeID() == Type::VoidTyID || Ty->getTypeID() == Type::__CodeTyID) +#else if (Ty->getTypeID() == Type::VoidTyID) +#endif return; O << " (";
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1320,7 +1320,11 @@ std::stringstream O; O << "prototype_" << UniqueCallSite << " : .callprototype "; +#ifndef noCbC + if (retTy->getTypeID() == Type::VoidTyID || retTy->getTypeID() == Type::__CodeTyID) { +#else if (retTy->getTypeID() == Type::VoidTyID) { +#endif O << "()"; } else { O << "(";
--- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -1877,7 +1877,11 @@ const AddrMode &AM, Type *Ty, unsigned AS, Instruction *I) const { +#ifndef noCbC + if (Ty->getTypeID() == Type::VoidTyID || Ty->getTypeID() == Type::__CodeTyID) +#else if (Ty->getTypeID() == Type::VoidTyID) +#endif return AM.Scale == 0 && isImmUs(AM.BaseOffs) && isImmUs4(AM.BaseOffs); unsigned Size = DL.getTypeAllocSize(Ty);
--- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -290,7 +290,13 @@ if (EnableMatrix && OptLevel == 0) FPM.add(createLowerMatrixIntrinsicsMinimalPass()); +#ifndef noCbC + if (OptLevel == 0) { + FPM.add(createSROAPass(true)); + } +#else if (OptLevel == 0) return; +#endif addInitialAliasAnalysisPasses(FPM); @@ -298,7 +304,11 @@ // Compare/branch metadata may alter the behavior of passes like SimplifyCFG. FPM.add(createLowerExpectIntrinsicPass()); FPM.add(createCFGSimplificationPass()); +#ifndef noCbC + FPM.add(createSROAPass(false)); +#else FPM.add(createSROAPass()); +#endif FPM.add(createEarlyCSEPass()); } @@ -307,7 +317,11 @@ // Start of function pass. // Break up aggregate allocas, using SSAUpdater. assert(OptLevel >= 1 && "Calling function optimizer with no optimization level!"); +#ifndef noCbC + MPM.add(createSROAPass(false)); +#else MPM.add(createSROAPass()); +#endif MPM.add(createEarlyCSEPass(true /* Enable mem-ssa. */)); // Catch trivial redundancies if (EnableKnowledgeRetention) MPM.add(createAssumeSimplifyPass()); @@ -344,11 +358,15 @@ addExtensionsToPM(EP_Peephole, MPM); // TODO: Investigate the cost/benefit of tail call elimination on debugging. +#ifndef noCbC + MPM.add(createTailCallEliminationPass(false)); // CbC +#else if (OptLevel > 1) MPM.add(createTailCallEliminationPass()); // Eliminate tail calls MPM.add( createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp( true))); // Merge & remove BBs +#endif MPM.add(createReassociatePass()); // Reassociate expressions // The matrix extension can introduce large vector operations early, which can @@ -598,6 +616,10 @@ else if (GlobalExtensionsNotEmpty() || !Extensions.empty()) MPM.add(createBarrierNoopPass()); +#ifndef noCbC + MPM.add(createTailCallEliminationPass(true)); // Eliminate tail calls +#endif + addExtensionsToPM(EP_EnabledOnOptLevel0, MPM); MPM.add(createAnnotationRemarksLegacyPass());
--- a/llvm/lib/Transforms/Scalar/SROA.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Transforms/Scalar/SROA.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -4807,6 +4807,13 @@ initializeSROALegacyPassPass(*PassRegistry::getPassRegistry()); } +#ifndef noCbC + SROALegacyPass(bool forCbC) : FunctionPass(ID) { + onlyForCbC = forCbC; + initializeSROALegacyPassPass(*PassRegistry::getPassRegistry()); + } +#endif + bool runOnFunction(Function &F) override { if (skipFunction(F)) return false; @@ -4824,12 +4831,21 @@ AU.setPreservesCFG(); } +#ifndef noCbC + bool onlyForCbC; + bool isOnlyForCbC() { return onlyForCbC; } +#endif + StringRef getPassName() const override { return "SROA"; } }; char SROALegacyPass::ID = 0; +#ifndef noCbC +FunctionPass *llvm::createSROAPass(bool forCbC) { return new SROALegacyPass(forCbC); } +#else FunctionPass *llvm::createSROAPass() { return new SROALegacyPass(); } +#endif INITIALIZE_PASS_BEGIN(SROALegacyPass, "sroa", "Scalar Replacement Of Aggregates", false, false)
--- a/llvm/lib/Transforms/Scalar/Scalar.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -247,7 +247,11 @@ } void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) { +#ifndef noCbC + unwrap(PM)->add(createTailCallEliminationPass(false)); +#else unwrap(PM)->add(createTailCallEliminationPass()); +#endif } void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
--- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -186,6 +186,28 @@ }; } +#ifndef noCbC +static bool markTailToCodeSegments(Function &F){ + bool Modified = false; + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { + for (auto &I : *BB) { + CallInst *CI = dyn_cast<CallInst>(&I); + Function* Called; + if (CI) + Called = CI->getCalledFunction(); + else + continue; + // We should touch only code segment call. + if (Called && Called->getReturnType()->is__CodeTy()) { + CI->setTailCall(); + Modified = true; + } + } + } + return Modified; +} +#endif + static bool markTails(Function &F, OptimizationRemarkEmitter *ORE) { if (F.callsFunctionThatReturnsTwice()) return false; @@ -204,6 +226,11 @@ bool Modified = false; +#ifndef noCbC + if (F.getReturnType()->is__CodeTy()) + Modified = markTailToCodeSegments(F); +#endif + // Track whether a block is reachable after an alloca has escaped. Blocks that // contain the escaping instruction will be marked as being visited without an // escaped alloca, since that is how the block began. @@ -875,6 +902,13 @@ initializeTailCallElimPass(*PassRegistry::getPassRegistry()); } +#ifndef noCbC + TailCallElim(bool f) : FunctionPass(ID) { + initializeTailCallElimPass(*PassRegistry::getPassRegistry()); + onlyForCbC = f; + } +#endif + void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<TargetTransformInfoWrapperPass>(); AU.addRequired<AAResultsWrapperPass>(); @@ -902,6 +936,12 @@ &getAnalysis<AAResultsWrapperPass>().getAAResults(), &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(), DTU); } +#ifndef noCbC + private: + bool onlyForCbC; + public: + bool isOnlyForCbC(); +#endif }; } @@ -913,10 +953,16 @@ INITIALIZE_PASS_END(TailCallElim, "tailcallelim", "Tail Call Elimination", false, false) +#ifndef noCbC // Public interface to the TailCallElimination pass +FunctionPass *llvm::createTailCallEliminationPass(bool isOnlyForCbC) { + return new TailCallElim(isOnlyForCbC); +} +#else FunctionPass *llvm::createTailCallEliminationPass() { return new TailCallElim(); } +#endif PreservedAnalyses TailCallElimPass::run(Function &F, FunctionAnalysisManager &AM) { @@ -939,3 +985,9 @@ PA.preserve<PostDominatorTreeAnalysis>(); return PA; } + +#ifndef noCbC +bool TailCallElim::isOnlyForCbC(){ + return onlyForCbC; +} +#endif
--- a/llvm/lib/Transforms/Utils/FunctionComparator.cpp Wed Nov 09 18:03:41 2022 +0900 +++ b/llvm/lib/Transforms/Utils/FunctionComparator.cpp Fri Jul 28 20:50:09 2023 +0900 @@ -459,6 +459,9 @@ case Type::LabelTyID: case Type::MetadataTyID: case Type::TokenTyID: +#ifndef noCbC + case Type::__CodeTyID: +#endif return 0; case Type::PointerTyID: