Skip to content

Commit eddd5be

Browse files
committed
[BitCode] Autoupgrade inline asm elementtype attribute
This is the autoupgrade part of D116531. If old bitcode is missing the elementtype attribute for indirect inline asm constraints, automatically add it. As usual, this only works when upgrading in typed mode, we haven't figured out upgrade in opaque mode yet.
1 parent 2c4a56c commit eddd5be

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,6 +3923,25 @@ void BitcodeReader::propagateAttributeTypes(CallBase *CB,
39233923
}
39243924
}
39253925

3926+
if (CB->isInlineAsm()) {
3927+
const InlineAsm *IA = cast<InlineAsm>(CB->getCalledOperand());
3928+
unsigned ArgNo = 0;
3929+
for (const InlineAsm::ConstraintInfo &CI : IA->ParseConstraints()) {
3930+
bool HasArg = CI.Type == InlineAsm::isInput ||
3931+
(CI.Type == InlineAsm::isOutput && CI.isIndirect);
3932+
if (!HasArg)
3933+
continue;
3934+
3935+
if (CI.isIndirect && !CB->getAttributes().getParamElementType(ArgNo)) {
3936+
Type *ElemTy = ArgsTys[ArgNo]->getPointerElementType();
3937+
CB->addParamAttr(
3938+
ArgNo, Attribute::get(Context, Attribute::ElementType, ElemTy));
3939+
}
3940+
3941+
ArgNo++;
3942+
}
3943+
}
3944+
39263945
switch (CB->getIntrinsicID()) {
39273946
case Intrinsic::preserve_array_access_index:
39283947
case Intrinsic::preserve_struct_access_index:
@@ -4826,15 +4845,18 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48264845
return error("Insufficient operands to call");
48274846

48284847
SmallVector<Value*, 16> Args;
4848+
SmallVector<Type *, 16> ArgsTys;
48294849
// Read the fixed params.
48304850
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
4851+
Value *Arg;
48314852
if (FTy->getParamType(i)->isLabelTy())
4832-
Args.push_back(getBasicBlock(Record[OpNum]));
4853+
Arg = getBasicBlock(Record[OpNum]);
48334854
else
4834-
Args.push_back(getValue(Record, OpNum, NextValueNo,
4835-
FTy->getParamType(i)));
4836-
if (!Args.back())
4855+
Arg = getValue(Record, OpNum, NextValueNo, FTy->getParamType(i));
4856+
if (!Arg)
48374857
return error("Invalid record");
4858+
Args.push_back(Arg);
4859+
ArgsTys.push_back(Arg->getType());
48384860
}
48394861

48404862
// Read type/value pairs for varargs params.
@@ -4847,6 +4869,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48474869
if (getValueTypePair(Record, OpNum, NextValueNo, Op))
48484870
return error("Invalid record");
48494871
Args.push_back(Op);
4872+
ArgsTys.push_back(Op->getType());
48504873
}
48514874
}
48524875

@@ -4857,6 +4880,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48574880
cast<CallBrInst>(I)->setCallingConv(
48584881
static_cast<CallingConv::ID>((0x7ff & CCInfo) >> bitc::CALL_CCONV));
48594882
cast<CallBrInst>(I)->setAttributes(PAL);
4883+
propagateAttributeTypes(cast<CallBase>(I), ArgsTys);
48604884
break;
48614885
}
48624886
case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llvm-dis < %s.bc | FileCheck %s
2+
3+
; CHECK: call void asm "", "=*rm,r"(i32* elementtype(i32) %p1, i32* %p2)
4+
define void @test_call(i32* %p1, i32* %p2) {
5+
call void asm "", "=*rm,r"(i32* %p1, i32* %p2)
6+
ret void
7+
}
8+
9+
; CHECK: invoke void asm "", "=*rm,r"(i32* elementtype(i32) %p1, i32* %p2)
10+
define void @test_invoke(i32* %p1, i32* %p2) personality i8* null {
11+
invoke void asm "", "=*rm,r"(i32* %p1, i32* %p2)
12+
to label %cont unwind label %lpad
13+
14+
lpad:
15+
%lp = landingpad i32
16+
cleanup
17+
ret void
18+
19+
cont:
20+
ret void
21+
}
22+
23+
; CHECK: callbr void asm "", "=*rm,r"(i32* elementtype(i32) %p1, i32* %p2)
24+
define void @test_callbr(i32* %p1, i32* %p2) {
25+
callbr void asm "", "=*rm,r"(i32* %p1, i32* %p2)
26+
to label %cont []
27+
28+
cont:
29+
ret void
30+
}
Binary file not shown.

0 commit comments

Comments
 (0)