Skip to content

Commit 27b6ede

Browse files
Make ElementCount get interfaces private. Reduce repeated calls to getType().
1 parent 1a494ec commit 27b6ede

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

llvm/include/llvm/IR/Constants.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,20 @@ class ConstantData : public Constant {
7878
/// Class for constant integers.
7979
class ConstantInt final : public ConstantData {
8080
friend class Constant;
81+
friend class ConstantVector;
8182

8283
APInt Val;
8384

8485
ConstantInt(Type *Ty, const APInt &V);
8586

8687
void destroyConstantImpl();
8788

89+
/// Return a ConstantInt with the specified value and an implied Type. The
90+
/// type is the vector type whose integer element type corresponds to the bit
91+
/// width of the value.
92+
static ConstantInt *get(LLVMContext &Context, ElementCount EC,
93+
const APInt &V);
94+
8895
public:
8996
ConstantInt(const ConstantInt &) = delete;
9097

@@ -123,12 +130,6 @@ class ConstantInt final : public ConstantData {
123130
/// type is the integer type that corresponds to the bit width of the value.
124131
static ConstantInt *get(LLVMContext &Context, const APInt &V);
125132

126-
/// Return a ConstantInt with the specified value and an implied Type. The
127-
/// type is the vector type whose integer element type corresponds to the bit
128-
/// width of the value.
129-
static ConstantInt *get(LLVMContext &Context, ElementCount EC,
130-
const APInt &V);
131-
132133
/// Return a ConstantInt constructed from the string strStart with the given
133134
/// radix.
134135
static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
@@ -265,13 +266,20 @@ class ConstantInt final : public ConstantData {
265266
///
266267
class ConstantFP final : public ConstantData {
267268
friend class Constant;
269+
friend class ConstantVector;
268270

269271
APFloat Val;
270272

271273
ConstantFP(Type *Ty, const APFloat &V);
272274

273275
void destroyConstantImpl();
274276

277+
/// Return a ConstantFP with the specified value and an implied Type. The
278+
/// type is the vector type whose element type has the same floating point
279+
/// semantics as the value.
280+
static ConstantFP *get(LLVMContext &Context, ElementCount EC,
281+
const APFloat &V);
282+
275283
public:
276284
ConstantFP(const ConstantFP &) = delete;
277285

@@ -287,8 +295,6 @@ class ConstantFP final : public ConstantData {
287295

288296
static Constant *get(Type *Ty, StringRef Str);
289297
static ConstantFP *get(LLVMContext &Context, const APFloat &V);
290-
static ConstantFP *get(LLVMContext &Context, ElementCount EC,
291-
const APFloat &V);
292298
static Constant *getNaN(Type *Ty, bool Negative = false,
293299
uint64_t Payload = 0);
294300
static Constant *getQNaN(Type *Ty, bool Negative = false,

llvm/lib/IR/AsmWriter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,33 +1502,37 @@ static void WriteAPFloatInternal(raw_ostream &Out, const APFloat &APF) {
15021502
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
15031503
AsmWriterContext &WriterCtx) {
15041504
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1505-
if (CI->getType()->isVectorTy()) {
1505+
Type *Ty = CI->getType();
1506+
1507+
if (Ty->isVectorTy()) {
15061508
Out << "splat (";
1507-
WriterCtx.TypePrinter->print(CI->getType()->getScalarType(), Out);
1509+
WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);
15081510
Out << " ";
15091511
}
15101512

1511-
if (CI->getType()->getScalarType()->isIntegerTy(1))
1513+
if (Ty->getScalarType()->isIntegerTy(1))
15121514
Out << (CI->getZExtValue() ? "true" : "false");
15131515
else
15141516
Out << CI->getValue();
15151517

1516-
if (CI->getType()->isVectorTy())
1518+
if (Ty->isVectorTy())
15171519
Out << ")";
15181520

15191521
return;
15201522
}
15211523

15221524
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1523-
if (CFP->getType()->isVectorTy()) {
1525+
Type *Ty = CFP->getType();
1526+
1527+
if (Ty->isVectorTy()) {
15241528
Out << "splat (";
1525-
WriterCtx.TypePrinter->print(CFP->getType()->getScalarType(), Out);
1529+
WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);
15261530
Out << " ";
15271531
}
15281532

15291533
WriteAPFloatInternal(Out, CFP->getValueAPF());
15301534

1531-
if (CFP->getType()->isVectorTy())
1535+
if (Ty->isVectorTy())
15321536
Out << ")";
15331537

15341538
return;

0 commit comments

Comments
 (0)