aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
committervitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
commit6ffe9e53658409f212834330e13564e4952558f6 (patch)
tree85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp')
-rw-r--r--contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp b/contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp
new file mode 100644
index 0000000000..e2de322933
--- /dev/null
+++ b/contrib/libs/llvm16/lib/Transforms/Scalar/LowerWidenableCondition.cpp
@@ -0,0 +1,87 @@
+//===- LowerWidenableCondition.cpp - Lower the guard intrinsic ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass lowers the llvm.widenable.condition intrinsic to default value
+// which is i1 true.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Scalar/LowerWidenableCondition.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Scalar.h"
+
+using namespace llvm;
+
+namespace {
+struct LowerWidenableConditionLegacyPass : public FunctionPass {
+ static char ID;
+ LowerWidenableConditionLegacyPass() : FunctionPass(ID) {
+ initializeLowerWidenableConditionLegacyPassPass(
+ *PassRegistry::getPassRegistry());
+ }
+
+ bool runOnFunction(Function &F) override;
+};
+}
+
+static bool lowerWidenableCondition(Function &F) {
+ // Check if we can cheaply rule out the possibility of not having any work to
+ // do.
+ auto *WCDecl = F.getParent()->getFunction(
+ Intrinsic::getName(Intrinsic::experimental_widenable_condition));
+ if (!WCDecl || WCDecl->use_empty())
+ return false;
+
+ using namespace llvm::PatternMatch;
+ SmallVector<CallInst *, 8> ToLower;
+ // Traverse through the users of WCDecl.
+ // This is presumably cheaper than traversing all instructions in the
+ // function.
+ for (auto *U : WCDecl->users())
+ if (auto *CI = dyn_cast<CallInst>(U))
+ if (CI->getFunction() == &F)
+ ToLower.push_back(CI);
+
+ if (ToLower.empty())
+ return false;
+
+ for (auto *CI : ToLower) {
+ CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
+ CI->eraseFromParent();
+ }
+ return true;
+}
+
+bool LowerWidenableConditionLegacyPass::runOnFunction(Function &F) {
+ return lowerWidenableCondition(F);
+}
+
+char LowerWidenableConditionLegacyPass::ID = 0;
+INITIALIZE_PASS(LowerWidenableConditionLegacyPass, "lower-widenable-condition",
+ "Lower the widenable condition to default true value", false,
+ false)
+
+Pass *llvm::createLowerWidenableConditionPass() {
+ return new LowerWidenableConditionLegacyPass();
+}
+
+PreservedAnalyses LowerWidenableConditionPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ if (lowerWidenableCondition(F))
+ return PreservedAnalyses::none();
+
+ return PreservedAnalyses::all();
+}