llvm.org GIT mirror llvm / 837e04a
bitcode writer support for blockaddress. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85376 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
4 changed file(s) with 54 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
137137 CST_CODE_CE_CMP = 17, // CE_CMP: [opty, opval, opval, pred]
138138 CST_CODE_INLINEASM = 18, // INLINEASM: [sideeffect,asmstr,conststr]
139139 CST_CODE_CE_SHUFVEC_EX = 19, // SHUFVEC_EX: [opty, opval, opval, opval]
140 CST_CODE_CE_INBOUNDS_GEP = 20 // INBOUNDS_GEP: [n x operands]
140 CST_CODE_CE_INBOUNDS_GEP = 20,// INBOUNDS_GEP: [n x operands]
141 CST_CODE_BLOCKADDRESS = 21 // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#]
141142 };
142143
143144 /// CastOpcodes - These are values used in the bitcode files to encode which
852852 Record.push_back(CE->getPredicate());
853853 break;
854854 }
855 } else if (const BlockAddress *BA = dyn_cast(C)) {
856 assert(BA->getFunction() == BA->getBasicBlock()->getParent() &&
857 "Malformed blockaddress");
858 Code = bitc::CST_CODE_BLOCKADDRESS;
859 Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
860 Record.push_back(VE.getValueID(BA->getFunction()));
861 Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
855862 } else {
856863 llvm_unreachable("Unknown constant!");
857864 }
222222 EnumerateType(Type::getVoidTy(MD->getContext()));
223223 }
224224 return;
225 } else if (const NamedMDNode *N = dyn_cast(MD)) {
225 }
226
227 if (const NamedMDNode *N = dyn_cast(MD)) {
226228 for(NamedMDNode::const_elem_iterator I = N->elem_begin(),
227229 E = N->elem_end(); I != E; ++I) {
228230 MetadataBase *M = *I;
273275 // graph that don't go through a global variable.
274276 for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
275277 I != E; ++I)
276 EnumerateValue(*I);
278 if (!isa(*I)) // Don't enumerate BB operand to BlockAddress.
279 EnumerateValue(*I);
277280
278281 // Finally, add the value. Doing this could make the ValueID reference be
279282 // dangling, don't reuse it.
319322
320323 // This constant may have operands, make sure to enumerate the types in
321324 // them.
322 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
323 EnumerateOperandType(C->getOperand(i));
325 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
326 const User *Op = C->getOperand(i);
327
328 // Don't enumerate basic blocks here, this happens as operands to
329 // blockaddress.
330 if (isa(Op)) continue;
331
332 EnumerateOperandType(cast(Op));
333 }
324334
325335 if (const MDNode *N = dyn_cast(V)) {
326 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
327 Value *Elem = N->getElement(i);
328 if (Elem)
336 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
337 if (Value *Elem = N->getElement(i))
329338 EnumerateOperandType(Elem);
330 }
331339 }
332340 } else if (isa(V) || isa(V))
333341 EnumerateValue(V);
396404 Values.resize(NumModuleValues);
397405 BasicBlocks.clear();
398406 }
407
408 static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
409 DenseMap &IDMap) {
410 unsigned Counter = 0;
411 for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
412 IDMap[BB] = ++Counter;
413 }
414
415 /// getGlobalBasicBlockID - This returns the function-specific ID for the
416 /// specified basic block. This is relatively expensive information, so it
417 /// should only be used by rare constructs such as address-of-label.
418 unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
419 unsigned &Idx = GlobalBasicBlockIDs[BB];
420 if (Idx != 0)
421 return Idx-1;
422
423 IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
424 return getGlobalBasicBlockID(BB);
425 }
426
5252 AttributeMapType AttributeMap;
5353 std::vector Attributes;
5454
55 /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
56 /// the "getGlobalBasicBlockID" method.
57 mutable DenseMap GlobalBasicBlockIDs;
58
5559 typedef DenseMap InstructionMapType;
5660 InstructionMapType InstructionMap;
5761 unsigned InstructionCount;
105109 const std::vector &getAttributes() const {
106110 return Attributes;
107111 }
112
113 /// getGlobalBasicBlockID - This returns the function-specific ID for the
114 /// specified basic block. This is relatively expensive information, so it
115 /// should only be used by rare constructs such as address-of-label.
116 unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
108117
109118 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
110119 /// use these two methods to get its data into the ValueEnumerator!