aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/Target/BPF
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/lib/Target/BPF
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Target/BPF')
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/AsmParser/ya.make20
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPF.h66
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFAbstractMemberAccess.cpp510
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFAdjustOpt.cpp646
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFCORE.h60
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFCheckAndAdjustIR.cpp260
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFInstrFormats.td22
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFInstrInfo.td366
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFMIChecking.cpp140
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFMIPeephole.cpp6
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFPreserveDIType.cpp148
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.cpp4
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.h2
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.cpp116
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.h12
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BPFTargetTransformInfo.h122
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BTF.def2
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BTFDebug.cpp174
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/BTFDebug.h34
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/Disassembler/BPFDisassembler.cpp4
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/Disassembler/ya.make16
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h2
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp18
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp2
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/ya.make16
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/TargetInfo/ya.make8
-rw-r--r--contrib/libs/llvm12/lib/Target/BPF/ya.make38
27 files changed, 1407 insertions, 1407 deletions
diff --git a/contrib/libs/llvm12/lib/Target/BPF/AsmParser/ya.make b/contrib/libs/llvm12/lib/Target/BPF/AsmParser/ya.make
index b61ac06cdd..25f1bc8eb5 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/AsmParser/ya.make
+++ b/contrib/libs/llvm12/lib/Target/BPF/AsmParser/ya.make
@@ -12,19 +12,19 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/include
- contrib/libs/llvm12/lib/MC
- contrib/libs/llvm12/lib/MC/MCParser
- contrib/libs/llvm12/lib/Support
- contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
- contrib/libs/llvm12/lib/Target/BPF/TargetInfo
+ contrib/libs/llvm12
+ contrib/libs/llvm12/include
+ contrib/libs/llvm12/lib/MC
+ contrib/libs/llvm12/lib/MC/MCParser
+ contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
+ contrib/libs/llvm12/lib/Target/BPF/TargetInfo
)
ADDINCL(
- ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF/AsmParser
+ ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF/AsmParser
)
NO_COMPILER_WARNINGS()
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPF.h b/contrib/libs/llvm12/lib/Target/BPF/BPF.h
index a98a3e08d5..ad49a647cc 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPF.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPF.h
@@ -10,17 +10,17 @@
#define LLVM_LIB_TARGET_BPF_BPF_H
#include "MCTargetDesc/BPFMCTargetDesc.h"
-#include "llvm/IR/PassManager.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Target/TargetMachine.h"
namespace llvm {
class BPFTargetMachine;
-ModulePass *createBPFAdjustOpt();
-ModulePass *createBPFCheckAndAdjustIR();
+ModulePass *createBPFAdjustOpt();
+ModulePass *createBPFCheckAndAdjustIR();
-FunctionPass *createBPFAbstractMemberAccess(BPFTargetMachine *TM);
-FunctionPass *createBPFPreserveDIType();
+FunctionPass *createBPFAbstractMemberAccess(BPFTargetMachine *TM);
+FunctionPass *createBPFPreserveDIType();
FunctionPass *createBPFISelDag(BPFTargetMachine &TM);
FunctionPass *createBPFMISimplifyPatchablePass();
FunctionPass *createBPFMIPeepholePass();
@@ -28,10 +28,10 @@ FunctionPass *createBPFMIPeepholeTruncElimPass();
FunctionPass *createBPFMIPreEmitPeepholePass();
FunctionPass *createBPFMIPreEmitCheckingPass();
-void initializeBPFAdjustOptPass(PassRegistry&);
-void initializeBPFCheckAndAdjustIRPass(PassRegistry&);
-
-void initializeBPFAbstractMemberAccessLegacyPassPass(PassRegistry &);
+void initializeBPFAdjustOptPass(PassRegistry&);
+void initializeBPFCheckAndAdjustIRPass(PassRegistry&);
+
+void initializeBPFAbstractMemberAccessLegacyPassPass(PassRegistry &);
void initializeBPFPreserveDITypePass(PassRegistry&);
void initializeBPFMISimplifyPatchablePass(PassRegistry&);
void initializeBPFMIPeepholePass(PassRegistry&);
@@ -39,28 +39,28 @@ void initializeBPFMIPeepholeTruncElimPass(PassRegistry&);
void initializeBPFMIPreEmitPeepholePass(PassRegistry&);
void initializeBPFMIPreEmitCheckingPass(PassRegistry&);
-class BPFAbstractMemberAccessPass
- : public PassInfoMixin<BPFAbstractMemberAccessPass> {
- BPFTargetMachine *TM;
-
-public:
- BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {}
- PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
-
- static bool isRequired() { return true; }
-};
-
-class BPFPreserveDITypePass : public PassInfoMixin<BPFPreserveDITypePass> {
-public:
- PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
-
- static bool isRequired() { return true; }
-};
-
-class BPFAdjustOptPass : public PassInfoMixin<BPFAdjustOptPass> {
-public:
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
-};
-} // namespace llvm
-
+class BPFAbstractMemberAccessPass
+ : public PassInfoMixin<BPFAbstractMemberAccessPass> {
+ BPFTargetMachine *TM;
+
+public:
+ BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {}
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+
+ static bool isRequired() { return true; }
+};
+
+class BPFPreserveDITypePass : public PassInfoMixin<BPFPreserveDITypePass> {
+public:
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+
+ static bool isRequired() { return true; }
+};
+
+class BPFAdjustOptPass : public PassInfoMixin<BPFAdjustOptPass> {
+public:
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+} // namespace llvm
+
#endif
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFAbstractMemberAccess.cpp
index cd994a9c83..5809fe501f 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFAbstractMemberAccess.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFAbstractMemberAccess.cpp
@@ -81,9 +81,9 @@
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
-#include "llvm/IR/IntrinsicsBPF.h"
+#include "llvm/IR/IntrinsicsBPF.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/PassManager.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
@@ -95,30 +95,30 @@
namespace llvm {
constexpr StringRef BPFCoreSharedInfo::AmaAttr;
-uint32_t BPFCoreSharedInfo::SeqNum;
-
-Instruction *BPFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB,
- Instruction *Input,
- Instruction *Before) {
- Function *Fn = Intrinsic::getDeclaration(
- M, Intrinsic::bpf_passthrough, {Input->getType(), Input->getType()});
- Constant *SeqNumVal = ConstantInt::get(Type::getInt32Ty(BB->getContext()),
- BPFCoreSharedInfo::SeqNum++);
-
- auto *NewInst = CallInst::Create(Fn, {SeqNumVal, Input});
- BB->getInstList().insert(Before->getIterator(), NewInst);
- return NewInst;
-}
+uint32_t BPFCoreSharedInfo::SeqNum;
+
+Instruction *BPFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB,
+ Instruction *Input,
+ Instruction *Before) {
+ Function *Fn = Intrinsic::getDeclaration(
+ M, Intrinsic::bpf_passthrough, {Input->getType(), Input->getType()});
+ Constant *SeqNumVal = ConstantInt::get(Type::getInt32Ty(BB->getContext()),
+ BPFCoreSharedInfo::SeqNum++);
+
+ auto *NewInst = CallInst::Create(Fn, {SeqNumVal, Input});
+ BB->getInstList().insert(Before->getIterator(), NewInst);
+ return NewInst;
+}
} // namespace llvm
using namespace llvm;
namespace {
-class BPFAbstractMemberAccess final {
-public:
- BPFAbstractMemberAccess(BPFTargetMachine *TM) : TM(TM) {}
+class BPFAbstractMemberAccess final {
+public:
+ BPFAbstractMemberAccess(BPFTargetMachine *TM) : TM(TM) {}
- bool run(Function &F);
+ bool run(Function &F);
struct CallInfo {
uint32_t Kind;
@@ -137,11 +137,11 @@ private:
BPFPreserveFieldInfoAI = 4,
};
- TargetMachine *TM;
+ TargetMachine *TM;
const DataLayout *DL = nullptr;
- Module *M = nullptr;
+ Module *M = nullptr;
- static std::map<std::string, GlobalVariable *> GEPGlobals;
+ static std::map<std::string, GlobalVariable *> GEPGlobals;
// A map to link preserve_*_access_index instrinsic calls.
std::map<CallInst *, std::pair<CallInst *, CallInfo>> AIChain;
// A map to hold all the base preserve_*_access_index instrinsic calls.
@@ -149,19 +149,19 @@ private:
// intrinsics.
std::map<CallInst *, CallInfo> BaseAICalls;
- bool doTransformation(Function &F);
+ bool doTransformation(Function &F);
void traceAICall(CallInst *Call, CallInfo &ParentInfo);
void traceBitCast(BitCastInst *BitCast, CallInst *Parent,
CallInfo &ParentInfo);
void traceGEP(GetElementPtrInst *GEP, CallInst *Parent,
CallInfo &ParentInfo);
- void collectAICallChains(Function &F);
+ void collectAICallChains(Function &F);
bool IsPreserveDIAccessIndexCall(const CallInst *Call, CallInfo &Cinfo);
bool IsValidAIChain(const MDNode *ParentMeta, uint32_t ParentAI,
const MDNode *ChildMeta);
- bool removePreserveAccessIndexIntrinsic(Function &F);
+ bool removePreserveAccessIndexIntrinsic(Function &F);
void replaceWithGEP(std::vector<CallInst *> &CallList,
uint32_t NumOfZerosIndex, uint32_t DIIndex);
bool HasPreserveFieldInfoCall(CallInfoStack &CallStack);
@@ -173,55 +173,55 @@ private:
Value *computeBaseAndAccessKey(CallInst *Call, CallInfo &CInfo,
std::string &AccessKey, MDNode *&BaseMeta);
- MDNode *computeAccessKey(CallInst *Call, CallInfo &CInfo,
- std::string &AccessKey, bool &IsInt32Ret);
+ MDNode *computeAccessKey(CallInst *Call, CallInfo &CInfo,
+ std::string &AccessKey, bool &IsInt32Ret);
uint64_t getConstant(const Value *IndexValue);
- bool transformGEPChain(CallInst *Call, CallInfo &CInfo);
-};
-
-std::map<std::string, GlobalVariable *> BPFAbstractMemberAccess::GEPGlobals;
-
-class BPFAbstractMemberAccessLegacyPass final : public FunctionPass {
- BPFTargetMachine *TM;
-
- bool runOnFunction(Function &F) override {
- return BPFAbstractMemberAccess(TM).run(F);
- }
-
-public:
- static char ID;
-
- // Add optional BPFTargetMachine parameter so that BPF backend can add the
- // phase with target machine to find out the endianness. The default
- // constructor (without parameters) is used by the pass manager for managing
- // purposes.
- BPFAbstractMemberAccessLegacyPass(BPFTargetMachine *TM = nullptr)
- : FunctionPass(ID), TM(TM) {}
+ bool transformGEPChain(CallInst *Call, CallInfo &CInfo);
};
-
+
+std::map<std::string, GlobalVariable *> BPFAbstractMemberAccess::GEPGlobals;
+
+class BPFAbstractMemberAccessLegacyPass final : public FunctionPass {
+ BPFTargetMachine *TM;
+
+ bool runOnFunction(Function &F) override {
+ return BPFAbstractMemberAccess(TM).run(F);
+ }
+
+public:
+ static char ID;
+
+ // Add optional BPFTargetMachine parameter so that BPF backend can add the
+ // phase with target machine to find out the endianness. The default
+ // constructor (without parameters) is used by the pass manager for managing
+ // purposes.
+ BPFAbstractMemberAccessLegacyPass(BPFTargetMachine *TM = nullptr)
+ : FunctionPass(ID), TM(TM) {}
+};
+
} // End anonymous namespace
-char BPFAbstractMemberAccessLegacyPass::ID = 0;
-INITIALIZE_PASS(BPFAbstractMemberAccessLegacyPass, DEBUG_TYPE,
- "BPF Abstract Member Access", false, false)
+char BPFAbstractMemberAccessLegacyPass::ID = 0;
+INITIALIZE_PASS(BPFAbstractMemberAccessLegacyPass, DEBUG_TYPE,
+ "BPF Abstract Member Access", false, false)
-FunctionPass *llvm::createBPFAbstractMemberAccess(BPFTargetMachine *TM) {
- return new BPFAbstractMemberAccessLegacyPass(TM);
+FunctionPass *llvm::createBPFAbstractMemberAccess(BPFTargetMachine *TM) {
+ return new BPFAbstractMemberAccessLegacyPass(TM);
}
-bool BPFAbstractMemberAccess::run(Function &F) {
+bool BPFAbstractMemberAccess::run(Function &F) {
LLVM_DEBUG(dbgs() << "********** Abstract Member Accesses **********\n");
- M = F.getParent();
- if (!M)
- return false;
-
+ M = F.getParent();
+ if (!M)
+ return false;
+
// Bail out if no debug info.
- if (M->debug_compile_units().empty())
+ if (M->debug_compile_units().empty())
return false;
- DL = &M->getDataLayout();
- return doTransformation(F);
+ DL = &M->getDataLayout();
+ return doTransformation(F);
}
static bool SkipDIDerivedTag(unsigned Tag, bool skipTypedef) {
@@ -320,34 +320,34 @@ bool BPFAbstractMemberAccess::IsPreserveDIAccessIndexCall(const CallInst *Call,
CInfo.AccessIndex = InfoKind;
return true;
}
- if (GV->getName().startswith("llvm.bpf.preserve.type.info")) {
- CInfo.Kind = BPFPreserveFieldInfoAI;
- CInfo.Metadata = Call->getMetadata(LLVMContext::MD_preserve_access_index);
- if (!CInfo.Metadata)
- report_fatal_error("Missing metadata for llvm.preserve.type.info intrinsic");
- uint64_t Flag = getConstant(Call->getArgOperand(1));
- if (Flag >= BPFCoreSharedInfo::MAX_PRESERVE_TYPE_INFO_FLAG)
- report_fatal_error("Incorrect flag for llvm.bpf.preserve.type.info intrinsic");
- if (Flag == BPFCoreSharedInfo::PRESERVE_TYPE_INFO_EXISTENCE)
- CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_EXISTENCE;
- else
- CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_SIZE;
- return true;
- }
- if (GV->getName().startswith("llvm.bpf.preserve.enum.value")) {
- CInfo.Kind = BPFPreserveFieldInfoAI;
- CInfo.Metadata = Call->getMetadata(LLVMContext::MD_preserve_access_index);
- if (!CInfo.Metadata)
- report_fatal_error("Missing metadata for llvm.preserve.enum.value intrinsic");
- uint64_t Flag = getConstant(Call->getArgOperand(2));
- if (Flag >= BPFCoreSharedInfo::MAX_PRESERVE_ENUM_VALUE_FLAG)
- report_fatal_error("Incorrect flag for llvm.bpf.preserve.enum.value intrinsic");
- if (Flag == BPFCoreSharedInfo::PRESERVE_ENUM_VALUE_EXISTENCE)
- CInfo.AccessIndex = BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE;
- else
- CInfo.AccessIndex = BPFCoreSharedInfo::ENUM_VALUE;
- return true;
- }
+ if (GV->getName().startswith("llvm.bpf.preserve.type.info")) {
+ CInfo.Kind = BPFPreserveFieldInfoAI;
+ CInfo.Metadata = Call->getMetadata(LLVMContext::MD_preserve_access_index);
+ if (!CInfo.Metadata)
+ report_fatal_error("Missing metadata for llvm.preserve.type.info intrinsic");
+ uint64_t Flag = getConstant(Call->getArgOperand(1));
+ if (Flag >= BPFCoreSharedInfo::MAX_PRESERVE_TYPE_INFO_FLAG)
+ report_fatal_error("Incorrect flag for llvm.bpf.preserve.type.info intrinsic");
+ if (Flag == BPFCoreSharedInfo::PRESERVE_TYPE_INFO_EXISTENCE)
+ CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_EXISTENCE;
+ else
+ CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_SIZE;
+ return true;
+ }
+ if (GV->getName().startswith("llvm.bpf.preserve.enum.value")) {
+ CInfo.Kind = BPFPreserveFieldInfoAI;
+ CInfo.Metadata = Call->getMetadata(LLVMContext::MD_preserve_access_index);
+ if (!CInfo.Metadata)
+ report_fatal_error("Missing metadata for llvm.preserve.enum.value intrinsic");
+ uint64_t Flag = getConstant(Call->getArgOperand(2));
+ if (Flag >= BPFCoreSharedInfo::MAX_PRESERVE_ENUM_VALUE_FLAG)
+ report_fatal_error("Incorrect flag for llvm.bpf.preserve.enum.value intrinsic");
+ if (Flag == BPFCoreSharedInfo::PRESERVE_ENUM_VALUE_EXISTENCE)
+ CInfo.AccessIndex = BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE;
+ else
+ CInfo.AccessIndex = BPFCoreSharedInfo::ENUM_VALUE;
+ return true;
+ }
return false;
}
@@ -374,27 +374,27 @@ void BPFAbstractMemberAccess::replaceWithGEP(std::vector<CallInst *> &CallList,
}
}
-bool BPFAbstractMemberAccess::removePreserveAccessIndexIntrinsic(Function &F) {
+bool BPFAbstractMemberAccess::removePreserveAccessIndexIntrinsic(Function &F) {
std::vector<CallInst *> PreserveArrayIndexCalls;
std::vector<CallInst *> PreserveUnionIndexCalls;
std::vector<CallInst *> PreserveStructIndexCalls;
bool Found = false;
- for (auto &BB : F)
- for (auto &I : BB) {
- auto *Call = dyn_cast<CallInst>(&I);
- CallInfo CInfo;
- if (!IsPreserveDIAccessIndexCall(Call, CInfo))
- continue;
-
- Found = true;
- if (CInfo.Kind == BPFPreserveArrayAI)
- PreserveArrayIndexCalls.push_back(Call);
- else if (CInfo.Kind == BPFPreserveUnionAI)
- PreserveUnionIndexCalls.push_back(Call);
- else
- PreserveStructIndexCalls.push_back(Call);
- }
+ for (auto &BB : F)
+ for (auto &I : BB) {
+ auto *Call = dyn_cast<CallInst>(&I);
+ CallInfo CInfo;
+ if (!IsPreserveDIAccessIndexCall(Call, CInfo))
+ continue;
+
+ Found = true;
+ if (CInfo.Kind == BPFPreserveArrayAI)
+ PreserveArrayIndexCalls.push_back(Call);
+ else if (CInfo.Kind == BPFPreserveUnionAI)
+ PreserveUnionIndexCalls.push_back(Call);
+ else
+ PreserveStructIndexCalls.push_back(Call);
+ }
// do the following transformation:
// . addr = preserve_array_access_index(base, dimension, index)
@@ -560,7 +560,7 @@ void BPFAbstractMemberAccess::traceGEP(GetElementPtrInst *GEP, CallInst *Parent,
}
}
-void BPFAbstractMemberAccess::collectAICallChains(Function &F) {
+void BPFAbstractMemberAccess::collectAICallChains(Function &F) {
AIChain.clear();
BaseAICalls.clear();
@@ -909,94 +909,94 @@ Value *BPFAbstractMemberAccess::computeBaseAndAccessKey(CallInst *Call,
return Base;
}
-MDNode *BPFAbstractMemberAccess::computeAccessKey(CallInst *Call,
- CallInfo &CInfo,
- std::string &AccessKey,
- bool &IsInt32Ret) {
- DIType *Ty = stripQualifiers(cast<DIType>(CInfo.Metadata), false);
- assert(!Ty->getName().empty());
-
- int64_t PatchImm;
- std::string AccessStr("0");
- if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_EXISTENCE) {
- PatchImm = 1;
- } else if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_SIZE) {
- // typedef debuginfo type has size 0, get the eventual base type.
- DIType *BaseTy = stripQualifiers(Ty, true);
- PatchImm = BaseTy->getSizeInBits() / 8;
- } else {
- // ENUM_VALUE_EXISTENCE and ENUM_VALUE
- IsInt32Ret = false;
-
- const auto *CE = cast<ConstantExpr>(Call->getArgOperand(1));
- const GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
- assert(GV->hasInitializer());
- const ConstantDataArray *DA = cast<ConstantDataArray>(GV->getInitializer());
- assert(DA->isString());
- StringRef ValueStr = DA->getAsString();
-
- // ValueStr format: <EnumeratorStr>:<Value>
- size_t Separator = ValueStr.find_first_of(':');
- StringRef EnumeratorStr = ValueStr.substr(0, Separator);
-
- // Find enumerator index in the debuginfo
- DIType *BaseTy = stripQualifiers(Ty, true);
- const auto *CTy = cast<DICompositeType>(BaseTy);
- assert(CTy->getTag() == dwarf::DW_TAG_enumeration_type);
- int EnumIndex = 0;
- for (const auto Element : CTy->getElements()) {
- const auto *Enum = cast<DIEnumerator>(Element);
- if (Enum->getName() == EnumeratorStr) {
- AccessStr = std::to_string(EnumIndex);
- break;
- }
- EnumIndex++;
- }
-
- if (CInfo.AccessIndex == BPFCoreSharedInfo::ENUM_VALUE) {
- StringRef EValueStr = ValueStr.substr(Separator + 1);
- PatchImm = std::stoll(std::string(EValueStr));
- } else {
- PatchImm = 1;
- }
- }
-
- AccessKey = "llvm." + Ty->getName().str() + ":" +
- std::to_string(CInfo.AccessIndex) + std::string(":") +
- std::to_string(PatchImm) + std::string("$") + AccessStr;
-
- return Ty;
-}
-
+MDNode *BPFAbstractMemberAccess::computeAccessKey(CallInst *Call,
+ CallInfo &CInfo,
+ std::string &AccessKey,
+ bool &IsInt32Ret) {
+ DIType *Ty = stripQualifiers(cast<DIType>(CInfo.Metadata), false);
+ assert(!Ty->getName().empty());
+
+ int64_t PatchImm;
+ std::string AccessStr("0");
+ if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_EXISTENCE) {
+ PatchImm = 1;
+ } else if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_SIZE) {
+ // typedef debuginfo type has size 0, get the eventual base type.
+ DIType *BaseTy = stripQualifiers(Ty, true);
+ PatchImm = BaseTy->getSizeInBits() / 8;
+ } else {
+ // ENUM_VALUE_EXISTENCE and ENUM_VALUE
+ IsInt32Ret = false;
+
+ const auto *CE = cast<ConstantExpr>(Call->getArgOperand(1));
+ const GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
+ assert(GV->hasInitializer());
+ const ConstantDataArray *DA = cast<ConstantDataArray>(GV->getInitializer());
+ assert(DA->isString());
+ StringRef ValueStr = DA->getAsString();
+
+ // ValueStr format: <EnumeratorStr>:<Value>
+ size_t Separator = ValueStr.find_first_of(':');
+ StringRef EnumeratorStr = ValueStr.substr(0, Separator);
+
+ // Find enumerator index in the debuginfo
+ DIType *BaseTy = stripQualifiers(Ty, true);
+ const auto *CTy = cast<DICompositeType>(BaseTy);
+ assert(CTy->getTag() == dwarf::DW_TAG_enumeration_type);
+ int EnumIndex = 0;
+ for (const auto Element : CTy->getElements()) {
+ const auto *Enum = cast<DIEnumerator>(Element);
+ if (Enum->getName() == EnumeratorStr) {
+ AccessStr = std::to_string(EnumIndex);
+ break;
+ }
+ EnumIndex++;
+ }
+
+ if (CInfo.AccessIndex == BPFCoreSharedInfo::ENUM_VALUE) {
+ StringRef EValueStr = ValueStr.substr(Separator + 1);
+ PatchImm = std::stoll(std::string(EValueStr));
+ } else {
+ PatchImm = 1;
+ }
+ }
+
+ AccessKey = "llvm." + Ty->getName().str() + ":" +
+ std::to_string(CInfo.AccessIndex) + std::string(":") +
+ std::to_string(PatchImm) + std::string("$") + AccessStr;
+
+ return Ty;
+}
+
/// Call/Kind is the base preserve_*_access_index() call. Attempts to do
/// transformation to a chain of relocable GEPs.
-bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
+bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
CallInfo &CInfo) {
std::string AccessKey;
MDNode *TypeMeta;
- Value *Base = nullptr;
- bool IsInt32Ret;
-
- IsInt32Ret = CInfo.Kind == BPFPreserveFieldInfoAI;
- if (CInfo.Kind == BPFPreserveFieldInfoAI && CInfo.Metadata) {
- TypeMeta = computeAccessKey(Call, CInfo, AccessKey, IsInt32Ret);
- } else {
- Base = computeBaseAndAccessKey(Call, CInfo, AccessKey, TypeMeta);
- if (!Base)
- return false;
- }
-
+ Value *Base = nullptr;
+ bool IsInt32Ret;
+
+ IsInt32Ret = CInfo.Kind == BPFPreserveFieldInfoAI;
+ if (CInfo.Kind == BPFPreserveFieldInfoAI && CInfo.Metadata) {
+ TypeMeta = computeAccessKey(Call, CInfo, AccessKey, IsInt32Ret);
+ } else {
+ Base = computeBaseAndAccessKey(Call, CInfo, AccessKey, TypeMeta);
+ if (!Base)
+ return false;
+ }
+
BasicBlock *BB = Call->getParent();
GlobalVariable *GV;
if (GEPGlobals.find(AccessKey) == GEPGlobals.end()) {
IntegerType *VarType;
- if (IsInt32Ret)
+ if (IsInt32Ret)
VarType = Type::getInt32Ty(BB->getContext()); // 32bit return value
else
- VarType = Type::getInt64Ty(BB->getContext()); // 64bit ptr or enum value
+ VarType = Type::getInt64Ty(BB->getContext()); // 64bit ptr or enum value
- GV = new GlobalVariable(*M, VarType, false, GlobalVariable::ExternalLinkage,
+ GV = new GlobalVariable(*M, VarType, false, GlobalVariable::ExternalLinkage,
NULL, AccessKey);
GV->addAttribute(BPFCoreSharedInfo::AmaAttr);
GV->setMetadata(LLVMContext::MD_preserve_access_index, TypeMeta);
@@ -1007,15 +1007,15 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
if (CInfo.Kind == BPFPreserveFieldInfoAI) {
// Load the global variable which represents the returned field info.
- LoadInst *LDInst;
- if (IsInt32Ret)
- LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "", Call);
- else
- LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
-
- Instruction *PassThroughInst =
- BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
- Call->replaceAllUsesWith(PassThroughInst);
+ LoadInst *LDInst;
+ if (IsInt32Ret)
+ LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "", Call);
+ else
+ LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
+
+ Instruction *PassThroughInst =
+ BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
+ Call->replaceAllUsesWith(PassThroughInst);
Call->eraseFromParent();
return true;
}
@@ -1023,7 +1023,7 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
// For any original GEP Call and Base %2 like
// %4 = bitcast %struct.net_device** %dev1 to i64*
// it is transformed to:
- // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
+ // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
// %7 = bitcast %struct.sk_buff* %2 to i8*
// %8 = getelementptr i8, i8* %7, %6
// %9 = bitcast i8* %8 to i64*
@@ -1046,75 +1046,75 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
auto *BCInst2 = new BitCastInst(GEP, Call->getType());
BB->getInstList().insert(Call->getIterator(), BCInst2);
- // For the following code,
- // Block0:
- // ...
- // if (...) goto Block1 else ...
- // Block1:
- // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
- // %7 = bitcast %struct.sk_buff* %2 to i8*
- // %8 = getelementptr i8, i8* %7, %6
- // ...
- // goto CommonExit
- // Block2:
- // ...
- // if (...) goto Block3 else ...
- // Block3:
- // %6 = load llvm.bpf_map:0:40$0:0:0:2:0
- // %7 = bitcast %struct.sk_buff* %2 to i8*
- // %8 = getelementptr i8, i8* %7, %6
- // ...
- // goto CommonExit
- // CommonExit
- // SimplifyCFG may generate:
- // Block0:
- // ...
- // if (...) goto Block_Common else ...
- // Block2:
- // ...
- // if (...) goto Block_Common else ...
- // Block_Common:
- // PHI = [llvm.sk_buff:0:50$0:0:0:2:0, llvm.bpf_map:0:40$0:0:0:2:0]
- // %6 = load PHI
- // %7 = bitcast %struct.sk_buff* %2 to i8*
- // %8 = getelementptr i8, i8* %7, %6
- // ...
- // goto CommonExit
- // For the above code, we cannot perform proper relocation since
- // "load PHI" has two possible relocations.
- //
- // To prevent above tail merging, we use __builtin_bpf_passthrough()
- // where one of its parameters is a seq_num. Since two
- // __builtin_bpf_passthrough() funcs will always have different seq_num,
- // tail merging cannot happen. The __builtin_bpf_passthrough() will be
- // removed in the beginning of Target IR passes.
- //
- // This approach is also used in other places when global var
- // representing a relocation is used.
- Instruction *PassThroughInst =
- BPFCoreSharedInfo::insertPassThrough(M, BB, BCInst2, Call);
- Call->replaceAllUsesWith(PassThroughInst);
+ // For the following code,
+ // Block0:
+ // ...
+ // if (...) goto Block1 else ...
+ // Block1:
+ // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
+ // %7 = bitcast %struct.sk_buff* %2 to i8*
+ // %8 = getelementptr i8, i8* %7, %6
+ // ...
+ // goto CommonExit
+ // Block2:
+ // ...
+ // if (...) goto Block3 else ...
+ // Block3:
+ // %6 = load llvm.bpf_map:0:40$0:0:0:2:0
+ // %7 = bitcast %struct.sk_buff* %2 to i8*
+ // %8 = getelementptr i8, i8* %7, %6
+ // ...
+ // goto CommonExit
+ // CommonExit
+ // SimplifyCFG may generate:
+ // Block0:
+ // ...
+ // if (...) goto Block_Common else ...
+ // Block2:
+ // ...
+ // if (...) goto Block_Common else ...
+ // Block_Common:
+ // PHI = [llvm.sk_buff:0:50$0:0:0:2:0, llvm.bpf_map:0:40$0:0:0:2:0]
+ // %6 = load PHI
+ // %7 = bitcast %struct.sk_buff* %2 to i8*
+ // %8 = getelementptr i8, i8* %7, %6
+ // ...
+ // goto CommonExit
+ // For the above code, we cannot perform proper relocation since
+ // "load PHI" has two possible relocations.
+ //
+ // To prevent above tail merging, we use __builtin_bpf_passthrough()
+ // where one of its parameters is a seq_num. Since two
+ // __builtin_bpf_passthrough() funcs will always have different seq_num,
+ // tail merging cannot happen. The __builtin_bpf_passthrough() will be
+ // removed in the beginning of Target IR passes.
+ //
+ // This approach is also used in other places when global var
+ // representing a relocation is used.
+ Instruction *PassThroughInst =
+ BPFCoreSharedInfo::insertPassThrough(M, BB, BCInst2, Call);
+ Call->replaceAllUsesWith(PassThroughInst);
Call->eraseFromParent();
return true;
}
-bool BPFAbstractMemberAccess::doTransformation(Function &F) {
+bool BPFAbstractMemberAccess::doTransformation(Function &F) {
bool Transformed = false;
- // Collect PreserveDIAccessIndex Intrinsic call chains.
- // The call chains will be used to generate the access
- // patterns similar to GEP.
- collectAICallChains(F);
-
- for (auto &C : BaseAICalls)
- Transformed = transformGEPChain(C.first, C.second) || Transformed;
+ // Collect PreserveDIAccessIndex Intrinsic call chains.
+ // The call chains will be used to generate the access
+ // patterns similar to GEP.
+ collectAICallChains(F);
- return removePreserveAccessIndexIntrinsic(F) || Transformed;
-}
+ for (auto &C : BaseAICalls)
+ Transformed = transformGEPChain(C.first, C.second) || Transformed;
-PreservedAnalyses
-BPFAbstractMemberAccessPass::run(Function &F, FunctionAnalysisManager &AM) {
- return BPFAbstractMemberAccess(TM).run(F) ? PreservedAnalyses::none()
- : PreservedAnalyses::all();
+ return removePreserveAccessIndexIntrinsic(F) || Transformed;
}
+
+PreservedAnalyses
+BPFAbstractMemberAccessPass::run(Function &F, FunctionAnalysisManager &AM) {
+ return BPFAbstractMemberAccess(TM).run(F) ? PreservedAnalyses::none()
+ : PreservedAnalyses::all();
+}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFAdjustOpt.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFAdjustOpt.cpp
index da543e7eba..9b774357bb 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -1,323 +1,323 @@
-//===---------------- BPFAdjustOpt.cpp - Adjust Optimization --------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// Adjust optimization to make the code more kernel verifier friendly.
-//
-//===----------------------------------------------------------------------===//
-
-#include "BPF.h"
-#include "BPFCORE.h"
-#include "BPFTargetMachine.h"
-#include "llvm/IR/Instruction.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/Type.h"
-#include "llvm/IR/User.h"
-#include "llvm/IR/Value.h"
-#include "llvm/Pass.h"
-#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-
-#define DEBUG_TYPE "bpf-adjust-opt"
-
-using namespace llvm;
-
-static cl::opt<bool>
- DisableBPFserializeICMP("bpf-disable-serialize-icmp", cl::Hidden,
- cl::desc("BPF: Disable Serializing ICMP insns."),
- cl::init(false));
-
-static cl::opt<bool> DisableBPFavoidSpeculation(
- "bpf-disable-avoid-speculation", cl::Hidden,
- cl::desc("BPF: Disable Avoiding Speculative Code Motion."),
- cl::init(false));
-
-namespace {
-
-class BPFAdjustOpt final : public ModulePass {
-public:
- static char ID;
-
- BPFAdjustOpt() : ModulePass(ID) {}
- bool runOnModule(Module &M) override;
-};
-
-class BPFAdjustOptImpl {
- struct PassThroughInfo {
- Instruction *Input;
- Instruction *UsedInst;
- uint32_t OpIdx;
- PassThroughInfo(Instruction *I, Instruction *U, uint32_t Idx)
- : Input(I), UsedInst(U), OpIdx(Idx) {}
- };
-
-public:
- BPFAdjustOptImpl(Module *M) : M(M) {}
-
- bool run();
-
-private:
- Module *M;
- SmallVector<PassThroughInfo, 16> PassThroughs;
-
- void adjustBasicBlock(BasicBlock &BB);
- bool serializeICMPCrossBB(BasicBlock &BB);
- void adjustInst(Instruction &I);
- bool serializeICMPInBB(Instruction &I);
- bool avoidSpeculation(Instruction &I);
- bool insertPassThrough();
-};
-
-} // End anonymous namespace
-
-char BPFAdjustOpt::ID = 0;
-INITIALIZE_PASS(BPFAdjustOpt, "bpf-adjust-opt", "BPF Adjust Optimization",
- false, false)
-
-ModulePass *llvm::createBPFAdjustOpt() { return new BPFAdjustOpt(); }
-
-bool BPFAdjustOpt::runOnModule(Module &M) { return BPFAdjustOptImpl(&M).run(); }
-
-bool BPFAdjustOptImpl::run() {
- for (Function &F : *M)
- for (auto &BB : F) {
- adjustBasicBlock(BB);
- for (auto &I : BB)
- adjustInst(I);
- }
-
- return insertPassThrough();
-}
-
-bool BPFAdjustOptImpl::insertPassThrough() {
- for (auto &Info : PassThroughs) {
- auto *CI = BPFCoreSharedInfo::insertPassThrough(
- M, Info.UsedInst->getParent(), Info.Input, Info.UsedInst);
- Info.UsedInst->setOperand(Info.OpIdx, CI);
- }
-
- return !PassThroughs.empty();
-}
-
-// To avoid combining conditionals in the same basic block by
-// instrcombine optimization.
-bool BPFAdjustOptImpl::serializeICMPInBB(Instruction &I) {
- // For:
- // comp1 = icmp <opcode> ...;
- // comp2 = icmp <opcode> ...;
- // ... or comp1 comp2 ...
- // changed to:
- // comp1 = icmp <opcode> ...;
- // comp2 = icmp <opcode> ...;
- // new_comp1 = __builtin_bpf_passthrough(seq_num, comp1)
- // ... or new_comp1 comp2 ...
- if (I.getOpcode() != Instruction::Or)
- return false;
- auto *Icmp1 = dyn_cast<ICmpInst>(I.getOperand(0));
- if (!Icmp1)
- return false;
- auto *Icmp2 = dyn_cast<ICmpInst>(I.getOperand(1));
- if (!Icmp2)
- return false;
-
- Value *Icmp1Op0 = Icmp1->getOperand(0);
- Value *Icmp2Op0 = Icmp2->getOperand(0);
- if (Icmp1Op0 != Icmp2Op0)
- return false;
-
- // Now we got two icmp instructions which feed into
- // an "or" instruction.
- PassThroughInfo Info(Icmp1, &I, 0);
- PassThroughs.push_back(Info);
- return true;
-}
-
-// To avoid combining conditionals in the same basic block by
-// instrcombine optimization.
-bool BPFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) {
- // For:
- // B1:
- // comp1 = icmp <opcode> ...;
- // if (comp1) goto B2 else B3;
- // B2:
- // comp2 = icmp <opcode> ...;
- // if (comp2) goto B4 else B5;
- // B4:
- // ...
- // changed to:
- // B1:
- // comp1 = icmp <opcode> ...;
- // comp1 = __builtin_bpf_passthrough(seq_num, comp1);
- // if (comp1) goto B2 else B3;
- // B2:
- // comp2 = icmp <opcode> ...;
- // if (comp2) goto B4 else B5;
- // B4:
- // ...
-
- // Check basic predecessors, if two of them (say B1, B2) are using
- // icmp instructions to generate conditions and one is the predesessor
- // of another (e.g., B1 is the predecessor of B2). Add a passthrough
- // barrier after icmp inst of block B1.
- BasicBlock *B2 = BB.getSinglePredecessor();
- if (!B2)
- return false;
-
- BasicBlock *B1 = B2->getSinglePredecessor();
- if (!B1)
- return false;
-
- Instruction *TI = B2->getTerminator();
- auto *BI = dyn_cast<BranchInst>(TI);
- if (!BI || !BI->isConditional())
- return false;
- auto *Cond = dyn_cast<ICmpInst>(BI->getCondition());
- if (!Cond || B2->getFirstNonPHI() != Cond)
- return false;
- Value *B2Op0 = Cond->getOperand(0);
- auto Cond2Op = Cond->getPredicate();
-
- TI = B1->getTerminator();
- BI = dyn_cast<BranchInst>(TI);
- if (!BI || !BI->isConditional())
- return false;
- Cond = dyn_cast<ICmpInst>(BI->getCondition());
- if (!Cond)
- return false;
- Value *B1Op0 = Cond->getOperand(0);
- auto Cond1Op = Cond->getPredicate();
-
- if (B1Op0 != B2Op0)
- return false;
-
- if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
- if (Cond2Op != ICmpInst::ICMP_SLT && Cond1Op != ICmpInst::ICMP_SLE)
- return false;
- } else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
- if (Cond2Op != ICmpInst::ICMP_SGT && Cond1Op != ICmpInst::ICMP_SGE)
- return false;
- } else {
- return false;
- }
-
- PassThroughInfo Info(Cond, BI, 0);
- PassThroughs.push_back(Info);
-
- return true;
-}
-
-// To avoid speculative hoisting certain computations out of
-// a basic block.
-bool BPFAdjustOptImpl::avoidSpeculation(Instruction &I) {
- if (auto *LdInst = dyn_cast<LoadInst>(&I)) {
- if (auto *GV = dyn_cast<GlobalVariable>(LdInst->getOperand(0))) {
- if (GV->hasAttribute(BPFCoreSharedInfo::AmaAttr) ||
- GV->hasAttribute(BPFCoreSharedInfo::TypeIdAttr))
- return false;
- }
- }
-
- if (!isa<LoadInst>(&I) && !isa<CallInst>(&I))
- return false;
-
- // For:
- // B1:
- // var = ...
- // ...
- // /* icmp may not be in the same block as var = ... */
- // comp1 = icmp <opcode> var, <const>;
- // if (comp1) goto B2 else B3;
- // B2:
- // ... var ...
- // change to:
- // B1:
- // var = ...
- // ...
- // /* icmp may not be in the same block as var = ... */
- // comp1 = icmp <opcode> var, <const>;
- // if (comp1) goto B2 else B3;
- // B2:
- // var = __builtin_bpf_passthrough(seq_num, var);
- // ... var ...
- bool isCandidate = false;
- SmallVector<PassThroughInfo, 4> Candidates;
- for (User *U : I.users()) {
- Instruction *Inst = dyn_cast<Instruction>(U);
- if (!Inst)
- continue;
-
- // May cover a little bit more than the
- // above pattern.
- if (auto *Icmp1 = dyn_cast<ICmpInst>(Inst)) {
- Value *Icmp1Op1 = Icmp1->getOperand(1);
- if (!isa<Constant>(Icmp1Op1))
- return false;
- isCandidate = true;
- continue;
- }
-
- // Ignore the use in the same basic block as the definition.
- if (Inst->getParent() == I.getParent())
- continue;
-
- // use in a different basic block, If there is a call or
- // load/store insn before this instruction in this basic
- // block. Most likely it cannot be hoisted out. Skip it.
- for (auto &I2 : *Inst->getParent()) {
- if (dyn_cast<CallInst>(&I2))
- return false;
- if (dyn_cast<LoadInst>(&I2) || dyn_cast<StoreInst>(&I2))
- return false;
- if (&I2 == Inst)
- break;
- }
-
- // It should be used in a GEP or a simple arithmetic like
- // ZEXT/SEXT which is used for GEP.
- if (Inst->getOpcode() == Instruction::ZExt ||
- Inst->getOpcode() == Instruction::SExt) {
- PassThroughInfo Info(&I, Inst, 0);
- Candidates.push_back(Info);
- } else if (auto *GI = dyn_cast<GetElementPtrInst>(Inst)) {
- // traverse GEP inst to find Use operand index
- unsigned i, e;
- for (i = 1, e = GI->getNumOperands(); i != e; ++i) {
- Value *V = GI->getOperand(i);
- if (V == &I)
- break;
- }
- if (i == e)
- continue;
-
- PassThroughInfo Info(&I, GI, i);
- Candidates.push_back(Info);
- }
- }
-
- if (!isCandidate || Candidates.empty())
- return false;
-
- llvm::append_range(PassThroughs, Candidates);
- return true;
-}
-
-void BPFAdjustOptImpl::adjustBasicBlock(BasicBlock &BB) {
- if (!DisableBPFserializeICMP && serializeICMPCrossBB(BB))
- return;
-}
-
-void BPFAdjustOptImpl::adjustInst(Instruction &I) {
- if (!DisableBPFserializeICMP && serializeICMPInBB(I))
- return;
- if (!DisableBPFavoidSpeculation && avoidSpeculation(I))
- return;
-}
-
-PreservedAnalyses BPFAdjustOptPass::run(Module &M, ModuleAnalysisManager &AM) {
- return BPFAdjustOptImpl(&M).run() ? PreservedAnalyses::none()
- : PreservedAnalyses::all();
-}
+//===---------------- BPFAdjustOpt.cpp - Adjust Optimization --------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Adjust optimization to make the code more kernel verifier friendly.
+//
+//===----------------------------------------------------------------------===//
+
+#include "BPF.h"
+#include "BPFCORE.h"
+#include "BPFTargetMachine.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#define DEBUG_TYPE "bpf-adjust-opt"
+
+using namespace llvm;
+
+static cl::opt<bool>
+ DisableBPFserializeICMP("bpf-disable-serialize-icmp", cl::Hidden,
+ cl::desc("BPF: Disable Serializing ICMP insns."),
+ cl::init(false));
+
+static cl::opt<bool> DisableBPFavoidSpeculation(
+ "bpf-disable-avoid-speculation", cl::Hidden,
+ cl::desc("BPF: Disable Avoiding Speculative Code Motion."),
+ cl::init(false));
+
+namespace {
+
+class BPFAdjustOpt final : public ModulePass {
+public:
+ static char ID;
+
+ BPFAdjustOpt() : ModulePass(ID) {}
+ bool runOnModule(Module &M) override;
+};
+
+class BPFAdjustOptImpl {
+ struct PassThroughInfo {
+ Instruction *Input;
+ Instruction *UsedInst;
+ uint32_t OpIdx;
+ PassThroughInfo(Instruction *I, Instruction *U, uint32_t Idx)
+ : Input(I), UsedInst(U), OpIdx(Idx) {}
+ };
+
+public:
+ BPFAdjustOptImpl(Module *M) : M(M) {}
+
+ bool run();
+
+private:
+ Module *M;
+ SmallVector<PassThroughInfo, 16> PassThroughs;
+
+ void adjustBasicBlock(BasicBlock &BB);
+ bool serializeICMPCrossBB(BasicBlock &BB);
+ void adjustInst(Instruction &I);
+ bool serializeICMPInBB(Instruction &I);
+ bool avoidSpeculation(Instruction &I);
+ bool insertPassThrough();
+};
+
+} // End anonymous namespace
+
+char BPFAdjustOpt::ID = 0;
+INITIALIZE_PASS(BPFAdjustOpt, "bpf-adjust-opt", "BPF Adjust Optimization",
+ false, false)
+
+ModulePass *llvm::createBPFAdjustOpt() { return new BPFAdjustOpt(); }
+
+bool BPFAdjustOpt::runOnModule(Module &M) { return BPFAdjustOptImpl(&M).run(); }
+
+bool BPFAdjustOptImpl::run() {
+ for (Function &F : *M)
+ for (auto &BB : F) {
+ adjustBasicBlock(BB);
+ for (auto &I : BB)
+ adjustInst(I);
+ }
+
+ return insertPassThrough();
+}
+
+bool BPFAdjustOptImpl::insertPassThrough() {
+ for (auto &Info : PassThroughs) {
+ auto *CI = BPFCoreSharedInfo::insertPassThrough(
+ M, Info.UsedInst->getParent(), Info.Input, Info.UsedInst);
+ Info.UsedInst->setOperand(Info.OpIdx, CI);
+ }
+
+ return !PassThroughs.empty();
+}
+
+// To avoid combining conditionals in the same basic block by
+// instrcombine optimization.
+bool BPFAdjustOptImpl::serializeICMPInBB(Instruction &I) {
+ // For:
+ // comp1 = icmp <opcode> ...;
+ // comp2 = icmp <opcode> ...;
+ // ... or comp1 comp2 ...
+ // changed to:
+ // comp1 = icmp <opcode> ...;
+ // comp2 = icmp <opcode> ...;
+ // new_comp1 = __builtin_bpf_passthrough(seq_num, comp1)
+ // ... or new_comp1 comp2 ...
+ if (I.getOpcode() != Instruction::Or)
+ return false;
+ auto *Icmp1 = dyn_cast<ICmpInst>(I.getOperand(0));
+ if (!Icmp1)
+ return false;
+ auto *Icmp2 = dyn_cast<ICmpInst>(I.getOperand(1));
+ if (!Icmp2)
+ return false;
+
+ Value *Icmp1Op0 = Icmp1->getOperand(0);
+ Value *Icmp2Op0 = Icmp2->getOperand(0);
+ if (Icmp1Op0 != Icmp2Op0)
+ return false;
+
+ // Now we got two icmp instructions which feed into
+ // an "or" instruction.
+ PassThroughInfo Info(Icmp1, &I, 0);
+ PassThroughs.push_back(Info);
+ return true;
+}
+
+// To avoid combining conditionals in the same basic block by
+// instrcombine optimization.
+bool BPFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) {
+ // For:
+ // B1:
+ // comp1 = icmp <opcode> ...;
+ // if (comp1) goto B2 else B3;
+ // B2:
+ // comp2 = icmp <opcode> ...;
+ // if (comp2) goto B4 else B5;
+ // B4:
+ // ...
+ // changed to:
+ // B1:
+ // comp1 = icmp <opcode> ...;
+ // comp1 = __builtin_bpf_passthrough(seq_num, comp1);
+ // if (comp1) goto B2 else B3;
+ // B2:
+ // comp2 = icmp <opcode> ...;
+ // if (comp2) goto B4 else B5;
+ // B4:
+ // ...
+
+ // Check basic predecessors, if two of them (say B1, B2) are using
+ // icmp instructions to generate conditions and one is the predesessor
+ // of another (e.g., B1 is the predecessor of B2). Add a passthrough
+ // barrier after icmp inst of block B1.
+ BasicBlock *B2 = BB.getSinglePredecessor();
+ if (!B2)
+ return false;
+
+ BasicBlock *B1 = B2->getSinglePredecessor();
+ if (!B1)
+ return false;
+
+ Instruction *TI = B2->getTerminator();
+ auto *BI = dyn_cast<BranchInst>(TI);
+ if (!BI || !BI->isConditional())
+ return false;
+ auto *Cond = dyn_cast<ICmpInst>(BI->getCondition());
+ if (!Cond || B2->getFirstNonPHI() != Cond)
+ return false;
+ Value *B2Op0 = Cond->getOperand(0);
+ auto Cond2Op = Cond->getPredicate();
+
+ TI = B1->getTerminator();
+ BI = dyn_cast<BranchInst>(TI);
+ if (!BI || !BI->isConditional())
+ return false;
+ Cond = dyn_cast<ICmpInst>(BI->getCondition());
+ if (!Cond)
+ return false;
+ Value *B1Op0 = Cond->getOperand(0);
+ auto Cond1Op = Cond->getPredicate();
+
+ if (B1Op0 != B2Op0)
+ return false;
+
+ if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
+ if (Cond2Op != ICmpInst::ICMP_SLT && Cond1Op != ICmpInst::ICMP_SLE)
+ return false;
+ } else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
+ if (Cond2Op != ICmpInst::ICMP_SGT && Cond1Op != ICmpInst::ICMP_SGE)
+ return false;
+ } else {
+ return false;
+ }
+
+ PassThroughInfo Info(Cond, BI, 0);
+ PassThroughs.push_back(Info);
+
+ return true;
+}
+
+// To avoid speculative hoisting certain computations out of
+// a basic block.
+bool BPFAdjustOptImpl::avoidSpeculation(Instruction &I) {
+ if (auto *LdInst = dyn_cast<LoadInst>(&I)) {
+ if (auto *GV = dyn_cast<GlobalVariable>(LdInst->getOperand(0))) {
+ if (GV->hasAttribute(BPFCoreSharedInfo::AmaAttr) ||
+ GV->hasAttribute(BPFCoreSharedInfo::TypeIdAttr))
+ return false;
+ }
+ }
+
+ if (!isa<LoadInst>(&I) && !isa<CallInst>(&I))
+ return false;
+
+ // For:
+ // B1:
+ // var = ...
+ // ...
+ // /* icmp may not be in the same block as var = ... */
+ // comp1 = icmp <opcode> var, <const>;
+ // if (comp1) goto B2 else B3;
+ // B2:
+ // ... var ...
+ // change to:
+ // B1:
+ // var = ...
+ // ...
+ // /* icmp may not be in the same block as var = ... */
+ // comp1 = icmp <opcode> var, <const>;
+ // if (comp1) goto B2 else B3;
+ // B2:
+ // var = __builtin_bpf_passthrough(seq_num, var);
+ // ... var ...
+ bool isCandidate = false;
+ SmallVector<PassThroughInfo, 4> Candidates;
+ for (User *U : I.users()) {
+ Instruction *Inst = dyn_cast<Instruction>(U);
+ if (!Inst)
+ continue;
+
+ // May cover a little bit more than the
+ // above pattern.
+ if (auto *Icmp1 = dyn_cast<ICmpInst>(Inst)) {
+ Value *Icmp1Op1 = Icmp1->getOperand(1);
+ if (!isa<Constant>(Icmp1Op1))
+ return false;
+ isCandidate = true;
+ continue;
+ }
+
+ // Ignore the use in the same basic block as the definition.
+ if (Inst->getParent() == I.getParent())
+ continue;
+
+ // use in a different basic block, If there is a call or
+ // load/store insn before this instruction in this basic
+ // block. Most likely it cannot be hoisted out. Skip it.
+ for (auto &I2 : *Inst->getParent()) {
+ if (dyn_cast<CallInst>(&I2))
+ return false;
+ if (dyn_cast<LoadInst>(&I2) || dyn_cast<StoreInst>(&I2))
+ return false;
+ if (&I2 == Inst)
+ break;
+ }
+
+ // It should be used in a GEP or a simple arithmetic like
+ // ZEXT/SEXT which is used for GEP.
+ if (Inst->getOpcode() == Instruction::ZExt ||
+ Inst->getOpcode() == Instruction::SExt) {
+ PassThroughInfo Info(&I, Inst, 0);
+ Candidates.push_back(Info);
+ } else if (auto *GI = dyn_cast<GetElementPtrInst>(Inst)) {
+ // traverse GEP inst to find Use operand index
+ unsigned i, e;
+ for (i = 1, e = GI->getNumOperands(); i != e; ++i) {
+ Value *V = GI->getOperand(i);
+ if (V == &I)
+ break;
+ }
+ if (i == e)
+ continue;
+
+ PassThroughInfo Info(&I, GI, i);
+ Candidates.push_back(Info);
+ }
+ }
+
+ if (!isCandidate || Candidates.empty())
+ return false;
+
+ llvm::append_range(PassThroughs, Candidates);
+ return true;
+}
+
+void BPFAdjustOptImpl::adjustBasicBlock(BasicBlock &BB) {
+ if (!DisableBPFserializeICMP && serializeICMPCrossBB(BB))
+ return;
+}
+
+void BPFAdjustOptImpl::adjustInst(Instruction &I) {
+ if (!DisableBPFserializeICMP && serializeICMPInBB(I))
+ return;
+ if (!DisableBPFavoidSpeculation && avoidSpeculation(I))
+ return;
+}
+
+PreservedAnalyses BPFAdjustOptPass::run(Module &M, ModuleAnalysisManager &AM) {
+ return BPFAdjustOptImpl(&M).run() ? PreservedAnalyses::none()
+ : PreservedAnalyses::all();
+}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFCORE.h b/contrib/libs/llvm12/lib/Target/BPF/BPFCORE.h
index 0c50441248..c7692786d4 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFCORE.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFCORE.h
@@ -13,10 +13,10 @@
namespace llvm {
-class BasicBlock;
-class Instruction;
-class Module;
-
+class BasicBlock;
+class Instruction;
+class Module;
+
class BPFCoreSharedInfo {
public:
enum PatchableRelocKind : uint32_t {
@@ -28,10 +28,10 @@ public:
FIELD_RSHIFT_U64,
BTF_TYPE_ID_LOCAL,
BTF_TYPE_ID_REMOTE,
- TYPE_EXISTENCE,
- TYPE_SIZE,
- ENUM_VALUE_EXISTENCE,
- ENUM_VALUE,
+ TYPE_EXISTENCE,
+ TYPE_SIZE,
+ ENUM_VALUE_EXISTENCE,
+ ENUM_VALUE,
MAX_FIELD_RELOC_KIND,
};
@@ -43,32 +43,32 @@ public:
MAX_BTF_TYPE_ID_FLAG,
};
- enum PreserveTypeInfo : uint32_t {
- PRESERVE_TYPE_INFO_EXISTENCE = 0,
- PRESERVE_TYPE_INFO_SIZE,
-
- MAX_PRESERVE_TYPE_INFO_FLAG,
- };
-
- enum PreserveEnumValue : uint32_t {
- PRESERVE_ENUM_VALUE_EXISTENCE = 0,
- PRESERVE_ENUM_VALUE,
-
- MAX_PRESERVE_ENUM_VALUE_FLAG,
- };
-
+ enum PreserveTypeInfo : uint32_t {
+ PRESERVE_TYPE_INFO_EXISTENCE = 0,
+ PRESERVE_TYPE_INFO_SIZE,
+
+ MAX_PRESERVE_TYPE_INFO_FLAG,
+ };
+
+ enum PreserveEnumValue : uint32_t {
+ PRESERVE_ENUM_VALUE_EXISTENCE = 0,
+ PRESERVE_ENUM_VALUE,
+
+ MAX_PRESERVE_ENUM_VALUE_FLAG,
+ };
+
/// The attribute attached to globals representing a field access
static constexpr StringRef AmaAttr = "btf_ama";
/// The attribute attached to globals representing a type id
static constexpr StringRef TypeIdAttr = "btf_type_id";
-
- /// llvm.bpf.passthrough builtin seq number
- static uint32_t SeqNum;
-
- /// Insert a bpf passthrough builtin function.
- static Instruction *insertPassThrough(Module *M, BasicBlock *BB,
- Instruction *Input,
- Instruction *Before);
+
+ /// llvm.bpf.passthrough builtin seq number
+ static uint32_t SeqNum;
+
+ /// Insert a bpf passthrough builtin function.
+ static Instruction *insertPassThrough(Module *M, BasicBlock *BB,
+ Instruction *Input,
+ Instruction *Before);
};
} // namespace llvm
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFCheckAndAdjustIR.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
index 5239218ad0..c829f923b1 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
@@ -1,130 +1,130 @@
-//===------------ BPFCheckAndAdjustIR.cpp - Check and Adjust IR -----------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// Check IR and adjust IR for verifier friendly codes.
-// The following are done for IR checking:
-// - no relocation globals in PHI node.
-// The following are done for IR adjustment:
-// - remove __builtin_bpf_passthrough builtins. Target independent IR
-// optimizations are done and those builtins can be removed.
-//
-//===----------------------------------------------------------------------===//
-
-#include "BPF.h"
-#include "BPFCORE.h"
-#include "BPFTargetMachine.h"
-#include "llvm/IR/DebugInfoMetadata.h"
-#include "llvm/IR/GlobalVariable.h"
-#include "llvm/IR/Instruction.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/Type.h"
-#include "llvm/IR/User.h"
-#include "llvm/IR/Value.h"
-#include "llvm/Pass.h"
-#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-
-#define DEBUG_TYPE "bpf-check-and-opt-ir"
-
-using namespace llvm;
-
-namespace {
-
-class BPFCheckAndAdjustIR final : public ModulePass {
- bool runOnModule(Module &F) override;
-
-public:
- static char ID;
- BPFCheckAndAdjustIR() : ModulePass(ID) {}
-
-private:
- void checkIR(Module &M);
- bool adjustIR(Module &M);
- bool removePassThroughBuiltin(Module &M);
-};
-} // End anonymous namespace
-
-char BPFCheckAndAdjustIR::ID = 0;
-INITIALIZE_PASS(BPFCheckAndAdjustIR, DEBUG_TYPE, "BPF Check And Adjust IR",
- false, false)
-
-ModulePass *llvm::createBPFCheckAndAdjustIR() {
- return new BPFCheckAndAdjustIR();
-}
-
-void BPFCheckAndAdjustIR::checkIR(Module &M) {
- // Ensure relocation global won't appear in PHI node
- // This may happen if the compiler generated the following code:
- // B1:
- // g1 = @llvm.skb_buff:0:1...
- // ...
- // goto B_COMMON
- // B2:
- // g2 = @llvm.skb_buff:0:2...
- // ...
- // goto B_COMMON
- // B_COMMON:
- // g = PHI(g1, g2)
- // x = load g
- // ...
- // If anything likes the above "g = PHI(g1, g2)", issue a fatal error.
- for (Function &F : M)
- for (auto &BB : F)
- for (auto &I : BB) {
- PHINode *PN = dyn_cast<PHINode>(&I);
- if (!PN || PN->use_empty())
- continue;
- for (int i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
- auto *GV = dyn_cast<GlobalVariable>(PN->getIncomingValue(i));
- if (!GV)
- continue;
- if (GV->hasAttribute(BPFCoreSharedInfo::AmaAttr) ||
- GV->hasAttribute(BPFCoreSharedInfo::TypeIdAttr))
- report_fatal_error("relocation global in PHI node");
- }
- }
-}
-
-bool BPFCheckAndAdjustIR::removePassThroughBuiltin(Module &M) {
- // Remove __builtin_bpf_passthrough()'s which are used to prevent
- // certain IR optimizations. Now major IR optimizations are done,
- // remove them.
- bool Changed = false;
- CallInst *ToBeDeleted = nullptr;
- for (Function &F : M)
- for (auto &BB : F)
- for (auto &I : BB) {
- if (ToBeDeleted) {
- ToBeDeleted->eraseFromParent();
- ToBeDeleted = nullptr;
- }
-
- auto *Call = dyn_cast<CallInst>(&I);
- if (!Call)
- continue;
- auto *GV = dyn_cast<GlobalValue>(Call->getCalledOperand());
- if (!GV)
- continue;
- if (!GV->getName().startswith("llvm.bpf.passthrough"))
- continue;
- Changed = true;
- Value *Arg = Call->getArgOperand(1);
- Call->replaceAllUsesWith(Arg);
- ToBeDeleted = Call;
- }
- return Changed;
-}
-
-bool BPFCheckAndAdjustIR::adjustIR(Module &M) {
- return removePassThroughBuiltin(M);
-}
-
-bool BPFCheckAndAdjustIR::runOnModule(Module &M) {
- checkIR(M);
- return adjustIR(M);
-}
+//===------------ BPFCheckAndAdjustIR.cpp - Check and Adjust IR -----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Check IR and adjust IR for verifier friendly codes.
+// The following are done for IR checking:
+// - no relocation globals in PHI node.
+// The following are done for IR adjustment:
+// - remove __builtin_bpf_passthrough builtins. Target independent IR
+// optimizations are done and those builtins can be removed.
+//
+//===----------------------------------------------------------------------===//
+
+#include "BPF.h"
+#include "BPFCORE.h"
+#include "BPFTargetMachine.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#define DEBUG_TYPE "bpf-check-and-opt-ir"
+
+using namespace llvm;
+
+namespace {
+
+class BPFCheckAndAdjustIR final : public ModulePass {
+ bool runOnModule(Module &F) override;
+
+public:
+ static char ID;
+ BPFCheckAndAdjustIR() : ModulePass(ID) {}
+
+private:
+ void checkIR(Module &M);
+ bool adjustIR(Module &M);
+ bool removePassThroughBuiltin(Module &M);
+};
+} // End anonymous namespace
+
+char BPFCheckAndAdjustIR::ID = 0;
+INITIALIZE_PASS(BPFCheckAndAdjustIR, DEBUG_TYPE, "BPF Check And Adjust IR",
+ false, false)
+
+ModulePass *llvm::createBPFCheckAndAdjustIR() {
+ return new BPFCheckAndAdjustIR();
+}
+
+void BPFCheckAndAdjustIR::checkIR(Module &M) {
+ // Ensure relocation global won't appear in PHI node
+ // This may happen if the compiler generated the following code:
+ // B1:
+ // g1 = @llvm.skb_buff:0:1...
+ // ...
+ // goto B_COMMON
+ // B2:
+ // g2 = @llvm.skb_buff:0:2...
+ // ...
+ // goto B_COMMON
+ // B_COMMON:
+ // g = PHI(g1, g2)
+ // x = load g
+ // ...
+ // If anything likes the above "g = PHI(g1, g2)", issue a fatal error.
+ for (Function &F : M)
+ for (auto &BB : F)
+ for (auto &I : BB) {
+ PHINode *PN = dyn_cast<PHINode>(&I);
+ if (!PN || PN->use_empty())
+ continue;
+ for (int i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
+ auto *GV = dyn_cast<GlobalVariable>(PN->getIncomingValue(i));
+ if (!GV)
+ continue;
+ if (GV->hasAttribute(BPFCoreSharedInfo::AmaAttr) ||
+ GV->hasAttribute(BPFCoreSharedInfo::TypeIdAttr))
+ report_fatal_error("relocation global in PHI node");
+ }
+ }
+}
+
+bool BPFCheckAndAdjustIR::removePassThroughBuiltin(Module &M) {
+ // Remove __builtin_bpf_passthrough()'s which are used to prevent
+ // certain IR optimizations. Now major IR optimizations are done,
+ // remove them.
+ bool Changed = false;
+ CallInst *ToBeDeleted = nullptr;
+ for (Function &F : M)
+ for (auto &BB : F)
+ for (auto &I : BB) {
+ if (ToBeDeleted) {
+ ToBeDeleted->eraseFromParent();
+ ToBeDeleted = nullptr;
+ }
+
+ auto *Call = dyn_cast<CallInst>(&I);
+ if (!Call)
+ continue;
+ auto *GV = dyn_cast<GlobalValue>(Call->getCalledOperand());
+ if (!GV)
+ continue;
+ if (!GV->getName().startswith("llvm.bpf.passthrough"))
+ continue;
+ Changed = true;
+ Value *Arg = Call->getArgOperand(1);
+ Call->replaceAllUsesWith(Arg);
+ ToBeDeleted = Call;
+ }
+ return Changed;
+}
+
+bool BPFCheckAndAdjustIR::adjustIR(Module &M) {
+ return removePassThroughBuiltin(M);
+}
+
+bool BPFCheckAndAdjustIR::runOnModule(Module &M) {
+ checkIR(M);
+ return adjustIR(M);
+}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFInstrFormats.td b/contrib/libs/llvm12/lib/Target/BPF/BPFInstrFormats.td
index a809065014..0601b400c4 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFInstrFormats.td
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFInstrFormats.td
@@ -44,9 +44,9 @@ def BPF_MOV : BPFArithOp<0xb>;
def BPF_ARSH : BPFArithOp<0xc>;
def BPF_END : BPFArithOp<0xd>;
-def BPF_XCHG : BPFArithOp<0xe>;
-def BPF_CMPXCHG : BPFArithOp<0xf>;
-
+def BPF_XCHG : BPFArithOp<0xe>;
+def BPF_CMPXCHG : BPFArithOp<0xf>;
+
class BPFEndDir<bits<1> val> {
bits<1> Value = val;
}
@@ -89,14 +89,14 @@ def BPF_IMM : BPFModeModifer<0x0>;
def BPF_ABS : BPFModeModifer<0x1>;
def BPF_IND : BPFModeModifer<0x2>;
def BPF_MEM : BPFModeModifer<0x3>;
-def BPF_ATOMIC : BPFModeModifer<0x6>;
-
-class BPFAtomicFlag<bits<4> val> {
- bits<4> Value = val;
-}
-
-def BPF_FETCH : BPFAtomicFlag<0x1>;
-
+def BPF_ATOMIC : BPFModeModifer<0x6>;
+
+class BPFAtomicFlag<bits<4> val> {
+ bits<4> Value = val;
+}
+
+def BPF_FETCH : BPFAtomicFlag<0x1>;
+
class InstBPF<dag outs, dag ins, string asmstr, list<dag> pattern>
: Instruction {
field bits<64> Inst;
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFInstrInfo.td b/contrib/libs/llvm12/lib/Target/BPF/BPFInstrInfo.td
index 082e1f4a92..b520ee7121 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFInstrInfo.td
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFInstrInfo.td
@@ -617,9 +617,9 @@ let Predicates = [BPFNoALU32] in {
def : Pat<(i64 (extloadi32 ADDRri:$src)), (i64 (LDW ADDRri:$src))>;
}
-// Atomic XADD for BPFNoALU32
+// Atomic XADD for BPFNoALU32
class XADD<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
(outs GPR:$dst),
(ins MEMri:$addr, GPR:$val),
"lock *("#OpcodeStr#" *)($addr) += $val",
@@ -630,88 +630,88 @@ class XADD<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
let Inst{51-48} = addr{19-16}; // base reg
let Inst{55-52} = dst;
let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = BPF_ADD.Value;
+ let Inst{7-4} = BPF_ADD.Value;
let BPFClass = BPF_STX;
}
-let Constraints = "$dst = $val" in {
- let Predicates = [BPFNoALU32] in {
- def XADDW : XADD<BPF_W, "u32", atomic_load_add_32>;
- }
-}
-
-// Atomic add, and, or, xor
-class ATOMIC_NOFETCH<BPFArithOp Opc, string Opstr>
- : TYPE_LD_ST<BPF_ATOMIC.Value, BPF_DW.Value,
- (outs GPR:$dst),
- (ins MEMri:$addr, GPR:$val),
- "lock *(u64 *)($addr) " #Opstr# "= $val",
- []> {
- bits<4> dst;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = dst;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = Opc.Value;
- let BPFClass = BPF_STX;
-}
-
-class ATOMIC32_NOFETCH<BPFArithOp Opc, string Opstr>
- : TYPE_LD_ST<BPF_ATOMIC.Value, BPF_W.Value,
+let Constraints = "$dst = $val" in {
+ let Predicates = [BPFNoALU32] in {
+ def XADDW : XADD<BPF_W, "u32", atomic_load_add_32>;
+ }
+}
+
+// Atomic add, and, or, xor
+class ATOMIC_NOFETCH<BPFArithOp Opc, string Opstr>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, BPF_DW.Value,
+ (outs GPR:$dst),
+ (ins MEMri:$addr, GPR:$val),
+ "lock *(u64 *)($addr) " #Opstr# "= $val",
+ []> {
+ bits<4> dst;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = dst;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = Opc.Value;
+ let BPFClass = BPF_STX;
+}
+
+class ATOMIC32_NOFETCH<BPFArithOp Opc, string Opstr>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, BPF_W.Value,
(outs GPR32:$dst),
(ins MEMri:$addr, GPR32:$val),
- "lock *(u32 *)($addr) " #Opstr# "= $val",
- []> {
- bits<4> dst;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = dst;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = Opc.Value;
- let BPFClass = BPF_STX;
-}
-
-let Constraints = "$dst = $val" in {
- let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
- def XADDW32 : ATOMIC32_NOFETCH<BPF_ADD, "+">;
- def XANDW32 : ATOMIC32_NOFETCH<BPF_AND, "&">;
- def XORW32 : ATOMIC32_NOFETCH<BPF_OR, "|">;
- def XXORW32 : ATOMIC32_NOFETCH<BPF_XOR, "^">;
- }
-
- def XADDD : ATOMIC_NOFETCH<BPF_ADD, "+">;
- def XANDD : ATOMIC_NOFETCH<BPF_AND, "&">;
- def XORD : ATOMIC_NOFETCH<BPF_OR, "|">;
- def XXORD : ATOMIC_NOFETCH<BPF_XOR, "^">;
-}
-
-// Atomic Fetch-and-<add, and, or, xor> operations
-class XFALU64<BPFWidthModifer SizeOp, BPFArithOp Opc, string OpcodeStr,
- string OpcStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs GPR:$dst),
- (ins MEMri:$addr, GPR:$val),
- "$dst = atomic_fetch_"#OpcStr#"(("#OpcodeStr#" *)($addr), $val)",
- [(set GPR:$dst, (OpNode ADDRri:$addr, GPR:$val))]> {
- bits<4> dst;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = dst;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = Opc.Value;
- let Inst{3-0} = BPF_FETCH.Value;
- let BPFClass = BPF_STX;
-}
-
-class XFALU32<BPFWidthModifer SizeOp, BPFArithOp Opc, string OpcodeStr,
- string OpcStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs GPR32:$dst),
- (ins MEMri:$addr, GPR32:$val),
- "$dst = atomic_fetch_"#OpcStr#"(("#OpcodeStr#" *)($addr), $val)",
+ "lock *(u32 *)($addr) " #Opstr# "= $val",
+ []> {
+ bits<4> dst;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = dst;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = Opc.Value;
+ let BPFClass = BPF_STX;
+}
+
+let Constraints = "$dst = $val" in {
+ let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
+ def XADDW32 : ATOMIC32_NOFETCH<BPF_ADD, "+">;
+ def XANDW32 : ATOMIC32_NOFETCH<BPF_AND, "&">;
+ def XORW32 : ATOMIC32_NOFETCH<BPF_OR, "|">;
+ def XXORW32 : ATOMIC32_NOFETCH<BPF_XOR, "^">;
+ }
+
+ def XADDD : ATOMIC_NOFETCH<BPF_ADD, "+">;
+ def XANDD : ATOMIC_NOFETCH<BPF_AND, "&">;
+ def XORD : ATOMIC_NOFETCH<BPF_OR, "|">;
+ def XXORD : ATOMIC_NOFETCH<BPF_XOR, "^">;
+}
+
+// Atomic Fetch-and-<add, and, or, xor> operations
+class XFALU64<BPFWidthModifer SizeOp, BPFArithOp Opc, string OpcodeStr,
+ string OpcStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs GPR:$dst),
+ (ins MEMri:$addr, GPR:$val),
+ "$dst = atomic_fetch_"#OpcStr#"(("#OpcodeStr#" *)($addr), $val)",
+ [(set GPR:$dst, (OpNode ADDRri:$addr, GPR:$val))]> {
+ bits<4> dst;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = dst;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = Opc.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
+ let BPFClass = BPF_STX;
+}
+
+class XFALU32<BPFWidthModifer SizeOp, BPFArithOp Opc, string OpcodeStr,
+ string OpcStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs GPR32:$dst),
+ (ins MEMri:$addr, GPR32:$val),
+ "$dst = atomic_fetch_"#OpcStr#"(("#OpcodeStr#" *)($addr), $val)",
[(set GPR32:$dst, (OpNode ADDRri:$addr, GPR32:$val))]> {
bits<4> dst;
bits<20> addr;
@@ -719,119 +719,119 @@ class XFALU32<BPFWidthModifer SizeOp, BPFArithOp Opc, string OpcodeStr,
let Inst{51-48} = addr{19-16}; // base reg
let Inst{55-52} = dst;
let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = Opc.Value;
- let Inst{3-0} = BPF_FETCH.Value;
+ let Inst{7-4} = Opc.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
let BPFClass = BPF_STX;
}
let Constraints = "$dst = $val" in {
- let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
- def XFADDW32 : XFALU32<BPF_W, BPF_ADD, "u32", "add", atomic_load_add_32>;
- def XFANDW32 : XFALU32<BPF_W, BPF_AND, "u32", "and", atomic_load_and_32>;
- def XFORW32 : XFALU32<BPF_W, BPF_OR, "u32", "or", atomic_load_or_32>;
- def XFXORW32 : XFALU32<BPF_W, BPF_XOR, "u32", "xor", atomic_load_xor_32>;
+ let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
+ def XFADDW32 : XFALU32<BPF_W, BPF_ADD, "u32", "add", atomic_load_add_32>;
+ def XFANDW32 : XFALU32<BPF_W, BPF_AND, "u32", "and", atomic_load_and_32>;
+ def XFORW32 : XFALU32<BPF_W, BPF_OR, "u32", "or", atomic_load_or_32>;
+ def XFXORW32 : XFALU32<BPF_W, BPF_XOR, "u32", "xor", atomic_load_xor_32>;
}
- def XFADDD : XFALU64<BPF_DW, BPF_ADD, "u64", "add", atomic_load_add_64>;
- def XFANDD : XFALU64<BPF_DW, BPF_AND, "u64", "and", atomic_load_and_64>;
- def XFORD : XFALU64<BPF_DW, BPF_OR, "u64", "or", atomic_load_or_64>;
- def XFXORD : XFALU64<BPF_DW, BPF_XOR, "u64", "xor", atomic_load_xor_64>;
-}
-
-// atomic_load_sub can be represented as a neg followed
-// by an atomic_load_add.
-def : Pat<(atomic_load_sub_32 ADDRri:$addr, GPR32:$val),
- (XFADDW32 ADDRri:$addr, (NEG_32 GPR32:$val))>;
-def : Pat<(atomic_load_sub_64 ADDRri:$addr, GPR:$val),
- (XFADDD ADDRri:$addr, (NEG_64 GPR:$val))>;
-
-// Atomic Exchange
-class XCHG<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs GPR:$dst),
- (ins MEMri:$addr, GPR:$val),
- "$dst = xchg_"#OpcodeStr#"($addr, $val)",
- [(set GPR:$dst, (OpNode ADDRri:$addr,GPR:$val))]> {
- bits<4> dst;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = dst;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = BPF_XCHG.Value;
- let Inst{3-0} = BPF_FETCH.Value;
- let BPFClass = BPF_STX;
-}
-
-class XCHG32<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs GPR32:$dst),
- (ins MEMri:$addr, GPR32:$val),
- "$dst = xchg32_"#OpcodeStr#"($addr, $val)",
- [(set GPR32:$dst, (OpNode ADDRri:$addr,GPR32:$val))]> {
- bits<4> dst;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = dst;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = BPF_XCHG.Value;
- let Inst{3-0} = BPF_FETCH.Value;
- let BPFClass = BPF_STX;
-}
-
-let Constraints = "$dst = $val" in {
+ def XFADDD : XFALU64<BPF_DW, BPF_ADD, "u64", "add", atomic_load_add_64>;
+ def XFANDD : XFALU64<BPF_DW, BPF_AND, "u64", "and", atomic_load_and_64>;
+ def XFORD : XFALU64<BPF_DW, BPF_OR, "u64", "or", atomic_load_or_64>;
+ def XFXORD : XFALU64<BPF_DW, BPF_XOR, "u64", "xor", atomic_load_xor_64>;
+}
+
+// atomic_load_sub can be represented as a neg followed
+// by an atomic_load_add.
+def : Pat<(atomic_load_sub_32 ADDRri:$addr, GPR32:$val),
+ (XFADDW32 ADDRri:$addr, (NEG_32 GPR32:$val))>;
+def : Pat<(atomic_load_sub_64 ADDRri:$addr, GPR:$val),
+ (XFADDD ADDRri:$addr, (NEG_64 GPR:$val))>;
+
+// Atomic Exchange
+class XCHG<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs GPR:$dst),
+ (ins MEMri:$addr, GPR:$val),
+ "$dst = xchg_"#OpcodeStr#"($addr, $val)",
+ [(set GPR:$dst, (OpNode ADDRri:$addr,GPR:$val))]> {
+ bits<4> dst;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = dst;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = BPF_XCHG.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
+ let BPFClass = BPF_STX;
+}
+
+class XCHG32<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs GPR32:$dst),
+ (ins MEMri:$addr, GPR32:$val),
+ "$dst = xchg32_"#OpcodeStr#"($addr, $val)",
+ [(set GPR32:$dst, (OpNode ADDRri:$addr,GPR32:$val))]> {
+ bits<4> dst;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = dst;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = BPF_XCHG.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
+ let BPFClass = BPF_STX;
+}
+
+let Constraints = "$dst = $val" in {
let Predicates = [BPFHasALU32], DecoderNamespace = "BPFALU32" in {
- def XCHGW32 : XCHG32<BPF_W, "32", atomic_swap_32>;
+ def XCHGW32 : XCHG32<BPF_W, "32", atomic_swap_32>;
}
- def XCHGD : XCHG<BPF_DW, "64", atomic_swap_64>;
-}
-
-// Compare-And-Exchange
-class CMPXCHG<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs),
- (ins MEMri:$addr, GPR:$new),
- "r0 = cmpxchg_"#OpcodeStr#"($addr, r0, $new)",
- [(set R0, (OpNode ADDRri:$addr, R0, GPR:$new))]> {
- bits<4> new;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = new;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = BPF_CMPXCHG.Value;
- let Inst{3-0} = BPF_FETCH.Value;
- let BPFClass = BPF_STX;
-}
-
-class CMPXCHG32<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
- : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
- (outs),
- (ins MEMri:$addr, GPR32:$new),
- "w0 = cmpxchg32_"#OpcodeStr#"($addr, w0, $new)",
- [(set W0, (OpNode ADDRri:$addr, W0, GPR32:$new))]> {
- bits<4> new;
- bits<20> addr;
-
- let Inst{51-48} = addr{19-16}; // base reg
- let Inst{55-52} = new;
- let Inst{47-32} = addr{15-0}; // offset
- let Inst{7-4} = BPF_CMPXCHG.Value;
- let Inst{3-0} = BPF_FETCH.Value;
- let BPFClass = BPF_STX;
-}
-
-let Predicates = [BPFHasALU32], Defs = [W0], Uses = [W0],
- DecoderNamespace = "BPFALU32" in {
- def CMPXCHGW32 : CMPXCHG32<BPF_W, "32", atomic_cmp_swap_32>;
-}
-
-let Defs = [R0], Uses = [R0] in {
- def CMPXCHGD : CMPXCHG<BPF_DW, "64", atomic_cmp_swap_64>;
-}
-
+ def XCHGD : XCHG<BPF_DW, "64", atomic_swap_64>;
+}
+
+// Compare-And-Exchange
+class CMPXCHG<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs),
+ (ins MEMri:$addr, GPR:$new),
+ "r0 = cmpxchg_"#OpcodeStr#"($addr, r0, $new)",
+ [(set R0, (OpNode ADDRri:$addr, R0, GPR:$new))]> {
+ bits<4> new;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = new;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = BPF_CMPXCHG.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
+ let BPFClass = BPF_STX;
+}
+
+class CMPXCHG32<BPFWidthModifer SizeOp, string OpcodeStr, PatFrag OpNode>
+ : TYPE_LD_ST<BPF_ATOMIC.Value, SizeOp.Value,
+ (outs),
+ (ins MEMri:$addr, GPR32:$new),
+ "w0 = cmpxchg32_"#OpcodeStr#"($addr, w0, $new)",
+ [(set W0, (OpNode ADDRri:$addr, W0, GPR32:$new))]> {
+ bits<4> new;
+ bits<20> addr;
+
+ let Inst{51-48} = addr{19-16}; // base reg
+ let Inst{55-52} = new;
+ let Inst{47-32} = addr{15-0}; // offset
+ let Inst{7-4} = BPF_CMPXCHG.Value;
+ let Inst{3-0} = BPF_FETCH.Value;
+ let BPFClass = BPF_STX;
+}
+
+let Predicates = [BPFHasALU32], Defs = [W0], Uses = [W0],
+ DecoderNamespace = "BPFALU32" in {
+ def CMPXCHGW32 : CMPXCHG32<BPF_W, "32", atomic_cmp_swap_32>;
+}
+
+let Defs = [R0], Uses = [R0] in {
+ def CMPXCHGD : CMPXCHG<BPF_DW, "64", atomic_cmp_swap_64>;
+}
+
// bswap16, bswap32, bswap64
class BSWAP<bits<32> SizeOp, string OpcodeStr, BPFSrcType SrcType, list<dag> Pattern>
: TYPE_ALU_JMP<BPF_END.Value, SrcType.Value,
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFMIChecking.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFMIChecking.cpp
index 4e24e3d911..5354a67571 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFMIChecking.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFMIChecking.cpp
@@ -41,7 +41,7 @@ private:
// Initialize class variables.
void initialize(MachineFunction &MFParm);
- bool processAtomicInsts(void);
+ bool processAtomicInsts(void);
public:
@@ -49,7 +49,7 @@ public:
bool runOnMachineFunction(MachineFunction &MF) override {
if (!skipFunction(MF.getFunction())) {
initialize(MF);
- return processAtomicInsts();
+ return processAtomicInsts();
}
return false;
}
@@ -145,13 +145,13 @@ static bool hasLiveDefs(const MachineInstr &MI, const TargetRegisterInfo *TRI) {
// Otherwise, return true if any aliased SuperReg of GPR32 is not dead.
for (auto I : GPR32LiveDefs)
for (MCSuperRegIterator SR(I, TRI); SR.isValid(); ++SR)
- if (!llvm::is_contained(GPR64DeadDefs, *SR))
- return true;
+ if (!llvm::is_contained(GPR64DeadDefs, *SR))
+ return true;
return false;
}
-bool BPFMIPreEmitChecking::processAtomicInsts(void) {
+bool BPFMIPreEmitChecking::processAtomicInsts(void) {
for (MachineBasicBlock &MBB : *MF) {
for (MachineInstr &MI : MBB) {
if (MI.getOpcode() != BPF::XADDW &&
@@ -172,71 +172,71 @@ bool BPFMIPreEmitChecking::processAtomicInsts(void) {
}
}
- // Check return values of atomic_fetch_and_{add,and,or,xor}.
- // If the return is not used, the atomic_fetch_and_<op> instruction
- // is replaced with atomic_<op> instruction.
- MachineInstr *ToErase = nullptr;
- bool Changed = false;
- const BPFInstrInfo *TII = MF->getSubtarget<BPFSubtarget>().getInstrInfo();
- for (MachineBasicBlock &MBB : *MF) {
- for (MachineInstr &MI : MBB) {
- if (ToErase) {
- ToErase->eraseFromParent();
- ToErase = nullptr;
- }
-
- if (MI.getOpcode() != BPF::XFADDW32 && MI.getOpcode() != BPF::XFADDD &&
- MI.getOpcode() != BPF::XFANDW32 && MI.getOpcode() != BPF::XFANDD &&
- MI.getOpcode() != BPF::XFXORW32 && MI.getOpcode() != BPF::XFXORD &&
- MI.getOpcode() != BPF::XFORW32 && MI.getOpcode() != BPF::XFORD)
- continue;
-
- if (hasLiveDefs(MI, TRI))
- continue;
-
- LLVM_DEBUG(dbgs() << "Transforming "; MI.dump());
- unsigned newOpcode;
- switch (MI.getOpcode()) {
- case BPF::XFADDW32:
- newOpcode = BPF::XADDW32;
- break;
- case BPF::XFADDD:
- newOpcode = BPF::XADDD;
- break;
- case BPF::XFANDW32:
- newOpcode = BPF::XANDW32;
- break;
- case BPF::XFANDD:
- newOpcode = BPF::XANDD;
- break;
- case BPF::XFXORW32:
- newOpcode = BPF::XXORW32;
- break;
- case BPF::XFXORD:
- newOpcode = BPF::XXORD;
- break;
- case BPF::XFORW32:
- newOpcode = BPF::XORW32;
- break;
- case BPF::XFORD:
- newOpcode = BPF::XORD;
- break;
- default:
- llvm_unreachable("Incorrect Atomic Instruction Opcode");
- }
-
- BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(newOpcode))
- .add(MI.getOperand(0))
- .add(MI.getOperand(1))
- .add(MI.getOperand(2))
- .add(MI.getOperand(3));
-
- ToErase = &MI;
- Changed = true;
- }
- }
-
- return Changed;
+ // Check return values of atomic_fetch_and_{add,and,or,xor}.
+ // If the return is not used, the atomic_fetch_and_<op> instruction
+ // is replaced with atomic_<op> instruction.
+ MachineInstr *ToErase = nullptr;
+ bool Changed = false;
+ const BPFInstrInfo *TII = MF->getSubtarget<BPFSubtarget>().getInstrInfo();
+ for (MachineBasicBlock &MBB : *MF) {
+ for (MachineInstr &MI : MBB) {
+ if (ToErase) {
+ ToErase->eraseFromParent();
+ ToErase = nullptr;
+ }
+
+ if (MI.getOpcode() != BPF::XFADDW32 && MI.getOpcode() != BPF::XFADDD &&
+ MI.getOpcode() != BPF::XFANDW32 && MI.getOpcode() != BPF::XFANDD &&
+ MI.getOpcode() != BPF::XFXORW32 && MI.getOpcode() != BPF::XFXORD &&
+ MI.getOpcode() != BPF::XFORW32 && MI.getOpcode() != BPF::XFORD)
+ continue;
+
+ if (hasLiveDefs(MI, TRI))
+ continue;
+
+ LLVM_DEBUG(dbgs() << "Transforming "; MI.dump());
+ unsigned newOpcode;
+ switch (MI.getOpcode()) {
+ case BPF::XFADDW32:
+ newOpcode = BPF::XADDW32;
+ break;
+ case BPF::XFADDD:
+ newOpcode = BPF::XADDD;
+ break;
+ case BPF::XFANDW32:
+ newOpcode = BPF::XANDW32;
+ break;
+ case BPF::XFANDD:
+ newOpcode = BPF::XANDD;
+ break;
+ case BPF::XFXORW32:
+ newOpcode = BPF::XXORW32;
+ break;
+ case BPF::XFXORD:
+ newOpcode = BPF::XXORD;
+ break;
+ case BPF::XFORW32:
+ newOpcode = BPF::XORW32;
+ break;
+ case BPF::XFORD:
+ newOpcode = BPF::XORD;
+ break;
+ default:
+ llvm_unreachable("Incorrect Atomic Instruction Opcode");
+ }
+
+ BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(newOpcode))
+ .add(MI.getOperand(0))
+ .add(MI.getOperand(1))
+ .add(MI.getOperand(2))
+ .add(MI.getOperand(3));
+
+ ToErase = &MI;
+ Changed = true;
+ }
+ }
+
+ return Changed;
}
} // end default namespace
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFMIPeephole.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFMIPeephole.cpp
index 354980e4bf..cf91a90278 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFMIPeephole.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFMIPeephole.cpp
@@ -475,9 +475,9 @@ bool BPFMIPeepholeTruncElim::eliminateTruncSeq(void) {
if (MI.getOpcode() == BPF::SRL_ri &&
MI.getOperand(2).getImm() == 32) {
SrcReg = MI.getOperand(1).getReg();
- if (!MRI->hasOneNonDBGUse(SrcReg))
- continue;
-
+ if (!MRI->hasOneNonDBGUse(SrcReg))
+ continue;
+
MI2 = MRI->getVRegDef(SrcReg);
DstReg = MI.getOperand(0).getReg();
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFPreserveDIType.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFPreserveDIType.cpp
index 0348e2200a..ac396e5471 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFPreserveDIType.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFPreserveDIType.cpp
@@ -17,7 +17,7 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/PassManager.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
@@ -34,32 +34,32 @@ using namespace llvm;
namespace {
-static bool BPFPreserveDITypeImpl(Function &F) {
- LLVM_DEBUG(dbgs() << "********** preserve debuginfo type **********\n");
+static bool BPFPreserveDITypeImpl(Function &F) {
+ LLVM_DEBUG(dbgs() << "********** preserve debuginfo type **********\n");
- Module *M = F.getParent();
+ Module *M = F.getParent();
// Bail out if no debug info.
- if (M->debug_compile_units().empty())
+ if (M->debug_compile_units().empty())
return false;
std::vector<CallInst *> PreserveDITypeCalls;
- for (auto &BB : F) {
- for (auto &I : BB) {
- auto *Call = dyn_cast<CallInst>(&I);
- if (!Call)
- continue;
-
- const auto *GV = dyn_cast<GlobalValue>(Call->getCalledOperand());
- if (!GV)
- continue;
-
- if (GV->getName().startswith("llvm.bpf.btf.type.id")) {
- if (!Call->getMetadata(LLVMContext::MD_preserve_access_index))
- report_fatal_error(
- "Missing metadata for llvm.bpf.btf.type.id intrinsic");
- PreserveDITypeCalls.push_back(Call);
+ for (auto &BB : F) {
+ for (auto &I : BB) {
+ auto *Call = dyn_cast<CallInst>(&I);
+ if (!Call)
+ continue;
+
+ const auto *GV = dyn_cast<GlobalValue>(Call->getCalledOperand());
+ if (!GV)
+ continue;
+
+ if (GV->getName().startswith("llvm.bpf.btf.type.id")) {
+ if (!Call->getMetadata(LLVMContext::MD_preserve_access_index))
+ report_fatal_error(
+ "Missing metadata for llvm.bpf.btf.type.id intrinsic");
+ PreserveDITypeCalls.push_back(Call);
}
}
}
@@ -68,81 +68,81 @@ static bool BPFPreserveDITypeImpl(Function &F) {
return false;
std::string BaseName = "llvm.btf_type_id.";
- static int Count = 0;
+ static int Count = 0;
for (auto Call : PreserveDITypeCalls) {
- const ConstantInt *Flag = dyn_cast<ConstantInt>(Call->getArgOperand(1));
+ const ConstantInt *Flag = dyn_cast<ConstantInt>(Call->getArgOperand(1));
assert(Flag);
uint64_t FlagValue = Flag->getValue().getZExtValue();
if (FlagValue >= BPFCoreSharedInfo::MAX_BTF_TYPE_ID_FLAG)
report_fatal_error("Incorrect flag for llvm.bpf.btf.type.id intrinsic");
- MDNode *MD = Call->getMetadata(LLVMContext::MD_preserve_access_index);
-
+ MDNode *MD = Call->getMetadata(LLVMContext::MD_preserve_access_index);
+
uint32_t Reloc;
- if (FlagValue == BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL_RELOC) {
+ if (FlagValue == BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL_RELOC) {
Reloc = BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL;
- } else {
+ } else {
Reloc = BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE;
- DIType *Ty = cast<DIType>(MD);
- while (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
- unsigned Tag = DTy->getTag();
- if (Tag != dwarf::DW_TAG_const_type &&
- Tag != dwarf::DW_TAG_volatile_type)
- break;
- Ty = DTy->getBaseType();
- }
-
- if (Ty->getName().empty())
- report_fatal_error("Empty type name for BTF_TYPE_ID_REMOTE reloc");
- MD = Ty;
- }
+ DIType *Ty = cast<DIType>(MD);
+ while (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
+ unsigned Tag = DTy->getTag();
+ if (Tag != dwarf::DW_TAG_const_type &&
+ Tag != dwarf::DW_TAG_volatile_type)
+ break;
+ Ty = DTy->getBaseType();
+ }
+
+ if (Ty->getName().empty())
+ report_fatal_error("Empty type name for BTF_TYPE_ID_REMOTE reloc");
+ MD = Ty;
+ }
BasicBlock *BB = Call->getParent();
- IntegerType *VarType = Type::getInt64Ty(BB->getContext());
+ IntegerType *VarType = Type::getInt64Ty(BB->getContext());
std::string GVName = BaseName + std::to_string(Count) + "$" +
std::to_string(Reloc);
- GlobalVariable *GV = new GlobalVariable(
- *M, VarType, false, GlobalVariable::ExternalLinkage, NULL, GVName);
+ GlobalVariable *GV = new GlobalVariable(
+ *M, VarType, false, GlobalVariable::ExternalLinkage, NULL, GVName);
GV->addAttribute(BPFCoreSharedInfo::TypeIdAttr);
GV->setMetadata(LLVMContext::MD_preserve_access_index, MD);
// Load the global variable which represents the type info.
- auto *LDInst =
- new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
- Instruction *PassThroughInst =
- BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
- Call->replaceAllUsesWith(PassThroughInst);
+ auto *LDInst =
+ new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
+ Instruction *PassThroughInst =
+ BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
+ Call->replaceAllUsesWith(PassThroughInst);
Call->eraseFromParent();
Count++;
}
return true;
}
-
-class BPFPreserveDIType final : public FunctionPass {
- bool runOnFunction(Function &F) override;
-
-public:
- static char ID;
- BPFPreserveDIType() : FunctionPass(ID) {}
-};
-} // End anonymous namespace
-
-char BPFPreserveDIType::ID = 0;
-INITIALIZE_PASS(BPFPreserveDIType, DEBUG_TYPE, "BPF Preserve Debuginfo Type",
- false, false)
-
-FunctionPass *llvm::createBPFPreserveDIType() {
- return new BPFPreserveDIType();
-}
-
-bool BPFPreserveDIType::runOnFunction(Function &F) {
- return BPFPreserveDITypeImpl(F);
-}
-
-PreservedAnalyses BPFPreserveDITypePass::run(Function &F,
- FunctionAnalysisManager &AM) {
- return BPFPreserveDITypeImpl(F) ? PreservedAnalyses::none()
- : PreservedAnalyses::all();
-}
+
+class BPFPreserveDIType final : public FunctionPass {
+ bool runOnFunction(Function &F) override;
+
+public:
+ static char ID;
+ BPFPreserveDIType() : FunctionPass(ID) {}
+};
+} // End anonymous namespace
+
+char BPFPreserveDIType::ID = 0;
+INITIALIZE_PASS(BPFPreserveDIType, DEBUG_TYPE, "BPF Preserve Debuginfo Type",
+ false, false)
+
+FunctionPass *llvm::createBPFPreserveDIType() {
+ return new BPFPreserveDIType();
+}
+
+bool BPFPreserveDIType::runOnFunction(Function &F) {
+ return BPFPreserveDITypeImpl(F);
+}
+
+PreservedAnalyses BPFPreserveDITypePass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ return BPFPreserveDITypeImpl(F) ? PreservedAnalyses::none()
+ : PreservedAnalyses::all();
+}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.cpp
index fac02e6476..7697603d22 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.cpp
@@ -29,7 +29,7 @@ BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU,
StringRef FS) {
initializeEnvironment();
initSubtargetFeatures(CPU, FS);
- ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
+ ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
return *this;
}
@@ -59,6 +59,6 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
const std::string &FS, const TargetMachine &TM)
- : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(),
+ : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(),
FrameLowering(initializeSubtargetDependencies(CPU, FS)),
TLInfo(TM, *this) {}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.h b/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.h
index 7649e0e922..59716ae777 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFSubtarget.h
@@ -67,7 +67,7 @@ public:
// ParseSubtargetFeatures - Parses features string setting specified
// subtarget options. Definition of function is auto generated by tblgen.
- void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
+ void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
bool getHasJmpExt() const { return HasJmpExt; }
bool getHasJmp32() const { return HasJmp32; }
bool getHasAlu32() const { return HasAlu32; }
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.cpp b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.cpp
index a8fef2517b..8cf9ef2921 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.cpp
@@ -12,22 +12,22 @@
#include "BPFTargetMachine.h"
#include "BPF.h"
-#include "BPFTargetTransformInfo.h"
+#include "BPFTargetTransformInfo.h"
#include "MCTargetDesc/BPFMCAsmInfo.h"
#include "TargetInfo/BPFTargetInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/PassManager.h"
-#include "llvm/Passes/PassBuilder.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/SimplifyCFG.h"
-#include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
+#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/SimplifyCFG.h"
+#include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
using namespace llvm;
static cl::
@@ -41,10 +41,10 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() {
RegisterTargetMachine<BPFTargetMachine> Z(getTheBPFTarget());
PassRegistry &PR = *PassRegistry::getPassRegistry();
- initializeBPFAbstractMemberAccessLegacyPassPass(PR);
+ initializeBPFAbstractMemberAccessLegacyPassPass(PR);
initializeBPFPreserveDITypePass(PR);
- initializeBPFAdjustOptPass(PR);
- initializeBPFCheckAndAdjustIRPass(PR);
+ initializeBPFAdjustOptPass(PR);
+ initializeBPFCheckAndAdjustIRPass(PR);
initializeBPFMIPeepholePass(PR);
initializeBPFMIPeepholeTruncElimPass(PR);
}
@@ -58,7 +58,7 @@ static std::string computeDataLayout(const Triple &TT) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
- return RM.getValueOr(Reloc::PIC_);
+ return RM.getValueOr(Reloc::PIC_);
}
BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
@@ -101,56 +101,56 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
return new BPFPassConfig(*this, PM);
}
-void BPFTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
- Builder.addExtension(
- PassManagerBuilder::EP_EarlyAsPossible,
- [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
- PM.add(createBPFAbstractMemberAccess(this));
- PM.add(createBPFPreserveDIType());
- });
-
- Builder.addExtension(
- PassManagerBuilder::EP_Peephole,
- [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
- PM.add(createCFGSimplificationPass(
- SimplifyCFGOptions().hoistCommonInsts(true)));
- });
- Builder.addExtension(
- PassManagerBuilder::EP_ModuleOptimizerEarly,
- [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
- PM.add(createBPFAdjustOpt());
- });
-}
-
-void BPFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
- bool DebugPassManager) {
- PB.registerPipelineStartEPCallback(
- [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) {
- FunctionPassManager FPM(DebugPassManager);
- FPM.addPass(BPFAbstractMemberAccessPass(this));
- FPM.addPass(BPFPreserveDITypePass());
- MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
- });
- PB.registerPeepholeEPCallback([=](FunctionPassManager &FPM,
- PassBuilder::OptimizationLevel Level) {
- FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().hoistCommonInsts(true)));
- });
- PB.registerPipelineEarlySimplificationEPCallback(
- [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) {
- MPM.addPass(BPFAdjustOptPass());
- });
-}
-
-void BPFPassConfig::addIRPasses() {
- addPass(createBPFCheckAndAdjustIR());
+void BPFTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
+ Builder.addExtension(
+ PassManagerBuilder::EP_EarlyAsPossible,
+ [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
+ PM.add(createBPFAbstractMemberAccess(this));
+ PM.add(createBPFPreserveDIType());
+ });
+
+ Builder.addExtension(
+ PassManagerBuilder::EP_Peephole,
+ [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
+ PM.add(createCFGSimplificationPass(
+ SimplifyCFGOptions().hoistCommonInsts(true)));
+ });
+ Builder.addExtension(
+ PassManagerBuilder::EP_ModuleOptimizerEarly,
+ [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
+ PM.add(createBPFAdjustOpt());
+ });
+}
+
+void BPFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
+ bool DebugPassManager) {
+ PB.registerPipelineStartEPCallback(
+ [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) {
+ FunctionPassManager FPM(DebugPassManager);
+ FPM.addPass(BPFAbstractMemberAccessPass(this));
+ FPM.addPass(BPFPreserveDITypePass());
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+ });
+ PB.registerPeepholeEPCallback([=](FunctionPassManager &FPM,
+ PassBuilder::OptimizationLevel Level) {
+ FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().hoistCommonInsts(true)));
+ });
+ PB.registerPipelineEarlySimplificationEPCallback(
+ [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) {
+ MPM.addPass(BPFAdjustOptPass());
+ });
+}
+
+void BPFPassConfig::addIRPasses() {
+ addPass(createBPFCheckAndAdjustIR());
TargetPassConfig::addIRPasses();
}
-TargetTransformInfo
-BPFTargetMachine::getTargetTransformInfo(const Function &F) {
- return TargetTransformInfo(BPFTTIImpl(this, F));
-}
-
+TargetTransformInfo
+BPFTargetMachine::getTargetTransformInfo(const Function &F) {
+ return TargetTransformInfo(BPFTTIImpl(this, F));
+}
+
// Install an instruction selector pass using
// the ISelDag to gen BPF code.
bool BPFPassConfig::addInstSelector() {
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.h b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.h
index 61c8a44cc4..2e78f5c4d3 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetMachine.h
@@ -34,15 +34,15 @@ public:
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
- TargetTransformInfo getTargetTransformInfo(const Function &F) override;
-
+ TargetTransformInfo getTargetTransformInfo(const Function &F) override;
+
TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
}
-
- void adjustPassManager(PassManagerBuilder &) override;
- void registerPassBuilderCallbacks(PassBuilder &PB,
- bool DebugPassManager) override;
+
+ void adjustPassManager(PassManagerBuilder &) override;
+ void registerPassBuilderCallbacks(PassBuilder &PB,
+ bool DebugPassManager) override;
};
}
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetTransformInfo.h b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetTransformInfo.h
index 62055497e6..01808aa50a 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BPFTargetTransformInfo.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -1,61 +1,61 @@
-//===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- C++ -*-===//
-//
-// 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 file uses the target's specific information to
-// provide more precise answers to certain TTI queries, while letting the
-// target independent and default TTI implementations handle the rest.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
-#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
-
-#include "BPFTargetMachine.h"
-#include "llvm/Analysis/TargetTransformInfo.h"
-#include "llvm/CodeGen/BasicTTIImpl.h"
-#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
-
-namespace llvm {
-class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
- typedef BasicTTIImplBase<BPFTTIImpl> BaseT;
- typedef TargetTransformInfo TTI;
- friend BaseT;
-
- const BPFSubtarget *ST;
- const BPFTargetLowering *TLI;
-
- const BPFSubtarget *getST() const { return ST; }
- const BPFTargetLowering *getTLI() const { return TLI; }
-
-public:
- explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
- : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
- TLI(ST->getTargetLowering()) {}
-
- int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) {
- if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
- return TTI::TCC_Free;
-
- return TTI::TCC_Basic;
- }
-
- int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
- CmpInst::Predicate VecPred,
- TTI::TargetCostKind CostKind,
- const llvm::Instruction *I = nullptr) {
- if (Opcode == Instruction::Select)
- return SCEVCheapExpansionBudget;
-
- return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
- I);
- }
-};
-
-} // end namespace llvm
-
-#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
+//===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- C++ -*-===//
+//
+// 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 file uses the target's specific information to
+// provide more precise answers to certain TTI queries, while letting the
+// target independent and default TTI implementations handle the rest.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
+#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
+
+#include "BPFTargetMachine.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/BasicTTIImpl.h"
+#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
+
+namespace llvm {
+class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
+ typedef BasicTTIImplBase<BPFTTIImpl> BaseT;
+ typedef TargetTransformInfo TTI;
+ friend BaseT;
+
+ const BPFSubtarget *ST;
+ const BPFTargetLowering *TLI;
+
+ const BPFSubtarget *getST() const { return ST; }
+ const BPFTargetLowering *getTLI() const { return TLI; }
+
+public:
+ explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
+ : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
+ TLI(ST->getTargetLowering()) {}
+
+ int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) {
+ if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
+ return TTI::TCC_Free;
+
+ return TTI::TCC_Basic;
+ }
+
+ int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
+ CmpInst::Predicate VecPred,
+ TTI::TargetCostKind CostKind,
+ const llvm::Instruction *I = nullptr) {
+ if (Opcode == Instruction::Select)
+ return SCEVCheapExpansionBudget;
+
+ return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
+ I);
+ }
+};
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BTF.def b/contrib/libs/llvm12/lib/Target/BPF/BTF.def
index 66cf2c90ea..557b4a5c03 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BTF.def
+++ b/contrib/libs/llvm12/lib/Target/BPF/BTF.def
@@ -30,6 +30,6 @@ HANDLE_BTF_KIND(12, FUNC)
HANDLE_BTF_KIND(13, FUNC_PROTO)
HANDLE_BTF_KIND(14, VAR)
HANDLE_BTF_KIND(15, DATASEC)
-HANDLE_BTF_KIND(16, FLOAT)
+HANDLE_BTF_KIND(16, FLOAT)
#undef HANDLE_BTF_KIND
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.cpp b/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.cpp
index 9249d679c7..4caf1ea3e2 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.cpp
@@ -22,7 +22,7 @@
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/LineIterator.h"
-#include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
using namespace llvm;
@@ -371,21 +371,21 @@ void BTFKindDataSec::emitType(MCStreamer &OS) {
}
}
-BTFTypeFloat::BTFTypeFloat(uint32_t SizeInBits, StringRef TypeName)
- : Name(TypeName) {
- Kind = BTF::BTF_KIND_FLOAT;
- BTFType.Info = Kind << 24;
- BTFType.Size = roundupToBytes(SizeInBits);
-}
-
-void BTFTypeFloat::completeType(BTFDebug &BDebug) {
- if (IsCompleted)
- return;
- IsCompleted = true;
-
- BTFType.NameOff = BDebug.addString(Name);
-}
-
+BTFTypeFloat::BTFTypeFloat(uint32_t SizeInBits, StringRef TypeName)
+ : Name(TypeName) {
+ Kind = BTF::BTF_KIND_FLOAT;
+ BTFType.Info = Kind << 24;
+ BTFType.Size = roundupToBytes(SizeInBits);
+}
+
+void BTFTypeFloat::completeType(BTFDebug &BDebug) {
+ if (IsCompleted)
+ return;
+ IsCompleted = true;
+
+ BTFType.NameOff = BDebug.addString(Name);
+}
+
uint32_t BTFStringTable::addString(StringRef S) {
// Check whether the string already exists.
for (auto &OffsetM : OffsetToIdMap) {
@@ -424,27 +424,27 @@ uint32_t BTFDebug::addType(std::unique_ptr<BTFTypeBase> TypeEntry) {
}
void BTFDebug::visitBasicType(const DIBasicType *BTy, uint32_t &TypeId) {
- // Only int and binary floating point types are supported in BTF.
+ // Only int and binary floating point types are supported in BTF.
uint32_t Encoding = BTy->getEncoding();
- std::unique_ptr<BTFTypeBase> TypeEntry;
- switch (Encoding) {
- case dwarf::DW_ATE_boolean:
- case dwarf::DW_ATE_signed:
- case dwarf::DW_ATE_signed_char:
- case dwarf::DW_ATE_unsigned:
- case dwarf::DW_ATE_unsigned_char:
- // Create a BTF type instance for this DIBasicType and put it into
- // DIToIdMap for cross-type reference check.
- TypeEntry = std::make_unique<BTFTypeInt>(
- Encoding, BTy->getSizeInBits(), BTy->getOffsetInBits(), BTy->getName());
- break;
- case dwarf::DW_ATE_float:
- TypeEntry =
- std::make_unique<BTFTypeFloat>(BTy->getSizeInBits(), BTy->getName());
- break;
- default:
+ std::unique_ptr<BTFTypeBase> TypeEntry;
+ switch (Encoding) {
+ case dwarf::DW_ATE_boolean:
+ case dwarf::DW_ATE_signed:
+ case dwarf::DW_ATE_signed_char:
+ case dwarf::DW_ATE_unsigned:
+ case dwarf::DW_ATE_unsigned_char:
+ // Create a BTF type instance for this DIBasicType and put it into
+ // DIToIdMap for cross-type reference check.
+ TypeEntry = std::make_unique<BTFTypeInt>(
+ Encoding, BTy->getSizeInBits(), BTy->getOffsetInBits(), BTy->getName());
+ break;
+ case dwarf::DW_ATE_float:
+ TypeEntry =
+ std::make_unique<BTFTypeFloat>(BTy->getSizeInBits(), BTy->getName());
+ break;
+ default:
return;
- }
+ }
TypeId = addType(std::move(TypeEntry), BTy);
}
@@ -1019,13 +1019,13 @@ void BTFDebug::generatePatchImmReloc(const MCSymbol *ORSym, uint32_t RootId,
FieldReloc.OffsetNameOff = addString(IndexPattern);
FieldReloc.RelocKind = std::stoull(std::string(RelocKindStr));
- PatchImms[GVar] = std::make_pair(std::stoll(std::string(PatchImmStr)),
- FieldReloc.RelocKind);
+ PatchImms[GVar] = std::make_pair(std::stoll(std::string(PatchImmStr)),
+ FieldReloc.RelocKind);
} else {
StringRef RelocStr = AccessPattern.substr(FirstDollar + 1);
FieldReloc.OffsetNameOff = addString("0");
FieldReloc.RelocKind = std::stoull(std::string(RelocStr));
- PatchImms[GVar] = std::make_pair(RootId, FieldReloc.RelocKind);
+ PatchImms[GVar] = std::make_pair(RootId, FieldReloc.RelocKind);
}
FieldRelocTable[SecNameOff].push_back(FieldReloc);
}
@@ -1101,9 +1101,9 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
}
}
- if (!CurMI) // no debug info
- return;
-
+ if (!CurMI) // no debug info
+ return;
+
// Skip this instruction if no DebugLoc or the DebugLoc
// is the same as the previous instruction.
const DebugLoc &DL = MI->getDebugLoc();
@@ -1155,20 +1155,20 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
if (ProcessingMapDef != SecName.startswith(".maps"))
continue;
- // Create a .rodata datasec if the global variable is an initialized
- // constant with private linkage and if it won't be in .rodata.str<#>
- // and .rodata.cst<#> sections.
- if (SecName == ".rodata" && Global.hasPrivateLinkage() &&
- DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
- SectionKind GVKind =
- TargetLoweringObjectFile::getKindForGlobal(&Global, Asm->TM);
- // skip .rodata.str<#> and .rodata.cst<#> sections
- if (!GVKind.isMergeableCString() && !GVKind.isMergeableConst()) {
- DataSecEntries[std::string(SecName)] =
- std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
- }
- }
-
+ // Create a .rodata datasec if the global variable is an initialized
+ // constant with private linkage and if it won't be in .rodata.str<#>
+ // and .rodata.cst<#> sections.
+ if (SecName == ".rodata" && Global.hasPrivateLinkage() &&
+ DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
+ SectionKind GVKind =
+ TargetLoweringObjectFile::getKindForGlobal(&Global, Asm->TM);
+ // skip .rodata.str<#> and .rodata.cst<#> sections
+ if (!GVKind.isMergeableCString() && !GVKind.isMergeableConst()) {
+ DataSecEntries[std::string(SecName)] =
+ std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
+ }
+ }
+
SmallVector<DIGlobalVariableExpression *, 1> GVs;
Global.getDebugInfo(GVs);
@@ -1196,7 +1196,7 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
if (Linkage != GlobalValue::InternalLinkage &&
Linkage != GlobalValue::ExternalLinkage &&
Linkage != GlobalValue::WeakAnyLinkage &&
- Linkage != GlobalValue::WeakODRLinkage &&
+ Linkage != GlobalValue::WeakODRLinkage &&
Linkage != GlobalValue::ExternalWeakLinkage)
continue;
@@ -1225,8 +1225,8 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
const DataLayout &DL = Global.getParent()->getDataLayout();
uint32_t Size = DL.getTypeAllocSize(Global.getType()->getElementType());
- DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
- Asm->getSymbol(&Global), Size);
+ DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
+ Asm->getSymbol(&Global), Size);
}
}
@@ -1239,23 +1239,23 @@ bool BTFDebug::InstLower(const MachineInstr *MI, MCInst &OutMI) {
auto *GVar = dyn_cast<GlobalVariable>(GVal);
if (GVar) {
// Emit "mov ri, <imm>"
- int64_t Imm;
- uint32_t Reloc;
+ int64_t Imm;
+ uint32_t Reloc;
if (GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr) ||
- GVar->hasAttribute(BPFCoreSharedInfo::TypeIdAttr)) {
- Imm = PatchImms[GVar].first;
- Reloc = PatchImms[GVar].second;
- } else {
+ GVar->hasAttribute(BPFCoreSharedInfo::TypeIdAttr)) {
+ Imm = PatchImms[GVar].first;
+ Reloc = PatchImms[GVar].second;
+ } else {
return false;
- }
-
- if (Reloc == BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE ||
- Reloc == BPFCoreSharedInfo::ENUM_VALUE ||
- Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL ||
- Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE)
- OutMI.setOpcode(BPF::LD_imm64);
- else
- OutMI.setOpcode(BPF::MOV_ri);
+ }
+
+ if (Reloc == BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE ||
+ Reloc == BPFCoreSharedInfo::ENUM_VALUE ||
+ Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL ||
+ Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE)
+ OutMI.setOpcode(BPF::LD_imm64);
+ else
+ OutMI.setOpcode(BPF::MOV_ri);
OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
OutMI.addOperand(MCOperand::createImm(Imm));
return true;
@@ -1269,7 +1269,7 @@ bool BTFDebug::InstLower(const MachineInstr *MI, MCInst &OutMI) {
const GlobalValue *GVal = MO.getGlobal();
auto *GVar = dyn_cast<GlobalVariable>(GVal);
if (GVar && GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr)) {
- uint32_t Imm = PatchImms[GVar].first;
+ uint32_t Imm = PatchImms[GVar].first;
OutMI.setOpcode(MI->getOperand(1).getImm());
if (MI->getOperand(0).isImm())
OutMI.addOperand(MCOperand::createImm(MI->getOperand(0).getImm()));
@@ -1304,19 +1304,19 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
uint8_t Scope = BTF::FUNC_EXTERN;
auto FuncTypeEntry =
std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
- uint32_t FuncId = addType(std::move(FuncTypeEntry));
- if (F->hasSection()) {
- StringRef SecName = F->getSection();
-
- if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
- DataSecEntries[std::string(SecName)] =
- std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
- }
-
- // We really don't know func size, set it to 0.
- DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
- Asm->getSymbol(F), 0);
- }
+ uint32_t FuncId = addType(std::move(FuncTypeEntry));
+ if (F->hasSection()) {
+ StringRef SecName = F->getSection();
+
+ if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
+ DataSecEntries[std::string(SecName)] =
+ std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
+ }
+
+ // We really don't know func size, set it to 0.
+ DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
+ Asm->getSymbol(F), 0);
+ }
}
void BTFDebug::endModule() {
diff --git a/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.h b/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.h
index 76f1901779..c9dd664467 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/BTFDebug.h
@@ -16,8 +16,8 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/DebugHandlerBase.h"
-#include <cstdint>
-#include <map>
+#include <cstdint>
+#include <map>
#include <set>
#include <unordered_map>
#include "BTF.h"
@@ -28,10 +28,10 @@ class AsmPrinter;
class BTFDebug;
class DIType;
class GlobalVariable;
-class MachineFunction;
-class MachineInstr;
-class MachineOperand;
-class MCInst;
+class MachineFunction;
+class MachineInstr;
+class MachineOperand;
+class MCInst;
class MCStreamer;
class MCSymbol;
@@ -187,7 +187,7 @@ public:
uint32_t getSize() override {
return BTFTypeBase::getSize() + BTF::BTFDataSecVarSize * Vars.size();
}
- void addDataSecEntry(uint32_t Id, const MCSymbol *Sym, uint32_t Size) {
+ void addDataSecEntry(uint32_t Id, const MCSymbol *Sym, uint32_t Size) {
Vars.push_back(std::make_tuple(Id, Sym, Size));
}
std::string getName() { return Name; }
@@ -195,15 +195,15 @@ public:
void emitType(MCStreamer &OS) override;
};
-/// Handle binary floating point type.
-class BTFTypeFloat : public BTFTypeBase {
- StringRef Name;
-
-public:
- BTFTypeFloat(uint32_t SizeInBits, StringRef TypeName);
- void completeType(BTFDebug &BDebug) override;
-};
-
+/// Handle binary floating point type.
+class BTFTypeFloat : public BTFTypeBase {
+ StringRef Name;
+
+public:
+ BTFTypeFloat(uint32_t SizeInBits, StringRef TypeName);
+ void completeType(BTFDebug &BDebug) override;
+};
+
/// String table.
class BTFStringTable {
/// String table size in bytes.
@@ -264,7 +264,7 @@ class BTFDebug : public DebugHandlerBase {
StringMap<std::vector<std::string>> FileContent;
std::map<std::string, std::unique_ptr<BTFKindDataSec>> DataSecEntries;
std::vector<BTFTypeStruct *> StructTypes;
- std::map<const GlobalVariable *, std::pair<int64_t, uint32_t>> PatchImms;
+ std::map<const GlobalVariable *, std::pair<int64_t, uint32_t>> PatchImms;
std::map<StringRef, std::pair<bool, std::vector<BTFTypeDerived *>>>
FixupDerivedTypes;
std::set<const Function *>ProtoFunctions;
diff --git a/contrib/libs/llvm12/lib/Target/BPF/Disassembler/BPFDisassembler.cpp b/contrib/libs/llvm12/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
index 3a1492743b..264ef42635 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
@@ -58,7 +58,7 @@ public:
BPF_MEM = 0x3,
BPF_LEN = 0x4,
BPF_MSH = 0x5,
- BPF_ATOMIC = 0x6
+ BPF_ATOMIC = 0x6
};
BPFDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
@@ -176,7 +176,7 @@ DecodeStatus BPFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
uint8_t InstMode = getInstMode(Insn);
if ((InstClass == BPF_LDX || InstClass == BPF_STX) &&
getInstSize(Insn) != BPF_DW &&
- (InstMode == BPF_MEM || InstMode == BPF_ATOMIC) &&
+ (InstMode == BPF_MEM || InstMode == BPF_ATOMIC) &&
STI.getFeatureBits()[BPF::ALU32])
Result = decodeInstruction(DecoderTableBPFALU3264, Instr, Insn, Address,
this, STI);
diff --git a/contrib/libs/llvm12/lib/Target/BPF/Disassembler/ya.make b/contrib/libs/llvm12/lib/Target/BPF/Disassembler/ya.make
index cb7872eeee..ca048de77d 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/Disassembler/ya.make
+++ b/contrib/libs/llvm12/lib/Target/BPF/Disassembler/ya.make
@@ -12,17 +12,17 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/include
- contrib/libs/llvm12/lib/MC/MCDisassembler
- contrib/libs/llvm12/lib/Support
- contrib/libs/llvm12/lib/Target/BPF/TargetInfo
+ contrib/libs/llvm12
+ contrib/libs/llvm12/include
+ contrib/libs/llvm12/lib/MC/MCDisassembler
+ contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12/lib/Target/BPF/TargetInfo
)
ADDINCL(
- ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF/Disassembler
+ ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF/Disassembler
)
NO_COMPILER_WARNINGS()
diff --git a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h
index e76067ea41..34fa4539e5 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h
+++ b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.h
@@ -32,7 +32,7 @@ public:
void printBrTargetOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
// Autogenerated by tblgen.
- std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
+ std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
static const char *getRegisterName(unsigned RegNo);
};
diff --git a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
index 12af92e0d1..3ecd8bd5a4 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
@@ -13,7 +13,7 @@
#include "MCTargetDesc/BPFMCTargetDesc.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/MCCodeEmitter.h"
-#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrInfo.h"
@@ -159,18 +159,18 @@ void BPFMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
uint64_t BPFMCCodeEmitter::getMemoryOpValue(const MCInst &MI, unsigned Op,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
- // For CMPXCHG instructions, output is implicitly in R0/W0,
- // so memory operand starts from operand 0.
- int MemOpStartIndex = 1, Opcode = MI.getOpcode();
- if (Opcode == BPF::CMPXCHGW32 || Opcode == BPF::CMPXCHGD)
- MemOpStartIndex = 0;
-
+ // For CMPXCHG instructions, output is implicitly in R0/W0,
+ // so memory operand starts from operand 0.
+ int MemOpStartIndex = 1, Opcode = MI.getOpcode();
+ if (Opcode == BPF::CMPXCHGW32 || Opcode == BPF::CMPXCHGD)
+ MemOpStartIndex = 0;
+
uint64_t Encoding;
- const MCOperand Op1 = MI.getOperand(MemOpStartIndex);
+ const MCOperand Op1 = MI.getOperand(MemOpStartIndex);
assert(Op1.isReg() && "First operand is not register.");
Encoding = MRI.getEncodingValue(Op1.getReg());
Encoding <<= 16;
- MCOperand Op2 = MI.getOperand(MemOpStartIndex + 1);
+ MCOperand Op2 = MI.getOperand(MemOpStartIndex + 1);
assert(Op2.isImm() && "Second operand is not immediate.");
Encoding |= Op2.getImm() & 0xffff;
return Encoding;
diff --git a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
index 8fb7d7e89f..0d9fcaa0e1 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
+++ b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
@@ -46,7 +46,7 @@ static MCRegisterInfo *createBPFMCRegisterInfo(const Triple &TT) {
static MCSubtargetInfo *createBPFMCSubtargetInfo(const Triple &TT,
StringRef CPU, StringRef FS) {
- return createBPFMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
+ return createBPFMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
}
static MCStreamer *createBPFMCStreamer(const Triple &T, MCContext &Ctx,
diff --git a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/ya.make b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/ya.make
index 6522c7ef00..9f1a1f9c3a 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/ya.make
+++ b/contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc/ya.make
@@ -12,17 +12,17 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/include
- contrib/libs/llvm12/lib/MC
- contrib/libs/llvm12/lib/Support
- contrib/libs/llvm12/lib/Target/BPF/TargetInfo
+ contrib/libs/llvm12
+ contrib/libs/llvm12/include
+ contrib/libs/llvm12/lib/MC
+ contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12/lib/Target/BPF/TargetInfo
)
ADDINCL(
- ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
+ ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
)
NO_COMPILER_WARNINGS()
diff --git a/contrib/libs/llvm12/lib/Target/BPF/TargetInfo/ya.make b/contrib/libs/llvm12/lib/Target/BPF/TargetInfo/ya.make
index 3a882dad3e..1498dd77d8 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/TargetInfo/ya.make
+++ b/contrib/libs/llvm12/lib/Target/BPF/TargetInfo/ya.make
@@ -12,13 +12,13 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12
+ contrib/libs/llvm12/lib/Support
)
ADDINCL(
- contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF/TargetInfo
+ contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF/TargetInfo
)
NO_COMPILER_WARNINGS()
diff --git a/contrib/libs/llvm12/lib/Target/BPF/ya.make b/contrib/libs/llvm12/lib/Target/BPF/ya.make
index 0f122e4afe..bc05712021 100644
--- a/contrib/libs/llvm12/lib/Target/BPF/ya.make
+++ b/contrib/libs/llvm12/lib/Target/BPF/ya.make
@@ -12,26 +12,26 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/include
- contrib/libs/llvm12/lib/Analysis
- contrib/libs/llvm12/lib/CodeGen
- contrib/libs/llvm12/lib/CodeGen/AsmPrinter
- contrib/libs/llvm12/lib/CodeGen/SelectionDAG
- contrib/libs/llvm12/lib/IR
- contrib/libs/llvm12/lib/MC
- contrib/libs/llvm12/lib/Support
- contrib/libs/llvm12/lib/Target
- contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
- contrib/libs/llvm12/lib/Target/BPF/TargetInfo
- contrib/libs/llvm12/lib/Transforms/IPO
- contrib/libs/llvm12/lib/Transforms/Scalar
- contrib/libs/llvm12/lib/Transforms/Utils
+ contrib/libs/llvm12
+ contrib/libs/llvm12/include
+ contrib/libs/llvm12/lib/Analysis
+ contrib/libs/llvm12/lib/CodeGen
+ contrib/libs/llvm12/lib/CodeGen/AsmPrinter
+ contrib/libs/llvm12/lib/CodeGen/SelectionDAG
+ contrib/libs/llvm12/lib/IR
+ contrib/libs/llvm12/lib/MC
+ contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12/lib/Target
+ contrib/libs/llvm12/lib/Target/BPF/MCTargetDesc
+ contrib/libs/llvm12/lib/Target/BPF/TargetInfo
+ contrib/libs/llvm12/lib/Transforms/IPO
+ contrib/libs/llvm12/lib/Transforms/Scalar
+ contrib/libs/llvm12/lib/Transforms/Utils
)
ADDINCL(
- ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
- contrib/libs/llvm12/lib/Target/BPF
+ ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/lib/Target/BPF
+ contrib/libs/llvm12/lib/Target/BPF
)
NO_COMPILER_WARNINGS()
@@ -40,9 +40,9 @@ NO_UTIL()
SRCS(
BPFAbstractMemberAccess.cpp
- BPFAdjustOpt.cpp
+ BPFAdjustOpt.cpp
BPFAsmPrinter.cpp
- BPFCheckAndAdjustIR.cpp
+ BPFCheckAndAdjustIR.cpp
BPFFrameLowering.cpp
BPFISelDAGToDAG.cpp
BPFISelLowering.cpp