Index: include/llvm/IR/CallSite.h =================================================================== --- include/llvm/IR/CallSite.h +++ include/llvm/IR/CallSite.h @@ -81,6 +81,9 @@ InstrTy *operator->() const { return I.getPointer(); } explicit operator bool() const { return I.getPointer(); } + BasicBlock* getParent() { return getInstruction()->getParent(); } + const BasicBlock* getParent() const { return getInstruction()->getParent(); } + /// getCalledValue - Return the pointer to function that is being called. /// ValTy *getCalledValue() const { @@ -150,6 +153,11 @@ } IterTy arg_end() const { return (*this)->op_end() - getArgumentEndOffset(); } + + iterator_range args() { + return iterator_range(arg_begin(), arg_end()); + } + bool arg_empty() const { return arg_end() == arg_begin(); } unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); } @@ -185,6 +193,20 @@ else \ cast(II)->METHOD + unsigned getNumArgOperands() const { + CALLSITE_DELEGATE_GETTER(getNumArgOperands()); + } + + Value *getArgOperand(unsigned i) const { + CALLSITE_DELEGATE_GETTER(getArgOperand(i)); + } + + bool isInlineAsm() const { + if (isCall()) + return cast(getInstruction())->isInlineAsm(); + return false; + } + /// getCallingConv/setCallingConv - get or set the calling convention of the /// call. CallingConv::ID getCallingConv() const { Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -102,6 +102,11 @@ OS << '\n'; } } + void Write(const CallSite *CS) { + if (!CS) + return; + Write(CS->getInstruction()); + } void Write(const Metadata *MD) { if (!MD) @@ -374,7 +379,7 @@ void visitSelectInst(SelectInst &SI); void visitUserOp1(Instruction &I); void visitUserOp2(Instruction &I) { visitUserOp1(I); } - void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI); + void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallSite CS); template void visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII); void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); @@ -2238,6 +2243,10 @@ "Function has metadata parameter but isn't an intrinsic", I); } + if (Function *F = CS.getCalledFunction()) + if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) + visitIntrinsicFunctionCall(ID, CS); + visitInstruction(*I); } @@ -2333,10 +2342,6 @@ if (CI.isMustTailCall()) verifyMustTailCall(CI); - - if (Function *F = CI.getCalledFunction()) - if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) - visitIntrinsicFunctionCall(ID, CI); } void Verifier::visitInvokeInst(InvokeInst &II) { @@ -2347,13 +2352,6 @@ Assert(II.getUnwindDest()->isLandingPad(), "The unwind destination does not have a landingpad instruction!", &II); - if (Function *F = II.getCalledFunction()) - // TODO: Ideally we should use visitIntrinsicFunction here. But it uses - // CallInst as an input parameter. It not woth updating this whole - // function only to support statepoint verification. - if (F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint) - VerifyStatepoint(ImmutableCallSite(&II)); - visitTerminatorInst(II); } @@ -3101,7 +3099,7 @@ /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways. /// -void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { +void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallSite CI) { Function *IF = CI.getCalledFunction(); Assert(IF->isDeclaration(), "Intrinsic functions should never be defined!", IF); @@ -3163,10 +3161,10 @@ case Intrinsic::dbg_declare: // llvm.dbg.declare Assert(isa(CI.getArgOperand(0)), "invalid llvm.dbg.declare intrinsic call 1", &CI); - visitDbgIntrinsic("declare", cast(CI)); + visitDbgIntrinsic("declare", cast(*CI.getInstruction())); break; case Intrinsic::dbg_value: // llvm.dbg.value - visitDbgIntrinsic("value", cast(CI)); + visitDbgIntrinsic("value", cast(*CI.getInstruction())); break; case Intrinsic::memcpy: case Intrinsic::memmove: @@ -3237,7 +3235,7 @@ "llvm.frameescape used outside of entry block", &CI); Assert(!SawFrameEscape, "multiple calls to llvm.frameescape in one function", &CI); - for (Value *Arg : CI.arg_operands()) { + for (Value *Arg : CI.args()) { if (isa(Arg)) continue; // Null values are allowed as placeholders. auto *AI = dyn_cast(Arg->stripPointerCasts()); @@ -3270,7 +3268,7 @@ Assert(CI.getParent()->getParent()->hasGC(), "Enclosing function does not use GC.", &CI); - VerifyStatepoint(ImmutableCallSite(&CI)); + VerifyStatepoint(ImmutableCallSite(CI)); break; case Intrinsic::experimental_gc_result_int: case Intrinsic::experimental_gc_result_float: @@ -3332,7 +3330,7 @@ // Verify rest of the relocate arguments - GCRelocateOperands ops(&CI); + GCRelocateOperands ops(CI); ImmutableCallSite StatepointCS(ops.getStatepoint()); // Both the base and derived must be piped through the safepoint @@ -3385,7 +3383,7 @@ &CI); // Assert that the result type matches the type of the relocated pointer - GCRelocateOperands Operands(&CI); + GCRelocateOperands Operands(CI); Assert(Operands.getDerivedPtr()->getType() == CI.getType(), "gc.relocate: relocating a pointer shouldn't change its type", &CI); break;