Skip to content

Commit 6fe8264

Browse files
committed
callbr
1 parent 84912ae commit 6fe8264

File tree

7 files changed

+40
-32
lines changed

7 files changed

+40
-32
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4249,7 +4249,8 @@ class TargetLowering : public TargetLoweringBase {
42494249
IsInReg = Call.hasRetAttr(Attribute::InReg);
42504250
DoesNotReturn =
42514251
Call.doesNotReturn() ||
4252-
(!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
4252+
(!isa<InvokeInst>(Call) && !isa<CallBrInst>(Call) &&
4253+
isa<UnreachableInst>(Call.getNextNode()));
42534254
IsVarArg = FTy->isVarArg();
42544255
IsReturnValueUsed = !Call.use_empty();
42554256
RetSExt = Call.hasRetAttr(Attribute::SExt);

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/Twine.h"
2222
#include "llvm/IR/DebugLoc.h"
23+
#include "llvm/IR/Instructions.h"
2324
#include "llvm/Support/CBindingWrapping.h"
2425
#include "llvm/Support/ErrorHandling.h"
2526
#include "llvm/Support/SourceMgr.h"
@@ -1096,7 +1097,7 @@ class DiagnosticInfoSrcMgr : public DiagnosticInfo {
10961097
}
10971098
};
10981099

1099-
void diagnoseDontCall(const CallInst &CI);
1100+
void diagnoseDontCall(const CallBase &CI);
11001101

11011102
class DiagnosticInfoDontCall : public DiagnosticInfo {
11021103
StringRef CalleeName;

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,8 +2640,13 @@ bool IRTranslator::translateInvoke(const User &U,
26402640

26412641
bool IRTranslator::translateCallBr(const User &U,
26422642
MachineIRBuilder &MIRBuilder) {
2643-
// FIXME: Implement this.
2644-
return false;
2643+
const CallBrInst &I = cast<CallBrInst>(U);
2644+
2645+
if (I.isInlineAsm()) {
2646+
return translateInlineAsm(I, MIRBuilder);
2647+
} else {
2648+
return translateCallBase(I, MIRBuilder);
2649+
}
26452650
}
26462651

26472652
bool IRTranslator::translateLandingPad(const User &U,

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,8 +3044,8 @@ void SelectionDAGBuilder::visitCallBr(const CallBrInst &I) {
30443044
{LLVMContext::OB_deopt, LLVMContext::OB_funclet}) &&
30453045
"Cannot lower callbrs with arbitrary operand bundles yet!");
30463046

3047-
assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
3048-
visitInlineAsm(I);
3047+
// assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
3048+
visitCall(I);
30493049
CopyToExportRegsIfNeeded(&I);
30503050

30513051
// Retrieve successors.
@@ -8092,7 +8092,7 @@ void SelectionDAGBuilder::processIntegerCallValue(const Instruction &I,
80928092
/// normal call.
80938093
/// The caller already checked that \p I calls the appropriate LibFunc with a
80948094
/// correct prototype.
8095-
bool SelectionDAGBuilder::visitMemCmpBCmpCall(const CallInst &I) {
8095+
bool SelectionDAGBuilder::visitMemCmpBCmpCall(const CallBase &I) {
80968096
const Value *LHS = I.getArgOperand(0), *RHS = I.getArgOperand(1);
80978097
const Value *Size = I.getArgOperand(2);
80988098
const ConstantSDNode *CSize = dyn_cast<ConstantSDNode>(getValue(Size));
@@ -8184,7 +8184,7 @@ bool SelectionDAGBuilder::visitMemCmpBCmpCall(const CallInst &I) {
81848184
/// normal call.
81858185
/// The caller already checked that \p I calls the appropriate LibFunc with a
81868186
/// correct prototype.
8187-
bool SelectionDAGBuilder::visitMemChrCall(const CallInst &I) {
8187+
bool SelectionDAGBuilder::visitMemChrCall(const CallBase &I) {
81888188
const Value *Src = I.getArgOperand(0);
81898189
const Value *Char = I.getArgOperand(1);
81908190
const Value *Length = I.getArgOperand(2);
@@ -8208,7 +8208,7 @@ bool SelectionDAGBuilder::visitMemChrCall(const CallInst &I) {
82088208
/// normal call.
82098209
/// The caller already checked that \p I calls the appropriate LibFunc with a
82108210
/// correct prototype.
8211-
bool SelectionDAGBuilder::visitMemPCpyCall(const CallInst &I) {
8211+
bool SelectionDAGBuilder::visitMemPCpyCall(const CallBase &I) {
82128212
SDValue Dst = getValue(I.getArgOperand(0));
82138213
SDValue Src = getValue(I.getArgOperand(1));
82148214
SDValue Size = getValue(I.getArgOperand(2));
@@ -8249,7 +8249,7 @@ bool SelectionDAGBuilder::visitMemPCpyCall(const CallInst &I) {
82498249
/// normal call.
82508250
/// The caller already checked that \p I calls the appropriate LibFunc with a
82518251
/// correct prototype.
8252-
bool SelectionDAGBuilder::visitStrCpyCall(const CallInst &I, bool isStpcpy) {
8252+
bool SelectionDAGBuilder::visitStrCpyCall(const CallBase &I, bool isStpcpy) {
82538253
const Value *Arg0 = I.getArgOperand(0), *Arg1 = I.getArgOperand(1);
82548254

82558255
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
@@ -8272,7 +8272,7 @@ bool SelectionDAGBuilder::visitStrCpyCall(const CallInst &I, bool isStpcpy) {
82728272
/// normal call.
82738273
/// The caller already checked that \p I calls the appropriate LibFunc with a
82748274
/// correct prototype.
8275-
bool SelectionDAGBuilder::visitStrCmpCall(const CallInst &I) {
8275+
bool SelectionDAGBuilder::visitStrCmpCall(const CallBase &I) {
82768276
const Value *Arg0 = I.getArgOperand(0), *Arg1 = I.getArgOperand(1);
82778277

82788278
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
@@ -8295,7 +8295,7 @@ bool SelectionDAGBuilder::visitStrCmpCall(const CallInst &I) {
82958295
/// normal call.
82968296
/// The caller already checked that \p I calls the appropriate LibFunc with a
82978297
/// correct prototype.
8298-
bool SelectionDAGBuilder::visitStrLenCall(const CallInst &I) {
8298+
bool SelectionDAGBuilder::visitStrLenCall(const CallBase &I) {
82998299
const Value *Arg0 = I.getArgOperand(0);
83008300

83018301
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
@@ -8316,7 +8316,7 @@ bool SelectionDAGBuilder::visitStrLenCall(const CallInst &I) {
83168316
/// normal call.
83178317
/// The caller already checked that \p I calls the appropriate LibFunc with a
83188318
/// correct prototype.
8319-
bool SelectionDAGBuilder::visitStrNLenCall(const CallInst &I) {
8319+
bool SelectionDAGBuilder::visitStrNLenCall(const CallBase &I) {
83208320
const Value *Arg0 = I.getArgOperand(0), *Arg1 = I.getArgOperand(1);
83218321

83228322
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
@@ -8338,7 +8338,7 @@ bool SelectionDAGBuilder::visitStrNLenCall(const CallInst &I) {
83388338
/// false and it will be lowered like a normal call.
83398339
/// The caller already checked that \p I calls the appropriate LibFunc with a
83408340
/// correct prototype.
8341-
bool SelectionDAGBuilder::visitUnaryFloatCall(const CallInst &I,
8341+
bool SelectionDAGBuilder::visitUnaryFloatCall(const CallBase &I,
83428342
unsigned Opcode) {
83438343
// We already checked this call's prototype; verify it doesn't modify errno.
83448344
if (!I.onlyReadsMemory())
@@ -8358,7 +8358,7 @@ bool SelectionDAGBuilder::visitUnaryFloatCall(const CallInst &I,
83588358
/// false, and it will be lowered like a normal call.
83598359
/// The caller already checked that \p I calls the appropriate LibFunc with a
83608360
/// correct prototype.
8361-
bool SelectionDAGBuilder::visitBinaryFloatCall(const CallInst &I,
8361+
bool SelectionDAGBuilder::visitBinaryFloatCall(const CallBase &I,
83628362
unsigned Opcode) {
83638363
// We already checked this call's prototype; verify it doesn't modify errno.
83648364
if (!I.onlyReadsMemory())
@@ -8374,7 +8374,7 @@ bool SelectionDAGBuilder::visitBinaryFloatCall(const CallInst &I,
83748374
return true;
83758375
}
83768376

8377-
void SelectionDAGBuilder::visitCall(const CallInst &I) {
8377+
void SelectionDAGBuilder::visitCall(const CallBase &I) {
83788378
// Handle inline assembly differently.
83798379
if (I.isInlineAsm()) {
83808380
visitInlineAsm(I);
@@ -8392,7 +8392,8 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
83928392
IID = II->getIntrinsicID(F);
83938393

83948394
if (IID) {
8395-
visitIntrinsicCall(I, IID);
8395+
assert(isa<CallInst>(I) && "Don't know how to handle intrinsic callbr");
8396+
visitIntrinsicCall(cast<CallInst>(I), IID);
83968397
return;
83978398
}
83988399
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,16 @@ class SelectionDAGBuilder {
598598
void visitAtomicRMW(const AtomicRMWInst &I);
599599
void visitFence(const FenceInst &I);
600600
void visitPHI(const PHINode &I);
601-
void visitCall(const CallInst &I);
602-
bool visitMemCmpBCmpCall(const CallInst &I);
603-
bool visitMemPCpyCall(const CallInst &I);
604-
bool visitMemChrCall(const CallInst &I);
605-
bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
606-
bool visitStrCmpCall(const CallInst &I);
607-
bool visitStrLenCall(const CallInst &I);
608-
bool visitStrNLenCall(const CallInst &I);
609-
bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
610-
bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode);
601+
void visitCall(const CallBase &I);
602+
bool visitMemCmpBCmpCall(const CallBase &I);
603+
bool visitMemPCpyCall(const CallBase &I);
604+
bool visitMemChrCall(const CallBase &I);
605+
bool visitStrCpyCall(const CallBase &I, bool isStpcpy);
606+
bool visitStrCmpCall(const CallBase &I);
607+
bool visitStrLenCall(const CallBase &I);
608+
bool visitStrNLenCall(const CallBase &I);
609+
bool visitUnaryFloatCall(const CallBase &I, unsigned Opcode);
610+
bool visitBinaryFloatCall(const CallBase &I, unsigned Opcode);
611611
void visitAtomicLoad(const LoadInst &I);
612612
void visitAtomicStore(const StoreInst &I);
613613
void visitLoadFromSwiftError(const LoadInst &I);

llvm/lib/IR/DiagnosticInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void DiagnosticInfoMisExpect::print(DiagnosticPrinter &DP) const {
415415
void OptimizationRemarkAnalysisFPCommute::anchor() {}
416416
void OptimizationRemarkAnalysisAliasing::anchor() {}
417417

418-
void llvm::diagnoseDontCall(const CallInst &CI) {
418+
void llvm::diagnoseDontCall(const CallBase &CI) {
419419
const auto *F =
420420
dyn_cast<Function>(CI.getCalledOperand()->stripPointerCasts());
421421

llvm/lib/IR/Verifier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,11 +2907,11 @@ void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
29072907
}
29082908

29092909
void Verifier::visitCallBrInst(CallBrInst &CBI) {
2910-
Check(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!", &CBI);
2911-
const InlineAsm *IA = cast<InlineAsm>(CBI.getCalledOperand());
2912-
Check(!IA->canThrow(), "Unwinding from Callbr is not allowed");
2910+
// Check(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!", &CBI);
2911+
// const InlineAsm *IA = cast<InlineAsm>(CBI.getCalledOperand());
2912+
// Check(!IA->canThrow(), "Unwinding from Callbr is not allowed");
29132913

2914-
verifyInlineAsmCall(CBI);
2914+
if (CBI.isInlineAsm()) verifyInlineAsmCall(CBI);
29152915
visitTerminator(CBI);
29162916
}
29172917

0 commit comments

Comments
 (0)