aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 18:49:54 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 18:49:54 +0900
commite2810c9a248f4c7fbfae84bb32b6f7e01027458b (patch)
treeae0b02a8491b969a1cee94ea16ffe42c559143c5 /llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
parentfa04eb4af95c1ca7377279728cb004bcd2324d01 (diff)
parentbdcf47e4bcb92889665825654bb80a8bbe30379e (diff)
downloadllvm-users/chapuni/cov/single/switch.zip
llvm-users/chapuni/cov/single/switch.tar.gz
llvm-users/chapuni/cov/single/switch.tar.bz2
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/switchusers/chapuni/cov/single/switch
Diffstat (limited to 'llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
index 47bb319..d47f1b4 100644
--- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -48,6 +48,21 @@ static void insertCall(Function &CurFn, StringRef Func,
/*isVarArg=*/false)),
{GV}, "", InsertionPt);
Call->setDebugLoc(DL);
+ } else if (TargetTriple.isRISCV() || TargetTriple.isAArch64() ||
+ TargetTriple.isLoongArch()) {
+ // On RISC-V, AArch64, and LoongArch, the `_mcount` function takes
+ // `__builtin_return_address(0)` as an argument since
+ // `__builtin_return_address(1)` is not available on these platforms.
+ Instruction *RetAddr = CallInst::Create(
+ Intrinsic::getOrInsertDeclaration(&M, Intrinsic::returnaddress),
+ ConstantInt::get(Type::getInt32Ty(C), 0), "", InsertionPt);
+ RetAddr->setDebugLoc(DL);
+
+ FunctionCallee Fn = M.getOrInsertFunction(
+ Func, FunctionType::get(Type::getVoidTy(C), PointerType::getUnqual(C),
+ false));
+ CallInst *Call = CallInst::Create(Fn, RetAddr, "", InsertionPt);
+ Call->setDebugLoc(DL);
} else {
FunctionCallee Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
CallInst *Call = CallInst::Create(Fn, "", InsertionPt);
@@ -88,6 +103,12 @@ static bool runOnFunction(Function &F, bool PostInlining) {
if (F.hasFnAttribute(Attribute::Naked))
return false;
+ // available_externally functions may not have definitions external to the
+ // module (e.g. gnu::always_inline). Instrumenting them might lead to linker
+ // errors if they are optimized out. Skip them like GCC.
+ if (F.hasAvailableExternallyLinkage())
+ return false;
+
StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
: "instrument-function-entry";