[llvm] r289803 - [AVR] Support floats in the instrumention pass

Dylan McKay via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 03:02:41 PST 2016


Author: dylanmckay
Date: Thu Dec 15 05:02:41 2016
New Revision: 289803

URL: http://llvm.org/viewvc/llvm-project?rev=289803&view=rev
Log:
[AVR] Support floats in the instrumention pass

This also refactors some common code into the 'GetTypeName' method.

Modified:
    llvm/trunk/lib/Target/AVR/AVRInstrumentFunctions.cpp
    llvm/trunk/test/CodeGen/AVR/instrumentation/basic.ll

Modified: llvm/trunk/lib/Target/AVR/AVRInstrumentFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/AVRInstrumentFunctions.cpp?rev=289803&r1=289802&r2=289803&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AVR/AVRInstrumentFunctions.cpp (original)
+++ llvm/trunk/lib/Target/AVR/AVRInstrumentFunctions.cpp Thu Dec 15 05:02:41 2016
@@ -72,6 +72,18 @@ static Value *CreateStringPtr(BasicBlock
     {ConstantInt::get(I8, 0), ConstantInt::get(I8, 0)}, "", &BB);
 }
 
+static std::string GetTypeName(Type &Ty) {
+  if (auto *IntTy = dyn_cast<IntegerType>(&Ty)) {
+    return std::string("i") + std::to_string(IntTy->getBitWidth());
+  }
+
+  if (Ty.isFloatingPointTy()) {
+    return std::string("f") + std::to_string(Ty.getPrimitiveSizeInBits());
+  }
+
+  llvm_unreachable("unknown return type");
+}
+
 /// Builds a call to one of the signature begin/end hooks.
 static void BuildSignatureCall(StringRef SymName, BasicBlock &BB, Function &F) {
   LLVMContext &Ctx = F.getContext();
@@ -103,13 +115,7 @@ static void BuildEndSignature(BasicBlock
 /// Get the name of the external symbol that we need to call
 /// to notify about this argument.
 static std::string GetArgumentSymbolName(Argument &Arg) {
-  Type *Ty = Arg.getType();
-
-  if (auto *IntTy = dyn_cast<IntegerType>(Ty)) {
-    return (symbols::PREFIX + "_argument_i" + std::to_string(IntTy->getBitWidth())).str();
-  }
-
-  llvm_unreachable("unknown argument type");
+  return (symbols::PREFIX + "_argument_" + GetTypeName(*Arg.getType())).str();
 }
 
 /// Builds a call to one of the argument hooks.
@@ -153,13 +159,7 @@ static void BuildEntryBlock(Function &F)
 }
 
 static std::string GetReturnSymbolName(Value &Val) {
-  Type *Ty = Val.getType();
-
-  if (auto *IntTy = dyn_cast<IntegerType>(Ty)) {
-    return (symbols::PREFIX + "_result_u" + std::to_string(IntTy->getBitWidth())).str();
-  }
-
-  llvm_unreachable("unknown return type");
+  return (symbols::PREFIX + "_result_" + GetTypeName(*Val.getType())).str();
 }
 
 static void BuildExitHook(Instruction &I) {

Modified: llvm/trunk/test/CodeGen/AVR/instrumentation/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AVR/instrumentation/basic.ll?rev=289803&r1=289802&r2=289803&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AVR/instrumentation/basic.ll (original)
+++ llvm/trunk/test/CodeGen/AVR/instrumentation/basic.ll Thu Dec 15 05:02:41 2016
@@ -14,17 +14,17 @@ define i8 @do_something(i16 %a, i16 %b)
   ; CHECK-NEXT: call void @avr_instrumentation_begin_signature(i8* %0, i16 2)
 
   ; CHECK-NEXT: %1 = getelementptr inbounds [2 x i8], [2 x i8]* @1, i8 0, i8 0
-  ; CHECK-NEXT: call void @avr_instrumentation_argument_i16(i8* %1, i16 %a)
+  ; CHECK-NEXT: call void @avr_instrumentation_argument_i16(i8* %1, i8 0, i16 %a)
 
   ; CHECK-NEXT: %2 = getelementptr inbounds [2 x i8], [2 x i8]* @2, i8 0, i8 0
-  ; CHECK-NEXT: call void @avr_instrumentation_argument_i16(i8* %2, i16 %b)
+  ; CHECK-NEXT: call void @avr_instrumentation_argument_i16(i8* %2, i8 1, i16 %b)
 
   ; CHECK-NEXT: %3 = getelementptr inbounds [13 x i8], [13 x i8]* @3, i8 0, i8 0
   ; CHECK-NEXT: call void @avr_instrumentation_end_signature(i8* %3, i16 2)
 
   ; CHECK-NEXT: br label %4
 
-  ; CHECK: call void @avr_instrumentation_result_u8(i8 1)
+  ; CHECK: call void @avr_instrumentation_result_i8(i8 1)
   ; CHECK-NEXT: ret i8 1
   ret i8 1
 }
@@ -39,7 +39,24 @@ define i32 @foo() {
 
   ; CHECK-NEXT:   br label %2
 
-  ; CHECK:         call void @avr_instrumentation_result_u32(i32 50)
+  ; CHECK:        call void @avr_instrumentation_result_i32(i32 50)
   ; CHECK-NEXT:   ret i32 50
   ret i32 50
 }
+
+; CHECK-LABEL: floaty
+define float @floaty(float %a) {
+  ; CHECK: instrumentation_entry:
+  ; CHECK-NEXT:   %0 = getelementptr inbounds [7 x i8], [7 x i8]* @6, i8 0, i8 0
+  ; CHECK-NEXT:   call void @avr_instrumentation_begin_signature(i8* %0, i16 1)
+  ; CHECK-NEXT:   %1 = getelementptr inbounds [2 x i8], [2 x i8]* @7, i8 0, i8 0
+  ; CHECK-NEXT:   call void @avr_instrumentation_argument_f32(i8* %1, i8 0, float %a)
+  ; CHECK-NEXT:   %2 = getelementptr inbounds [7 x i8], [7 x i8]* @8, i8 0, i8 0
+  ; CHECK-NEXT:   call void @avr_instrumentation_end_signature(i8* %2, i16 1)
+
+  ; CHECK-NEXT:   br label %3
+  ;
+  ; CHECK:        call void @avr_instrumentation_result_f32(float 1.200000e+01)
+  ; CHECK-NEXT:   ret float 1.200000e+01
+  ret float 12.0
+}




More information about the llvm-commits mailing list