X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FAsmWriter.cpp;h=b4d7a660688da9ea90becb7930c2167ce2b40175;hb=ee97a1a33b2cb1173e0b4c601ed5976e56654063;hp=bc9b00e7de14ae3aac6666da99b6f7c183b28c27;hpb=d034925a3423deda6aa3c99aeeca7b9d749ba885;p=oota-llvm.git diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index bc9b00e7de1..b4d7a660688 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -319,6 +319,8 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) { case CallingConv::X86_64_Win64: Out << "x86_64_win64cc"; break; case CallingConv::SPIR_FUNC: Out << "spir_func"; break; case CallingConv::SPIR_KERNEL: Out << "spir_kernel"; break; + case CallingConv::HHVM: Out << "hhvmcc"; break; + case CallingConv::HHVM_C: Out << "hhvm_ccc"; break; } } @@ -708,10 +710,6 @@ int ModuleSlotTracker::getLocalSlot(const Value *V) { return Machine->getLocalSlot(V); } -static SlotTracker *createSlotTracker(const Module *M) { - return new SlotTracker(M); -} - static SlotTracker *createSlotTracker(const Value *V) { if (const Argument *FA = dyn_cast(V)) return new SlotTracker(FA->getParent()); @@ -811,6 +809,10 @@ void SlotTracker::processFunction() { ST_DEBUG("begin processFunction!\n"); fNext = 0; + // Process function metadata if it wasn't hit at the module-level. + if (!ShouldInitializeAllMetadata) + processFunctionMetadata(*TheFunction); + // Add all the function arguments with no names. for(Function::const_arg_iterator AI = TheFunction->arg_begin(), AE = TheFunction->arg_end(); AI != AE; ++AI) @@ -824,8 +826,6 @@ void SlotTracker::processFunction() { if (!BB.hasName()) CreateFunctionSlot(&BB); - processFunctionMetadata(*TheFunction); - for (auto &I : BB) { if (!I.getType()->isVoidTy() && !I.hasName()) CreateFunctionSlot(&I); @@ -853,11 +853,11 @@ void SlotTracker::processFunction() { void SlotTracker::processFunctionMetadata(const Function &F) { SmallVector, 4> MDs; - for (auto &BB : F) { - F.getAllMetadata(MDs); - for (auto &MD : MDs) - CreateMetadataSlot(MD.second); + F.getAllMetadata(MDs); + for (auto &MD : MDs) + CreateMetadataSlot(MD.second); + for (auto &BB : F) { for (auto &I : BB) processInstructionMetadata(I); } @@ -2007,6 +2007,7 @@ class AssemblyWriter { TypePrinting TypePrinter; AssemblyAnnotationWriter *AnnotationWriter; SetVector Comdats; + bool IsForDebug; bool ShouldPreserveUseListOrder; UseListOrderStack UseListOrders; SmallVector MDNames; @@ -2014,12 +2015,7 @@ class AssemblyWriter { public: /// Construct an AssemblyWriter with an external SlotTracker AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, const Module *M, - AssemblyAnnotationWriter *AAW, - bool ShouldPreserveUseListOrder = false); - - /// Construct an AssemblyWriter with an internally allocated SlotTracker - AssemblyWriter(formatted_raw_ostream &o, const Module *M, - AssemblyAnnotationWriter *AAW, + AssemblyAnnotationWriter *AAW, bool IsForDebug, bool ShouldPreserveUseListOrder = false); void printMDNodeBody(const MDNode *MD); @@ -2029,6 +2025,7 @@ public: void writeOperand(const Value *Op, bool PrintType); void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx); + void writeOperandBundles(ImmutableCallSite CS); void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope); void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, @@ -2052,8 +2049,6 @@ public: void printUseLists(const Function *F); private: - void init(); - /// \brief Print out metadata attachments. void printMetadataAttachments( const SmallVectorImpl> &MDs, @@ -2069,7 +2064,12 @@ private: }; } // namespace -void AssemblyWriter::init() { +AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, + const Module *M, AssemblyAnnotationWriter *AAW, + bool IsForDebug, bool ShouldPreserveUseListOrder) + : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW), + IsForDebug(IsForDebug), + ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { if (!TheModule) return; TypePrinter.incorporateTypes(*TheModule); @@ -2081,23 +2081,6 @@ void AssemblyWriter::init() { Comdats.insert(C); } -AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, - const Module *M, AssemblyAnnotationWriter *AAW, - bool ShouldPreserveUseListOrder) - : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW), - ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { - init(); -} - -AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, const Module *M, - AssemblyAnnotationWriter *AAW, - bool ShouldPreserveUseListOrder) - : Out(o), TheModule(M), SlotTrackerStorage(createSlotTracker(M)), - Machine(*SlotTrackerStorage), AnnotationWriter(AAW), - ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { - init(); -} - void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) { if (!Operand) { Out << ""; @@ -2179,6 +2162,43 @@ void AssemblyWriter::writeParamOperand(const Value *Operand, WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule); } +void AssemblyWriter::writeOperandBundles(ImmutableCallSite CS) { + if (!CS.hasOperandBundles()) + return; + + Out << " [ "; + + bool FirstBundle = true; + for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) { + OperandBundleUse BU = CS.getOperandBundle(i); + + if (!FirstBundle) + Out << ", "; + FirstBundle = false; + + Out << '"'; + PrintEscapedString(BU.Tag, Out); + Out << '"'; + + Out << '('; + + bool FirstInput = true; + for (const auto &Input : BU.Inputs) { + if (!FirstInput) + Out << ", "; + FirstInput = false; + + TypePrinter.print(Input->getType(), Out); + Out << " "; + WriteAsOperandInternal(Out, Input, &TypePrinter, &Machine, TheModule); + } + + Out << ')'; + } + + Out << " ]"; +} + void AssemblyWriter::printModule(const Module *M) { Machine.initialize(); @@ -2431,6 +2451,10 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { Out << "alias "; + TypePrinter.print(GA->getValueType(), Out); + + Out << ", "; + const Constant *Aliasee = GA->getAliasee(); if (!Aliasee) { @@ -2545,7 +2569,7 @@ void AssemblyWriter::printFunction(const Function *F) { Machine.incorporateFunction(F); // Loop over the arguments, printing them... - if (F->isDeclaration()) { + if (F->isDeclaration() && !IsForDebug) { // We're only interested in the type here - don't print argument names. for (unsigned I = 0, E = FT->getNumParams(); I != E; ++I) { // Insert commas as we go... the first arg doesn't get a comma @@ -2865,7 +2889,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << ", "; writeOperand(CPI->getArgOperand(Op), /*PrintType=*/true); } - Out << "] to "; + Out << "]\n to "; writeOperand(CPI->getNormalDest(), /*PrintType=*/true); Out << " unwind "; writeOperand(CPI->getUnwindDest(), /*PrintType=*/true); @@ -2908,6 +2932,15 @@ void AssemblyWriter::printInstruction(const Instruction &I) { else Out << "to caller"; } else if (const auto *CEPI = dyn_cast(&I)) { + Out << " unwind "; + if (CEPI->hasUnwindDest()) + writeOperand(CEPI->getUnwindDest(), /*PrintType=*/true); + else + Out << "to caller"; + } else if (const auto *CEPI = dyn_cast(&I)) { + Out << ' '; + writeOperand(CEPI->getCleanupPad(), /*PrintType=*/false); + Out << " unwind "; if (CEPI->hasUnwindDest()) writeOperand(CEPI->getUnwindDest(), /*PrintType=*/true); @@ -2953,6 +2986,9 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << ')'; if (PAL.hasAttributes(AttributeSet::FunctionIndex)) Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes()); + + writeOperandBundles(CI); + } else if (const InvokeInst *II = dyn_cast(&I)) { Operand = II->getCalledValue(); FunctionType *FTy = cast(II->getFunctionType()); @@ -2987,6 +3023,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) { if (PAL.hasAttributes(AttributeSet::FunctionIndex)) Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes()); + writeOperandBundles(II); + Out << "\n to "; writeOperand(II->getNormalDest(), true); Out << " unwind "; @@ -3200,21 +3238,22 @@ void AssemblyWriter::printUseLists(const Function *F) { //===----------------------------------------------------------------------===// void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW, - bool ShouldPreserveUseListOrder) const { + bool ShouldPreserveUseListOrder, bool IsForDebug) const { SlotTracker SlotTable(this); formatted_raw_ostream OS(ROS); - AssemblyWriter W(OS, SlotTable, this, AAW, ShouldPreserveUseListOrder); + AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug, + ShouldPreserveUseListOrder); W.printModule(this); } -void NamedMDNode::print(raw_ostream &ROS) const { +void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const { SlotTracker SlotTable(getParent()); formatted_raw_ostream OS(ROS); - AssemblyWriter W(OS, SlotTable, getParent(), nullptr); + AssemblyWriter W(OS, SlotTable, getParent(), nullptr, IsForDebug); W.printNamedMDNode(this); } -void Comdat::print(raw_ostream &ROS) const { +void Comdat::print(raw_ostream &ROS, bool /*IsForDebug*/) const { PrintLLVMName(ROS, getName(), ComdatPrefix); ROS << " = comdat "; @@ -3239,7 +3278,7 @@ void Comdat::print(raw_ostream &ROS) const { ROS << '\n'; } -void Type::print(raw_ostream &OS) const { +void Type::print(raw_ostream &OS, bool /*IsForDebug*/) const { TypePrinting TP; TP.print(const_cast(this), OS); @@ -3262,7 +3301,7 @@ static bool isReferencingMDNode(const Instruction &I) { return false; } -void Value::print(raw_ostream &ROS) const { +void Value::print(raw_ostream &ROS, bool IsForDebug) const { bool ShouldInitializeAllMetadata = false; if (auto *I = dyn_cast(this)) ShouldInitializeAllMetadata = isReferencingMDNode(*I); @@ -3270,10 +3309,11 @@ void Value::print(raw_ostream &ROS) const { ShouldInitializeAllMetadata = true; ModuleSlotTracker MST(getModuleFromVal(this), ShouldInitializeAllMetadata); - print(ROS, MST); + print(ROS, MST, IsForDebug); } -void Value::print(raw_ostream &ROS, ModuleSlotTracker &MST) const { +void Value::print(raw_ostream &ROS, ModuleSlotTracker &MST, + bool IsForDebug) const { formatted_raw_ostream OS(ROS); SlotTracker EmptySlotTable(static_cast(nullptr)); SlotTracker &SlotTable = @@ -3285,14 +3325,14 @@ void Value::print(raw_ostream &ROS, ModuleSlotTracker &MST) const { if (const Instruction *I = dyn_cast(this)) { incorporateFunction(I->getParent() ? I->getParent()->getParent() : nullptr); - AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), nullptr); + AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), nullptr, IsForDebug); W.printInstruction(*I); } else if (const BasicBlock *BB = dyn_cast(this)) { incorporateFunction(BB->getParent()); - AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), nullptr); + AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), nullptr, IsForDebug); W.printBasicBlock(BB); } else if (const GlobalValue *GV = dyn_cast(this)) { - AssemblyWriter W(OS, SlotTable, GV->getParent(), nullptr); + AssemblyWriter W(OS, SlotTable, GV->getParent(), nullptr, IsForDebug); if (const GlobalVariable *V = dyn_cast(GV)) W.printGlobal(V); else if (const Function *F = dyn_cast(GV)) @@ -3394,41 +3434,45 @@ void Metadata::printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST, printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ true); } -void Metadata::print(raw_ostream &OS, const Module *M) const { +void Metadata::print(raw_ostream &OS, const Module *M, + bool /*IsForDebug*/) const { ModuleSlotTracker MST(M, isa(this)); printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ false); } void Metadata::print(raw_ostream &OS, ModuleSlotTracker &MST, - const Module *M) const { + const Module *M, bool /*IsForDebug*/) const { printMetadataImpl(OS, *this, MST, M, /* OnlyAsOperand */ false); } // Value::dump - allow easy printing of Values from the debugger. LLVM_DUMP_METHOD -void Value::dump() const { print(dbgs()); dbgs() << '\n'; } +void Value::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } // Type::dump - allow easy printing of Types from the debugger. LLVM_DUMP_METHOD -void Type::dump() const { print(dbgs()); dbgs() << '\n'; } +void Type::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } // Module::dump() - Allow printing of Modules from the debugger. LLVM_DUMP_METHOD -void Module::dump() const { print(dbgs(), nullptr); } +void Module::dump() const { + print(dbgs(), nullptr, + /*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true); +} // \brief Allow printing of Comdats from the debugger. LLVM_DUMP_METHOD -void Comdat::dump() const { print(dbgs()); } +void Comdat::dump() const { print(dbgs(), /*IsForDebug=*/true); } // NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger. LLVM_DUMP_METHOD -void NamedMDNode::dump() const { print(dbgs()); } +void NamedMDNode::dump() const { print(dbgs(), /*IsForDebug=*/true); } LLVM_DUMP_METHOD void Metadata::dump() const { dump(nullptr); } LLVM_DUMP_METHOD void Metadata::dump(const Module *M) const { - print(dbgs(), M); + print(dbgs(), M, /*IsForDebug=*/true); dbgs() << '\n'; }