aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/BPF
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/BPF')
-rw-r--r--llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp1
-rw-r--r--llvm/lib/Target/BPF/BPF.h2
-rw-r--r--llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp50
-rw-r--r--llvm/lib/Target/BPF/BPFAdjustOpt.cpp10
-rw-r--r--llvm/lib/Target/BPF/BPFCORE.h2
-rw-r--r--llvm/lib/Target/BPF/BPFISelLowering.cpp3
-rw-r--r--llvm/lib/Target/BPF/BPFInstrFormats.td1
-rw-r--r--llvm/lib/Target/BPF/BPFInstrInfo.cpp3
-rw-r--r--llvm/lib/Target/BPF/BPFInstrInfo.td2
-rw-r--r--llvm/lib/Target/BPF/BPFMIChecking.cpp1
-rw-r--r--llvm/lib/Target/BPF/BPFMIPeephole.cpp7
-rw-r--r--llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp24
-rw-r--r--llvm/lib/Target/BPF/BPFPreserveDIType.cpp1
-rw-r--r--llvm/lib/Target/BPF/BPFTargetMachine.cpp4
-rw-r--r--llvm/lib/Target/BPF/BPFTargetMachine.h2
-rw-r--r--llvm/lib/Target/BPF/BPFTargetTransformInfo.h9
-rw-r--r--llvm/lib/Target/BPF/BTF.def1
-rw-r--r--llvm/lib/Target/BPF/BTF.h10
-rw-r--r--llvm/lib/Target/BPF/BTFDebug.cpp197
-rw-r--r--llvm/lib/Target/BPF/BTFDebug.h26
-rw-r--r--llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp16
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp5
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp1
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h2
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp6
-rw-r--r--llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h3
26 files changed, 289 insertions, 100 deletions
diff --git a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
index 697deb117bcb..4c064d65d919 100644
--- a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
+++ b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
@@ -13,6 +13,7 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
diff --git a/llvm/lib/Target/BPF/BPF.h b/llvm/lib/Target/BPF/BPF.h
index 89990f7e15c2..3de761bf6601 100644
--- a/llvm/lib/Target/BPF/BPF.h
+++ b/llvm/lib/Target/BPF/BPF.h
@@ -11,6 +11,8 @@
#include "MCTargetDesc/BPFMCTargetDesc.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
#include "llvm/Target/TargetMachine.h"
namespace llvm {
diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
index 46141e69d9d4..349cdd92ae62 100644
--- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
+++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
@@ -77,6 +77,7 @@
#include "BPF.h"
#include "BPFCORE.h"
#include "BPFTargetMachine.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
@@ -123,7 +124,7 @@ public:
struct CallInfo {
uint32_t Kind;
uint32_t AccessIndex;
- Align RecordAlignment;
+ MaybeAlign RecordAlignment;
MDNode *Metadata;
Value *Base;
};
@@ -142,9 +143,9 @@ private:
Module *M = nullptr;
static std::map<std::string, GlobalVariable *> GEPGlobals;
- // A map to link preserve_*_access_index instrinsic calls.
+ // A map to link preserve_*_access_index intrinsic calls.
std::map<CallInst *, std::pair<CallInst *, CallInfo>> AIChain;
- // A map to hold all the base preserve_*_access_index instrinsic calls.
+ // A map to hold all the base preserve_*_access_index intrinsic calls.
// The base call is not an input of any other preserve_*
// intrinsics.
std::map<CallInst *, CallInfo> BaseAICalls;
@@ -169,7 +170,7 @@ private:
uint32_t &StartBitOffset, uint32_t &EndBitOffset);
uint32_t GetFieldInfo(uint32_t InfoKind, DICompositeType *CTy,
uint32_t AccessIndex, uint32_t PatchImm,
- Align RecordAlignment);
+ MaybeAlign RecordAlignment);
Value *computeBaseAndAccessKey(CallInst *Call, CallInfo &CInfo,
std::string &AccessKey, MDNode *&BaseMeta);
@@ -270,7 +271,7 @@ static uint32_t calcArraySize(const DICompositeType *CTy, uint32_t StartDim) {
static Type *getBaseElementType(const CallInst *Call) {
// Element type is stored in an elementtype() attribute on the first param.
- return Call->getAttributes().getParamElementType(0);
+ return Call->getParamElementType(0);
}
/// Check whether a call is a preserve_*_access_index intrinsic call or not.
@@ -299,8 +300,6 @@ bool BPFAbstractMemberAccess::IsPreserveDIAccessIndexCall(const CallInst *Call,
report_fatal_error("Missing metadata for llvm.preserve.union.access.index intrinsic");
CInfo.AccessIndex = getConstant(Call->getArgOperand(1));
CInfo.Base = Call->getArgOperand(0);
- CInfo.RecordAlignment =
- DL->getABITypeAlign(CInfo.Base->getType()->getPointerElementType());
return true;
}
if (GV->getName().startswith("llvm.preserve.struct.access.index")) {
@@ -333,6 +332,8 @@ bool BPFAbstractMemberAccess::IsPreserveDIAccessIndexCall(const CallInst *Call,
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 if (Flag == BPFCoreSharedInfo::PRESERVE_TYPE_INFO_MATCH)
+ CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_MATCH;
else
CInfo.AccessIndex = BPFCoreSharedInfo::TYPE_SIZE;
return true;
@@ -592,10 +593,20 @@ void BPFAbstractMemberAccess::GetStorageBitRange(DIDerivedType *MemberTy,
uint32_t &EndBitOffset) {
uint32_t MemberBitSize = MemberTy->getSizeInBits();
uint32_t MemberBitOffset = MemberTy->getOffsetInBits();
+
+ if (RecordAlignment > 8) {
+ // If the Bits are within an aligned 8-byte, set the RecordAlignment
+ // to 8, other report the fatal error.
+ if (MemberBitOffset / 64 != (MemberBitOffset + MemberBitSize) / 64)
+ report_fatal_error("Unsupported field expression for llvm.bpf.preserve.field.info, "
+ "requiring too big alignment");
+ RecordAlignment = Align(8);
+ }
+
uint32_t AlignBits = RecordAlignment.value() * 8;
- if (RecordAlignment > 8 || MemberBitSize > AlignBits)
+ if (MemberBitSize > AlignBits)
report_fatal_error("Unsupported field expression for llvm.bpf.preserve.field.info, "
- "requiring too big alignment");
+ "bitfield size greater than record alignment");
StartBitOffset = MemberBitOffset & ~(AlignBits - 1);
if ((StartBitOffset + AlignBits) < (MemberBitOffset + MemberBitSize))
@@ -608,7 +619,7 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
DICompositeType *CTy,
uint32_t AccessIndex,
uint32_t PatchImm,
- Align RecordAlignment) {
+ MaybeAlign RecordAlignment) {
if (InfoKind == BPFCoreSharedInfo::FIELD_EXISTENCE)
return 1;
@@ -624,7 +635,7 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
PatchImm += MemberTy->getOffsetInBits() >> 3;
} else {
unsigned SBitOffset, NextSBitOffset;
- GetStorageBitRange(MemberTy, RecordAlignment, SBitOffset,
+ GetStorageBitRange(MemberTy, *RecordAlignment, SBitOffset,
NextSBitOffset);
PatchImm += SBitOffset >> 3;
}
@@ -643,7 +654,8 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
return SizeInBits >> 3;
unsigned SBitOffset, NextSBitOffset;
- GetStorageBitRange(MemberTy, RecordAlignment, SBitOffset, NextSBitOffset);
+ GetStorageBitRange(MemberTy, *RecordAlignment, SBitOffset,
+ NextSBitOffset);
SizeInBits = NextSBitOffset - SBitOffset;
if (SizeInBits & (SizeInBits - 1))
report_fatal_error("Unsupported field expression for llvm.bpf.preserve.field.info");
@@ -703,7 +715,7 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
}
unsigned SBitOffset, NextSBitOffset;
- GetStorageBitRange(MemberTy, RecordAlignment, SBitOffset, NextSBitOffset);
+ GetStorageBitRange(MemberTy, *RecordAlignment, SBitOffset, NextSBitOffset);
if (NextSBitOffset - SBitOffset > 64)
report_fatal_error("too big field size for llvm.bpf.preserve.field.info");
@@ -734,7 +746,7 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
}
unsigned SBitOffset, NextSBitOffset;
- GetStorageBitRange(MemberTy, RecordAlignment, SBitOffset, NextSBitOffset);
+ GetStorageBitRange(MemberTy, *RecordAlignment, SBitOffset, NextSBitOffset);
if (NextSBitOffset - SBitOffset > 64)
report_fatal_error("too big field size for llvm.bpf.preserve.field.info");
@@ -923,7 +935,8 @@ MDNode *BPFAbstractMemberAccess::computeAccessKey(CallInst *Call,
int64_t PatchImm;
std::string AccessStr("0");
- if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_EXISTENCE) {
+ if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_EXISTENCE ||
+ CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_MATCH) {
PatchImm = 1;
} else if (CInfo.AccessIndex == BPFCoreSharedInfo::TYPE_SIZE) {
// typedef debuginfo type has size 0, get the eventual base type.
@@ -933,8 +946,11 @@ MDNode *BPFAbstractMemberAccess::computeAccessKey(CallInst *Call,
// ENUM_VALUE_EXISTENCE and ENUM_VALUE
IsInt32Ret = false;
- const auto *CE = cast<ConstantExpr>(Call->getArgOperand(1));
- const GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
+ // The argument could be a global variable or a getelementptr with base to
+ // a global variable depending on whether the clang option `opaque-options`
+ // is set or not.
+ const GlobalVariable *GV =
+ cast<GlobalVariable>(Call->getArgOperand(1)->stripPointerCasts());
assert(GV->hasInitializer());
const ConstantDataArray *DA = cast<ConstantDataArray>(GV->getInitializer());
assert(DA->isString());
diff --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
index 69d0bca0bd77..98f8d59fbe01 100644
--- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -259,10 +259,16 @@ bool BPFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) {
return false;
if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
- if (Cond2Op != ICmpInst::ICMP_SLT && Cond1Op != ICmpInst::ICMP_SLE)
+ if (Cond2Op != ICmpInst::ICMP_SLT && Cond2Op != ICmpInst::ICMP_SLE)
return false;
} else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
- if (Cond2Op != ICmpInst::ICMP_SGT && Cond1Op != ICmpInst::ICMP_SGE)
+ if (Cond2Op != ICmpInst::ICMP_SGT && Cond2Op != ICmpInst::ICMP_SGE)
+ return false;
+ } else if (Cond1Op == ICmpInst::ICMP_ULT || Cond1Op == ICmpInst::ICMP_ULE) {
+ if (Cond2Op != ICmpInst::ICMP_UGT && Cond2Op != ICmpInst::ICMP_UGE)
+ return false;
+ } else if (Cond1Op == ICmpInst::ICMP_UGT || Cond1Op == ICmpInst::ICMP_UGE) {
+ if (Cond2Op != ICmpInst::ICMP_ULT && Cond2Op != ICmpInst::ICMP_ULE)
return false;
} else {
return false;
diff --git a/llvm/lib/Target/BPF/BPFCORE.h b/llvm/lib/Target/BPF/BPFCORE.h
index 0c504412480d..c9aa135232c1 100644
--- a/llvm/lib/Target/BPF/BPFCORE.h
+++ b/llvm/lib/Target/BPF/BPFCORE.h
@@ -32,6 +32,7 @@ public:
TYPE_SIZE,
ENUM_VALUE_EXISTENCE,
ENUM_VALUE,
+ TYPE_MATCH,
MAX_FIELD_RELOC_KIND,
};
@@ -46,6 +47,7 @@ public:
enum PreserveTypeInfo : uint32_t {
PRESERVE_TYPE_INFO_EXISTENCE = 0,
PRESERVE_TYPE_INFO_SIZE,
+ PRESERVE_TYPE_INFO_MATCH,
MAX_PRESERVE_TYPE_INFO_FLAG,
};
diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp
index 0587cb0e16e3..16876e74c4a1 100644
--- a/llvm/lib/Target/BPF/BPFISelLowering.cpp
+++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp
@@ -103,7 +103,6 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::SDIVREM, VT, Expand);
setOperationAction(ISD::UDIVREM, VT, Expand);
setOperationAction(ISD::SREM, VT, Expand);
- setOperationAction(ISD::UREM, VT, Expand);
setOperationAction(ISD::MULHU, VT, Expand);
setOperationAction(ISD::MULHS, VT, Expand);
setOperationAction(ISD::UMUL_LOHI, VT, Expand);
@@ -168,6 +167,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
MaxStoresPerMemset = MaxStoresPerMemsetOptSize = 0;
MaxStoresPerMemcpy = MaxStoresPerMemcpyOptSize = 0;
MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = 0;
+ MaxLoadsPerMemcmp = 0;
} else {
// inline memcpy() for kernel to see explicit copy
unsigned CommonMaxStores =
@@ -176,6 +176,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
MaxStoresPerMemset = MaxStoresPerMemsetOptSize = CommonMaxStores;
MaxStoresPerMemcpy = MaxStoresPerMemcpyOptSize = CommonMaxStores;
MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = CommonMaxStores;
+ MaxLoadsPerMemcmp = MaxLoadsPerMemcmpOptSize = CommonMaxStores;
}
// CPU/Feature control
diff --git a/llvm/lib/Target/BPF/BPFInstrFormats.td b/llvm/lib/Target/BPF/BPFInstrFormats.td
index a809065014e5..27db0be080ae 100644
--- a/llvm/lib/Target/BPF/BPFInstrFormats.td
+++ b/llvm/lib/Target/BPF/BPFInstrFormats.td
@@ -39,6 +39,7 @@ def BPF_AND : BPFArithOp<0x5>;
def BPF_LSH : BPFArithOp<0x6>;
def BPF_RSH : BPFArithOp<0x7>;
def BPF_NEG : BPFArithOp<0x8>;
+def BPF_MOD : BPFArithOp<0x9>;
def BPF_XOR : BPFArithOp<0xa>;
def BPF_MOV : BPFArithOp<0xb>;
def BPF_ARSH : BPFArithOp<0xc>;
diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.cpp b/llvm/lib/Target/BPF/BPFInstrInfo.cpp
index 54360a89782b..e61e32b62d83 100644
--- a/llvm/lib/Target/BPF/BPFInstrInfo.cpp
+++ b/llvm/lib/Target/BPF/BPFInstrInfo.cpp
@@ -192,8 +192,7 @@ bool BPFInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
}
// If the block has any instructions after a J, delete them.
- while (std::next(I) != MBB.end())
- std::next(I)->eraseFromParent();
+ MBB.erase(std::next(I), MBB.end());
Cond.clear();
FBB = nullptr;
diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.td b/llvm/lib/Target/BPF/BPFInstrInfo.td
index 082e1f4a92c2..6cac478561b2 100644
--- a/llvm/lib/Target/BPF/BPFInstrInfo.td
+++ b/llvm/lib/Target/BPF/BPFInstrInfo.td
@@ -298,6 +298,7 @@ let isAsCheapAsAMove = 1 in {
}
defm MUL : ALU<BPF_MUL, "*=", mul>;
defm DIV : ALU<BPF_DIV, "/=", udiv>;
+ defm MOD : ALU<BPF_MOD, "%=", urem>;
}
class NEG_RR<BPFOpClass Class, BPFArithOp Opc,
@@ -372,6 +373,7 @@ def FI_ri
let Inst{47-32} = 0;
let Inst{31-0} = 0;
let BPFClass = BPF_LD;
+ bit isPseudo = true;
}
def LD_pseudo
diff --git a/llvm/lib/Target/BPF/BPFMIChecking.cpp b/llvm/lib/Target/BPF/BPFMIChecking.cpp
index 2bc2302cf55c..b462f1d1427d 100644
--- a/llvm/lib/Target/BPF/BPFMIChecking.cpp
+++ b/llvm/lib/Target/BPF/BPFMIChecking.cpp
@@ -17,6 +17,7 @@
#include "BPF.h"
#include "BPFInstrInfo.h"
#include "BPFTargetMachine.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
diff --git a/llvm/lib/Target/BPF/BPFMIPeephole.cpp b/llvm/lib/Target/BPF/BPFMIPeephole.cpp
index 7f69c8a63443..cefbe48b7217 100644
--- a/llvm/lib/Target/BPF/BPFMIPeephole.cpp
+++ b/llvm/lib/Target/BPF/BPFMIPeephole.cpp
@@ -24,6 +24,7 @@
#include "BPFInstrInfo.h"
#include "BPFTargetMachine.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
@@ -123,9 +124,8 @@ bool BPFMIPeephole::isPhiFrom32Def(MachineInstr *PhiMI)
if (!PhiDef)
return false;
if (PhiDef->isPHI()) {
- if (PhiInsns.find(PhiDef) != PhiInsns.end())
+ if (!PhiInsns.insert(PhiDef).second)
return false;
- PhiInsns.insert(PhiDef);
if (!isPhiFrom32Def(PhiDef))
return false;
}
@@ -143,9 +143,8 @@ bool BPFMIPeephole::isInsnFrom32Def(MachineInstr *DefInsn)
return false;
if (DefInsn->isPHI()) {
- if (PhiInsns.find(DefInsn) != PhiInsns.end())
+ if (!PhiInsns.insert(DefInsn).second)
return false;
- PhiInsns.insert(DefInsn);
if (!isPhiFrom32Def(DefInsn))
return false;
} else if (DefInsn->getOpcode() == BPF::COPY) {
diff --git a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
index b4232875383c..088195994edd 100644
--- a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
+++ b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
@@ -31,9 +31,11 @@
#include "BPFCORE.h"
#include "BPFInstrInfo.h"
#include "BPFTargetMachine.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
+#include <set>
using namespace llvm;
@@ -52,9 +54,12 @@ struct BPFMISimplifyPatchable : public MachineFunctionPass {
}
private:
+ std::set<MachineInstr *> SkipInsts;
+
// Initialize class variables.
void initialize(MachineFunction &MFParm);
+ bool isLoadInst(unsigned Opcode);
bool removeLD();
void processCandidate(MachineRegisterInfo *MRI, MachineBasicBlock &MBB,
MachineInstr &MI, Register &SrcReg, Register &DstReg,
@@ -88,6 +93,12 @@ void BPFMISimplifyPatchable::initialize(MachineFunction &MFParm) {
LLVM_DEBUG(dbgs() << "*** BPF simplify patchable insts pass ***\n\n");
}
+bool BPFMISimplifyPatchable::isLoadInst(unsigned Opcode) {
+ return Opcode == BPF::LDD || Opcode == BPF::LDW || Opcode == BPF::LDH ||
+ Opcode == BPF::LDB || Opcode == BPF::LDW32 || Opcode == BPF::LDH32 ||
+ Opcode == BPF::LDB32;
+}
+
void BPFMISimplifyPatchable::checkADDrr(MachineRegisterInfo *MRI,
MachineOperand *RelocOp, const GlobalValue *GVal) {
const MachineInstr *Inst = RelocOp->getParent();
@@ -229,6 +240,11 @@ void BPFMISimplifyPatchable::processDstReg(MachineRegisterInfo *MRI,
void BPFMISimplifyPatchable::processInst(MachineRegisterInfo *MRI,
MachineInstr *Inst, MachineOperand *RelocOp, const GlobalValue *GVal) {
unsigned Opcode = Inst->getOpcode();
+ if (isLoadInst(Opcode)) {
+ SkipInsts.insert(Inst);
+ return;
+ }
+
if (Opcode == BPF::ADD_rr)
checkADDrr(MRI, RelocOp, GVal);
else if (Opcode == BPF::SLL_rr)
@@ -253,10 +269,10 @@ bool BPFMISimplifyPatchable::removeLD() {
}
// Ensure the register format is LOAD <reg>, <reg>, 0
- if (MI.getOpcode() != BPF::LDD && MI.getOpcode() != BPF::LDW &&
- MI.getOpcode() != BPF::LDH && MI.getOpcode() != BPF::LDB &&
- MI.getOpcode() != BPF::LDW32 && MI.getOpcode() != BPF::LDH32 &&
- MI.getOpcode() != BPF::LDB32)
+ if (!isLoadInst(MI.getOpcode()))
+ continue;
+
+ if (SkipInsts.find(&MI) != SkipInsts.end())
continue;
if (!MI.getOperand(0).isReg() || !MI.getOperand(1).isReg())
diff --git a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
index 6dfb7dc39922..8c58aae5b618 100644
--- a/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
+++ b/llvm/lib/Target/BPF/BPFPreserveDIType.cpp
@@ -12,6 +12,7 @@
#include "BPF.h"
#include "BPFCORE.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
index 2fb76ab5c440..97d9ed3cad47 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
@@ -59,7 +59,7 @@ static std::string computeDataLayout(const Triple &TT) {
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
- return RM.getValueOr(Reloc::PIC_);
+ return RM.value_or(Reloc::PIC_);
}
BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
@@ -149,7 +149,7 @@ void BPFPassConfig::addIRPasses() {
}
TargetTransformInfo
-BPFTargetMachine::getTargetTransformInfo(const Function &F) {
+BPFTargetMachine::getTargetTransformInfo(const Function &F) const {
return TargetTransformInfo(BPFTTIImpl(this, F));
}
diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.h b/llvm/lib/Target/BPF/BPFTargetMachine.h
index 98f64ccc3793..fede52089725 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.h
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.h
@@ -34,7 +34,7 @@ public:
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
- TargetTransformInfo getTargetTransformInfo(const Function &F) override;
+ TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
diff --git a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
index 6b86bf6e6cc1..0c8f9604b665 100644
--- a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
+++ b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -71,6 +71,15 @@ public:
Opd2Info, Opd1PropInfo,
Opd2PropInfo);
}
+
+ TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
+ bool IsZeroCmp) const {
+ TTI::MemCmpExpansionOptions Options;
+ Options.LoadSizes = {8, 4, 2, 1};
+ Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
+ return Options;
+ }
+
};
} // end namespace llvm
diff --git a/llvm/lib/Target/BPF/BTF.def b/llvm/lib/Target/BPF/BTF.def
index 0ae4194bc512..1de0e51b4757 100644
--- a/llvm/lib/Target/BPF/BTF.def
+++ b/llvm/lib/Target/BPF/BTF.def
@@ -33,5 +33,6 @@ HANDLE_BTF_KIND(15, DATASEC)
HANDLE_BTF_KIND(16, FLOAT)
HANDLE_BTF_KIND(17, DECL_TAG)
HANDLE_BTF_KIND(18, TYPE_TAG)
+HANDLE_BTF_KIND(19, ENUM64)
#undef HANDLE_BTF_KIND
diff --git a/llvm/lib/Target/BPF/BTF.h b/llvm/lib/Target/BPF/BTF.h
index e54b97cd49a9..4540054aaf34 100644
--- a/llvm/lib/Target/BPF/BTF.h
+++ b/llvm/lib/Target/BPF/BTF.h
@@ -60,6 +60,7 @@ enum {
CommonTypeSize = 12,
BTFArraySize = 12,
BTFEnumSize = 8,
+ BTFEnum64Size = 12,
BTFMemberSize = 12,
BTFParamSize = 8,
BTFDataSecVarSize = 12,
@@ -145,6 +146,15 @@ struct BTFEnum {
int32_t Val; ///< Enum member value
};
+/// BTF_KIND_ENUM64 is followed by multiple "struct BTFEnum64".
+/// The exact number of BTFEnum64 is stored in the vlen (of the
+/// info in "struct CommonType").
+struct BTFEnum64 {
+ uint32_t NameOff; ///< Enum name offset in the string table
+ uint32_t Val_Lo32; ///< Enum member lo32 value
+ uint32_t Val_Hi32; ///< Enum member hi32 value
+};
+
/// BTF_KIND_ARRAY is followed by one "struct BTFArray".
struct BTFArray {
uint32_t ElemType; ///< Element type
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index d536aed1d211..a949e925eb60 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -22,6 +22,7 @@
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
using namespace llvm;
@@ -161,9 +162,10 @@ void BTFTypeInt::emitType(MCStreamer &OS) {
OS.emitInt32(IntVal);
}
-BTFTypeEnum::BTFTypeEnum(const DICompositeType *ETy, uint32_t VLen) : ETy(ETy) {
+BTFTypeEnum::BTFTypeEnum(const DICompositeType *ETy, uint32_t VLen,
+ bool IsSigned) : ETy(ETy) {
Kind = BTF::BTF_KIND_ENUM;
- BTFType.Info = Kind << 24 | VLen;
+ BTFType.Info = IsSigned << 31 | Kind << 24 | VLen;
BTFType.Size = roundupToBytes(ETy->getSizeInBits());
}
@@ -199,6 +201,48 @@ void BTFTypeEnum::emitType(MCStreamer &OS) {
}
}
+BTFTypeEnum64::BTFTypeEnum64(const DICompositeType *ETy, uint32_t VLen,
+ bool IsSigned) : ETy(ETy) {
+ Kind = BTF::BTF_KIND_ENUM64;
+ BTFType.Info = IsSigned << 31 | Kind << 24 | VLen;
+ BTFType.Size = roundupToBytes(ETy->getSizeInBits());
+}
+
+void BTFTypeEnum64::completeType(BTFDebug &BDebug) {
+ if (IsCompleted)
+ return;
+ IsCompleted = true;
+
+ BTFType.NameOff = BDebug.addString(ETy->getName());
+
+ DINodeArray Elements = ETy->getElements();
+ for (const auto Element : Elements) {
+ const auto *Enum = cast<DIEnumerator>(Element);
+
+ struct BTF::BTFEnum64 BTFEnum;
+ BTFEnum.NameOff = BDebug.addString(Enum->getName());
+ uint64_t Value;
+ if (Enum->isUnsigned())
+ Value = static_cast<uint64_t>(Enum->getValue().getZExtValue());
+ else
+ Value = static_cast<uint64_t>(Enum->getValue().getSExtValue());
+ BTFEnum.Val_Lo32 = Value;
+ BTFEnum.Val_Hi32 = Value >> 32;
+ EnumValues.push_back(BTFEnum);
+ }
+}
+
+void BTFTypeEnum64::emitType(MCStreamer &OS) {
+ BTFTypeBase::emitType(OS);
+ for (const auto &Enum : EnumValues) {
+ OS.emitInt32(Enum.NameOff);
+ OS.AddComment("0x" + Twine::utohexstr(Enum.Val_Lo32));
+ OS.emitInt32(Enum.Val_Lo32);
+ OS.AddComment("0x" + Twine::utohexstr(Enum.Val_Hi32));
+ OS.emitInt32(Enum.Val_Hi32);
+ }
+}
+
BTFTypeArray::BTFTypeArray(uint32_t ElemTypeId, uint32_t NumElems) {
Kind = BTF::BTF_KIND_ARRAY;
BTFType.NameOff = 0;
@@ -552,6 +596,46 @@ void BTFDebug::processDeclAnnotations(DINodeArray Annotations,
}
}
+/// Generate btf_type_tag chains.
+int BTFDebug::genBTFTypeTags(const DIDerivedType *DTy, int BaseTypeId) {
+ SmallVector<const MDString *, 4> MDStrs;
+ DINodeArray Annots = DTy->getAnnotations();
+ if (Annots) {
+ // For type with "int __tag1 __tag2 *p", the MDStrs will have
+ // content: [__tag1, __tag2].
+ for (const Metadata *Annotations : Annots->operands()) {
+ const MDNode *MD = cast<MDNode>(Annotations);
+ const MDString *Name = cast<MDString>(MD->getOperand(0));
+ if (!Name->getString().equals("btf_type_tag"))
+ continue;
+ MDStrs.push_back(cast<MDString>(MD->getOperand(1)));
+ }
+ }
+
+ if (MDStrs.size() == 0)
+ return -1;
+
+ // With MDStrs [__tag1, __tag2], the output type chain looks like
+ // PTR -> __tag2 -> __tag1 -> BaseType
+ // In the below, we construct BTF types with the order of __tag1, __tag2
+ // and PTR.
+ unsigned TmpTypeId;
+ std::unique_ptr<BTFTypeTypeTag> TypeEntry;
+ if (BaseTypeId >= 0)
+ TypeEntry =
+ std::make_unique<BTFTypeTypeTag>(BaseTypeId, MDStrs[0]->getString());
+ else
+ TypeEntry = std::make_unique<BTFTypeTypeTag>(DTy, MDStrs[0]->getString());
+ TmpTypeId = addType(std::move(TypeEntry));
+
+ for (unsigned I = 1; I < MDStrs.size(); I++) {
+ const MDString *Value = MDStrs[I];
+ TypeEntry = std::make_unique<BTFTypeTypeTag>(TmpTypeId, Value->getString());
+ TmpTypeId = addType(std::move(TypeEntry));
+ }
+ return TmpTypeId;
+}
+
/// Handle structure/union types.
void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
uint32_t &TypeId) {
@@ -633,8 +717,25 @@ void BTFDebug::visitEnumType(const DICompositeType *CTy, uint32_t &TypeId) {
if (VLen > BTF::MAX_VLEN)
return;
- auto TypeEntry = std::make_unique<BTFTypeEnum>(CTy, VLen);
- TypeId = addType(std::move(TypeEntry), CTy);
+ bool IsSigned = false;
+ unsigned NumBits = 32;
+ // No BaseType implies forward declaration in which case a
+ // BTFTypeEnum with Vlen = 0 is emitted.
+ if (CTy->getBaseType() != nullptr) {
+ const auto *BTy = cast<DIBasicType>(CTy->getBaseType());
+ IsSigned = BTy->getEncoding() == dwarf::DW_ATE_signed ||
+ BTy->getEncoding() == dwarf::DW_ATE_signed_char;
+ NumBits = BTy->getSizeInBits();
+ }
+
+ if (NumBits <= 32) {
+ auto TypeEntry = std::make_unique<BTFTypeEnum>(CTy, VLen, IsSigned);
+ TypeId = addType(std::move(TypeEntry), CTy);
+ } else {
+ assert(NumBits == 64);
+ auto TypeEntry = std::make_unique<BTFTypeEnum64>(CTy, VLen, IsSigned);
+ TypeId = addType(std::move(TypeEntry), CTy);
+ }
// No need to visit base type as BTF does not encode it.
}
@@ -684,9 +785,8 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
/// pointee type will be replaced with either a real type or
/// a forward declaration.
auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true);
- auto &Fixup = FixupDerivedTypes[CTy->getName()];
- Fixup.first = CTag == dwarf::DW_TAG_union_type;
- Fixup.second.push_back(TypeEntry.get());
+ auto &Fixup = FixupDerivedTypes[CTy];
+ Fixup.push_back(std::make_pair(DTy, TypeEntry.get()));
TypeId = addType(std::move(TypeEntry), DTy);
return;
}
@@ -695,34 +795,8 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
}
if (Tag == dwarf::DW_TAG_pointer_type) {
- SmallVector<const MDString *, 4> MDStrs;
- DINodeArray Annots = DTy->getAnnotations();
- if (Annots) {
- // For type with "int __tag1 __tag2 *p", the MDStrs will have
- // content: [__tag1, __tag2].
- for (const Metadata *Annotations : Annots->operands()) {
- const MDNode *MD = cast<MDNode>(Annotations);
- const MDString *Name = cast<MDString>(MD->getOperand(0));
- if (!Name->getString().equals("btf_type_tag"))
- continue;
- MDStrs.push_back(cast<MDString>(MD->getOperand(1)));
- }
- }
-
- if (MDStrs.size() > 0) {
- // With MDStrs [__tag1, __tag2], the output type chain looks like
- // PTR -> __tag2 -> __tag1 -> BaseType
- // In the below, we construct BTF types with the order of __tag1, __tag2
- // and PTR.
- auto TypeEntry =
- std::make_unique<BTFTypeTypeTag>(DTy, MDStrs[0]->getString());
- unsigned TmpTypeId = addType(std::move(TypeEntry));
- for (unsigned I = 1; I < MDStrs.size(); I++) {
- const MDString *Value = MDStrs[I];
- TypeEntry =
- std::make_unique<BTFTypeTypeTag>(TmpTypeId, Value->getString());
- TmpTypeId = addType(std::move(TypeEntry));
- }
+ int TmpTypeId = genBTFTypeTags(DTy, -1);
+ if (TmpTypeId >= 0) {
auto TypeDEntry =
std::make_unique<BTFTypeDerived>(TmpTypeId, Tag, DTy->getName());
TypeId = addType(std::move(TypeDEntry), DTy);
@@ -773,15 +847,31 @@ void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId,
// already defined, we should keep moving to eventually
// bring in types for "struct t". Otherwise, the "struct s2"
// definition won't be correct.
+ //
+ // In the above, we have following debuginfo:
+ // {ptr, struct_member} -> typedef -> struct
+ // and BTF type for 'typedef' is generated while 'struct' may
+ // be in FixUp. But let us generalize the above to handle
+ // {different types} -> [various derived types]+ -> another type.
+ // For example,
+ // {func_param, struct_member} -> const -> ptr -> volatile -> struct
+ // We will traverse const/ptr/volatile which already have corresponding
+ // BTF types and generate type for 'struct' which might be in Fixup
+ // state.
if (Ty && (!CheckPointer || !SeenPointer)) {
if (const auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
- unsigned Tag = DTy->getTag();
- if (Tag == dwarf::DW_TAG_typedef || Tag == dwarf::DW_TAG_const_type ||
- Tag == dwarf::DW_TAG_volatile_type ||
- Tag == dwarf::DW_TAG_restrict_type) {
- uint32_t TmpTypeId;
- visitTypeEntry(DTy->getBaseType(), TmpTypeId, CheckPointer,
- SeenPointer);
+ while (DTy) {
+ const DIType *BaseTy = DTy->getBaseType();
+ if (!BaseTy)
+ break;
+
+ if (DIToIdMap.find(BaseTy) != DIToIdMap.end()) {
+ DTy = dyn_cast<DIDerivedType>(BaseTy);
+ } else {
+ uint32_t TmpTypeId;
+ visitTypeEntry(BaseTy, TmpTypeId, CheckPointer, SeenPointer);
+ break;
+ }
}
}
}
@@ -908,7 +998,7 @@ void BTFDebug::emitBTFSection() {
MCContext &Ctx = OS.getContext();
MCSectionELF *Sec = Ctx.getELFSection(".BTF", ELF::SHT_PROGBITS, 0);
Sec->setAlignment(Align(4));
- OS.SwitchSection(Sec);
+ OS.switchSection(Sec);
// Emit header.
emitCommonHeader();
@@ -948,7 +1038,7 @@ void BTFDebug::emitBTFExtSection() {
MCContext &Ctx = OS.getContext();
MCSectionELF *Sec = Ctx.getELFSection(".BTF.ext", ELF::SHT_PROGBITS, 0);
Sec->setAlignment(Align(4));
- OS.SwitchSection(Sec);
+ OS.switchSection(Sec);
// Emit header.
emitCommonHeader();
@@ -1436,9 +1526,8 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
return;
// Do not emit again if already emitted.
- if (ProtoFunctions.find(F) != ProtoFunctions.end())
+ if (!ProtoFunctions.insert(F).second)
return;
- ProtoFunctions.insert(F);
uint32_t ProtoTypeId;
const std::unordered_map<uint32_t, StringRef> FuncArgNames;
@@ -1480,8 +1569,9 @@ void BTFDebug::endModule() {
// Fixups
for (auto &Fixup : FixupDerivedTypes) {
- StringRef TypeName = Fixup.first;
- bool IsUnion = Fixup.second.first;
+ const DICompositeType *CTy = Fixup.first;
+ StringRef TypeName = CTy->getName();
+ bool IsUnion = CTy->getTag() == dwarf::DW_TAG_union_type;
// Search through struct types
uint32_t StructTypeId = 0;
@@ -1497,8 +1587,15 @@ void BTFDebug::endModule() {
StructTypeId = addType(std::move(FwdTypeEntry));
}
- for (auto &DType : Fixup.second.second) {
- DType->setPointeeType(StructTypeId);
+ for (auto &TypeInfo : Fixup.second) {
+ const DIDerivedType *DTy = TypeInfo.first;
+ BTFTypeDerived *BDType = TypeInfo.second;
+
+ int TmpTypeId = genBTFTypeTags(DTy, StructTypeId);
+ if (TmpTypeId >= 0)
+ BDType->setPointeeType(TmpTypeId);
+ else
+ BDType->setPointeeType(StructTypeId);
}
}
diff --git a/llvm/lib/Target/BPF/BTFDebug.h b/llvm/lib/Target/BPF/BTFDebug.h
index 7c30675c553c..1ad8ec5d918c 100644
--- a/llvm/lib/Target/BPF/BTFDebug.h
+++ b/llvm/lib/Target/BPF/BTFDebug.h
@@ -103,7 +103,7 @@ class BTFTypeEnum : public BTFTypeBase {
std::vector<struct BTF::BTFEnum> EnumValues;
public:
- BTFTypeEnum(const DICompositeType *ETy, uint32_t NumValues);
+ BTFTypeEnum(const DICompositeType *ETy, uint32_t NumValues, bool IsSigned);
uint32_t getSize() override {
return BTFTypeBase::getSize() + EnumValues.size() * BTF::BTFEnumSize;
}
@@ -218,6 +218,20 @@ public:
void emitType(MCStreamer &OS) override;
};
+/// Handle 64-bit enumerate type.
+class BTFTypeEnum64 : public BTFTypeBase {
+ const DICompositeType *ETy;
+ std::vector<struct BTF::BTFEnum64> EnumValues;
+
+public:
+ BTFTypeEnum64(const DICompositeType *ETy, uint32_t NumValues, bool IsSigned);
+ uint32_t getSize() override {
+ return BTFTypeBase::getSize() + EnumValues.size() * BTF::BTFEnum64Size;
+ }
+ void completeType(BTFDebug &BDebug) override;
+ void emitType(MCStreamer &OS) override;
+};
+
class BTFTypeTypeTag : public BTFTypeBase {
const DIDerivedType *DTy;
StringRef Tag;
@@ -289,7 +303,8 @@ class BTFDebug : public DebugHandlerBase {
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<StringRef, std::pair<bool, std::vector<BTFTypeDerived *>>>
+ std::map<const DICompositeType *,
+ std::vector<std::pair<const DIDerivedType *, BTFTypeDerived *>>>
FixupDerivedTypes;
std::set<const Function *>ProtoFunctions;
@@ -341,6 +356,13 @@ class BTFDebug : public DebugHandlerBase {
void processDeclAnnotations(DINodeArray Annotations, uint32_t BaseTypeId,
int ComponentId);
+ /// Generate BTF type_tag's. If BaseTypeId is nonnegative, the last
+ /// BTF type_tag in the chain points to BaseTypeId. Otherwise, it points to
+ /// the base type of DTy. Return the type id of the first BTF type_tag
+ /// in the chain. If no type_tag's are generated, a negative value
+ /// is returned.
+ int genBTFTypeTags(const DIDerivedType *DTy, int BaseTypeId);
+
/// Generate one field relocation record.
void generatePatchImmReloc(const MCSymbol *ORSym, uint32_t RootId,
const GlobalVariable *, bool IsAma);
diff --git a/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp b/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
index 3f643d47f934..aa408f8b65f7 100644
--- a/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
+++ b/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
@@ -15,9 +15,10 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCDecoderOps.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
-#include "llvm/MC/MCFixedLenDisassembler.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/SubtargetFeature.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/MathExtras.h"
#include <cstdint>
@@ -99,7 +100,7 @@ static const unsigned GPRDecoderTable[] = {
static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo,
uint64_t /*Address*/,
- const void * /*Decoder*/) {
+ const MCDisassembler * /*Decoder*/) {
if (RegNo > 11)
return MCDisassembler::Fail;
@@ -112,9 +113,9 @@ static const unsigned GPR32DecoderTable[] = {
BPF::W0, BPF::W1, BPF::W2, BPF::W3, BPF::W4, BPF::W5,
BPF::W6, BPF::W7, BPF::W8, BPF::W9, BPF::W10, BPF::W11};
-static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo,
- uint64_t /*Address*/,
- const void * /*Decoder*/) {
+static DecodeStatus
+DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/,
+ const MCDisassembler * /*Decoder*/) {
if (RegNo > 11)
return MCDisassembler::Fail;
@@ -124,7 +125,8 @@ static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo,
}
static DecodeStatus decodeMemoryOpValue(MCInst &Inst, unsigned Insn,
- uint64_t Address, const void *Decoder) {
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
unsigned Register = (Insn >> 16) & 0xf;
if (Register > 11)
return MCDisassembler::Fail;
@@ -220,4 +222,4 @@ DecodeStatus BPFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
}
typedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address,
- const void *Decoder);
+ const MCDisassembler *Decoder);
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
index bacd00360f82..56fdd6766132 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
@@ -87,6 +87,11 @@ void BPFAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
}
} else {
assert(Fixup.getKind() == FK_PCRel_2);
+
+ int64_t ByteOff = (int64_t)Value - 8;
+ if (ByteOff > INT16_MAX * 8 || ByteOff < INT16_MIN * 8)
+ report_fatal_error("Branch target out of insn range");
+
Value = (uint16_t)((Value - 8) / 8);
support::endian::write<uint16_t>(&Data[Fixup.getOffset() + 2], Value,
Endian);
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
index 200c72a07ed6..6f041584a955 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFInstPrinter.cpp
@@ -15,6 +15,7 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
using namespace llvm;
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h
index 3292c3e5ebb5..14f6b367b8c7 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h
@@ -41,8 +41,6 @@ public:
// section will be parsable, but with odd offsets and
// line numbers, etc.
CodePointerSize = 8;
-
- UseIntegratedAssembler = false;
}
void setDwarfUsesRelocationsAcrossSections(bool enable) {
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
index 12af92e0d198..a98d001097bc 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp
@@ -73,15 +73,13 @@ private:
} // end anonymous namespace
MCCodeEmitter *llvm::createBPFMCCodeEmitter(const MCInstrInfo &MCII,
- const MCRegisterInfo &MRI,
MCContext &Ctx) {
- return new BPFMCCodeEmitter(MCII, MRI, true);
+ return new BPFMCCodeEmitter(MCII, *Ctx.getRegisterInfo(), true);
}
MCCodeEmitter *llvm::createBPFbeMCCodeEmitter(const MCInstrInfo &MCII,
- const MCRegisterInfo &MRI,
MCContext &Ctx) {
- return new BPFMCCodeEmitter(MCII, MRI, false);
+ return new BPFMCCodeEmitter(MCII, *Ctx.getRegisterInfo(), false);
}
unsigned BPFMCCodeEmitter::getMachineOpValue(const MCInst &MI,
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h
index a426a132cf47..fc190504581c 100644
--- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h
+++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h
@@ -14,6 +14,7 @@
#define LLVM_LIB_TARGET_BPF_MCTARGETDESC_BPFMCTARGETDESC_H
#include "llvm/Config/config.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/Support/DataTypes.h"
#include <memory>
@@ -30,10 +31,8 @@ class MCTargetOptions;
class Target;
MCCodeEmitter *createBPFMCCodeEmitter(const MCInstrInfo &MCII,
- const MCRegisterInfo &MRI,
MCContext &Ctx);
MCCodeEmitter *createBPFbeMCCodeEmitter(const MCInstrInfo &MCII,
- const MCRegisterInfo &MRI,
MCContext &Ctx);
MCAsmBackend *createBPFAsmBackend(const Target &T, const MCSubtargetInfo &STI,