[llvm] Fix build failure caused by PR 68235 (PR #71219)
Manman Ren via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 12:56:32 PDT 2023
https://github.com/manman-ren updated https://github.com/llvm/llvm-project/pull/71219
>From 78fee925e39999907444420cc2f5e63245d469d8 Mon Sep 17 00:00:00 2001
From: Manman Ren <mren at fb.com>
Date: Fri, 3 Nov 2023 11:51:45 -0700
Subject: [PATCH 1/2] Fix build failure caused by PR 68235
We move the implementations to Transforms/Utils:
isEligibleInstrunctionForConstantSharing
isEligibleOperandForConstantSharing
as they are used from Transforms/Utils/FunctionComparatorIgnoringConst.cpp.
---
.../IPO/MergeFunctionsIgnoringConst.cpp | 74 +------------------
.../Utils/FunctionComparatorIgnoringConst.cpp | 62 ++++++++++++++++
.../merge_with_exception.ll | 2 +-
3 files changed, 65 insertions(+), 73 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp b/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
index d6ae788ddb9e1a1..225709b8b3caf69 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
@@ -50,6 +50,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/FunctionComparatorIgnoringConst.h"
+#include "llvm/Transforms/Utils/MergeFunctionsIgnoringConst.h"
#include <vector>
using namespace llvm;
@@ -112,64 +113,11 @@ static cl::list<std::string> MergeAllowRegexFilters(
"regular expression"),
cl::ZeroOrMore);
-bool isEligibleInstrunctionForConstantSharing(const Instruction *I) {
- switch (I->getOpcode()) {
- case Instruction::Load:
- case Instruction::Store:
- case Instruction::Call:
- return true;
- default: {
- if (EnableAggressiveMergeFunc && I->getOpcode() == Instruction::Invoke)
- return true;
- return false;
- }
- }
-}
-
/// Returns true if the \OpIdx operand of \p CI is the callee operand.
static bool isCalleeOperand(const CallBase *CI, unsigned OpIdx) {
return &CI->getCalledOperandUse() == &CI->getOperandUse(OpIdx);
}
-static bool canParameterizeCallOperand(const CallBase *CI, unsigned OpIdx) {
- if (CI->isInlineAsm())
- return false;
- Function *Callee = CI->getCalledOperand()
- ? dyn_cast_or_null<Function>(
- CI->getCalledOperand()->stripPointerCasts())
- : nullptr;
- if (Callee) {
- if (Callee->isIntrinsic())
- return false;
- // objc_msgSend stubs must be called, and can't have their address taken.
- if (Callee->getName().startswith("objc_msgSend$"))
- return false;
- }
- if (isCalleeOperand(CI, OpIdx) &&
- CI->getOperandBundle(LLVMContext::OB_ptrauth).has_value()) {
- // The operand is the callee and it has already been signed. Ignore this
- // because we cannot add another ptrauth bundle to the call instruction.
- return false;
- }
- return true;
-}
-
-bool isEligibleOperandForConstantSharing(const Instruction *I, unsigned OpIdx) {
- assert(OpIdx < I->getNumOperands() && "Invalid operand index");
-
- if (!isEligibleInstrunctionForConstantSharing(I))
- return false;
-
- auto Opnd = I->getOperand(OpIdx);
- if (!isa<Constant>(Opnd))
- return false;
-
- if (const auto *CI = dyn_cast<CallBase>(I))
- return canParameterizeCallOperand(CI, OpIdx);
-
- return true;
-}
-
namespace {
/// MergeFuncIgnoringConst finds functions which only differ by constants in
@@ -1268,25 +1216,7 @@ static llvm::AttributeList
fixUpTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
llvm::AttributeList attrList) {
auto &context = fnType->getContext();
- if (!context.supportsTypedPointers())
- return attrList;
-
- for (unsigned i = 0; i < fnType->getNumParams(); ++i) {
- auto paramTy = fnType->getParamType(i);
- auto attrListIndex = llvm::AttributeList::FirstArgIndex + i;
- if (attrList.hasParamAttr(i, llvm::Attribute::StructRet) &&
- paramTy->getNonOpaquePointerElementType() !=
- attrList.getParamStructRetType(i))
- attrList = attrList.replaceAttributeTypeAtIndex(
- context, attrListIndex, llvm::Attribute::StructRet,
- paramTy->getNonOpaquePointerElementType());
- if (attrList.hasParamAttr(i, llvm::Attribute::ByVal) &&
- paramTy->getNonOpaquePointerElementType() !=
- attrList.getParamByValType(i))
- attrList = attrList.replaceAttributeTypeAtIndex(
- context, attrListIndex, llvm::Attribute::ByVal,
- paramTy->getNonOpaquePointerElementType());
- }
+ // supportsTypedPointers always returns false now.
return attrList;
}
diff --git a/llvm/lib/Transforms/Utils/FunctionComparatorIgnoringConst.cpp b/llvm/lib/Transforms/Utils/FunctionComparatorIgnoringConst.cpp
index 9cfd95345598083..ab0de3659c92a7c 100644
--- a/llvm/lib/Transforms/Utils/FunctionComparatorIgnoringConst.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionComparatorIgnoringConst.cpp
@@ -10,9 +10,71 @@
#include "llvm/Transforms/Utils/FunctionComparatorIgnoringConst.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Utils/MergeFunctionsIgnoringConst.h"
using namespace llvm;
+static cl::opt<bool> EnableMergeOnInvoke(
+ "enable-aggressive-mergefunc-invoke", cl::init(false), cl::Hidden,
+ cl::desc("Enable aggressive function merger on Invoke"));
+
+/// Returns true if the \OpIdx operand of \p CI is the callee operand.
+static bool isCalleeOperand(const CallBase *CI, unsigned OpIdx) {
+ return &CI->getCalledOperandUse() == &CI->getOperandUse(OpIdx);
+}
+
+bool isEligibleInstrunctionForConstantSharing(const Instruction *I) {
+ switch (I->getOpcode()) {
+ case Instruction::Load:
+ case Instruction::Store:
+ case Instruction::Call:
+ return true;
+ default: {
+ if (EnableMergeOnInvoke && I->getOpcode() == Instruction::Invoke)
+ return true;
+ return false;
+ }
+ }
+}
+
+static bool canParameterizeCallOperand(const CallBase *CI, unsigned OpIdx) {
+ if (CI->isInlineAsm())
+ return false;
+ Function *Callee = CI->getCalledOperand()
+ ? dyn_cast_or_null<Function>(
+ CI->getCalledOperand()->stripPointerCasts())
+ : nullptr;
+ if (Callee) {
+ if (Callee->isIntrinsic())
+ return false;
+ // objc_msgSend stubs must be called, and can't have their address taken.
+ if (Callee->getName().startswith("objc_msgSend$"))
+ return false;
+ }
+ if (isCalleeOperand(CI, OpIdx) &&
+ CI->getOperandBundle(LLVMContext::OB_ptrauth).has_value()) {
+ // The operand is the callee and it has already been signed. Ignore this
+ // because we cannot add another ptrauth bundle to the call instruction.
+ return false;
+ }
+ return true;
+}
+
+bool isEligibleOperandForConstantSharing(const Instruction *I, unsigned OpIdx) {
+ assert(OpIdx < I->getNumOperands() && "Invalid operand index");
+
+ if (!isEligibleInstrunctionForConstantSharing(I))
+ return false;
+
+ auto Opnd = I->getOperand(OpIdx);
+ if (!isa<Constant>(Opnd))
+ return false;
+
+ if (const auto *CI = dyn_cast<CallBase>(I))
+ return canParameterizeCallOperand(CI, OpIdx);
+
+ return true;
+}
int FunctionComparatorIgnoringConst::cmpOperandsIgnoringConsts(
const Instruction *L, const Instruction *R, unsigned opIdx) {
diff --git a/llvm/test/Transforms/MergeFuncIgnoringConst/merge_with_exception.ll b/llvm/test/Transforms/MergeFuncIgnoringConst/merge_with_exception.ll
index c5c8b898c046e51..6544cafc8880d6b 100644
--- a/llvm/test/Transforms/MergeFuncIgnoringConst/merge_with_exception.ll
+++ b/llvm/test/Transforms/MergeFuncIgnoringConst/merge_with_exception.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -enable-aggressive-mergefunc-ignoringconst -passes=mergefunc-ignoring-const %s -o - | FileCheck %s
+; RUN: opt -S -enable-aggressive-mergefunc-ignoringconst -enable-aggressive-mergefunc-invoke -passes=mergefunc-ignoring-const %s -o - | FileCheck %s
%4 = type opaque
%10 = type opaque
>From c978328c4f8c0ddcba08b90eb626b991a45c5551 Mon Sep 17 00:00:00 2001
From: Manman Ren <mren at fb.com>
Date: Fri, 3 Nov 2023 12:56:03 -0700
Subject: [PATCH 2/2] address review comments
---
llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp b/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
index 225709b8b3caf69..83df2fc81614619 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctionsIgnoringConst.cpp
@@ -1215,7 +1215,6 @@ void MergeFuncIgnoringConstImpl::writeThunk(Function *ToFunc, Function *Thunk,
static llvm::AttributeList
fixUpTypesInByValAndStructRetAttributes(llvm::FunctionType *fnType,
llvm::AttributeList attrList) {
- auto &context = fnType->getContext();
// supportsTypedPointers always returns false now.
return attrList;
}
More information about the llvm-commits
mailing list