From e0aa414acf9bb455376df4579e244dcca1434e1f Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Thu, 12 May 2016 01:17:38 +0000 Subject: All llvm.deoptimize declarations must use the same calling convention This new verifier rule lets us unambigously pick a calling convention when creating a new declaration for `@llvm.experimental.deoptimize.`. It is also congruent with our lowering strategy -- since all calls to `@llvm.experimental.deoptimize` are lowered to calls to `__llvm_deoptimize`, it is reasonable to enforce a unique calling convention. Some of the tests that were breaking this verifier rule have had to be split up into different .ll files. The inliner was violating this rule as well, and has been fixed to avoid producing invalid IR. llvm-svn: 269261 --- llvm/lib/IR/Verifier.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'llvm/lib/IR/Verifier.cpp') diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 5621962497a..1b36eb9bd68 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -243,6 +243,9 @@ class Verifier : public InstVisitor, VerifierSupport { /// Cache of constants visited in search of ConstantExprs. SmallPtrSet ConstantExprVisited; + /// Cache of declarations of the llvm.experimental.deoptimize. intrinsic. + SmallVector DeoptimizeDeclarations; + // Verify that this GlobalValue is only used in this module. // This map is used to avoid visiting uses twice. We can arrive at a user // twice, if they have multiple operands. In particular for very large @@ -322,8 +325,11 @@ public: visitGlobalValue(F); // Check to make sure function prototypes are okay. - if (F.isDeclaration()) + if (F.isDeclaration()) { visitFunction(F); + if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) + DeoptimizeDeclarations.push_back(&F); + } } // Now that we've visited every function, verify that we never asked to @@ -346,6 +352,8 @@ public: verifyCompileUnits(); + verifyDeoptimizeCallingConvs(); + return !Broken; } @@ -470,6 +478,10 @@ private: /// Module-level debug info verification... void verifyCompileUnits(); + + /// Module-level verification that all @llvm.experimental.deoptimize + /// declarations share the same calling convention. + void verifyDeoptimizeCallingConvs(); }; } // End anonymous namespace @@ -4396,6 +4408,18 @@ void Verifier::verifyCompileUnits() { CUVisited.clear(); } +void Verifier::verifyDeoptimizeCallingConvs() { + if (DeoptimizeDeclarations.empty()) + return; + + const Function *First = DeoptimizeDeclarations[0]; + for (auto *F : makeArrayRef(DeoptimizeDeclarations).slice(1)) + Assert(First->getCallingConv() == F->getCallingConv(), + "All llvm.experimental.deoptimize declarations must have the same " + "calling convention", + First, F); +} + //===----------------------------------------------------------------------===// // Implement the public interfaces to this file... //===----------------------------------------------------------------------===// -- cgit v1.2.3