Skip to content

Commit 0fea027

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6-beta.1
2 parents c2f0af5 + de7d14c commit 0fea027

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+903
-85
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ Convert a pointer to an integer.
169169
170170
%1:_(s32) = G_PTRTOINT %0:_(p0)
171171
172+
G_PTRTOADDR
173+
^^^^^^^^^^^
174+
175+
Extract the address part of a pointer to an integer.
176+
177+
.. code-block:: none
178+
179+
%1:_(s32) = G_PTRTOADDR %0:_(p0)
180+
172181
G_BITCAST
173182
^^^^^^^^^
174183

llvm/docs/LangRef.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12466,6 +12466,61 @@ Example:
1246612466
%Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
1246712467
%Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
1246812468

12469+
.. _i_ptrtoaddr:
12470+
12471+
'``ptrtoaddr .. to``' Instruction
12472+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12473+
12474+
Syntax:
12475+
"""""""
12476+
12477+
::
12478+
12479+
<result> = ptrtoaddr <ty> <value> to <ty2> ; yields ty2
12480+
12481+
Overview:
12482+
"""""""""
12483+
12484+
The '``ptrtoaddr``' instruction converts the pointer or a vector of
12485+
pointers ``value`` to the underlying integer address (or vector of integers) of
12486+
type ``ty2``. This is different from :ref:`ptrtoint <i_ptrtoint>` in that it
12487+
only operates on the index bits of the pointer and ignores all other bits.
12488+
12489+
Arguments:
12490+
""""""""""
12491+
12492+
The '``ptrtoaddr``' instruction takes a ``value`` to cast, which must be
12493+
a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
12494+
type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
12495+
a vector of integers type.
12496+
12497+
Semantics:
12498+
""""""""""
12499+
12500+
The '``ptrtoaddr``' instruction converts ``value`` to integer type
12501+
``ty2`` by interpreting the lowest index-width pointer representation bits as an
12502+
integer and either truncating or zero extending that value to the size of the
12503+
integer type.
12504+
If the address of ``value`` is smaller than ``ty2`` then a zero extension is
12505+
done. If the address of ``value`` is larger than ``ty2`` then a truncation is
12506+
done. If the address size and the pointer representation size are the same and
12507+
``value`` and ``ty2`` are the same size, then nothing is done (*no-op cast*)
12508+
other than a type change.
12509+
12510+
The ``ptrtoaddr`` always :ref:`captures the address (but not provenance) <pointercapture>`
12511+
of the pointer argument.
12512+
12513+
Example:
12514+
""""""""
12515+
This example assumes pointers in address space 1 are 64 bits in size with an
12516+
address width of 32 bits (``p1:64:64:64:32`` :ref:`datalayout string<langref_datalayout>`)
12517+
.. code-block:: llvm
12518+
12519+
%X = ptrtoaddr ptr addrspace(1) %P to i8 ; extracts low 32 bits and truncates
12520+
%Y = ptrtoaddr ptr addrspace(1) %P to i64 ; extracts low 32 bits and zero extends
12521+
%Z = ptrtoaddr <4 x ptr addrspace(1)> %P to <4 x i64>; yields vector zero extension of low 32 bits for each pointer
12522+
12523+
1246912524
.. _i_inttoptr:
1247012525

1247112526
'``inttoptr .. to``' Instruction

llvm/include/llvm-c/Core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef enum {
110110
LLVMFPTrunc = 37,
111111
LLVMFPExt = 38,
112112
LLVMPtrToInt = 39,
113+
LLVMPtrToAddr = 69,
113114
LLVMIntToPtr = 40,
114115
LLVMBitCast = 41,
115116
LLVMAddrSpaceCast = 60,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@ class TargetTransformInfoImplBase {
732732
return 0;
733733
break;
734734
}
735+
case Instruction::PtrToAddr: {
736+
unsigned DstSize = Dst->getScalarSizeInBits();
737+
if (DL.isLegalInteger(DstSize) && DstSize >= DL.getAddressSizeInBits(Src))
738+
return 0;
739+
break;
740+
}
735741
case Instruction::PtrToInt: {
736742
unsigned DstSize = Dst->getScalarSizeInBits();
737743
if (DL.isLegalInteger(DstSize) &&
@@ -1438,6 +1444,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
14381444
Op2Info, Operands, I);
14391445
}
14401446
case Instruction::IntToPtr:
1447+
case Instruction::PtrToAddr:
14411448
case Instruction::PtrToInt:
14421449
case Instruction::SIToFP:
14431450
case Instruction::UIToFP:

llvm/include/llvm/AsmParser/LLToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ enum Kind {
318318
kw_fptoui,
319319
kw_fptosi,
320320
kw_inttoptr,
321+
kw_ptrtoaddr,
321322
kw_ptrtoint,
322323
kw_bitcast,
323324
kw_addrspacecast,

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ enum CastOpcodes {
456456
CAST_PTRTOINT = 9,
457457
CAST_INTTOPTR = 10,
458458
CAST_BITCAST = 11,
459-
CAST_ADDRSPACECAST = 12
459+
CAST_ADDRSPACECAST = 12,
460+
CAST_PTRTOADDR = 13,
460461
};
461462

462463
/// UnaryOpcodes - These are values used in the bitcode files to encode which

llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ class GCastOp : public GenericMachineInstr {
870870
case TargetOpcode::G_FPTOUI_SAT:
871871
case TargetOpcode::G_FPTRUNC:
872872
case TargetOpcode::G_INTTOPTR:
873+
case TargetOpcode::G_PTRTOADDR:
873874
case TargetOpcode::G_PTRTOINT:
874875
case TargetOpcode::G_SEXT:
875876
case TargetOpcode::G_SITOFP:

llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ class IRTranslator : public MachineFunctionPass {
486486
bool translatePtrToInt(const User &U, MachineIRBuilder &MIRBuilder) {
487487
return translateCast(TargetOpcode::G_PTRTOINT, U, MIRBuilder);
488488
}
489+
bool translatePtrToAddr(const User &U, MachineIRBuilder &MIRBuilder) {
490+
return translateCast(TargetOpcode::G_PTRTOADDR, U, MIRBuilder);
491+
}
489492
bool translateTrunc(const User &U, MachineIRBuilder &MIRBuilder) {
490493
return translateCast(TargetOpcode::G_TRUNC, U, MIRBuilder);
491494
}

llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ class LegalizerHelper {
429429
LLVM_ABI LegalizeResult lowerFunnelShift(MachineInstr &MI);
430430
LLVM_ABI LegalizeResult lowerEXT(MachineInstr &MI);
431431
LLVM_ABI LegalizeResult lowerTRUNC(MachineInstr &MI);
432+
LLVM_ABI LegalizeResult lowerPTRTOADDR(MachineInstr &MI);
432433
LLVM_ABI LegalizeResult lowerRotateWithReverseRotate(MachineInstr &MI);
433434
LLVM_ABI LegalizeResult lowerRotate(MachineInstr &MI);
434435

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ class LLVM_ABI MachineIRBuilder {
715715
return buildInstr(TargetOpcode::G_PTRTOINT, {Dst}, {Src});
716716
}
717717

718+
/// Build and insert a G_PTRTOADDR instruction.
719+
MachineInstrBuilder buildPtrToAddr(const DstOp &Dst, const SrcOp &Src) {
720+
return buildInstr(TargetOpcode::G_PTRTOADDR, {Dst}, {Src});
721+
}
722+
718723
/// Build and insert a G_INTTOPTR instruction.
719724
MachineInstrBuilder buildIntToPtr(const DstOp &Dst, const SrcOp &Src) {
720725
return buildInstr(TargetOpcode::G_INTTOPTR, {Dst}, {Src});

0 commit comments

Comments
 (0)