summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Target/AVR/AVRInstrumentFunctions.cpp28
-rw-r--r--llvm/test/CodeGen/AVR/instrumentation/basic.ll25
2 files changed, 35 insertions, 18 deletions
diff --git a/llvm/lib/Target/AVR/AVRInstrumentFunctions.cpp b/llvm/lib/Target/AVR/AVRInstrumentFunctions.cpp
index a2f20e02be1..5553dc2da31 100644
--- a/llvm/lib/Target/AVR/AVRInstrumentFunctions.cpp
+++ b/llvm/lib/Target/AVR/AVRInstrumentFunctions.cpp
@@ -72,6 +72,18 @@ static Value *CreateStringPtr(BasicBlock &BB, StringRef Str) {
{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 &BB, Function &F) {
/// 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) {
diff --git a/llvm/test/CodeGen/AVR/instrumentation/basic.ll b/llvm/test/CodeGen/AVR/instrumentation/basic.ll
index 232868a97f7..f8a0321d417 100644
--- a/llvm/test/CodeGen/AVR/instrumentation/basic.ll
+++ b/llvm/test/CodeGen/AVR/instrumentation/basic.ll
@@ -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
+}
OpenPOWER on IntegriCloud