[PATCH] D135384: Enable the use of the -pg flag

Michael Francis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 11:28:30 PDT 2022


francii created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
francii requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135384

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/CodeGen/mcount-aix.c
  llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp


Index: llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
===================================================================
--- llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -40,6 +40,21 @@
     return;
   }
 
+  if (Func == "__mcount.aix") {
+    Type *SizeTy = M.getDataLayout().getIntPtrType(C);
+    Type *SizePtrTy = SizeTy->getPointerTo();
+    GlobalVariable *GV = new GlobalVariable(M, SizeTy, /*isConstant=*/false,
+                                            GlobalValue::InternalLinkage,
+                                            ConstantInt::get(SizeTy, 0));
+    CallInst *Call = CallInst::Create(
+        M.getOrInsertFunction("__mcount",
+                              FunctionType::get(Type::getVoidTy(C), {SizePtrTy},
+                                                /*isVarArg=*/false)),
+        {GV}, "", InsertionPt);
+    Call->setDebugLoc(DL);
+    return;
+  }
+
   if (Func == "__cyg_profile_func_enter" || Func == "__cyg_profile_func_exit") {
     Type *ArgTypes[] = {Type::getInt8PtrTy(C), Type::getInt8PtrTy(C)};
 
Index: clang/test/CodeGen/mcount-aix.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/mcount-aix.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -pg -no-opaque-pointers -triple powerpc-ibm-aix7.2.0.0 -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -pg -no-opaque-pointers -triple powerpc64-ibm-aix7.2.0.0 -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK64
+
+void foo() {
+}
+
+void bar() {
+    foo();
+}
+// CHECK: @[[GLOB0:[0-9]+]] = internal global i32 0
+// CHECK: @[[GLOB1:[0-9]+]] = internal global i32 0
+// CHECK64: @[[GLOB0:[0-9]+]] = internal global i64 0
+// CHECK64: @[[GLOB1:[0-9]+]] = internal global i64 0
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    call void @__mcount(i32* @[[GLOB0]])
+// CHECK64-LABEL: @foo(
+// CHECK64-NEXT:  entry:
+// CHECK64-NEXT:    call void @__mcount(i64* @[[GLOB0]])
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    call void @__mcount(i32* @[[GLOB1]])
+// CHECK64-LABEL: @bar(
+// CHECK64-NEXT:  entry:
+// CHECK64-NEXT:    call void @__mcount(i64* @[[GLOB1]])
Index: clang/lib/Basic/Targets/OSTargets.h
===================================================================
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -751,6 +751,7 @@
 public:
   AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
       : OSTargetInfo<Target>(Triple, Opts) {
+    this->MCountName = "__mcount.aix";
     this->TheCXXABI.set(TargetCXXABI::XL);
 
     if (this->PointerWidth == 64) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135384.465808.patch
Type: text/x-patch
Size: 2688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221006/5a0c6904/attachment.bin>


More information about the cfe-commits mailing list