llvm.org GIT mirror llvm / 407a616
Remove trailing whitespace git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168103 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Ilseman 7 years ago
10 changed file(s) with 205 addition(s) and 205 deletion(s). Raw diff Collapse all Expand all
5656
5757 /// SimplifyUDivInst - Given operands for a UDiv, see if we can
5858 /// fold the result. If not, this returns null.
59 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
59 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
6060 const TargetLibraryInfo *TLI = 0,
6161 const DominatorTree *DT = 0);
6262
6868
6969 /// SimplifySRemInst - Given operands for an SRem, see if we can
7070 /// fold the result. If not, this returns null.
71 Value *SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
71 Value *SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
7272 const TargetLibraryInfo *TLI = 0,
7373 const DominatorTree *DT = 0);
7474
8787 /// SimplifyShlInst - Given operands for a Shl, see if we can
8888 /// fold the result. If not, this returns null.
8989 Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
90 const DataLayout *TD = 0,
90 const DataLayout *TD = 0,
9191 const TargetLibraryInfo *TLI = 0,
9292 const DominatorTree *DT = 0);
9393
126126 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
127127 /// fold the result. If not, this returns null.
128128 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
129 const DataLayout *TD = 0,
129 const DataLayout *TD = 0,
130130 const TargetLibraryInfo *TLI = 0,
131131 const DominatorTree *DT = 0);
132132
133133 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
134134 /// fold the result. If not, this returns null.
135135 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
136 const DataLayout *TD = 0,
136 const DataLayout *TD = 0,
137137 const TargetLibraryInfo *TLI = 0,
138138 const DominatorTree *DT = 0);
139139
177177 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
178178 /// fold the result. If not, this returns null.
179179 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
180 const DataLayout *TD = 0,
180 const DataLayout *TD = 0,
181181 const TargetLibraryInfo *TLI = 0,
182182 const DominatorTree *DT = 0);
183183
3030 PARAMATTR_BLOCK_ID,
3131
3232 UNUSED_ID1,
33
33
3434 CONSTANTS_BLOCK_ID,
3535 FUNCTION_BLOCK_ID,
36
36
3737 UNUSED_ID2,
38
38
3939 VALUE_SYMTAB_BLOCK_ID,
4040 METADATA_BLOCK_ID,
4141 METADATA_ATTACHMENT_ID,
42
42
4343 TYPE_BLOCK_ID_NEW,
4444
4545 USELIST_BLOCK_ID
9292
9393 TYPE_CODE_FUNCTION_OLD = 9, // FUNCTION: [vararg, attrid, retty,
9494 // paramty x N]
95
95
9696 TYPE_CODE_HALF = 10, // HALF
97
97
9898 TYPE_CODE_ARRAY = 11, // ARRAY: [numelts, eltty]
9999 TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
100100
108108 TYPE_CODE_METADATA = 16, // METADATA
109109
110110 TYPE_CODE_X86_MMX = 17, // X86 MMX
111
111
112112 TYPE_CODE_STRUCT_ANON = 18, // STRUCT_ANON: [ispacked, eltty x N]
113113 TYPE_CODE_STRUCT_NAME = 19, // STRUCT_NAME: [strchr x N]
114114 TYPE_CODE_STRUCT_NAMED = 20,// STRUCT_NAMED: [ispacked, eltty x N]
233233 OBO_NO_SIGNED_WRAP = 1
234234 };
235235
236 /// PossiblyExactOperatorOptionalFlags - Flags for serializing
236 /// PossiblyExactOperatorOptionalFlags - Flags for serializing
237237 /// PossiblyExactOperator's SubclassOptionalData contents.
238238 enum PossiblyExactOperatorOptionalFlags {
239239 PEO_EXACT = 0
3232
3333 BasicBlock *Parent;
3434 DebugLoc DbgLoc; // 'dbg' Metadata cache.
35
35
3636 enum {
3737 /// HasMetadataBit - This is a bit stored in the SubClassData field which
3838 /// indicates whether this instruction has metadata attached to it or not.
4141 public:
4242 // Out of line virtual method, so the vtable, etc has a home.
4343 ~Instruction();
44
44
4545 /// use_back - Specialize the methods defined in Value, as we know that an
4646 /// instruction can only be used by other instructions.
4747 Instruction *use_back() { return cast(*use_begin());}
4848 const Instruction *use_back() const { return cast(*use_begin());}
49
49
5050 inline const BasicBlock *getParent() const { return Parent; }
5151 inline BasicBlock *getParent() { return Parent; }
5252
7676 //===--------------------------------------------------------------------===//
7777 // Subclass classification.
7878 //===--------------------------------------------------------------------===//
79
79
8080 /// getOpcode() returns a member of one of the enums like Instruction::Add.
8181 unsigned getOpcode() const { return getValueID() - InstructionVal; }
82
82
8383 const char *getOpcodeName() const { return getOpcodeName(getOpcode()); }
8484 bool isTerminator() const { return isTerminator(getOpcode()); }
8585 bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
8686 bool isShift() { return isShift(getOpcode()); }
8787 bool isCast() const { return isCast(getOpcode()); }
88
88
8989 static const char* getOpcodeName(unsigned OpCode);
9090
9191 static inline bool isTerminator(unsigned OpCode) {
120120 //===--------------------------------------------------------------------===//
121121 // Metadata manipulation.
122122 //===--------------------------------------------------------------------===//
123
123
124124 /// hasMetadata() - Return true if this instruction has any metadata attached
125125 /// to it.
126126 bool hasMetadata() const {
127127 return !DbgLoc.isUnknown() || hasMetadataHashEntry();
128128 }
129
129
130130 /// hasMetadataOtherThanDebugLoc - Return true if this instruction has
131131 /// metadata attached to it other than a debug location.
132132 bool hasMetadataOtherThanDebugLoc() const {
133133 return hasMetadataHashEntry();
134134 }
135
135
136136 /// getMetadata - Get the metadata of given kind attached to this Instruction.
137137 /// If the metadata is not found then return null.
138138 MDNode *getMetadata(unsigned KindID) const {
139139 if (!hasMetadata()) return 0;
140140 return getMetadataImpl(KindID);
141141 }
142
142
143143 /// getMetadata - Get the metadata of given kind attached to this Instruction.
144144 /// If the metadata is not found then return null.
145145 MDNode *getMetadata(StringRef Kind) const {
146146 if (!hasMetadata()) return 0;
147147 return getMetadataImpl(Kind);
148148 }
149
149
150150 /// getAllMetadata - Get all metadata attached to this Instruction. The first
151151 /// element of each pair returned is the KindID, the second element is the
152152 /// metadata value. This list is returned sorted by the KindID.
154154 if (hasMetadata())
155155 getAllMetadataImpl(MDs);
156156 }
157
157
158158 /// getAllMetadataOtherThanDebugLoc - This does the same thing as
159159 /// getAllMetadata, except that it filters out the debug location.
160160 void getAllMetadataOtherThanDebugLoc(SmallVectorImpl
162162 if (hasMetadataOtherThanDebugLoc())
163163 getAllMetadataOtherThanDebugLocImpl(MDs);
164164 }
165
165
166166 /// setMetadata - Set the metadata of the specified kind to the specified
167167 /// node. This updates/replaces metadata if already present, or removes it if
168168 /// Node is null.
171171
172172 /// setDebugLoc - Set the debug location information for this instruction.
173173 void setDebugLoc(const DebugLoc &Loc) { DbgLoc = Loc; }
174
174
175175 /// getDebugLoc - Return the debug location for this node as a DebugLoc.
176176 const DebugLoc &getDebugLoc() const { return DbgLoc; }
177
177
178178 private:
179179 /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side
180180 /// metadata hash.
181181 bool hasMetadataHashEntry() const {
182182 return (getSubclassDataFromValue() & HasMetadataBit) != 0;
183183 }
184
184
185185 // These are all implemented in Metadata.cpp.
186186 MDNode *getMetadataImpl(unsigned KindID) const;
187187 MDNode *getMetadataImpl(StringRef Kind) const;
193193 //===--------------------------------------------------------------------===//
194194 // Predicates and helper methods.
195195 //===--------------------------------------------------------------------===//
196
197
196
197
198198 /// isAssociative - Return true if the instruction is associative:
199199 ///
200200 /// Associative operators satisfy: x op (y op z) === (x op y) op z
270270 /// * The instruction has no name
271271 ///
272272 Instruction *clone() const;
273
273
274274 /// isIdenticalTo - Return true if the specified instruction is exactly
275275 /// identical to the current one. This means that all operands match and any
276276 /// extra information (e.g. load is volatile) agree.
277277 bool isIdenticalTo(const Instruction *I) const;
278
278
279279 /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it
280280 /// ignores the SubclassOptionalData flags, which specify conditions
281281 /// under which the instruction's result is undefined.
290290 /// as equivalent.
291291 CompareUsingScalarTypes = 1<<1
292292 };
293
293
294294 /// This function determines if the specified instruction executes the same
295295 /// operation as the current one. This means that the opcodes, type, operand
296296 /// types and any other factors affecting the operation must be the same. This
300300 /// the current one.
301301 /// @brief Determine if one instruction is the same operation as another.
302302 bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const;
303
303
304304 /// isUsedOutsideOfBlock - Return true if there are any uses of this
305305 /// instruction in blocks other than the specified block. Note that PHI nodes
306306 /// are considered to evaluate their operands in the corresponding predecessor
307307 /// block.
308308 bool isUsedOutsideOfBlock(const BasicBlock *BB) const;
309
310
309
310
311311 /// Methods for support type inquiry through isa, cast, and dyn_cast:
312312 static inline bool classof(const Value *V) {
313313 return V->getValueID() >= Value::InstructionVal;
359359 unsigned short getSubclassDataFromValue() const {
360360 return Value::getSubclassDataFromValue();
361361 }
362
362
363363 void setHasMetadataHashEntry(bool V) {
364364 setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) |
365365 (V ? HasMetadataBit : 0));
366366 }
367
367
368368 friend class SymbolTableListTraits;
369369 void setParent(BasicBlock *P);
370370 protected:
371371 // Instruction subclasses can stick up to 15 bits of stuff into the
372372 // SubclassData field of instruction with these members.
373
373
374374 // Verify that only the low 15 bits are used.
375375 void setInstructionSubclassData(unsigned short D) {
376376 assert((D & HasMetadataBit) == 0 && "Out of range value put into field");
377377 setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D);
378378 }
379
379
380380 unsigned getSubclassDataFromInstruction() const {
381381 return getSubclassDataFromValue() & ~HasMetadataBit;
382382 }
383
383
384384 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
385385 Instruction *InsertBefore = 0);
386386 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
387387 BasicBlock *InsertAtEnd);
388388 virtual Instruction *clone_impl() const = 0;
389
389
390390 };
391391
392392 // Instruction* is only 4-byte aligned.
400400 }
401401 enum { NumLowBitsAvailable = 2 };
402402 };
403
403
404404 } // End llvm namespace
405405
406406 #endif
130130 enum {
131131 IsExact = (1 << 0)
132132 };
133
133
134134 private:
135135 friend class BinaryOperator;
136136 friend class ConstantExpr;
137137 void setIsExact(bool B) {
138138 SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
139139 }
140
140
141141 public:
142142 /// isExact - Test whether this division is known to be exact, with
143143 /// zero remainder.
144144 bool isExact() const {
145145 return SubclassOptionalData & IsExact;
146146 }
147
147
148148 static bool isPossiblyExactOpcode(unsigned OpC) {
149149 return OpC == Instruction::SDiv ||
150150 OpC == Instruction::UDiv ||
181181 }
182182 };
183183
184
184
185185 /// ConcreteOperator - A helper template for defining operators for individual
186186 /// opcodes.
187187 template
5151 I != E; ++I) {
5252 Instruction *Inst = I->first;
5353 const std::vector &MDList = I->second;
54
54
5555 for (unsigned i = 0, e = MDList.size(); i != e; ++i) {
5656 unsigned SlotNo = MDList[i].MDSlot;
57
57
5858 if (SlotNo >= NumberedMetadata.size() || NumberedMetadata[SlotNo] == 0)
5959 return Error(MDList[i].Loc, "use of undefined metadata '!" +
6060 Twine(SlotNo) + "'");
6363 }
6464 ForwardRefInstMetadata.clear();
6565 }
66
67
66
67
6868 // If there are entries in ForwardRefBlockAddresses at this point, they are
6969 // references after the function was defined. Resolve those now.
7070 while (!ForwardRefBlockAddresses.empty()) {
7575 TheFn = M->getFunction(Fn.StrVal);
7676 else if (Fn.UIntVal < NumberedVals.size())
7777 TheFn = dyn_cast(NumberedVals[Fn.UIntVal]);
78
78
7979 if (TheFn == 0)
8080 return Error(Fn.Loc, "unknown function referenced by blockaddress");
81
81
8282 // Resolve all these references.
83 if (ResolveForwardRefBlockAddresses(TheFn,
83 if (ResolveForwardRefBlockAddresses(TheFn,
8484 ForwardRefBlockAddresses.begin()->second,
8585 0))
8686 return true;
87
87
8888 ForwardRefBlockAddresses.erase(ForwardRefBlockAddresses.begin());
8989 }
90
90
9191 for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i)
9292 if (NumberedTypes[i].second.isValid())
9393 return Error(NumberedTypes[i].second,
122122 return false;
123123 }
124124
125 bool LLParser::ResolveForwardRefBlockAddresses(Function *TheFn,
125 bool LLParser::ResolveForwardRefBlockAddresses(Function *TheFn,
126126 std::vector > &Refs,
127127 PerFunctionState *PFS) {
128128 // Loop over all the references, resolving them.
140140 Res = dyn_cast_or_null(
141141 TheFn->getValueSymbolTable().lookup(Refs[i].first.StrVal));
142142 }
143
143
144144 if (Res == 0)
145145 return Error(Refs[i].first.Loc,
146146 "referenced value is not a basic block");
147
147
148148 // Get the BlockAddress for this and update references to use it.
149149 BlockAddress *BA = BlockAddress::get(TheFn, Res);
150150 Refs[i].second->replaceAllUsesWith(BA);
301301
302302 if (TypeID >= NumberedTypes.size())
303303 NumberedTypes.resize(TypeID+1);
304
304
305305 Type *Result = 0;
306306 if (ParseStructDefinition(TypeLoc, "",
307307 NumberedTypes[TypeID], Result)) return true;
308
308
309309 if (!isa(Result)) {
310310 std::pair &Entry = NumberedTypes[TypeID];
311311 if (Entry.first)
328328 if (ParseToken(lltok::equal, "expected '=' after name") ||
329329 ParseToken(lltok::kw_type, "expected 'type' after name"))
330330 return true;
331
331
332332 Type *Result = 0;
333333 if (ParseStructDefinition(NameLoc, Name,
334334 NamedTypes[Name], Result)) return true;
335
335
336336 if (!isa(Result)) {
337337 std::pair &Entry = NamedTypes[Name];
338338 if (Entry.first)
340340 Entry.first = Result;
341341 Entry.second = SMLoc();
342342 }
343
343
344344 return false;
345345 }
346346
472472 // Otherwise, create MDNode forward reference.
473473 MDNode *FwdNode = MDNode::getTemporary(Context, ArrayRef());
474474 ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
475
475
476476 if (NumberedMetadata.size() <= MID)
477477 NumberedMetadata.resize(MID+1);
478478 NumberedMetadata[MID] = FwdNode;
497497 do {
498498 if (ParseToken(lltok::exclaim, "Expected '!' here"))
499499 return true;
500
500
501501 MDNode *N = 0;
502502 if (ParseMDNodeID(N)) return true;
503503 NMD->addOperand(N);
529529 return true;
530530
531531 MDNode *Init = MDNode::get(Context, Elts);
532
532
533533 // See if this was forward referenced, if so, handle it.
534534 std::map, LocTy> >::iterator
535535 FI = ForwardRefMDNodes.find(MetadataID);
538538 Temp->replaceAllUsesWith(Init);
539539 MDNode::deleteTemporary(Temp);
540540 ForwardRefMDNodes.erase(FI);
541
541
542542 assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
543543 } else {
544544 if (MetadataID >= NumberedMetadata.size())
12041204 }
12051205
12061206 /// ParseOptionalCommaAlign
1207 /// ::=
1207 /// ::=
12081208 /// ::= ',' align 4
12091209 ///
12101210 /// This returns with AteExtraComma set to true if it ate an excess comma at the
12181218 AteExtraComma = true;
12191219 return false;
12201220 }
1221
1221
12221222 if (Lex.getKind() != lltok::kw_align)
12231223 return Error(Lex.getLoc(), "expected metadata or 'align'");
12241224
12861286 bool LLParser::ParseIndexList(SmallVectorImpl &Indices,
12871287 bool &AteExtraComma) {
12881288 AteExtraComma = false;
1289
1289
12901290 if (Lex.getKind() != lltok::comma)
12911291 return TokError("expected ',' as start of index list");
12921292
13421342 case lltok::LocalVar: {
13431343 // Type ::= %foo
13441344 std::pair &Entry = NamedTypes[Lex.getStrVal()];
1345
1345
13461346 // If the type hasn't been defined yet, create a forward definition and
13471347 // remember where that forward def'n was seen (in case it never is defined).
13481348 if (Entry.first == 0) {
13591359 if (Lex.getUIntVal() >= NumberedTypes.size())
13601360 NumberedTypes.resize(Lex.getUIntVal()+1);
13611361 std::pair &Entry = NumberedTypes[Lex.getUIntVal()];
1362
1362
13631363 // If the type hasn't been defined yet, create a forward definition and
13641364 // remember where that forward def'n was seen (in case it never is defined).
13651365 if (Entry.first == 0) {
15681568 bool LLParser::ParseAnonStructType(Type *&Result, bool Packed) {
15691569 SmallVector Elts;
15701570 if (ParseStructBody(Elts)) return true;
1571
1571
15721572 Result = StructType::get(Context, Elts, Packed);
15731573 return false;
15741574 }
15801580 // If the type was already defined, diagnose the redefinition.
15811581 if (Entry.first && !Entry.second.isValid())
15821582 return Error(TypeLoc, "redefinition of type");
1583
1583
15841584 // If we have opaque, just return without filling in the definition for the
15851585 // struct. This counts as a definition as far as the .ll file goes.
15861586 if (EatIfPresent(lltok::kw_opaque)) {
15871587 // This type is being defined, so clear the location to indicate this.
15881588 Entry.second = SMLoc();
1589
1589
15901590 // If this type number has never been uttered, create it.
15911591 if (Entry.first == 0)
15921592 Entry.first = StructType::create(Context, Name);
15931593 ResultTy = Entry.first;
15941594 return false;
15951595 }
1596
1596
15971597 // If the type starts with '<', then it is either a packed struct or a vector.
15981598 bool isPacked = EatIfPresent(lltok::less);
15991599
16031603 if (Lex.getKind() != lltok::lbrace) {
16041604 if (Entry.first)
16051605 return Error(TypeLoc, "forward references to non-struct type");
1606
1606
16071607 ResultTy = 0;
16081608 if (isPacked)
16091609 return ParseArrayVectorType(ResultTy, true);
16101610 return ParseType(ResultTy);
16111611 }
1612
1612
16131613 // This type is being defined, so clear the location to indicate this.
16141614 Entry.second = SMLoc();
1615
1615
16161616 // If this type number has never been uttered, create it.
16171617 if (Entry.first == 0)
16181618 Entry.first = StructType::create(Context, Name);
1619
1619
16201620 StructType *STy = cast(Entry.first);
1621
1621
16221622 SmallVector Body;
16231623 if (ParseStructBody(Body) ||
16241624 (isPacked && ParseToken(lltok::greater, "expected '>' in packed struct")))
16251625 return true;
1626
1626
16271627 STy->setBody(Body, isPacked);
16281628 ResultTy = STy;
16291629 return false;
17531753 FunctionID.Kind = ValID::t_GlobalID;
17541754 FunctionID.UIntVal = FunctionNumber;
17551755 }
1756
1756
17571757 std::map > >::iterator
17581758 FRBAI = P.ForwardRefBlockAddresses.find(FunctionID);
17591759 if (FRBAI != P.ForwardRefBlockAddresses.end()) {
17601760 // Resolve all these references.
17611761 if (P.ResolveForwardRefBlockAddresses(&F, FRBAI->second, this))
17621762 return true;
1763
1763
17641764 P.ForwardRefBlockAddresses.erase(FRBAI);
17651765 }
17661766 }
1767
1767
17681768 if (!ForwardRefVals.empty())
17691769 return P.Error(ForwardRefVals.begin()->second.second,
17701770 "use of undefined value '%" + ForwardRefVals.begin()->first +
21372137
21382138 ValID Fn, Label;
21392139 LocTy FnLoc, LabelLoc;
2140
2140
21412141 if (ParseToken(lltok::lparen, "expected '(' in block address expression") ||
21422142 ParseValID(Fn) ||
21432143 ParseToken(lltok::comma, "expected comma in block address expression")||
21442144 ParseValID(Label) ||
21452145 ParseToken(lltok::rparen, "expected ')' in block address expression"))
21462146 return true;
2147
2147
21482148 if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
21492149 return Error(Fn.Loc, "expected function name in blockaddress");
21502150 if (Label.Kind != ValID::t_LocalID && Label.Kind != ValID::t_LocalName)
21512151 return Error(Label.Loc, "expected basic block name in blockaddress");
2152
2152
21532153 // Make a global variable as a placeholder for this reference.
21542154 GlobalVariable *FwdRef = new GlobalVariable(*M, Type::getInt8Ty(Context),
21552155 false, GlobalValue::InternalLinkage,
21592159 ID.Kind = ValID::t_Constant;
21602160 return false;
21612161 }
2162
2162
21632163 case lltok::kw_trunc:
21642164 case lltok::kw_zext:
21652165 case lltok::kw_sext:
25392539 return (V == 0);
25402540 case ValID::t_InlineAsm: {
25412541 PointerType *PTy = dyn_cast(Ty);
2542 FunctionType *FTy =
2542 FunctionType *FTy =
25432543 PTy ? dyn_cast(PTy->getElementType()) : 0;
25442544 if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
25452545 return Error(ID.Loc, "invalid type for inline asm constraint string");
26282628 "initializer with struct type has wrong # elements");
26292629 if (ST->isPacked() != (ID.Kind == ValID::t_PackedConstantStruct))
26302630 return Error(ID.Loc, "packed'ness of initializer and type don't match");
2631
2631
26322632 // Verify that the elements are compatible with the structtype.
26332633 for (unsigned i = 0, e = ID.UIntVal; i != e; ++i)
26342634 if (ID.ConstantStructElts[i]->getType() != ST->getElementType(i))
26352635 return Error(ID.Loc, "element " + Twine(i) +
26362636 " of struct initializer doesn't match struct element type");
2637
2637
26382638 V = ConstantStruct::get(ST, makeArrayRef(ID.ConstantStructElts,
26392639 ID.UIntVal));
26402640 } else
28142814 if (Fn->getType() != PFT)
28152815 return Error(FRVI->second.second, "invalid forward reference to "
28162816 "function '" + FunctionName + "' with wrong type!");
2817
2817
28182818 ForwardRefVals.erase(FRVI);
28192819 } else if ((Fn = M->getFunction(FunctionName))) {
28202820 // Reject redefinitions.
28832883
28842884 int FunctionNumber = -1;
28852885 if (!Fn.hasName()) FunctionNumber = NumberedVals.size()-1;
2886
2886
28872887 PerFunctionState PFS(*this, Fn, FunctionNumber);
28882888
28892889 // We need at least one basic block.
28902890 if (Lex.getKind() == lltok::rbrace)
28912891 return TokError("function body requires at least one basic block");
2892
2892
28932893 while (Lex.getKind() != lltok::rbrace)
28942894 if (ParseBasicBlock(PFS)) return true;
28952895
29572957 // *must* be followed by metadata.
29582958 if (ParseInstructionMetadata(Inst, &PFS))
29592959 return true;
2960 break;
2960 break;
29612961 }
29622962
29632963 // Set the name on the instruction.
30003000 bool NUW = EatIfPresent(lltok::kw_nuw);
30013001 bool NSW = EatIfPresent(lltok::kw_nsw);
30023002 if (!NUW) NUW = EatIfPresent(lltok::kw_nuw);
3003
3003
30043004 if (ParseArithmetic(Inst, PFS, KeywordVal, 1)) return true;
3005
3005
30063006 if (NUW) cast(Inst)->setHasNoUnsignedWrap(true);
30073007 if (NSW) cast(Inst)->setHasNoSignedWrap(true);
30083008 return false;
31223122 if (ParseType(Ty, true /*void allowed*/)) return true;
31233123
31243124 Type *ResType = PFS.getFunction().getReturnType();
3125
3125
31263126 if (Ty->isVoidTy()) {
31273127 if (!ResType->isVoidTy())
31283128 return Error(TypeLoc, "value doesn't match function result type '" +
31293129 getTypeString(ResType) + "'");
3130
3130
31313131 Inst = ReturnInst::Create(Context);
31323132 return false;
31333133 }
31383138 if (ResType != RV->getType())
31393139 return Error(TypeLoc, "value doesn't match function result type '" +
31403140 getTypeString(ResType) + "'");
3141
3141
31423142 Inst = ReturnInst::Create(Context, RV);
31433143 return false;
31443144 }
32003200 ParseToken(lltok::comma, "expected ',' after case value") ||
32013201 ParseTypeAndBasicBlock(DestBB, PFS))
32023202 return true;
3203
3203
32043204 if (!SeenCases.insert(Constant))
32053205 return Error(CondLoc, "duplicate case value in switch");
32063206 if (!isa(Constant))
32283228 ParseToken(lltok::comma, "expected ',' after indirectbr address") ||
32293229 ParseToken(lltok::lsquare, "expected '[' with indirectbr"))
32303230 return true;
3231
3231
32323232 if (!Address->getType()->isPointerTy())
32333233 return Error(AddrLoc, "indirectbr address must have pointer type");
3234
3234
32353235 // Parse the destination list.
32363236 SmallVector DestList;
3237
3237
32383238 if (Lex.getKind() != lltok::rsquare) {
32393239 BasicBlock *DestBB;
32403240 if (ParseTypeAndBasicBlock(DestBB, PFS))
32413241 return true;
32423242 DestList.push_back(DestBB);
3243
3243
32443244 while (EatIfPresent(lltok::comma)) {
32453245 if (ParseTypeAndBasicBlock(DestBB, PFS))
32463246 return true;
32473247 DestList.push_back(DestBB);
32483248 }
32493249 }
3250
3250
32513251 if (ParseToken(lltok::rsquare, "expected ']' at end of block list"))
32523252 return true;
32533253
37943794
37953795 /// ParseLoad
37963796 /// ::= 'load' 'volatile'? TypeAndValue (',' 'align' i32)?
3797 /// ::= 'load' 'atomic' 'volatile'? TypeAndValue
3797 /// ::= 'load' 'atomic' 'volatile'? TypeAndValue
37983798 /// 'singlethread'? AtomicOrdering (',' 'align' i32)?
37993799 int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
38003800 Value *Val; LocTy Loc;
40684068 ParseTypeAndValue(Val1, Loc1, PFS) ||
40694069 ParseIndexList(Indices, AteExtraComma))
40704070 return true;
4071
4071
40724072 if (!Val0->getType()->isAggregateType())
40734073 return Error(Loc0, "insertvalue operand must be aggregate type");
40744074
40984098 Elts.push_back(0);
40994099 continue;
41004100 }
4101
4101
41024102 Value *V = 0;
41034103 if (ParseTypeAndValue(V, PFS)) return true;
41044104 Elts.push_back(V);
5454 t_ConstantStruct, // Value in ConstantStructElts.
5555 t_PackedConstantStruct // Value in ConstantStructElts.
5656 } Kind;
57
57
5858 LLLexer::LocTy Loc;
5959 unsigned UIntVal;
6060 std::string StrVal, StrVal2;
6464 MDNode *MDNodeVal;
6565 MDString *MDStringVal;
6666 Constant **ConstantStructElts;
67
67
6868 ValID() : Kind(t_LocalID), APFloatVal(0.0) {}
6969 ~ValID() {
7070 if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct)
7171 delete [] ConstantStructElts;
7272 }
73
73
7474 bool operator<(const ValID &RHS) const {
7575 if (Kind == t_LocalID || Kind == t_GlobalID)
7676 return UIntVal < RHS.UIntVal;
7777 assert((Kind == t_LocalName || Kind == t_GlobalName ||
78 Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
78 Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
7979 "Ordering not defined for this ValID kind yet");
8080 return StrVal < RHS.StrVal;
8181 }
8282 };
83
83
8484 class LLParser {
8585 public:
8686 typedef LLLexer::LocTy LocTy;
8888 LLVMContext &Context;
8989 LLLexer Lex;
9090 Module *M;
91
91
9292 // Instruction metadata resolution. Each instruction can have a list of
9393 // MDRef info associated with them.
9494 //
109109 // have processed a use of the type but not a definition yet.
110110 StringMap > NamedTypes;
111111 std::vector > NumberedTypes;
112
112
113113 std::vector > NumberedMetadata;
114114 std::map, LocTy> > ForwardRefMDNodes;
115115
117117 std::map > ForwardRefVals;
118118 std::map > ForwardRefValIDs;
119119 std::vector NumberedVals;
120
120
121121 // References to blockaddress. The key is the function ValID, the value is
122122 // a list of references to blocks in that function.
123123 std::map > >
124124 ForwardRefBlockAddresses;
125
125
126126 public:
127 LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
127 LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
128128 Context(m->getContext()), Lex(F, SM, Err, m->getContext()),
129129 M(m) {}
130130 bool Run();
240240 std::map > ForwardRefVals;
241241 std::map > ForwardRefValIDs;
242242 std::vector NumberedVals;
243
243
244244 /// FunctionNumber - If this is an unnamed function, this is the slot
245245 /// number of it, otherwise it is -1.
246246 int FunctionNumber;
374374 int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
375375 int ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
376376 int ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
377
378 bool ResolveForwardRefBlockAddresses(Function *TheFn,
377
378 bool ResolveForwardRefBlockAddresses(Function *TheFn,
379379 std::vector > &Refs,
380380 PerFunctionState *PFS);
381381 };
606606 else
607607 break;
608608 }
609
609
610610 ResultTy = getTypeByID(Record[2]);
611611 if (ResultTy == 0 || ArgTys.size() < Record.size()-3)
612612 return Error("invalid type in function type");
625625 else
626626 break;
627627 }
628
628
629629 ResultTy = getTypeByID(Record[1]);
630630 if (ResultTy == 0 || ArgTys.size() < Record.size()-2)
631631 return Error("invalid type in function type");
656656 case bitc::TYPE_CODE_STRUCT_NAMED: { // STRUCT: [ispacked, eltty x N]
657657 if (Record.size() < 1)
658658 return Error("Invalid STRUCT type record");
659
659
660660 if (NumRecords >= TypeList.size())
661661 return Error("invalid TYPE table");
662
662
663663 // Check to see if this was forward referenced, if so fill in the temp.
664664 StructType *Res = cast_or_null(TypeList[NumRecords]);
665665 if (Res) {
668668 } else // Otherwise, create a new struct.
669669 Res = StructType::create(Context, TypeName);
670670 TypeName.clear();
671
671
672672 SmallVector EltTys;
673673 for (unsigned i = 1, e = Record.size(); i != e; ++i) {
674674 if (Type *T = getTypeByID(Record[i]))
688688
689689 if (NumRecords >= TypeList.size())
690690 return Error("invalid TYPE table");
691
691
692692 // Check to see if this was forward referenced, if so fill in the temp.
693693 StructType *Res = cast_or_null(TypeList[NumRecords]);
694694 if (Res) {
699699 TypeName.clear();
700700 ResultTy = Res;
701701 break;
702 }
702 }
703703 case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
704704 if (Record.size() < 2)
705705 return Error("Invalid ARRAY type record");
10051005 APInt VInt = ReadWideAPInt(Record,
10061006 cast(CurTy)->getBitWidth());
10071007 V = ConstantInt::get(Context, VInt);
1008
1008
10091009 break;
10101010 }
10111011 case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
10721072 case bitc::CST_CODE_DATA: {// DATA: [n x value]
10731073 if (Record.empty())
10741074 return Error("Invalid CST_DATA record");
1075
1075
10761076 Type *EltTy = cast(CurTy)->getElementType();
10771077 unsigned Size = Record.size();
1078
1078
10791079 if (EltTy->isIntegerTy(8)) {
10801080 SmallVector Elts(Record.begin(), Record.end());
10811081 if (isa(CurTy))
13231323 V = FwdRef;
13241324 }
13251325 break;
1326 }
1326 }
13271327 }
13281328
13291329 ValueList.AssignValue(V, NextCstNo);
13471347 return Error("Malformed block record");
13481348
13491349 SmallVector Record;
1350
1350
13511351 // Read all the records.
13521352 while (1) {
13531353 unsigned Code = Stream.ReadCode();
13561356 return Error("Error at end of use-list table block");
13571357 return false;
13581358 }
1359
1359
13601360 if (Code == bitc::ENTER_SUBBLOCK) {
13611361 // No known subblocks, always skip them.
13621362 Stream.ReadSubBlockID();
13641364 return Error("Malformed block record");
13651365 continue;
13661366 }
1367
1367
13681368 if (Code == bitc::DEFINE_ABBREV) {
13691369 Stream.ReadAbbrevRecord();
13701370 continue;
13711371 }
1372
1372
13731373 // Read a use list record.
13741374 Record.clear();
13751375 switch (Stream.ReadRecord(Code, Record)) {
19181918 unsigned CurBBNo = 0;
19191919
19201920 DebugLoc LastLoc;
1921
1921
19221922 // Read all the records.
19231923 SmallVector Record;
19241924 while (1) {
19731973 FunctionBBs[i] = BasicBlock::Create(Context, "", F);
19741974 CurBB = FunctionBBs[0];
19751975 continue;
1976
1976
19771977 case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: // DEBUG_LOC_AGAIN
19781978 // This record indicates that the last instruction is at the same
19791979 // location as the previous instruction with a location.
19801980 I = 0;
1981
1981
19821982 // Get the last instruction emitted.
19831983 if (CurBB && !CurBB->empty())
19841984 I = &CurBB->back();
19851985 else if (CurBBNo && FunctionBBs[CurBBNo-1] &&
19861986 !FunctionBBs[CurBBNo-1]->empty())
19871987 I = &FunctionBBs[CurBBNo-1]->back();
1988
1988
19891989 if (I == 0) return Error("Invalid DEBUG_LOC_AGAIN record");
19901990 I->setDebugLoc(LastLoc);
19911991 I = 0;
19921992 continue;
1993
1993
19941994 case bitc::FUNC_CODE_DEBUG_LOC: { // DEBUG_LOC: [line, col, scope, ia]
19951995 I = 0; // Get the last instruction emitted.
19961996 if (CurBB && !CurBB->empty())
20002000 I = &FunctionBBs[CurBBNo-1]->back();
20012001 if (I == 0 || Record.size() < 4)
20022002 return Error("Invalid FUNC_CODE_DEBUG_LOC record");
2003
2003
20042004 unsigned Line = Record[0], Col = Record[1];
20052005 unsigned ScopeID = Record[2], IAID = Record[3];
2006
2006
20072007 MDNode *Scope = 0, *IA = 0;
20082008 if (ScopeID) Scope = cast(MDValueList.getValueFwdRef(ScopeID-1));
20092009 if (IAID) IA = cast(MDValueList.getValueFwdRef(IAID-1));
22712271 break;
22722272 }
22732273 case bitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, op0, op1, ...]
2274 // Check magic
2274 // Check magic
22752275 if ((Record[0] >> 16) == SWITCH_INST_MAGIC) {
22762276 // New SwitchInst format with case ranges.
2277
2277
22782278 Type *OpTy = getTypeByID(Record[1]);
22792279 unsigned ValueBitWidth = cast(OpTy)->getBitWidth();
22802280
22842284 return Error("Invalid SWITCH record");
22852285
22862286 unsigned NumCases = Record[4];
2287
2287
22882288 SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
22892289 InstructionList.push_back(SI);
2290
2290
22912291 unsigned CurIdx = 5;
22922292 for (unsigned i = 0; i != NumCases; ++i) {
22932293 IntegersSubsetToBB CaseBuilder;
22942294 unsigned NumItems = Record[CurIdx++];
22952295 for (unsigned ci = 0; ci != NumItems; ++ci) {
22962296 bool isSingleNumber = Record[CurIdx++];
2297
2297
22982298 APInt Low;
22992299 unsigned ActiveWords = 1;
23002300 if (ValueBitWidth > 64)
23102310 APInt High =
23112311 ReadWideAPInt(makeArrayRef(&Record[CurIdx], ActiveWords),
23122312 ValueBitWidth);
2313
2313
23142314 CaseBuilder.add(IntItem::fromType(OpTy, Low),
23152315 IntItem::fromType(OpTy, High));
23162316 CurIdx += ActiveWords;
23182318 CaseBuilder.add(IntItem::fromType(OpTy, Low));
23192319 }
23202320 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]);
2321 IntegersSubset Case = CaseBuilder.getCase();
2321 IntegersSubset Case = CaseBuilder.getCase();
23222322 SI->addCase(Case, DestBB);
23232323 }
23242324 uint16_t Hash = SI->hash();
23272327 I = SI;
23282328 break;
23292329 }
2330
2330
23312331 // Old SwitchInst format without case ranges.
2332
2332
23332333 if (Record.size() < 3 || (Record.size() & 1) == 0)
23342334 return Error("Invalid SWITCH record");
23352335 Type *OpTy = getTypeByID(Record[0]);
23742374 I = IBI;
23752375 break;
23762376 }
2377
2377
23782378 case bitc::FUNC_CODE_INST_INVOKE: {
23792379 // INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
23802380 if (Record.size() < 4) return Error("Invalid INVOKE record");
25332533 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
25342534 OpNum+4 != Record.size())
25352535 return Error("Invalid LOADATOMIC record");
2536
2536
25372537
25382538 AtomicOrdering Ordering = GetDecodedOrdering(Record[OpNum+2]);
25392539 if (Ordering == NotAtomic || Ordering == Release ||
27492749 unsigned BlockIdx = RefList[i].first;
27502750 if (BlockIdx >= FunctionBBs.size())
27512751 return Error("Invalid blockaddress block #");
2752
2752
27532753 GlobalVariable *FwdRef = RefList[i].second;
27542754 FwdRef->replaceAllUsesWith(BlockAddress::get(F, FunctionBBs[BlockIdx]));
27552755 FwdRef->eraseFromParent();
27562756 }
2757
2757
27582758 BlockAddrFwdRefs.erase(BAFRI);
27592759 }
2760
2760
27612761 // Trim the value list down to the size it was before we parsed this function.
27622762 ValueList.shrinkTo(ModuleValueListSize);
27632763 MDValueList.shrinkTo(ModuleMDValueListSize);
6060 FUNCTION_INST_RET_VOID_ABBREV,
6161 FUNCTION_INST_RET_VAL_ABBREV,
6262 FUNCTION_INST_UNREACHABLE_ABBREV,
63
63
6464 // SwitchInst Magic
6565 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex
6666 };
233233 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
234234
235235 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv);
236
236
237237 // Abbrev for TYPE_CODE_ARRAY.
238238 Abbv = new BitCodeAbbrev();
239239 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
299299 for (StructType::element_iterator I = ST->element_begin(),
300300 E = ST->element_end(); I != E; ++I)
301301 TypeVals.push_back(VE.getTypeID(*I));
302
302
303303 if (ST->isLiteral()) {
304304 Code = bitc::TYPE_CODE_STRUCT_ANON;
305305 AbbrevToUse = StructAnonAbbrev;
657657 }
658658 WriteMDNode(N, VE, Stream, Record);
659659 }
660
660
661661 if (StartedMetadataBlock)
662662 Stream.ExitBlock();
663663 }
672672 // Write metadata attachments
673673 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
674674 SmallVector, 4> MDs;
675
675
676676 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
677677 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
678678 I != E; ++I) {
679679 MDs.clear();
680680 I->getAllMetadataOtherThanDebugLoc(MDs);
681
681
682682 // If no metadata, ignore instruction.
683683 if (MDs.empty()) continue;
684684
685685 Record.push_back(VE.getInstructionID(I));
686
686
687687 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
688688 Record.push_back(MDs[i].first);
689689 Record.push_back(VE.getValueID(MDs[i].second));
702702 // METADATA_KIND - [n x [id, name]]
703703 SmallVector Names;
704704 M->getMDKindNames(Names);
705
705
706706 if (Names.empty()) return;
707707
708708 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
709
709
710710 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
711711 Record.push_back(MDKindID);
712712 StringRef KName = Names[MDKindID];
713713 Record.append(KName.begin(), KName.end());
714
714
715715 Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
716716 Record.clear();
717717 }
742742 // format it is likely that the high bits are going to be zero.
743743 // So, we only write the number of active words.
744744 unsigned NWords = Val.getActiveWords();
745
745
746746 if (EmitSizeForWideNumbers)
747747 Vals.push_back(NWords);
748
748
749749 const uint64_t *RawWords = Val.getRawData();
750750 for (unsigned i = 0; i != NWords; ++i) {
751751 emitSignedInt64(Vals, RawWords[i]);
880880 if (isCStrChar6)
881881 isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
882882 }
883
883
884884 if (isCStrChar6)
885885 AbbrevToUse = CString6Abbrev;
886886 else if (isCStr7)
887887 AbbrevToUse = CString7Abbrev;
888 } else if (const ConstantDataSequential *CDS =
888 } else if (const ConstantDataSequential *CDS =
889889 dyn_cast(C)) {
890890 Code = bitc::CST_CODE_DATA;
891891 Type *EltTy = CDS->getType()->getElementType();
11781178 // Redefine Vals, since here we need to use 64 bit values
11791179 // explicitly to store large APInt numbers.
11801180 SmallVector Vals64;
1181
1181
11821182 Code = bitc::FUNC_CODE_INST_SWITCH;
11831183 SwitchInst &SI = cast(I);
1184
1185 uint32_t SwitchRecordHeader = SI.hash() | (SWITCH_INST_MAGIC << 16);
1186 Vals64.push_back(SwitchRecordHeader);
1187
1184
1185 uint32_t SwitchRecordHeader = SI.hash() | (SWITCH_INST_MAGIC << 16);
1186 Vals64.push_back(SwitchRecordHeader);
1187
11881188 Vals64.push_back(VE.getTypeID(SI.getCondition()->getType()));
11891189 pushValue64(SI.getCondition(), InstID, Vals64, VE);
11901190 Vals64.push_back(VE.getValueID(SI.getDefaultDest()));
11931193 i != e; ++i) {
11941194 IntegersSubset& CaseRanges = i.getCaseValueEx();
11951195 unsigned Code, Abbrev; // will unused.
1196
1196
11971197 if (CaseRanges.isSingleNumber()) {
11981198 Vals64.push_back(1/*NumItems = 1*/);
11991199 Vals64.push_back(true/*IsSingleNumber = true*/);
12001200 EmitAPInt(Vals64, Code, Abbrev, CaseRanges.getSingleNumber(0), true);
12011201 } else {
1202
1202
12031203 Vals64.push_back(CaseRanges.getNumItems());
1204
1204
12051205 if (CaseRanges.isSingleNumbersOnly()) {
12061206 for (unsigned ri = 0, rn = CaseRanges.getNumItems();
12071207 ri != rn; ++ri) {
1208
1208
12091209 Vals64.push_back(true/*IsSingleNumber = true*/);
1210
1210
12111211 EmitAPInt(Vals64, Code, Abbrev,
12121212 CaseRanges.getSingleNumber(ri), true);
12131213 }
12161216 ri != rn; ++ri) {
12171217 IntegersSubset::Range r = CaseRanges.getItem(ri);
12181218 bool IsSingleNumber = CaseRanges.isSingleNumber(ri);
1219
1219
12201220 Vals64.push_back(IsSingleNumber);
1221
1221
12221222 EmitAPInt(Vals64, Code, Abbrev, r.getLow(), true);
12231223 if (!IsSingleNumber)
12241224 EmitAPInt(Vals64, Code, Abbrev, r.getHigh(), true);
12261226 }
12271227 Vals64.push_back(VE.getValueID(i.getCaseSuccessor()));
12281228 }
1229
1229
12301230 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
1231
1231
12321232 // Also do expected action - clear external Vals collection:
12331233 Vals.clear();
12341234 return;
12421242 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i)
12431243 Vals.push_back(VE.getValueID(I.getOperand(i)));
12441244 break;
1245
1245
12461246 case Instruction::Invoke: {
12471247 const InvokeInst *II = cast(&I);
12481248 const Value *Callee(II->getCalledValue());
15011501 unsigned InstID = CstEnd;
15021502
15031503 bool NeedsMetadataAttachment = false;
1504
1504
15051505 DebugLoc LastDL;
1506
1506
15071507 // Finally, emit all the instructions, in order.
15081508 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
15091509 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
15101510 I != E; ++I) {
15111511 WriteInstruction(*I, InstID, VE, Stream, Vals);
1512
1512
15131513 if (!I->getType()->isVoidTy())
15141514 ++InstID;
1515
1515
15161516 // If the instruction has metadata, write a metadata attachment later.
15171517 NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
1518
1518
15191519 // If the instruction has a debug location, emit it.
15201520 DebugLoc DL = I->getDebugLoc();
15211521 if (DL.isUnknown()) {
15261526 } else {
15271527 MDNode *Scope, *IA;
15281528 DL.getScopeAndInlinedAt(Scope, IA, I->getContext());
1529
1529
15301530 Vals.push_back(DL.getLine());
15311531 Vals.push_back(DL.getCol());
15321532 Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
15331533 Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
15341534 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
15351535 Vals.clear();
1536
1536
15371537 LastDL = DL;
15381538 }
15391539 }
17081708 Stream.ExitBlock();
17091709 }
17101710
1711 // Sort the Users based on the order in which the reader parses the bitcode
1711 // Sort the Users based on the order in which the reader parses the bitcode
17121712 // file.
17131713 static bool bitcodereader_order(const User *lhs, const User *rhs) {
17141714 // TODO: Implement.
17771777 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
17781778 I != E; ++I)
17791779 I->removeDeadConstantUsers();
1780
1780
17811781 // Write the global variables.
1782 for (Module::const_global_iterator GI = M->global_begin(),
1782 for (Module::const_global_iterator GI = M->global_begin(),
17831783 GE = M->global_end(); GI != GE; ++GI) {
17841784 WriteUseList(GI, VE, Stream);
17851785
8383 default: Out << "cc" << cc; break;
8484 }
8585 }
86
86
8787 // PrintEscapedString - Print each character of the specified string, escaping
8888 // it if it is not printable or if it is an escape char.
8989 static void PrintEscapedString(StringRef Name, raw_ostream &Out) {
877877 Out << ']';
878878 return;
879879 }
880
880
881881 if (const ConstantDataArray *CA = dyn_cast(CV)) {
882882 // As a special case, print the array as a string if it is an array of
883883 // i8 with ConstantInt values.
433433 New->SubclassOptionalData = SubclassOptionalData;
434434 if (!hasMetadata())
435435 return New;
436
436
437437 // Otherwise, enumerate and copy over metadata from the old instruction to the
438438 // new one.
439439 SmallVector, 4> TheMDs;
440440 getAllMetadataOtherThanDebugLoc(TheMDs);
441441 for (unsigned i = 0, e = TheMDs.size(); i != e; ++i)
442442 New->setMetadata(TheMDs[i].first, TheMDs[i].second);
443
443
444444 New->setDebugLoc(getDebugLoc());
445445 return New;
446446 }