llvm.org GIT mirror llvm / f70eb72
[Bitcode][Asm] Teach LLVM to read and write operand bundles. Summary: This also adds the first set of tests for operand bundles. The optimizer has not been audited to ensure that it does the right thing with operand bundles. Depends on D12456. Reviewers: reames, chandlerc, majnemer, dexonsmith, kmod, JosephTremoulet, rnk, bogner Subscribers: maksfb, llvm-commits Differential Revision: http://reviews.llvm.org/D12457 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248551 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 5 years ago
10 changed file(s) with 651 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
14361436 show that no exceptions passes by it. This is normally the case for
14371437 the ELF x86-64 abi, but it can be disabled for some compilation
14381438 units.
1439
1440
1441 .. _opbundles:
1442
1443 Operand Bundles
1444 ---------------
1445
1446 Note: operand bundles are a work in progress, and they should be
1447 considered experimental at this time.
1448
1449 Operand bundles are tagged sets of SSA values that can be associated
1450 with certain LLVM instructions (currently only ``call``s and
1451 ``invoke``s). In a way they are like metadata, but dropping them is
1452 incorrect and will change program semantics.
1453
1454 Syntax::
1455 operand bundle set ::= '[' operand bundle ']'
1456 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
1457 bundle operand ::= SSA value
1458 tag ::= string constant
1459
1460 Operand bundles are **not** part of a function's signature, and a
1461 given function may be called from multiple places with different kinds
1462 of operand bundles. This reflects the fact that the operand bundles
1463 are conceptually a part of the ``call`` (or ``invoke``), not the
1464 callee being dispatched to.
1465
1466 Operand bundles are a generic mechanism intended to support
1467 runtime-introspection-like functionality for managed languages. While
1468 the exact semantics of an operand bundle depend on the bundle tag,
1469 there are certain limitations to how much the presence of an operand
1470 bundle can influence the semantics of a program. These restrictions
1471 are described as the semantics of an "unknown" operand bundle. As
1472 long as the behavior of an operand bundle is describable within these
1473 restrictions, LLVM does not need to have special knowledge of the
1474 operand bundle to not miscompile programs containing it.
1475
1476 - The bundle operands for an unknown operand bundle escape in unknown
1477 ways before control is transferred to the callee or invokee.
1478
1479 - Calls and invokes with operand bundles have unknown read / write
1480 effect on the heap on entry and exit (even if the call target is
1481 ``readnone`` or ``readonly``).
1482
1483 - An operand bundle at a call site cannot change the implementation
1484 of the called function. Inter-procedural optimizations work as
1485 usual as long as they take into account the first two properties.
14391486
14401487 .. _moduleasm:
14411488
50605107 ::
50615108
50625109 = invoke [cconv] [ret attrs] () [fn attrs]
5063 to label unwind label
5110 [operand bundles] to label unwind label
50645111
50655112 Overview:
50665113 """""""""
51145161 #. The optional :ref:`function attributes ` list. Only
51155162 '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
51165163 attributes are valid here.
5164 #. The optional :ref:`operand bundles ` list.
51175165
51185166 Semantics:
51195167 """"""""""
83098357 ::
83108358
83118359 = [tail | musttail] call [cconv] [ret attrs] [*] () [fn attrs]
8360 [ operand bundles ]
83128361
83138362 Overview:
83148363 """""""""
83888437 #. The optional :ref:`function attributes ` list. Only
83898438 '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
83908439 attributes are valid here.
8440 #. The optional :ref:`operand bundles ` list.
83918441
83928442 Semantics:
83938443 """"""""""
4242 TYPE_BLOCK_ID_NEW,
4343
4444 USELIST_BLOCK_ID,
45
46 MODULE_STRTAB_BLOCK_ID,
47 FUNCTION_SUMMARY_BLOCK_ID,
48
49 OPERAND_BUNDLE_TAGS_BLOCK_ID
4550 };
4651
4752
128133 TYPE_CODE_FUNCTION = 21, // FUNCTION: [vararg, retty, paramty x N]
129134
130135 TYPE_CODE_TOKEN = 22 // TOKEN
136 };
137
138 enum OperandBundleTagCode {
139 OPERAND_BUNDLE_TAG = 1, // TAG: [strchr x N]
131140 };
132141
133142 // The type symbol table only has one code (TST_ENTRY_CODE).
368377 FUNC_CODE_INST_CLEANUPPAD = 52, // CLEANUPPAD: [num,args...]
369378 FUNC_CODE_INST_CATCHENDPAD = 53, // CATCHENDPAD: [] or [bb#]
370379 FUNC_CODE_INST_CLEANUPENDPAD = 54, // CLEANUPENDPAD: [val] or [val,bb#]
380
381 FUNC_CODE_OPERAND_BUNDLE = 55, // OPERAND_BUNDLE: [tag#, value...]
371382 };
372383
373384 enum UseListCodes {
19411941 return false;
19421942 }
19431943
1944
1944 /// ParseOptionalOperandBundles
1945 /// ::= /*empty*/
1946 /// ::= '[' OperandBundle [, OperandBundle ]* ']'
1947 ///
1948 /// OperandBundle
1949 /// ::= bundle-tag '(' ')'
1950 /// ::= bundle-tag '(' Type Value [, Type Value ]* ')'
1951 ///
1952 /// bundle-tag ::= String Constant
1953 bool LLParser::ParseOptionalOperandBundles(
1954 SmallVectorImpl &BundleList, PerFunctionState &PFS) {
1955 LocTy BeginLoc = Lex.getLoc();
1956 if (!EatIfPresent(lltok::lsquare))
1957 return false;
1958
1959 while (Lex.getKind() != lltok::rsquare) {
1960 // If this isn't the first operand bundle, we need a comma.
1961 if (!BundleList.empty() &&
1962 ParseToken(lltok::comma, "expected ',' in input list"))
1963 return true;
1964
1965 std::string Tag;
1966 if (ParseStringConstant(Tag))
1967 return true;
1968
1969 BundleList.emplace_back();
1970 auto &OBI = BundleList.back();
1971
1972 OBI.Tag = std::move(Tag);
1973
1974 if (ParseToken(lltok::lparen, "expected '(' in operand bundle"))
1975 return true;
1976
1977 while (Lex.getKind() != lltok::rparen) {
1978 // If this isn't the first input, we need a comma.
1979 if (!OBI.Inputs.empty() &&
1980 ParseToken(lltok::comma, "expected ',' in input list"))
1981 return true;
1982
1983 Type *Ty = nullptr;
1984 Value *Input = nullptr;
1985 if (ParseType(Ty) || ParseValue(Ty, Input, PFS))
1986 return true;
1987 OBI.Inputs.push_back(Input);
1988 }
1989
1990 Lex.Lex(); // Lex the ')'.
1991 }
1992
1993 if (BundleList.empty())
1994 return Error(BeginLoc, "operand bundle set must not be empty");
1995
1996 Lex.Lex(); // Lex the ']'.
1997 return false;
1998 }
19451999
19462000 /// ParseArgumentList - Parse the argument list for a function type or function
19472001 /// prototype.
49905044 LocTy RetTypeLoc;
49915045 ValID CalleeID;
49925046 SmallVector ArgList;
5047 SmallVector BundleList;
49935048
49945049 BasicBlock *NormalBB, *UnwindBB;
4995 if (ParseOptionalCallingConv(CC) ||
4996 ParseOptionalReturnAttrs(RetAttrs) ||
5050 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
49975051 ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
4998 ParseValID(CalleeID) ||
4999 ParseParameterList(ArgList, PFS) ||
5052 ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) ||
50005053 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps, false,
50015054 NoBuiltinLoc) ||
5055 ParseOptionalOperandBundles(BundleList, PFS) ||
50025056 ParseToken(lltok::kw_to, "expected 'to' in invoke") ||
50035057 ParseTypeAndBasicBlock(NormalBB, PFS) ||
50045058 ParseToken(lltok::kw_unwind, "expected 'unwind' in invoke") ||
50745128 // Finish off the Attribute and check them
50755129 AttributeSet PAL = AttributeSet::get(Context, Attrs);
50765130
5077 InvokeInst *II = InvokeInst::Create(Ty, Callee, NormalBB, UnwindBB, Args);
5131 InvokeInst *II =
5132 InvokeInst::Create(Ty, Callee, NormalBB, UnwindBB, Args, BundleList);
50785133 II->setCallingConv(CC);
50795134 II->setAttributes(PAL);
50805135 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
55885643 LocTy RetTypeLoc;
55895644 ValID CalleeID;
55905645 SmallVector ArgList;
5646 SmallVector BundleList;
55915647 LocTy CallLoc = Lex.getLoc();
55925648
55935649 if ((TCK != CallInst::TCK_None &&
55945650 ParseToken(lltok::kw_call, "expected 'tail call'")) ||
5595 ParseOptionalCallingConv(CC) ||
5596 ParseOptionalReturnAttrs(RetAttrs) ||
5651 ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
55975652 ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
55985653 ParseValID(CalleeID) ||
55995654 ParseParameterList(ArgList, PFS, TCK == CallInst::TCK_MustTail,
56005655 PFS.getFunction().isVarArg()) ||
5601 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps, false,
5602 BuiltinLoc))
5656 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps, false, BuiltinLoc) ||
5657 ParseOptionalOperandBundles(BundleList, PFS))
56035658 return true;
56045659
56055660 // If RetType is a non-function pointer type, then this is the short syntax
56715726 // Finish off the Attribute and check them
56725727 AttributeSet PAL = AttributeSet::get(Context, Attrs);
56735728
5674 CallInst *CI = CallInst::Create(Ty, Callee, Args);
5729 CallInst *CI = CallInst::Create(Ty, Callee, Args, BundleList);
56755730 CI->setTailCallKind(TCK);
56765731 CI->setCallingConv(CC);
56775732 CI->setAttributes(PAL);
404404 PerFunctionState &PFS,
405405 bool IsMustTailCall = false,
406406 bool InVarArgsFunc = false);
407
408 bool
409 ParseOptionalOperandBundles(SmallVectorImpl &BundleList,
410 PerFunctionState &PFS);
407411
408412 bool ParseExceptionArgs(SmallVectorImpl &Args,
409413 PerFunctionState &PFS);
225225
226226 bool StripDebugInfo = false;
227227
228 std::vector BundleTags;
229
228230 public:
229231 std::error_code error(BitcodeError E, const Twine &Message);
230232 std::error_code error(BitcodeError E);
369371 std::error_code parseAttributeGroupBlock();
370372 std::error_code parseTypeTable();
371373 std::error_code parseTypeTableBody();
374 std::error_code parseOperandBundleTags();
372375
373376 ErrorOr recordValue(SmallVectorImpl &Record,
374377 unsigned NameIndex, Triple &TT);
15851588 }
15861589 }
15871590
1591 std::error_code BitcodeReader::parseOperandBundleTags() {
1592 if (Stream.EnterSubBlock(bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID))
1593 return error("Invalid record");
1594
1595 if (!BundleTags.empty())
1596 return error("Invalid multiple blocks");
1597
1598 SmallVector Record;
1599
1600 while (1) {
1601 BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
1602
1603 switch (Entry.Kind) {
1604 case BitstreamEntry::SubBlock: // Handled for us already.
1605 case BitstreamEntry::Error:
1606 return error("Malformed block");
1607 case BitstreamEntry::EndBlock:
1608 return std::error_code();
1609 case BitstreamEntry::Record:
1610 // The interesting case.
1611 break;
1612 }
1613
1614 // Tags are implicitly mapped to integers by their order.
1615
1616 if (Stream.readRecord(Entry.ID, Record) != bitc::OPERAND_BUNDLE_TAG)
1617 return error("Invalid record");
1618
1619 // OPERAND_BUNDLE_TAG: [strchr x N]
1620 BundleTags.emplace_back();
1621 if (convertToString(Record, 0, BundleTags.back()))
1622 return error("Invalid record");
1623 Record.clear();
1624 }
1625 }
1626
15881627 /// Associate a value with its name from the given index in the provided record.
15891628 ErrorOr BitcodeReader::recordValue(SmallVectorImpl &Record,
15901629 unsigned NameIndex, Triple &TT) {
30183057 if (std::error_code EC = parseUseLists())
30193058 return EC;
30203059 break;
3060 case bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID:
3061 if (std::error_code EC = parseOperandBundleTags())
3062 return EC;
3063 break;
30213064 }
30223065 continue;
30233066
35543597 return &FunctionBBs[CurBBNo - 1]->back();
35553598 return nullptr;
35563599 };
3600
3601 std::vector OperandBundles;
35573602
35583603 // Read all the records.
35593604 SmallVector Record;
43244369 }
43254370 }
43264371
4327 I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops);
4372 I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops, OperandBundles);
4373 OperandBundles.clear();
43284374 InstructionList.push_back(I);
43294375 cast(I)
43304376 ->setCallingConv(static_cast(~(1U << 13) & CCInfo));
47074753 }
47084754 }
47094755
4710 I = CallInst::Create(FTy, Callee, Args);
4756 I = CallInst::Create(FTy, Callee, Args, OperandBundles);
4757 OperandBundles.clear();
47114758 InstructionList.push_back(I);
47124759 cast(I)->setCallingConv(
47134760 static_cast((~(1U << 14) & CCInfo) >> 1));
47324779 InstructionList.push_back(I);
47334780 break;
47344781 }
4782
4783 case bitc::FUNC_CODE_OPERAND_BUNDLE: {
4784 // A call or an invoke can be optionally prefixed with some variable
4785 // number of operand bundle blocks. These blocks are read into
4786 // OperandBundles and consumed at the next call or invoke instruction.
4787
4788 if (Record.size() < 1 || Record[0] >= BundleTags.size())
4789 return error("Invalid record");
4790
4791 OperandBundles.emplace_back();
4792 OperandBundles.back().Tag = BundleTags[Record[0]];
4793
4794 std::vector &Inputs = OperandBundles.back().Inputs;
4795
4796 unsigned OpNum = 1;
4797 while (OpNum != Record.size()) {
4798 Value *Op;
4799 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4800 return error("Invalid record");
4801 Inputs.push_back(Op);
4802 }
4803
4804 continue;
4805 }
47354806 }
47364807
47374808 // Add instruction to end of current BB. If there is no current BB, reject
47404811 delete I;
47414812 return error("Invalid instruction with no BB");
47424813 }
4814 if (!OperandBundles.empty()) {
4815 delete I;
4816 return error("Operand bundles found with no consumer");
4817 }
47434818 CurBB->getInstList().push_back(I);
47444819
47454820 // If this was a terminator instruction, move to the next block.
47554830 }
47564831
47574832 OutOfRecordLoop:
4833
4834 if (!OperandBundles.empty())
4835 return error("Operand bundles found with no consumer");
47584836
47594837 // Check the function list for unresolved values.
47604838 if (Argument *A = dyn_cast(ValueList.back())) {
1515 #include "llvm/ADT/Triple.h"
1616 #include "llvm/Bitcode/BitstreamWriter.h"
1717 #include "llvm/Bitcode/LLVMBitCodes.h"
18 #include "llvm/IR/CallSite.h"
1819 #include "llvm/IR/Constants.h"
1920 #include "llvm/IR/DebugInfoMetadata.h"
2021 #include "llvm/IR/DerivedTypes.h"
2122 #include "llvm/IR/InlineAsm.h"
2223 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/LLVMContext.h"
2325 #include "llvm/IR/Module.h"
2426 #include "llvm/IR/Operator.h"
2527 #include "llvm/IR/UseListOrder.h"
13851387 Record.append(KName.begin(), KName.end());
13861388
13871389 Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
1390 Record.clear();
1391 }
1392
1393 Stream.ExitBlock();
1394 }
1395
1396 static void WriteOperandBundleTags(const Module *M, BitstreamWriter &Stream) {
1397 // Write metadata kinds
1398 //
1399 // OPERAND_BUNDLE_TAGS_BLOCK_ID : N x OPERAND_BUNDLE_TAG
1400 //
1401 // OPERAND_BUNDLE_TAG - [strchr x N]
1402
1403 SmallVector Tags;
1404 M->getOperandBundleTags(Tags);
1405
1406 if (Tags.empty())
1407 return;
1408
1409 Stream.EnterSubblock(bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID, 3);
1410
1411 SmallVector Record;
1412
1413 for (auto Tag : Tags) {
1414 Record.append(Tag.begin(), Tag.end());
1415
1416 Stream.EmitRecord(bitc::OPERAND_BUNDLE_TAG, Record, 0);
13881417 Record.clear();
13891418 }
13901419
16991728 return false;
17001729 }
17011730
1731 static void WriteOperandBundles(BitstreamWriter &Stream, ImmutableCallSite CS,
1732 unsigned InstID, ValueEnumerator &VE) {
1733 SmallVector Record;
1734 LLVMContext &C = CS.getInstruction()->getContext();
1735
1736 for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) {
1737 const auto &Bundle = CS.getOperandBundle(i);
1738 Record.push_back(C.getOperandBundleTagID(Bundle.Tag));
1739
1740 for (auto &Input : Bundle.Inputs)
1741 PushValueAndType(Input, InstID, Record, VE);
1742
1743 Stream.EmitRecord(bitc::FUNC_CODE_OPERAND_BUNDLE, Record);
1744 Record.clear();
1745 }
1746 }
1747
17021748 /// pushValue - Like PushValueAndType, but where the type of the value is
17031749 /// omitted (perhaps it was already encoded in an earlier operand).
17041750 static void pushValue(const Value *V, unsigned InstID,
18611907 const InvokeInst *II = cast(&I);
18621908 const Value *Callee = II->getCalledValue();
18631909 FunctionType *FTy = II->getFunctionType();
1910
1911 if (II->hasOperandBundles())
1912 WriteOperandBundles(Stream, II, InstID, VE);
1913
18641914 Code = bitc::FUNC_CODE_INST_INVOKE;
18651915
18661916 Vals.push_back(VE.getAttributeID(II->getAttributes()));
20702120 const CallInst &CI = cast(I);
20712121 FunctionType *FTy = CI.getFunctionType();
20722122
2123 if (CI.hasOperandBundles())
2124 WriteOperandBundles(Stream, &CI, InstID, VE);
2125
20732126 Code = bitc::FUNC_CODE_INST_CALL;
20742127
20752128 Vals.push_back(VE.getAttributeID(CI.getAttributes()));
25892642 // Emit module-level use-lists.
25902643 if (VE.shouldPreserveUseListOrder())
25912644 WriteUseListBlock(nullptr, VE, Stream);
2645
2646 WriteOperandBundleTags(M, Stream);
25922647
25932648 // Emit function bodies.
25942649 DenseMap FunctionIndex;
20212021
20222022 void writeOperand(const Value *Op, bool PrintType);
20232023 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
2024 void writeOperandBundles(ImmutableCallSite CS);
20242025 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
20252026 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
20262027 AtomicOrdering FailureOrdering,
21542155 Out << ' ';
21552156 // Print the operand
21562157 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
2158 }
2159
2160 void AssemblyWriter::writeOperandBundles(ImmutableCallSite CS) {
2161 if (!CS.hasOperandBundles())
2162 return;
2163
2164 Out << " [ ";
2165
2166 bool FirstBundle = true;
2167 for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) {
2168 OperandBundleUse BU = CS.getOperandBundle(i);
2169
2170 if (!FirstBundle)
2171 Out << ", ";
2172 FirstBundle = false;
2173
2174 Out << '"';
2175 PrintEscapedString(BU.Tag, Out);
2176 Out << '"';
2177
2178 Out << '(';
2179
2180 bool FirstInput = true;
2181 for (const auto &Input : BU.Inputs) {
2182 if (!FirstInput)
2183 Out << ", ";
2184 FirstInput = false;
2185
2186 TypePrinter.print(Input->getType(), Out);
2187 Out << " ";
2188 WriteAsOperandInternal(Out, Input, &TypePrinter, &Machine, TheModule);
2189 }
2190
2191 Out << ')';
2192 }
2193
2194 Out << " ]";
21572195 }
21582196
21592197 void AssemblyWriter::printModule(const Module *M) {
29432981 Out << ')';
29442982 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
29452983 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
2984
2985 writeOperandBundles(CI);
2986
29462987 } else if (const InvokeInst *II = dyn_cast(&I)) {
29472988 Operand = II->getCalledValue();
29482989 FunctionType *FTy = cast(II->getFunctionType());
29763017 Out << ')';
29773018 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
29783019 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
3020
3021 writeOperandBundles(II);
29793022
29803023 Out << "\n to ";
29813024 writeOperand(II->getNormalDest(), true);
55 ; http://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility
66
77 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
8 ; RUN: verify-uselistorder < %s
8 ; RUN-PR24755: verify-uselistorder < %s
99
1010 target datalayout = "E"
1111 ; CHECK: target datalayout = "E"
13121312 ret void
13131313 }
13141314
1315 declare void @op_bundle_callee_0()
1316 declare void @op_bundle_callee_1(i32,i32)
1317
1318 define void @call_with_operand_bundle0(i32* %ptr) {
1319 ; CHECK-LABEL: call_with_operand_bundle0(
1320 entry:
1321 %l = load i32, i32* %ptr
1322 %x = add i32 42, 1
1323 call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
1324 ; CHECK: call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
1325 ret void
1326 }
1327
1328 define void @call_with_operand_bundle1(i32* %ptr) {
1329 ; CHECK-LABEL: call_with_operand_bundle1(
1330 entry:
1331 %l = load i32, i32* %ptr
1332 %x = add i32 42, 1
1333
1334 call void @op_bundle_callee_0()
1335 call void @op_bundle_callee_0() [ "foo"() ]
1336 call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
1337 ; CHECK: @op_bundle_callee_0(){{$}}
1338 ; CHECK-NEXT: call void @op_bundle_callee_0() [ "foo"() ]
1339 ; CHECK-NEXT: call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
1340 ret void
1341 }
1342
1343 define void @call_with_operand_bundle2(i32* %ptr) {
1344 ; CHECK-LABEL: call_with_operand_bundle2(
1345 entry:
1346 call void @op_bundle_callee_0() [ "foo"() ]
1347 ; CHECK: call void @op_bundle_callee_0() [ "foo"() ]
1348 ret void
1349 }
1350
1351 define void @call_with_operand_bundle3(i32* %ptr) {
1352 ; CHECK-LABEL: call_with_operand_bundle3(
1353 entry:
1354 %l = load i32, i32* %ptr
1355 %x = add i32 42, 1
1356 call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1357 ; CHECK: call void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1358 ret void
1359 }
1360
1361 define void @call_with_operand_bundle4(i32* %ptr) {
1362 ; CHECK-LABEL: call_with_operand_bundle4(
1363 entry:
1364 %l = load i32, i32* %ptr
1365 %x = add i32 42, 1
1366 call void @op_bundle_callee_1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1367 ; CHECK: call void @op_bundle_callee_1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1368 ret void
1369 }
1370
1371 ; Invoke versions of the above tests:
1372
1373
1374 define void @invoke_with_operand_bundle0(i32* %ptr) personality i8 3 {
1375 ; CHECK-LABEL: @invoke_with_operand_bundle0(
1376 entry:
1377 %l = load i32, i32* %ptr
1378 %x = add i32 42, 1
1379 invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ] to label %normal unwind label %exception
1380 ; CHECK: invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
1381
1382 exception:
1383 %cleanup = landingpad i8 cleanup
1384 br label %normal
1385 normal:
1386 ret void
1387 }
1388
1389 define void @invoke_with_operand_bundle1(i32* %ptr) personality i8 3 {
1390 ; CHECK-LABEL: @invoke_with_operand_bundle1(
1391 entry:
1392 %l = load i32, i32* %ptr
1393 %x = add i32 42, 1
1394
1395 invoke void @op_bundle_callee_0() to label %normal unwind label %exception
1396 ; CHECK: invoke void @op_bundle_callee_0(){{$}}
1397
1398 exception:
1399 %cleanup = landingpad i8 cleanup
1400 br label %normal
1401
1402 normal:
1403 invoke void @op_bundle_callee_0() [ "foo"() ] to label %normal1 unwind label %exception1
1404 ; CHECK: invoke void @op_bundle_callee_0() [ "foo"() ]
1405
1406 exception1:
1407 %cleanup1 = landingpad i8 cleanup
1408 br label %normal1
1409
1410 normal1:
1411 invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ] to label %normal2 unwind label %exception2
1412 ; CHECK: invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1413
1414 exception2:
1415 %cleanup2 = landingpad i8 cleanup
1416 br label %normal2
1417
1418 normal2:
1419 ret void
1420 }
1421
1422 define void @invoke_with_operand_bundle2(i32* %ptr) personality i8 3 {
1423 ; CHECK-LABEL: @invoke_with_operand_bundle2(
1424 entry:
1425 invoke void @op_bundle_callee_0() [ "foo"() ] to label %normal unwind label %exception
1426 ; CHECK: invoke void @op_bundle_callee_0() [ "foo"() ]
1427
1428 exception:
1429 %cleanup = landingpad i8 cleanup
1430 br label %normal
1431 normal:
1432 ret void
1433 }
1434
1435 define void @invoke_with_operand_bundle3(i32* %ptr) personality i8 3 {
1436 ; CHECK-LABEL: @invoke_with_operand_bundle3(
1437 entry:
1438 %l = load i32, i32* %ptr
1439 %x = add i32 42, 1
1440 invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ] to label %normal unwind label %exception
1441 ; CHECK: invoke void @op_bundle_callee_0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1442
1443 exception:
1444 %cleanup = landingpad i8 cleanup
1445 br label %normal
1446 normal:
1447 ret void
1448 }
1449
1450 define void @invoke_with_operand_bundle4(i32* %ptr) personality i8 3 {
1451 ; CHECK-LABEL: @invoke_with_operand_bundle4(
1452 entry:
1453 %l = load i32, i32* %ptr
1454 %x = add i32 42, 1
1455 invoke void @op_bundle_callee_1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1456 to label %normal unwind label %exception
1457 ; CHECK: invoke void @op_bundle_callee_1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
1458
1459 exception:
1460 %cleanup = landingpad i8 cleanup
1461 br label %normal
1462 normal:
1463 ret void
1464 }
1465
1466
13151467 ; CHECK: attributes #0 = { alignstack=4 }
13161468 ; CHECK: attributes #1 = { alignstack=8 }
13171469 ; CHECK: attributes #2 = { alwaysinline }
0 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
1
2 declare void @callee0()
3 declare void @callee1(i32,i32)
4
5 define void @f0(i32* %ptr) {
6 ; CHECK-LABEL: @f0(
7 entry:
8 %l = load i32, i32* %ptr
9 %x = add i32 42, 1
10 call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
11 ; CHECK: call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
12 ret void
13 }
14
15 define void @f1(i32* %ptr) {
16 ; CHECK-LABEL: @f1(
17 entry:
18 %l = load i32, i32* %ptr
19 %x = add i32 42, 1
20
21 call void @callee0()
22 call void @callee0() [ "foo"() ]
23 call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
24 ; CHECK: @callee0(){{$}}
25 ; CHECK-NEXT: call void @callee0() [ "foo"() ]
26 ; CHECK-NEXT: call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
27 ret void
28 }
29
30 define void @f2(i32* %ptr) {
31 ; CHECK-LABEL: @f2(
32 entry:
33 call void @callee0() [ "foo"() ]
34 ; CHECK: call void @callee0() [ "foo"() ]
35 ret void
36 }
37
38 define void @f3(i32* %ptr) {
39 ; CHECK-LABEL: @f3(
40 entry:
41 %l = load i32, i32* %ptr
42 %x = add i32 42, 1
43 call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
44 ; CHECK: call void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
45 ret void
46 }
47
48 define void @f4(i32* %ptr) {
49 ; CHECK-LABEL: @f4(
50 entry:
51 %l = load i32, i32* %ptr
52 %x = add i32 42, 1
53 call void @callee1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
54 ; CHECK: call void @callee1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
55 ret void
56 }
57
58 ; Invoke versions of the above tests:
59
60
61 define void @g0(i32* %ptr) personality i8 3 {
62 ; CHECK-LABEL: @g0(
63 entry:
64 %l = load i32, i32* %ptr
65 %x = add i32 42, 1
66 invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ] to label %normal unwind label %exception
67 ; CHECK: invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
68
69 exception:
70 %cleanup = landingpad i8 cleanup
71 br label %normal
72 normal:
73 ret void
74 }
75
76 define void @g1(i32* %ptr) personality i8 3 {
77 ; CHECK-LABEL: @g1(
78 entry:
79 %l = load i32, i32* %ptr
80 %x = add i32 42, 1
81
82 invoke void @callee0() to label %normal unwind label %exception
83 ; CHECK: invoke void @callee0(){{$}}
84
85 exception:
86 %cleanup = landingpad i8 cleanup
87 br label %normal
88
89 normal:
90 invoke void @callee0() [ "foo"() ] to label %normal1 unwind label %exception1
91 ; CHECK: invoke void @callee0() [ "foo"() ]
92
93 exception1:
94 %cleanup1 = landingpad i8 cleanup
95 br label %normal1
96
97 normal1:
98 invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ] to label %normal2 unwind label %exception2
99 ; CHECK: invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
100
101 exception2:
102 %cleanup2 = landingpad i8 cleanup
103 br label %normal2
104
105 normal2:
106 ret void
107 }
108
109 define void @g2(i32* %ptr) personality i8 3 {
110 ; CHECK-LABEL: @g2(
111 entry:
112 invoke void @callee0() [ "foo"() ] to label %normal unwind label %exception
113 ; CHECK: invoke void @callee0() [ "foo"() ]
114
115 exception:
116 %cleanup = landingpad i8 cleanup
117 br label %normal
118 normal:
119 ret void
120 }
121
122 define void @g3(i32* %ptr) personality i8 3 {
123 ; CHECK-LABEL: @g3(
124 entry:
125 %l = load i32, i32* %ptr
126 %x = add i32 42, 1
127 invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ] to label %normal unwind label %exception
128 ; CHECK: invoke void @callee0() [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
129
130 exception:
131 %cleanup = landingpad i8 cleanup
132 br label %normal
133 normal:
134 ret void
135 }
136
137 define void @g4(i32* %ptr) personality i8 3 {
138 ; CHECK-LABEL: @g4(
139 entry:
140 %l = load i32, i32* %ptr
141 %x = add i32 42, 1
142 invoke void @callee1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
143 to label %normal unwind label %exception
144 ; CHECK: invoke void @callee1(i32 10, i32 %x) [ "foo"(i32 42, i64 100, i32 %x), "foo"(i32 42, float 0.000000e+00, i32 %l) ]
145
146 exception:
147 %cleanup = landingpad i8 cleanup
148 br label %normal
149 normal:
150 ret void
151 }
0 ; RUN: not opt -verify < %s 2>&1 | FileCheck %s
1
2 ; Operand bundles uses are like regular uses, and need to be dominated
3 ; by their defs.
4
5 declare void @g()
6
7 define void @f0(i32* %ptr) {
8 ; CHECK: Instruction does not dominate all uses!
9 ; CHECK-NEXT: %x = add i32 42, 1
10 ; CHECK-NEXT: call void @g() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
11
12 entry:
13 %l = load i32, i32* %ptr
14 call void @g() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.0, i64 100, i32 %l) ]
15 %x = add i32 42, 1
16 ret void
17 }
18
19 define void @f1(i32* %ptr) personality i8 3 {
20 ; CHECK: Instruction does not dominate all uses!
21 ; CHECK-NEXT: %x = add i32 42, 1
22 ; CHECK-NEXT: invoke void @g() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.000000e+00, i64 100, i32 %l) ]
23
24 entry:
25 %l = load i32, i32* %ptr
26 invoke void @g() [ "foo"(i32 42, i64 100, i32 %x), "bar"(float 0.0, i64 100, i32 %l) ] to label %normal unwind label %exception
27
28 exception:
29 %cleanup = landingpad i8 cleanup
30 br label %normal
31
32 normal:
33 %x = add i32 42, 1
34 ret void
35 }