[llvm-commits] [llvm] r139820 - in /llvm/trunk: include/llvm/MC/MCInst.h include/llvm/MC/MCInstPrinter.h lib/MC/MCInst.cpp lib/MC/MCInstPrinter.cpp lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp

Jim Grosbach grosbach at apple.com
Thu Sep 15 12:30:12 PDT 2011


On Sep 15, 2011, at 11:36 AM, Owen Anderson wrote:

> Author: resistor
> Date: Thu Sep 15 13:36:29 2011
> New Revision: 139820
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=139820&view=rev
> Log:
> Add support for stored annotations to MCInst, and provide facilities for MC-based InstPrinters to print them out.  Enhance the ARM and X86 InstPrinter's to do so in verbose mode.
> 
> Modified:
>    llvm/trunk/include/llvm/MC/MCInst.h
>    llvm/trunk/include/llvm/MC/MCInstPrinter.h
>    llvm/trunk/lib/MC/MCInst.cpp
>    llvm/trunk/lib/MC/MCInstPrinter.cpp
>    llvm/trunk/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
>    llvm/trunk/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp
>    llvm/trunk/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp
> 
> Modified: llvm/trunk/include/llvm/MC/MCInst.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInst.h?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCInst.h (original)
> +++ llvm/trunk/include/llvm/MC/MCInst.h Thu Sep 15 13:36:29 2011
> @@ -129,6 +129,7 @@
> class MCInst {
>   unsigned Opcode;
>   SmallVector<MCOperand, 8> Operands;
> +  SmallVector<std::string, 1> Annotations;

We should really try very hard to find another way to do this. MCInst's are intended to be very small objects copied around by value on a regular basis, unlike MachineInstrs.


> public:
>   MCInst() : Opcode(0) {}
> 
> @@ -144,7 +145,15 @@
>     Operands.push_back(Op);
>   }
> 
> -  void clear() { Operands.clear(); }
> +  void addAnnotation(const std::string &Annot) {
> +    Annotations.push_back(Annot);
> +  }
> +
> +  void clear() {
> +    Operands.clear();
> +    Annotations.clear();
> +  }
> +
>   size_t size() { return Operands.size(); }
> 
>   typedef SmallVector<MCOperand, 8>::iterator iterator;
> @@ -154,6 +163,9 @@
>     return Operands.insert(I, Op);
>   }
> 
> +  size_t getNumAnnotations() const { return Annotations.size(); }
> +  std::string getAnnotation(size_t i) const { return Annotations[i]; }
> +
>   void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
>   void dump() const;
> 
> 
> Modified: llvm/trunk/include/llvm/MC/MCInstPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInstPrinter.h?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCInstPrinter.h (original)
> +++ llvm/trunk/include/llvm/MC/MCInstPrinter.h Thu Sep 15 13:36:29 2011
> @@ -41,6 +41,10 @@
>   ///
>   virtual void printInst(const MCInst *MI, raw_ostream &OS) = 0;
> 
> +  /// printAnnotations - Print the annotation comments attached to specified
> +  /// MCInst to the specified raw_ostream.
> +  void printAnnotations(const MCInst *MI, raw_ostream &OS);
> +
>   /// getOpcodeName - Return the name of the specified opcode enum (e.g.
>   /// "MOV32ri") or empty if we can't resolve it.
>   virtual StringRef getOpcodeName(unsigned Opcode) const;
> 
> Modified: llvm/trunk/lib/MC/MCInst.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCInst.cpp?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCInst.cpp (original)
> +++ llvm/trunk/lib/MC/MCInst.cpp Thu Sep 15 13:36:29 2011
> @@ -41,6 +41,16 @@
>     OS << " ";
>     getOperand(i).print(OS, MAI);
>   }
> +
> +  if (getNumAnnotations()) {
> +    OS << " # Annots: ";
> +    for (unsigned i = 0, e = getNumAnnotations(); i != e; ++i) {
> +      OS << " \"";
> +      OS << getAnnotation(i);
> +      OS << '"';
> +    }
> +  }
> +
>   OS << ">";
> }
> 
> @@ -57,6 +67,17 @@
>     OS << Separator;
>     getOperand(i).print(OS, MAI);
>   }
> +
> +  if (getNumAnnotations()) {
> +    OS << " # Annots: ";
> +    for (unsigned i = 0, e = getNumAnnotations(); i != e; ++i) {
> +      OS << Separator;
> +      OS << '"';
> +      OS << getAnnotation(i);
> +      OS << '"';
> +    }
> +  }
> +
>   OS << ">";
> }
> 
> 
> Modified: llvm/trunk/lib/MC/MCInstPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCInstPrinter.cpp?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCInstPrinter.cpp (original)
> +++ llvm/trunk/lib/MC/MCInstPrinter.cpp Thu Sep 15 13:36:29 2011
> @@ -8,7 +8,10 @@
> //===----------------------------------------------------------------------===//
> 
> #include "llvm/MC/MCInstPrinter.h"
> +#include "llvm/MC/MCAsmInfo.h"
> +#include "llvm/MC/MCInst.h"
> #include "llvm/ADT/StringRef.h"
> +#include "llvm/Support/raw_ostream.h"
> using namespace llvm;
> 
> MCInstPrinter::~MCInstPrinter() {
> @@ -23,3 +26,9 @@
> void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
>   assert(0 && "Target should implement this");
> }
> +
> +void MCInstPrinter::printAnnotations(const MCInst *MI, raw_ostream &OS) {
> +  for (unsigned i = 0, e = MI->getNumAnnotations(); i != e; ++i) {
> +    OS << MI->getAnnotation(i) << "\n";
> +  }
> +}
> 
> Modified: llvm/trunk/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/InstPrinter/ARMInstPrinter.cpp Thu Sep 15 13:36:29 2011
> @@ -71,6 +71,9 @@
> 
>     O << ", " << getRegisterName(MO2.getReg());
>     assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
> +
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
> +
>     return;
>   }
> 
> @@ -87,10 +90,14 @@
>     O << '\t' << getRegisterName(Dst.getReg())
>       << ", " << getRegisterName(MO1.getReg());
> 
> -    if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx)
> +    if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
> +      if (CommentStream) printAnnotations(MI, *CommentStream);
>       return;
> +    }
> 
>     O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
> +
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -104,6 +111,7 @@
>       O << ".w";
>     O << '\t';
>     printRegisterList(MI, 4, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
>   if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
> @@ -111,6 +119,7 @@
>     O << '\t' << "push";
>     printPredicateOperand(MI, 4, O);
>     O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -123,6 +132,7 @@
>       O << ".w";
>     O << '\t';
>     printRegisterList(MI, 4, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
>   if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
> @@ -130,6 +140,7 @@
>     O << '\t' << "pop";
>     printPredicateOperand(MI, 5, O);
>     O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -141,6 +152,7 @@
>     printPredicateOperand(MI, 2, O);
>     O << '\t';
>     printRegisterList(MI, 4, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -151,6 +163,7 @@
>     printPredicateOperand(MI, 2, O);
>     O << '\t';
>     printRegisterList(MI, 4, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -169,6 +182,7 @@
>     if (Writeback) O << "!";
>     O << ", ";
>     printRegisterList(MI, 3, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
> @@ -177,10 +191,12 @@
>       MI->getOperand(1).getReg() == ARM::R8) {
>     O << "\tnop";
>     printPredicateOperand(MI, 2, O);
> +    if (CommentStream) printAnnotations(MI, *CommentStream);
>     return;
>   }
> 
>   printInstruction(MI, O);
> +  if (CommentStream) printAnnotations(MI, *CommentStream);
> }
> 
> void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
> 
> Modified: llvm/trunk/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp Thu Sep 15 13:36:29 2011
> @@ -45,8 +45,10 @@
>     printInstruction(MI, OS);
> 
>   // If verbose assembly is enabled, we can print some informative comments.
> -  if (CommentStream)
> +  if (CommentStream) {
> +    printAnnotations(MI, *CommentStream);
>     EmitAnyX86InstComments(MI, *CommentStream, getRegisterName);
> +  }
> }
> 
> StringRef X86ATTInstPrinter::getOpcodeName(unsigned Opcode) const {
> 
> Modified: llvm/trunk/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp?rev=139820&r1=139819&r2=139820&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp Thu Sep 15 13:36:29 2011
> @@ -36,8 +36,10 @@
>   printInstruction(MI, OS);
> 
>   // If verbose assembly is enabled, we can print some informative comments.
> -  if (CommentStream)
> +  if (CommentStream) {
> +    printAnnotations(MI, *CommentStream);
>     EmitAnyX86InstComments(MI, *CommentStream, getRegisterName);
> +  }
> }
> StringRef X86IntelInstPrinter::getOpcodeName(unsigned Opcode) const {
>   return getInstructionName(Opcode);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list