Skip to content

Commit 5548e80

Browse files
committed
[IR] Remove support for extractvalue constant expression
This removes the extractvalue constant expression, as part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. extractvalue is already not supported in bitcode, so we do not need to worry about bitcode auto-upgrade. Uses of ConstantExpr::getExtractValue() should be replaced with IRBuilder::CreateExtractValue() (if the fact that the result is constant is not important) or ConstantFoldExtractValueInstruction() (if it is). Though for this particular case, it is also possible and usually preferable to use getAggregateElement() instead. The C API function LLVMConstExtractValue() is removed, as the underlying constant expression no longer exists. Instead, LLVMBuildExtractValue() should be used (which will constant fold or create an instruction). Depending on the use-case, LLVMGetAggregateElement() may also be used instead. Differential Revision: https://reviews.llvm.org/D125795
1 parent ab72182 commit 5548e80

File tree

26 files changed

+61
-179
lines changed

26 files changed

+61
-179
lines changed

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ ItaniumCXXABI::EmitMemberPointerConversion(const CastExpr *E,
955955
adj = llvm::ConstantInt::get(adj->getType(), offset);
956956
}
957957

958-
llvm::Constant *srcAdj = llvm::ConstantExpr::getExtractValue(src, 1);
958+
llvm::Constant *srcAdj = src->getAggregateElement(1);
959959
llvm::Constant *dstAdj;
960960
if (isDerivedToBase)
961961
dstAdj = llvm::ConstantExpr::getNSWSub(srcAdj, adj);

llvm/bindings/go/llvm/ir.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -993,20 +993,6 @@ func ConstShuffleVector(veca, vecb, mask Value) (rv Value) {
993993
return
994994
}
995995

996-
//TODO
997-
//LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
998-
// unsigned NumIdx);
999-
1000-
func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
1001-
n := len(indices)
1002-
if n == 0 {
1003-
panic("one or more indices are required")
1004-
}
1005-
ptr := (*C.unsigned)(&indices[0])
1006-
rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
1007-
return
1008-
}
1009-
1010996
func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {
1011997
n := len(indices)
1012998
if n == 0 {

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,6 @@ external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
704704
= "LLVMConstInsertElement"
705705
external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
706706
= "LLVMConstShuffleVector"
707-
external const_extractvalue : llvalue -> int array -> llvalue
708-
= "llvm_const_extractvalue"
709707
external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
710708
= "llvm_const_insertvalue"
711709
external const_inline_asm : lltype -> string -> string -> bool -> bool ->

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,11 +1347,6 @@ val const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
13471347
See the method [llvm::ConstantExpr::getShuffleVector]. *)
13481348
val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
13491349

1350-
(** [const_extractvalue agg idxs] returns the constant [idxs]th value of
1351-
constant aggregate [agg]. Each [idxs] must be less than the size of the
1352-
aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *)
1353-
val const_extractvalue : llvalue -> int array -> llvalue
1354-
13551350
(** [const_insertvalue agg val idxs] inserts the value [val] in the specified
13561351
indexs [idxs] in the aggregate [agg]. Each [idxs] must be less than the size
13571352
of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,22 +1013,6 @@ LLVMValueRef llvm_const_intcast(LLVMValueRef CV, LLVMTypeRef T,
10131013
return LLVMConstIntCast(CV, T, Bool_val(IsSigned));
10141014
}
10151015

1016-
/* llvalue -> int array -> llvalue */
1017-
LLVMValueRef llvm_const_extractvalue(LLVMValueRef Aggregate, value Indices) {
1018-
int size = Wosize_val(Indices);
1019-
int i;
1020-
LLVMValueRef result;
1021-
1022-
unsigned *idxs = (unsigned *)malloc(size * sizeof(unsigned));
1023-
for (i = 0; i < size; i++) {
1024-
idxs[i] = Int_val(Field(Indices, i));
1025-
}
1026-
1027-
result = LLVMConstExtractValue(Aggregate, idxs, size);
1028-
free(idxs);
1029-
return result;
1030-
}
1031-
10321016
/* llvalue -> llvalue -> int array -> llvalue */
10331017
LLVMValueRef llvm_const_insertvalue(LLVMValueRef Aggregate, LLVMValueRef Val,
10341018
value Indices) {

llvm/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Changes to the LLVM IR
6868

6969
* Renamed ``llvm.experimental.vector.extract`` intrinsic to ``llvm.vector.extract``.
7070
* Renamed ``llvm.experimental.vector.insert`` intrinsic to ``llvm.vector.insert``.
71+
* The constant expression variants of the following instructions have been
72+
removed:
73+
* ``extractvalue``
7174

7275
Changes to building LLVM
7376
------------------------
@@ -171,6 +174,12 @@ Changes to the C API
171174
favor of the new function, which works on all constant aggregates, rather than
172175
only instances of ``ConstantDataSequential``.
173176

177+
* The following functions for creating constant expressions have been removed,
178+
because the underlying constant expressions are no longer supported. Instead,
179+
an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
180+
constant fold the operands if possible and create an instruction otherwise:
181+
* ``LLVMConstExtractValue``
182+
174183
Changes to the Go bindings
175184
--------------------------
176185

llvm/include/llvm-c/Core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,8 +2238,6 @@ LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
22382238
LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
22392239
LLVMValueRef VectorBConstant,
22402240
LLVMValueRef MaskConstant);
2241-
LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2242-
unsigned NumIdx);
22432241
LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
22442242
LLVMValueRef ElementValueConstant,
22452243
unsigned *IdxList, unsigned NumIdx);

llvm/include/llvm/Analysis/TargetFolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class TargetFolder final : public IRBuilderFolder {
109109
Value *FoldExtractValue(Value *Agg,
110110
ArrayRef<unsigned> IdxList) const override {
111111
if (auto *CAgg = dyn_cast<Constant>(Agg))
112-
return Fold(ConstantExpr::getExtractValue(CAgg, IdxList));
112+
return ConstantFoldExtractValueInstruction(CAgg, IdxList);
113113
return nullptr;
114114
};
115115

llvm/include/llvm/IR/ConstantFolder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/STLExtras.h"
2121
#include "llvm/IR/Constants.h"
22+
#include "llvm/IR/ConstantFold.h"
2223
#include "llvm/IR/IRBuilderFolder.h"
2324
#include "llvm/IR/Instruction.h"
2425

@@ -97,7 +98,7 @@ class ConstantFolder final : public IRBuilderFolder {
9798
Value *FoldExtractValue(Value *Agg,
9899
ArrayRef<unsigned> IdxList) const override {
99100
if (auto *CAgg = dyn_cast<Constant>(Agg))
100-
return ConstantExpr::getExtractValue(CAgg, IdxList);
101+
return ConstantFoldExtractValueInstruction(CAgg, IdxList);
101102
return nullptr;
102103
};
103104

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,6 @@ class ConstantExpr : public Constant {
12941294
static Constant *getShuffleVector(Constant *V1, Constant *V2,
12951295
ArrayRef<int> Mask,
12961296
Type *OnlyIfReducedTy = nullptr);
1297-
static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs,
1298-
Type *OnlyIfReducedTy = nullptr);
12991297
static Constant *getInsertValue(Constant *Agg, Constant *Val,
13001298
ArrayRef<unsigned> Idxs,
13011299
Type *OnlyIfReducedTy = nullptr);

0 commit comments

Comments
 (0)