[llvm] r239790 - MIR Serialization: Print and parse simple machine function attributes.

Alex Lorenz arphaman at gmail.com
Mon Jun 15 17:10:48 PDT 2015


Author: arphaman
Date: Mon Jun 15 19:10:47 2015
New Revision: 239790

URL: http://llvm.org/viewvc/llvm-project?rev=239790&view=rev
Log:
MIR Serialization: Print and parse simple machine function attributes.

This commit serializes the simple, scalar attributes from the 
'MachineFunction' class.

Reviewers: Duncan P. N. Exon Smith

Differential Revision: http://reviews.llvm.org/D10449

Modified:
    llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
    llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
    llvm/trunk/lib/CodeGen/MIRPrinter.cpp
    llvm/trunk/test/CodeGen/MIR/machine-function.mir

Modified: llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h?rev=239790&r1=239789&r2=239790&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h Mon Jun 15 19:10:47 2015
@@ -26,11 +26,17 @@ namespace yaml {
 
 struct MachineFunction {
   StringRef Name;
+  unsigned Alignment;
+  bool ExposesReturnsTwice;
+  bool HasInlineAsm;
 };
 
 template <> struct MappingTraits<MachineFunction> {
   static void mapping(IO &YamlIO, MachineFunction &MF) {
     YamlIO.mapRequired("name", MF.Name);
+    YamlIO.mapOptional("alignment", MF.Alignment);
+    YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
+    YamlIO.mapOptional("hasInlineAsm", MF.HasInlineAsm);
   }
 };
 

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp?rev=239790&r1=239789&r2=239790&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp Mon Jun 15 19:10:47 2015
@@ -190,6 +190,11 @@ bool MIRParserImpl::initializeMachineFun
     return error(Twine("no machine function information for function '") +
                  MF.getName() + "' in the MIR file");
   // TODO: Recreate the machine function.
+  const yaml::MachineFunction &YamlMF = *It->getValue();
+  if (YamlMF.Alignment)
+    MF.setAlignment(YamlMF.Alignment);
+  MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice);
+  MF.setHasInlineAsm(YamlMF.HasInlineAsm);
   return false;
 }
 

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=239790&r1=239789&r2=239790&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Mon Jun 15 19:10:47 2015
@@ -58,6 +58,9 @@ template <> struct BlockScalarTraits<Mod
 void MIRPrinter::print(const MachineFunction &MF) {
   yaml::MachineFunction YamlMF;
   YamlMF.Name = MF.getName();
+  YamlMF.Alignment = MF.getAlignment();
+  YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
+  YamlMF.HasInlineAsm = MF.hasInlineAsm();
   yaml::Output Out(OS);
   Out << YamlMF;
 }

Modified: llvm/trunk/test/CodeGen/MIR/machine-function.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/machine-function.mir?rev=239790&r1=239789&r2=239790&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/machine-function.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/machine-function.mir Mon Jun 15 19:10:47 2015
@@ -10,15 +10,49 @@
   define i32 @bar() {
     ret i32 0
   }
+
+  define i32 @func() {
+    ret i32 0
+  }
+
+  define i32 @func2() {
+    ret i32 0
+  }
   
 ...
 ---
 # CHECK: name: foo
+# CHECK-NEXT: alignment:
+# CHECK-NEXT: exposesReturnsTwice: false
+# CHECK-NEXT: hasInlineAsm: false
 # CHECK-NEXT: ...
 name:            foo
 ...
 ---
 # CHECK: name: bar
+# CHECK-NEXT: alignment:
+# CHECK-NEXT: exposesReturnsTwice: false
+# CHECK-NEXT: hasInlineAsm: false
 # CHECK-NEXT: ...
 name:            bar
 ...
+---
+# CHECK: name: func
+# CHECK-NEXT: alignment: 8
+# CHECK-NEXT: exposesReturnsTwice: false
+# CHECK-NEXT: hasInlineAsm: false
+# CHECK-NEXT: ...
+name:            func
+alignment:       8
+...
+---
+# CHECK: name: func2
+# CHECK-NEXT: alignment: 16
+# CHECK-NEXT: exposesReturnsTwice: true
+# CHECK-NEXT: hasInlineAsm: true
+# CHECK-NEXT: ...
+name:            func2
+alignment:       16
+exposesReturnsTwice: true
+hasInlineAsm:    true
+...





More information about the llvm-commits mailing list