From 2e1263b37e287feddcfd84abca92b530e370589d Mon Sep 17 00:00:00 2001 From: akashk4 <akashk4@illinois.edu> Date: Wed, 8 Jan 2020 04:29:04 -0600 Subject: [PATCH] Updated LLParser header for LLVM-9 --- hpvm/llvm_patches/lib/AsmParser/LLParser.h | 220 +++++++++++++++------ 1 file changed, 161 insertions(+), 59 deletions(-) diff --git a/hpvm/llvm_patches/lib/AsmParser/LLParser.h b/hpvm/llvm_patches/lib/AsmParser/LLParser.h index 16d4e8b5ba..610e2e2620 100644 --- a/hpvm/llvm_patches/lib/AsmParser/LLParser.h +++ b/hpvm/llvm_patches/lib/AsmParser/LLParser.h @@ -1,9 +1,8 @@ //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -20,6 +19,7 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Operator.h" #include "llvm/IR/Type.h" #include "llvm/IR/ValueHandle.h" @@ -90,7 +90,10 @@ namespace llvm { private: LLVMContext &Context; LLLexer Lex; + // Module being parsed, null if we are only parsing summary index. Module *M; + // Summary index being parsed, null if we are only parsing Module. + ModuleSummaryIndex *Index; SlotMapping *Slots; // Instruction metadata resolution. Each instruction can have a list of @@ -139,11 +142,40 @@ namespace llvm { std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups; std::map<unsigned, AttrBuilder> NumberedAttrBuilders; + // Summary global value reference information. + std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>> + ForwardRefValueInfos; + std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>> + ForwardRefAliasees; + std::vector<ValueInfo> NumberedValueInfos; + + // Summary type id reference information. + std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>> + ForwardRefTypeIds; + + // Map of module ID to path. + std::map<unsigned, StringRef> ModuleIdMap; + + /// Only the llvm-as tool may set this to false to bypass + /// UpgradeDebuginfo so it can generate broken bitcode. + bool UpgradeDebugInfo; + + /// DataLayout string to override that in LLVM assembly. + StringRef DataLayoutStr; + + std::string SourceFileName; + public: LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, - SlotMapping *Slots = nullptr) - : Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M), - Slots(Slots), BlockAddressPFS(nullptr) {} + ModuleSummaryIndex *Index, LLVMContext &Context, + SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true, + StringRef DataLayoutString = "") + : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index), + Slots(Slots), BlockAddressPFS(nullptr), + UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) { + if (!DataLayoutStr.empty()) + M->setDataLayout(DataLayoutStr); + } bool Run(); bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots); @@ -169,12 +201,13 @@ namespace llvm { /// GetGlobalVal - Get a value with the specified name or ID, creating a /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. - GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc); - GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc); + GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc, + bool IsCall); + GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); /// Get a Comdat with the specified name, creating a forward reference /// record if needed. - Comdat *getComdat(const std::string &N, LocTy Loc); + Comdat *getComdat(const std::string &Name, LocTy Loc); // Helper Routines. bool ParseToken(lltok::Kind T, const char *ErrMsg); @@ -188,11 +221,17 @@ namespace llvm { FastMathFlags FMF; while (true) switch (Lex.getKind()) { - case lltok::kw_fast: FMF.setUnsafeAlgebra(); Lex.Lex(); continue; + case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue; case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue; case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue; case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue; case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue; + case lltok::kw_contract: + FMF.setAllowContract(true); + Lex.Lex(); + continue; + case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue; + case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue; default: return FMF; } return FMF; @@ -221,29 +260,39 @@ namespace llvm { Loc = Lex.getLoc(); return ParseUInt64(Val); } + bool ParseFlag(unsigned &Val); bool ParseStringAttribute(AttrBuilder &B); bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM); bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM); bool ParseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr); - bool ParseOptionalAddrSpace(unsigned &AddrSpace); + bool ParseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0); + bool ParseOptionalProgramAddrSpace(unsigned &AddrSpace) { + return ParseOptionalAddrSpace( + AddrSpace, M->getDataLayout().getProgramAddressSpace()); + }; bool ParseOptionalParamAttrs(AttrBuilder &B); bool ParseOptionalReturnAttrs(AttrBuilder &B); - bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage, - unsigned &Visibility, unsigned &DLLStorageClass); - void ParseOptionalVisibility(unsigned &Visibility); - void ParseOptionalDLLStorageClass(unsigned &DLLStorageClass); + bool ParseOptionalLinkage(unsigned &Res, bool &HasLinkage, + unsigned &Visibility, unsigned &DLLStorageClass, + bool &DSOLocal); + void ParseOptionalDSOLocal(bool &DSOLocal); + void ParseOptionalVisibility(unsigned &Res); + void ParseOptionalDLLStorageClass(unsigned &Res); bool ParseOptionalCallingConv(unsigned &CC); bool ParseOptionalAlignment(unsigned &Alignment); bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes); - bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, + bool ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID, AtomicOrdering &Ordering); + bool ParseScope(SyncScope::ID &SSID); bool ParseOrdering(AtomicOrdering &Ordering); bool ParseOptionalStackAlignment(unsigned &Alignment); bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); + bool ParseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc, + bool &AteExtraComma); bool ParseOptionalCommaInAlloca(bool &IsInAlloca); - bool parseAllocSizeArguments(unsigned &ElemSizeArg, + bool parseAllocSizeArguments(unsigned &BaseSizeArg, Optional<unsigned> &HowManyArg); bool ParseIndexList(SmallVectorImpl<unsigned> &Indices, bool &AteExtraComma); @@ -258,6 +307,7 @@ namespace llvm { // Top-Level Entities bool ParseTopLevelEntities(); bool ValidateEndOfModule(); + bool ValidateEndOfIndex(); bool ParseTargetDefinition(); bool ParseModuleAsm(); bool ParseSourceFileName(); @@ -270,14 +320,14 @@ namespace llvm { bool ParseGlobalType(bool &IsConstant); bool ParseUnnamedGlobal(); bool ParseNamedGlobal(); - bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, + bool ParseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage, bool HasLinkage, unsigned Visibility, - unsigned DLLStorageClass, + unsigned DLLStorageClass, bool DSOLocal, GlobalVariable::ThreadLocalMode TLM, GlobalVariable::UnnamedAddr UnnamedAddr); - bool parseIndirectSymbol(const std::string &Name, LocTy Loc, - unsigned Linkage, unsigned Visibility, - unsigned DLLStorageClass, + bool parseIndirectSymbol(const std::string &Name, LocTy NameLoc, + unsigned L, unsigned Visibility, + unsigned DLLStorageClass, bool DSOLocal, GlobalVariable::ThreadLocalMode TLM, GlobalVariable::UnnamedAddr UnnamedAddr); bool parseComdat(); @@ -289,6 +339,52 @@ namespace llvm { bool ParseFnAttributeValuePairs(AttrBuilder &B, std::vector<unsigned> &FwdRefAttrGrps, bool inAttrGrp, LocTy &BuiltinLoc); + bool ParseByValWithOptionalType(Type *&Result); + + // Module Summary Index Parsing. + bool SkipModuleSummaryEntry(); + bool ParseSummaryEntry(); + bool ParseModuleEntry(unsigned ID); + bool ParseModuleReference(StringRef &ModulePath); + bool ParseGVReference(ValueInfo &VI, unsigned &GVId); + bool ParseGVEntry(unsigned ID); + bool ParseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID); + bool ParseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID); + bool ParseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID); + bool ParseGVFlags(GlobalValueSummary::GVFlags &GVFlags); + bool ParseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags); + bool ParseOptionalFFlags(FunctionSummary::FFlags &FFlags); + bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls); + bool ParseHotness(CalleeInfo::HotnessType &Hotness); + bool ParseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo); + bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests); + bool ParseVFuncIdList(lltok::Kind Kind, + std::vector<FunctionSummary::VFuncId> &VFuncIdList); + bool ParseConstVCallList( + lltok::Kind Kind, + std::vector<FunctionSummary::ConstVCall> &ConstVCallList); + using IdToIndexMapType = + std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>; + bool ParseConstVCall(FunctionSummary::ConstVCall &ConstVCall, + IdToIndexMapType &IdToIndexMap, unsigned Index); + bool ParseVFuncId(FunctionSummary::VFuncId &VFuncId, + IdToIndexMapType &IdToIndexMap, unsigned Index); + bool ParseOptionalVTableFuncs(VTableFuncList &VTableFuncs); + bool ParseOptionalRefs(std::vector<ValueInfo> &Refs); + bool ParseTypeIdEntry(unsigned ID); + bool ParseTypeIdSummary(TypeIdSummary &TIS); + bool ParseTypeIdCompatibleVtableEntry(unsigned ID); + bool ParseTypeTestResolution(TypeTestResolution &TTRes); + bool ParseOptionalWpdResolutions( + std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap); + bool ParseWpdRes(WholeProgramDevirtResolution &WPDRes); + bool ParseOptionalResByArg( + std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> + &ResByArg); + bool ParseArgs(std::vector<uint64_t> &Args); + void AddGlobalValueToIndex(std::string Name, GlobalValue::GUID, + GlobalValue::LinkageTypes Linkage, unsigned ID, + std::unique_ptr<GlobalValueSummary> Summary); // Type Parsing. bool ParseType(Type *&Result, const Twine &Msg, bool AllowVoid = false); @@ -325,7 +421,7 @@ namespace llvm { /// number of it, otherwise it is -1. int FunctionNumber; public: - PerFunctionState(LLParser &p, Function &f, int FunctionNumber); + PerFunctionState(LLParser &p, Function &f, int functionNumber); ~PerFunctionState(); Function &getFunction() const { return F; } @@ -335,8 +431,8 @@ namespace llvm { /// GetVal - Get a value with the specified name or ID, creating a /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. - Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc); - Value *GetVal(unsigned ID, Type *Ty, LocTy Loc); + Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc, bool IsCall); + Value *GetVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); /// SetInstName - After an instruction is parsed and inserted into its /// basic block, this installs its name. @@ -352,13 +448,16 @@ namespace llvm { /// DefineBB - Define the specified basic block, which is either named or /// unnamed. If there is an error, this returns null otherwise it returns /// the block being defined. - BasicBlock *DefineBB(const std::string &Name, LocTy Loc); + BasicBlock *DefineBB(const std::string &Name, int NameID, LocTy Loc); bool resolveForwardRefBlockAddresses(); }; bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V, - PerFunctionState *PFS); + PerFunctionState *PFS, bool IsCall); + + Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, + Value *Val, bool IsCall); bool parseConstantValue(Type *Ty, Constant *&C); bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS); @@ -393,7 +492,7 @@ namespace llvm { Value *V; AttributeSet Attrs; ParamInfo(LocTy loc, Value *v, AttributeSet attrs) - : Loc(loc), V(v), Attrs(attrs) {} + : Loc(loc), V(v), Attrs(attrs) {} }; bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, PerFunctionState &PFS, @@ -409,7 +508,7 @@ namespace llvm { // Constant Parsing. bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr); - bool ParseGlobalValue(Type *Ty, Constant *&V); + bool ParseGlobalValue(Type *Ty, Constant *&C); bool ParseGlobalTypeAndValue(Constant *&V); bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts, Optional<unsigned> *InRangeOp = nullptr); @@ -419,9 +518,9 @@ namespace llvm { PerFunctionState *PFS); bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS); bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false); - bool ParseMDNode(MDNode *&MD); - bool ParseMDNodeTail(MDNode *&MD); - bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs); + bool ParseMDNode(MDNode *&N); + bool ParseMDNodeTail(MDNode *&N); + bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &Elts); bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD); bool ParseInstructionMetadata(Instruction &Inst); bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO); @@ -447,7 +546,7 @@ namespace llvm { AttributeSet Attrs; std::string Name; ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N) - : Loc(L), Ty(ty), Attrs(Attr), Name(N) {} + : Loc(L), Ty(ty), Attrs(Attr), Name(N) {} }; bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg); bool ParseFunctionHeader(Function *&Fn, bool isDefine); @@ -461,7 +560,7 @@ namespace llvm { enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; int ParseInstruction(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); - bool ParseCmpPredicate(unsigned &Pred, unsigned Opc); + bool ParseCmpPredicate(unsigned &P, unsigned Opc); bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); @@ -474,30 +573,33 @@ namespace llvm { bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS); bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS); bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS); - - bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, - unsigned OperandType); - bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc); - bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc); - bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc); - bool ParseSelect(Instruction *&I, PerFunctionState &PFS); - bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS); - bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS); - bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS); - bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); - int ParsePHI(Instruction *&I, PerFunctionState &PFS); - bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS); - bool ParseCall(Instruction *&I, PerFunctionState &PFS, - CallInst::TailCallKind IsTail); - int ParseAlloc(Instruction *&I, PerFunctionState &PFS); - int ParseLoad(Instruction *&I, PerFunctionState &PFS); - int ParseStore(Instruction *&I, PerFunctionState &PFS); - int ParseCmpXchg(Instruction *&I, PerFunctionState &PFS); - int ParseAtomicRMW(Instruction *&I, PerFunctionState &PFS); - int ParseFence(Instruction *&I, PerFunctionState &PFS); - int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS); - int ParseExtractValue(Instruction *&I, PerFunctionState &PFS); - int ParseInsertValue(Instruction *&I, PerFunctionState &PFS); + bool ParseCallBr(Instruction *&Inst, PerFunctionState &PFS); + + bool ParseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, + bool IsFP); + bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, + bool IsFP); + bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); + bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); + bool ParseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); + bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS); + bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS); + bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS); + bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS); + bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS); + int ParsePHI(Instruction *&Inst, PerFunctionState &PFS); + bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCall(Instruction *&Inst, PerFunctionState &PFS, + CallInst::TailCallKind TCK); + int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS); + int ParseLoad(Instruction *&Inst, PerFunctionState &PFS); + int ParseStore(Instruction *&Inst, PerFunctionState &PFS); + int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS); + int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS); + int ParseFence(Instruction *&Inst, PerFunctionState &PFS); + int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS); + int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS); + int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS); // Use-list order directives. bool ParseUseListOrder(PerFunctionState *PFS = nullptr); -- GitLab