Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 1 | //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the parser class for .ll files. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 13 | #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H |
| 14 | #define LLVM_LIB_ASMPARSER_LLPARSER_H |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 15 | |
| 16 | #include "LLLexer.h" |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringMap.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Attributes.h" |
| 20 | #include "llvm/IR/Instructions.h" |
| 21 | #include "llvm/IR/Module.h" |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 22 | #include "llvm/IR/ModuleSummaryIndex.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Operator.h" |
| 24 | #include "llvm/IR/Type.h" |
Chandler Carruth | 4220e9c | 2014-03-04 11:17:44 +0000 | [diff] [blame] | 25 | #include "llvm/IR/ValueHandle.h" |
Chris Lattner | 218b22f | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 26 | #include <map> |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 27 | |
| 28 | namespace llvm { |
| 29 | class Module; |
| 30 | class OpaqueType; |
| 31 | class Function; |
| 32 | class Value; |
| 33 | class BasicBlock; |
| 34 | class Instruction; |
| 35 | class Constant; |
| 36 | class GlobalValue; |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 37 | class Comdat; |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 38 | class MDString; |
| 39 | class MDNode; |
Alex Lorenz | 8955f7d | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 40 | struct SlotMapping; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 41 | class StructType; |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 43 | /// ValID - Represents a reference of a definition of some sort with no type. |
| 44 | /// There are several cases where we have to parse the value but where the |
| 45 | /// type can depend on later context. This may either be a numeric reference |
| 46 | /// or a symbolic (%var) reference. This is just a discriminated union. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 47 | struct ValID { |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 48 | enum { |
David Majnemer | f0f224d | 2015-11-11 21:57:16 +0000 | [diff] [blame] | 49 | t_LocalID, t_GlobalID, // ID in UIntVal. |
| 50 | t_LocalName, t_GlobalName, // Name in StrVal. |
| 51 | t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal. |
| 52 | t_Null, t_Undef, t_Zero, t_None, // No value. |
| 53 | t_EmptyArray, // No value: [] |
| 54 | t_Constant, // Value in ConstantVal. |
| 55 | t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal. |
| 56 | t_ConstantStruct, // Value in ConstantStructElts. |
| 57 | t_PackedConstantStruct // Value in ConstantStructElts. |
David Blaikie | adbda4b | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 58 | } Kind = t_LocalID; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 60 | LLLexer::LocTy Loc; |
| 61 | unsigned UIntVal; |
Karl Schimpf | 44876c5 | 2015-09-03 16:18:32 +0000 | [diff] [blame] | 62 | FunctionType *FTy = nullptr; |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 63 | std::string StrVal, StrVal2; |
| 64 | APSInt APSIntVal; |
David Blaikie | adbda4b | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 65 | APFloat APFloatVal{0.0}; |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 66 | Constant *ConstantVal; |
David Blaikie | adbda4b | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 67 | std::unique_ptr<Constant *[]> ConstantStructElts; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 68 | |
David Blaikie | adbda4b | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 69 | ValID() = default; |
David Blaikie | 6937441 | 2015-08-03 20:30:53 +0000 | [diff] [blame] | 70 | ValID(const ValID &RHS) |
David Blaikie | adbda4b | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 71 | : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy), |
David Blaikie | 6937441 | 2015-08-03 20:30:53 +0000 | [diff] [blame] | 72 | StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal), |
| 73 | APFloatVal(RHS.APFloatVal), ConstantVal(RHS.ConstantVal) { |
| 74 | assert(!RHS.ConstantStructElts); |
| 75 | } |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 76 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 77 | bool operator<(const ValID &RHS) const { |
| 78 | if (Kind == t_LocalID || Kind == t_GlobalID) |
| 79 | return UIntVal < RHS.UIntVal; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 80 | assert((Kind == t_LocalName || Kind == t_GlobalName || |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 81 | Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) && |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 82 | "Ordering not defined for this ValID kind yet"); |
| 83 | return StrVal < RHS.StrVal; |
| 84 | } |
| 85 | }; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 86 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 87 | class LLParser { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 88 | public: |
| 89 | typedef LLLexer::LocTy LocTy; |
| 90 | private: |
Chris Lattner | 2e664bd | 2010-04-07 04:08:57 +0000 | [diff] [blame] | 91 | LLVMContext &Context; |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 92 | LLLexer Lex; |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 93 | // Module being parsed, null if we are only parsing summary index. |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 94 | Module *M; |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 95 | // Summary index being parsed, null if we are only parsing Module. |
| 96 | ModuleSummaryIndex *Index; |
Alex Lorenz | 8955f7d | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 97 | SlotMapping *Slots; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 98 | |
Chris Lattner | 8eff015 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 99 | // Instruction metadata resolution. Each instruction can have a list of |
| 100 | // MDRef info associated with them. |
Dan Gohman | 7c7f13a | 2010-08-24 14:31:06 +0000 | [diff] [blame] | 101 | // |
| 102 | // The simpler approach of just creating temporary MDNodes and then calling |
| 103 | // RAUW on them when the definition is processed doesn't work because some |
| 104 | // instruction metadata kinds, such as dbg, get stored in the IR in an |
| 105 | // "optimized" format which doesn't participate in the normal value use |
| 106 | // lists. This means that RAUW doesn't work, even on temporary MDNodes |
| 107 | // which otherwise support RAUW. Instead, we defer resolving MDNode |
| 108 | // references until the definitions have been processed. |
Chris Lattner | 8eff015 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 109 | struct MDRef { |
| 110 | SMLoc Loc; |
| 111 | unsigned MDKind, MDSlot; |
| 112 | }; |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 113 | |
Manman Ren | 209b17c | 2013-09-28 00:22:27 +0000 | [diff] [blame] | 114 | SmallVector<Instruction*, 64> InstsWithTBAATag; |
| 115 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 116 | // Type resolution handling data structures. The location is set when we |
| 117 | // have processed a use of the type but not a definition yet. |
| 118 | StringMap<std::pair<Type*, LocTy> > NamedTypes; |
David Majnemer | 19b5105 | 2015-02-11 07:43:56 +0000 | [diff] [blame] | 119 | std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 120 | |
David Majnemer | 19b5105 | 2015-02-11 07:43:56 +0000 | [diff] [blame] | 121 | std::map<unsigned, TrackingMDNodeRef> NumberedMetadata; |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 122 | std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes; |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 123 | |
| 124 | // Global Value reference information. |
| 125 | std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals; |
| 126 | std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs; |
| 127 | std::vector<GlobalValue*> NumberedVals; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 128 | |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 129 | // Comdat forward reference information. |
| 130 | std::map<std::string, LocTy> ForwardRefComdats; |
| 131 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 132 | // References to blockaddress. The key is the function ValID, the value is |
| 133 | // a list of references to blocks in that function. |
Duncan P. N. Exon Smith | 1716990 | 2014-08-19 00:13:19 +0000 | [diff] [blame] | 134 | std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses; |
| 135 | class PerFunctionState; |
| 136 | /// Reference to per-function state to allow basic blocks to be |
| 137 | /// forward-referenced by blockaddress instructions within the same |
| 138 | /// function. |
| 139 | PerFunctionState *BlockAddressPFS; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 140 | |
Bill Wendling | 63b8819 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 141 | // Attribute builder reference information. |
Bill Wendling | b32b041 | 2013-02-08 06:32:06 +0000 | [diff] [blame] | 142 | std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups; |
| 143 | std::map<unsigned, AttrBuilder> NumberedAttrBuilders; |
Bill Wendling | 63b8819 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 144 | |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 145 | // Summary global value reference information. |
| 146 | std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>> |
| 147 | ForwardRefValueInfos; |
| 148 | std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>> |
| 149 | ForwardRefAliasees; |
| 150 | std::vector<ValueInfo> NumberedValueInfos; |
| 151 | |
| 152 | // Summary type id reference information. |
| 153 | std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>> |
| 154 | ForwardRefTypeIds; |
| 155 | |
| 156 | // Map of module ID to path. |
| 157 | std::map<unsigned, StringRef> ModuleIdMap; |
| 158 | |
Adrian Prantl | a8b2ddb | 2017-10-02 18:31:29 +0000 | [diff] [blame] | 159 | /// Only the llvm-as tool may set this to false to bypass |
| 160 | /// UpgradeDebuginfo so it can generate broken bitcode. |
| 161 | bool UpgradeDebugInfo; |
| 162 | |
Yaxun Liu | c00d81e | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 163 | /// DataLayout string to override that in LLVM assembly. |
| 164 | StringRef DataLayoutStr; |
| 165 | |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 166 | std::string SourceFileName; |
| 167 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 168 | public: |
Alex Lorenz | 8955f7d | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 169 | LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 170 | ModuleSummaryIndex *Index, LLVMContext &Context, |
Yaxun Liu | c00d81e | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 171 | SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true, |
| 172 | StringRef DataLayoutString = "") |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 173 | : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index), |
Adrian Prantl | a8b2ddb | 2017-10-02 18:31:29 +0000 | [diff] [blame] | 174 | Slots(Slots), BlockAddressPFS(nullptr), |
Yaxun Liu | c00d81e | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 175 | UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) { |
| 176 | if (!DataLayoutStr.empty()) |
| 177 | M->setDataLayout(DataLayoutStr); |
| 178 | } |
Chris Lattner | ad6f335 | 2009-01-04 20:44:11 +0000 | [diff] [blame] | 179 | bool Run(); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 180 | |
Alex Lorenz | 1de2acd | 2015-08-21 21:32:39 +0000 | [diff] [blame] | 181 | bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots); |
Alex Lorenz | d225595 | 2015-07-17 22:07:03 +0000 | [diff] [blame] | 182 | |
Quentin Colombet | dafed5d | 2016-03-08 00:37:07 +0000 | [diff] [blame] | 183 | bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, |
| 184 | const SlotMapping *Slots); |
Quentin Colombet | 81e72b4 | 2016-03-07 22:09:05 +0000 | [diff] [blame] | 185 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 186 | LLVMContext &getContext() { return Context; } |
Owen Anderson | 09063ce | 2009-07-02 17:04:01 +0000 | [diff] [blame] | 187 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 188 | private: |
| 189 | |
Benjamin Kramer | c758311 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 190 | bool Error(LocTy L, const Twine &Msg) const { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 191 | return Lex.Error(L, Msg); |
| 192 | } |
Benjamin Kramer | c758311 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 193 | bool TokError(const Twine &Msg) const { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 194 | return Error(Lex.getLoc(), Msg); |
| 195 | } |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 196 | |
Alex Lorenz | 1de2acd | 2015-08-21 21:32:39 +0000 | [diff] [blame] | 197 | /// Restore the internal name and slot mappings using the mappings that |
| 198 | /// were created at an earlier parsing stage. |
| 199 | void restoreParsingState(const SlotMapping *Slots); |
| 200 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 201 | /// GetGlobalVal - Get a value with the specified name or ID, creating a |
| 202 | /// forward reference record if needed. This can return null if the value |
| 203 | /// exists but does not have the right type. |
Alexander Richardson | 6bcf2ba | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 204 | GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc, |
| 205 | bool IsCall); |
| 206 | GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 207 | |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 208 | /// Get a Comdat with the specified name, creating a forward reference |
| 209 | /// record if needed. |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 210 | Comdat *getComdat(const std::string &Name, LocTy Loc); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 211 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 212 | // Helper Routines. |
| 213 | bool ParseToken(lltok::Kind T, const char *ErrMsg); |
Chris Lattner | 3822f63 | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 214 | bool EatIfPresent(lltok::Kind T) { |
| 215 | if (Lex.getKind() != T) return false; |
| 216 | Lex.Lex(); |
| 217 | return true; |
| 218 | } |
Michael Ilseman | 9205317 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 219 | |
| 220 | FastMathFlags EatFastMathFlagsIfPresent() { |
| 221 | FastMathFlags FMF; |
| 222 | while (true) |
| 223 | switch (Lex.getKind()) { |
Sanjay Patel | 629c411 | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 224 | case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue; |
Michael Ilseman | 65f1435 | 2012-12-09 21:12:04 +0000 | [diff] [blame] | 225 | case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue; |
| 226 | case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue; |
| 227 | case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue; |
| 228 | case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue; |
Adam Nemet | cd847a8 | 2017-03-28 20:11:52 +0000 | [diff] [blame] | 229 | case lltok::kw_contract: |
| 230 | FMF.setAllowContract(true); |
| 231 | Lex.Lex(); |
| 232 | continue; |
Sanjay Patel | 629c411 | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 233 | case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue; |
| 234 | case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue; |
Michael Ilseman | 9205317 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 235 | default: return FMF; |
| 236 | } |
| 237 | return FMF; |
| 238 | } |
| 239 | |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 240 | bool ParseOptionalToken(lltok::Kind T, bool &Present, |
| 241 | LocTy *Loc = nullptr) { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 242 | if (Lex.getKind() != T) { |
| 243 | Present = false; |
| 244 | } else { |
Rafael Espindola | 026d152 | 2011-01-13 01:30:30 +0000 | [diff] [blame] | 245 | if (Loc) |
| 246 | *Loc = Lex.getLoc(); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 247 | Lex.Lex(); |
| 248 | Present = true; |
| 249 | } |
| 250 | return false; |
| 251 | } |
Chris Lattner | 3822f63 | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 252 | bool ParseStringConstant(std::string &Result); |
| 253 | bool ParseUInt32(unsigned &Val); |
| 254 | bool ParseUInt32(unsigned &Val, LocTy &Loc) { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 255 | Loc = Lex.getLoc(); |
Chris Lattner | 3822f63 | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 256 | return ParseUInt32(Val); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 257 | } |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 258 | bool ParseUInt64(uint64_t &Val); |
| 259 | bool ParseUInt64(uint64_t &Val, LocTy &Loc) { |
| 260 | Loc = Lex.getLoc(); |
| 261 | return ParseUInt64(Val); |
| 262 | } |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 263 | bool ParseFlag(unsigned &Val); |
Hans Wennborg | cbe34b4 | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 264 | |
Artur Pilipenko | 17376c4 | 2015-08-03 14:31:49 +0000 | [diff] [blame] | 265 | bool ParseStringAttribute(AttrBuilder &B); |
| 266 | |
Hans Wennborg | cbe34b4 | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 267 | bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM); |
| 268 | bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM); |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 269 | bool ParseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr); |
Alexander Richardson | 6bcf2ba | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 270 | bool ParseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0); |
| 271 | bool ParseOptionalProgramAddrSpace(unsigned &AddrSpace) { |
| 272 | return ParseOptionalAddrSpace( |
| 273 | AddrSpace, M->getDataLayout().getProgramAddressSpace()); |
| 274 | }; |
Bill Wendling | 34c2eb2 | 2012-12-04 23:40:58 +0000 | [diff] [blame] | 275 | bool ParseOptionalParamAttrs(AttrBuilder &B); |
| 276 | bool ParseOptionalReturnAttrs(AttrBuilder &B); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 277 | bool ParseOptionalLinkage(unsigned &Res, bool &HasLinkage, |
Sean Fertile | c70d28b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 278 | unsigned &Visibility, unsigned &DLLStorageClass, |
| 279 | bool &DSOLocal); |
| 280 | void ParseOptionalDSOLocal(bool &DSOLocal); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 281 | void ParseOptionalVisibility(unsigned &Res); |
| 282 | void ParseOptionalDLLStorageClass(unsigned &Res); |
Alexey Samsonov | 17a9cff | 2014-09-10 18:00:17 +0000 | [diff] [blame] | 283 | bool ParseOptionalCallingConv(unsigned &CC); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 284 | bool ParseOptionalAlignment(unsigned &Alignment); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 285 | bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes); |
Konstantin Zhuravlyov | bb80d3e | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 286 | bool ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID, |
Eli Friedman | fee02c6 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 287 | AtomicOrdering &Ordering); |
Konstantin Zhuravlyov | bb80d3e | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 288 | bool ParseScope(SyncScope::ID &SSID); |
Tim Northover | e94a518 | 2014-03-11 10:48:52 +0000 | [diff] [blame] | 289 | bool ParseOrdering(AtomicOrdering &Ordering); |
Charles Davis | be5557e | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 290 | bool ParseOptionalStackAlignment(unsigned &Alignment); |
Chris Lattner | b2f3950 | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 291 | bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); |
Matt Arsenault | 3c1fc76 | 2017-04-10 22:27:50 +0000 | [diff] [blame] | 292 | bool ParseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc, |
| 293 | bool &AteExtraComma); |
Reid Kleckner | 436c42e | 2014-01-17 23:58:17 +0000 | [diff] [blame] | 294 | bool ParseOptionalCommaInAlloca(bool &IsInAlloca); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 295 | bool parseAllocSizeArguments(unsigned &BaseSizeArg, |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 296 | Optional<unsigned> &HowManyArg); |
| 297 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices, |
| 298 | bool &AteExtraComma); |
Chris Lattner | 28f1eeb | 2009-12-30 05:14:00 +0000 | [diff] [blame] | 299 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) { |
| 300 | bool AteExtraComma; |
| 301 | if (ParseIndexList(Indices, AteExtraComma)) return true; |
| 302 | if (AteExtraComma) |
| 303 | return TokError("expected index"); |
| 304 | return false; |
| 305 | } |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 306 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 307 | // Top-Level Entities |
| 308 | bool ParseTopLevelEntities(); |
| 309 | bool ValidateEndOfModule(); |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 310 | bool ValidateEndOfIndex(); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 311 | bool ParseTargetDefinition(); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 312 | bool ParseModuleAsm(); |
Teresa Johnson | 83c517c | 2016-03-30 18:15:08 +0000 | [diff] [blame] | 313 | bool ParseSourceFileName(); |
Bill Wendling | 706d3d6 | 2012-11-28 08:41:48 +0000 | [diff] [blame] | 314 | bool ParseDepLibs(); // FIXME: Remove in 4.0. |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 315 | bool ParseUnnamedType(); |
| 316 | bool ParseNamedType(); |
| 317 | bool ParseDeclare(); |
| 318 | bool ParseDefine(); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 319 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 320 | bool ParseGlobalType(bool &IsConstant); |
Dan Gohman | 466876b | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 321 | bool ParseUnnamedGlobal(); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 322 | bool ParseNamedGlobal(); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 323 | bool ParseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage, |
Nico Rieck | 7157bb7 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 324 | bool HasLinkage, unsigned Visibility, |
Sean Fertile | c70d28b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 325 | unsigned DLLStorageClass, bool DSOLocal, |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 326 | GlobalVariable::ThreadLocalMode TLM, |
| 327 | GlobalVariable::UnnamedAddr UnnamedAddr); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 328 | bool parseIndirectSymbol(const std::string &Name, LocTy NameLoc, |
| 329 | unsigned L, unsigned Visibility, |
Sean Fertile | c70d28b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 330 | unsigned DLLStorageClass, bool DSOLocal, |
Dmitry Polukhin | a3d5b0b | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 331 | GlobalVariable::ThreadLocalMode TLM, |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 332 | GlobalVariable::UnnamedAddr UnnamedAddr); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 333 | bool parseComdat(); |
Devang Patel | 39e64d4 | 2009-07-01 19:21:12 +0000 | [diff] [blame] | 334 | bool ParseStandaloneMetadata(); |
Devang Patel | be62697 | 2009-07-29 00:34:02 +0000 | [diff] [blame] | 335 | bool ParseNamedMetadata(); |
Chris Lattner | 1797fc7 | 2009-12-29 21:53:55 +0000 | [diff] [blame] | 336 | bool ParseMDString(MDString *&Result); |
Chris Lattner | 6dac02a | 2009-12-30 04:15:23 +0000 | [diff] [blame] | 337 | bool ParseMDNodeID(MDNode *&Result); |
Bill Wendling | 63b8819 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 338 | bool ParseUnnamedAttrGrp(); |
Bill Wendling | b32b041 | 2013-02-08 06:32:06 +0000 | [diff] [blame] | 339 | bool ParseFnAttributeValuePairs(AttrBuilder &B, |
| 340 | std::vector<unsigned> &FwdRefAttrGrps, |
Michael Gottesman | 41748d7 | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 341 | bool inAttrGrp, LocTy &BuiltinLoc); |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 342 | |
| 343 | // Module Summary Index Parsing. |
Teresa Johnson | 08d5b4e | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 344 | bool SkipModuleSummaryEntry(); |
| 345 | bool ParseSummaryEntry(); |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 346 | bool ParseModuleEntry(unsigned ID); |
| 347 | bool ParseModuleReference(StringRef &ModulePath); |
| 348 | bool ParseGVReference(ValueInfo &VI, unsigned &GVId); |
| 349 | bool ParseGVEntry(unsigned ID); |
| 350 | bool ParseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 351 | bool ParseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 352 | bool ParseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 353 | bool ParseGVFlags(GlobalValueSummary::GVFlags &GVFlags); |
Eugene Leviant | 009d833 | 2018-11-23 10:54:51 +0000 | [diff] [blame] | 354 | bool ParseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags); |
Teresa Johnson | 63ee0e7 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 355 | bool ParseOptionalFFlags(FunctionSummary::FFlags &FFlags); |
| 356 | bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls); |
| 357 | bool ParseHotness(CalleeInfo::HotnessType &Hotness); |
| 358 | bool ParseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo); |
| 359 | bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests); |
| 360 | bool ParseVFuncIdList(lltok::Kind Kind, |
| 361 | std::vector<FunctionSummary::VFuncId> &VFuncIdList); |
| 362 | bool ParseConstVCallList( |
| 363 | lltok::Kind Kind, |
| 364 | std::vector<FunctionSummary::ConstVCall> &ConstVCallList); |
| 365 | using IdToIndexMapType = |
| 366 | std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>; |
| 367 | bool ParseConstVCall(FunctionSummary::ConstVCall &ConstVCall, |
| 368 | IdToIndexMapType &IdToIndexMap, unsigned Index); |
| 369 | bool ParseVFuncId(FunctionSummary::VFuncId &VFuncId, |
| 370 | IdToIndexMapType &IdToIndexMap, unsigned Index); |
| 371 | bool ParseOptionalRefs(std::vector<ValueInfo> &Refs); |
| 372 | bool ParseTypeIdEntry(unsigned ID); |
| 373 | bool ParseTypeIdSummary(TypeIdSummary &TIS); |
| 374 | bool ParseTypeTestResolution(TypeTestResolution &TTRes); |
| 375 | bool ParseOptionalWpdResolutions( |
| 376 | std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap); |
| 377 | bool ParseWpdRes(WholeProgramDevirtResolution &WPDRes); |
| 378 | bool ParseOptionalResByArg( |
| 379 | std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> |
| 380 | &ResByArg); |
| 381 | bool ParseArgs(std::vector<uint64_t> &Args); |
| 382 | void AddGlobalValueToIndex(std::string Name, GlobalValue::GUID, |
| 383 | GlobalValue::LinkageTypes Linkage, unsigned ID, |
| 384 | std::unique_ptr<GlobalValueSummary> Summary); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 385 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 386 | // Type Parsing. |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 387 | bool ParseType(Type *&Result, const Twine &Msg, bool AllowVoid = false); |
| 388 | bool ParseType(Type *&Result, bool AllowVoid = false) { |
| 389 | return ParseType(Result, "expected type", AllowVoid); |
| 390 | } |
| 391 | bool ParseType(Type *&Result, const Twine &Msg, LocTy &Loc, |
| 392 | bool AllowVoid = false) { |
| 393 | Loc = Lex.getLoc(); |
| 394 | return ParseType(Result, Msg, AllowVoid); |
| 395 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 396 | bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) { |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 397 | Loc = Lex.getLoc(); |
Chris Lattner | f880ca2 | 2009-03-09 04:49:14 +0000 | [diff] [blame] | 398 | return ParseType(Result, AllowVoid); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 399 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 400 | bool ParseAnonStructType(Type *&Result, bool Packed); |
| 401 | bool ParseStructBody(SmallVectorImpl<Type*> &Body); |
| 402 | bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name, |
| 403 | std::pair<Type*, LocTy> &Entry, |
| 404 | Type *&ResultTy); |
| 405 | |
| 406 | bool ParseArrayVectorType(Type *&Result, bool isVector); |
| 407 | bool ParseFunctionType(Type *&Result); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 408 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 409 | // Function Semantic Analysis. |
| 410 | class PerFunctionState { |
| 411 | LLParser &P; |
| 412 | Function &F; |
| 413 | std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals; |
| 414 | std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs; |
| 415 | std::vector<Value*> NumberedVals; |
Michael Ilseman | 26ee2b8 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 416 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 417 | /// FunctionNumber - If this is an unnamed function, this is the slot |
| 418 | /// number of it, otherwise it is -1. |
| 419 | int FunctionNumber; |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 420 | public: |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 421 | PerFunctionState(LLParser &p, Function &f, int functionNumber); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 422 | ~PerFunctionState(); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 423 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 424 | Function &getFunction() const { return F; } |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 425 | |
Chris Lattner | 3432c62 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 426 | bool FinishFunction(); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 427 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 428 | /// GetVal - Get a value with the specified name or ID, creating a |
| 429 | /// forward reference record if needed. This can return null if the value |
| 430 | /// exists but does not have the right type. |
Alexander Richardson | c11ae18 | 2018-02-27 11:15:11 +0000 | [diff] [blame] | 431 | Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc, bool IsCall); |
| 432 | Value *GetVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 433 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 434 | /// SetInstName - After an instruction is parsed and inserted into its |
| 435 | /// basic block, this installs its name. |
| 436 | bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, |
| 437 | Instruction *Inst); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 438 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 439 | /// GetBB - Get a basic block with the specified name or ID, creating a |
| 440 | /// forward reference record if needed. This can return null if the value |
| 441 | /// is not a BasicBlock. |
| 442 | BasicBlock *GetBB(const std::string &Name, LocTy Loc); |
| 443 | BasicBlock *GetBB(unsigned ID, LocTy Loc); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 444 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 445 | /// DefineBB - Define the specified basic block, which is either named or |
| 446 | /// unnamed. If there is an error, this returns null otherwise it returns |
| 447 | /// the block being defined. |
James Y Knight | c0e6b8a | 2019-03-22 18:27:13 +0000 | [diff] [blame] | 448 | BasicBlock *DefineBB(const std::string &Name, int NameID, LocTy Loc); |
Duncan P. N. Exon Smith | 1716990 | 2014-08-19 00:13:19 +0000 | [diff] [blame] | 449 | |
| 450 | bool resolveForwardRefBlockAddresses(); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 451 | }; |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 452 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 453 | bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V, |
Alexander Richardson | c11ae18 | 2018-02-27 11:15:11 +0000 | [diff] [blame] | 454 | PerFunctionState *PFS, bool IsCall); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 455 | |
Alexander Richardson | 6bcf2ba | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 456 | Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, |
| 457 | Value *Val, bool IsCall); |
| 458 | |
Alex Lorenz | d225595 | 2015-07-17 22:07:03 +0000 | [diff] [blame] | 459 | bool parseConstantValue(Type *Ty, Constant *&C); |
David Majnemer | 8a1c45d | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 460 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS); |
| 461 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) { |
| 462 | return ParseValue(Ty, V, &PFS); |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 463 | } |
David Majnemer | 8a1c45d | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 464 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 465 | bool ParseValue(Type *Ty, Value *&V, LocTy &Loc, |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 466 | PerFunctionState &PFS) { |
| 467 | Loc = Lex.getLoc(); |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 468 | return ParseValue(Ty, V, &PFS); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 469 | } |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 470 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 471 | bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS); |
| 472 | bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) { |
| 473 | return ParseTypeAndValue(V, &PFS); |
| 474 | } |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 475 | bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) { |
| 476 | Loc = Lex.getLoc(); |
| 477 | return ParseTypeAndValue(V, PFS); |
| 478 | } |
Chris Lattner | 3ed871f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 479 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc, |
| 480 | PerFunctionState &PFS); |
| 481 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) { |
| 482 | LocTy Loc; |
| 483 | return ParseTypeAndBasicBlock(BB, Loc, PFS); |
| 484 | } |
Victor Hernandez | fa23223 | 2009-12-03 23:40:58 +0000 | [diff] [blame] | 485 | |
Chris Lattner | 392be58 | 2010-02-12 20:49:41 +0000 | [diff] [blame] | 486 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 487 | struct ParamInfo { |
| 488 | LocTy Loc; |
| 489 | Value *V; |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 490 | AttributeSet Attrs; |
| 491 | ParamInfo(LocTy loc, Value *v, AttributeSet attrs) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 492 | : Loc(loc), V(v), Attrs(attrs) {} |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 493 | }; |
| 494 | bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, |
Reid Kleckner | 8349864 | 2014-08-26 00:33:28 +0000 | [diff] [blame] | 495 | PerFunctionState &PFS, |
| 496 | bool IsMustTailCall = false, |
| 497 | bool InVarArgsFunc = false); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 498 | |
Sanjoy Das | b513a9f | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 499 | bool |
| 500 | ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList, |
| 501 | PerFunctionState &PFS); |
| 502 | |
David Majnemer | 654e130 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 503 | bool ParseExceptionArgs(SmallVectorImpl<Value *> &Args, |
| 504 | PerFunctionState &PFS); |
| 505 | |
Victor Hernandez | dc6e65a | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 506 | // Constant Parsing. |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 507 | bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 508 | bool ParseGlobalValue(Type *Ty, Constant *&C); |
Victor Hernandez | dc6e65a | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 509 | bool ParseGlobalTypeAndValue(Constant *&V); |
Peter Collingbourne | d93620b | 2016-11-10 22:34:55 +0000 | [diff] [blame] | 510 | bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts, |
| 511 | Optional<unsigned> *InRangeOp = nullptr); |
Rafael Espindola | 83a362c | 2015-01-06 22:55:16 +0000 | [diff] [blame] | 512 | bool parseOptionalComdat(StringRef GlobalName, Comdat *&C); |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 513 | bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS); |
Duncan P. N. Exon Smith | 19fc5ed | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 514 | bool ParseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg, |
| 515 | PerFunctionState *PFS); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 516 | bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS); |
Duncan P. N. Exon Smith | 58ef9d1 | 2015-01-12 21:23:11 +0000 | [diff] [blame] | 517 | bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 518 | bool ParseMDNode(MDNode *&N); |
| 519 | bool ParseMDNodeTail(MDNode *&N); |
| 520 | bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &Elts); |
Duncan P. N. Exon Smith | 19717ea | 2015-04-24 21:21:57 +0000 | [diff] [blame] | 521 | bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD); |
Duncan P. N. Exon Smith | 27d702c | 2015-04-24 21:29:36 +0000 | [diff] [blame] | 522 | bool ParseInstructionMetadata(Instruction &Inst); |
Peter Collingbourne | cceae7f | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 523 | bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO); |
Duncan P. N. Exon Smith | 3d4cd75 | 2015-04-24 22:04:41 +0000 | [diff] [blame] | 524 | bool ParseOptionalFunctionMetadata(Function &F); |
Victor Hernandez | dc6e65a | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 525 | |
Duncan P. N. Exon Smith | 077c031 | 2015-02-04 22:05:21 +0000 | [diff] [blame] | 526 | template <class FieldTy> |
| 527 | bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result); |
Duncan P. N. Exon Smith | a747728 | 2015-01-20 02:42:29 +0000 | [diff] [blame] | 528 | template <class FieldTy> bool ParseMDField(StringRef Name, FieldTy &Result); |
Duncan P. N. Exon Smith | 13890af | 2015-01-19 23:32:36 +0000 | [diff] [blame] | 529 | template <class ParserTy> |
Duncan P. N. Exon Smith | 66ca92e | 2015-01-19 23:39:32 +0000 | [diff] [blame] | 530 | bool ParseMDFieldsImplBody(ParserTy parseField); |
| 531 | template <class ParserTy> |
Duncan P. N. Exon Smith | 13890af | 2015-01-19 23:32:36 +0000 | [diff] [blame] | 532 | bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc); |
Duncan P. N. Exon Smith | 6a48483 | 2015-01-13 21:10:44 +0000 | [diff] [blame] | 533 | bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false); |
Duncan P. N. Exon Smith | ed458fa | 2015-02-10 01:08:16 +0000 | [diff] [blame] | 534 | |
| 535 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ |
| 536 | bool Parse##CLASS(MDNode *&Result, bool IsDistinct); |
| 537 | #include "llvm/IR/Metadata.def" |
Duncan P. N. Exon Smith | 6a48483 | 2015-01-13 21:10:44 +0000 | [diff] [blame] | 538 | |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 539 | // Function Parsing. |
| 540 | struct ArgInfo { |
| 541 | LocTy Loc; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 542 | Type *Ty; |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 543 | AttributeSet Attrs; |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 544 | std::string Name; |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 545 | ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 546 | : Loc(L), Ty(ty), Attrs(Attr), Name(N) {} |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 547 | }; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 548 | bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 549 | bool ParseFunctionHeader(Function *&Fn, bool isDefine); |
| 550 | bool ParseFunctionBody(Function &Fn); |
| 551 | bool ParseBasicBlock(PerFunctionState &PFS); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 552 | |
Reid Kleckner | 5772b77 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 553 | enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail }; |
| 554 | |
Chris Lattner | 77b89dc | 2009-12-30 05:23:43 +0000 | [diff] [blame] | 555 | // Instruction Parsing. Each instruction parsing routine can return with a |
| 556 | // normal result, an error result, or return having eaten an extra comma. |
| 557 | enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; |
| 558 | int ParseInstruction(Instruction *&Inst, BasicBlock *BB, |
| 559 | PerFunctionState &PFS); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 560 | bool ParseCmpPredicate(unsigned &P, unsigned Opc); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 561 | |
Chris Lattner | 33de427 | 2011-06-17 06:49:41 +0000 | [diff] [blame] | 562 | bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 563 | bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); |
| 564 | bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | d04cb6d | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 565 | bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 566 | bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); |
Bill Wendling | f891bf8 | 2011-07-31 06:30:59 +0000 | [diff] [blame] | 567 | bool ParseResume(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 654e130 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 568 | bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS); |
| 569 | bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 8a1c45d | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 570 | bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 654e130 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 571 | bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 654e130 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 572 | bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS); |
Craig Topper | 784929d | 2019-02-08 20:48:56 +0000 | [diff] [blame] | 573 | bool ParseCallBr(Instruction *&Inst, PerFunctionState &PFS); |
Misha Brukman | 1d9a93d | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 574 | |
Cameron McInally | cbde0d9 | 2018-11-13 18:15:47 +0000 | [diff] [blame] | 575 | bool ParseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, |
Craig Topper | 8279695 | 2019-05-05 17:19:19 +0000 | [diff] [blame] | 576 | bool IsFP); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 577 | bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, |
Craig Topper | 8279695 | 2019-05-05 17:19:19 +0000 | [diff] [blame] | 578 | bool IsFP); |
Fangrui Song | 28f69c7 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 579 | bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 580 | bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 581 | bool ParseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 582 | bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS); |
| 583 | bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS); |
| 584 | bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS); |
| 585 | bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS); |
| 586 | bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS); |
| 587 | int ParsePHI(Instruction *&Inst, PerFunctionState &PFS); |
| 588 | bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS); |
| 589 | bool ParseCall(Instruction *&Inst, PerFunctionState &PFS, |
| 590 | CallInst::TailCallKind TCK); |
| 591 | int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS); |
| 592 | int ParseLoad(Instruction *&Inst, PerFunctionState &PFS); |
| 593 | int ParseStore(Instruction *&Inst, PerFunctionState &PFS); |
| 594 | int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS); |
| 595 | int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS); |
| 596 | int ParseFence(Instruction *&Inst, PerFunctionState &PFS); |
| 597 | int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS); |
| 598 | int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS); |
| 599 | int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS); |
Duncan P. N. Exon Smith | 0a448fb | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 600 | |
| 601 | // Use-list order directives. |
| 602 | bool ParseUseListOrder(PerFunctionState *PFS = nullptr); |
| 603 | bool ParseUseListOrderBB(); |
| 604 | bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes); |
| 605 | bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc); |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 606 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 607 | } // End llvm namespace |
Chris Lattner | ac161bf | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 608 | |
| 609 | #endif |