-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SandboxIR] Functions to find vectorizor-relevant properties #109221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ies. When vectorizing, the destintation type and value of stores is more relevant than the type of the instruction itself. Similarly for return instructions. These functions provide a convenient way to do that without special-casing them everywhere, and avoids the need for friending any class that needs access to Value::LLVMTy to calculate it. Open to better naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of having these functions as member functions of the Value/User class, but not super against it either. Their semantics are fairly simple, so they might as well be part of the IR.
@@ -411,6 +411,11 @@ class Value { | |||
|
|||
Type *getType() const; | |||
|
|||
/// \Returns the expected type of \p V. For most Values this is equivalent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the expected type "of \p V"
Perhaps "the expected type of this Value" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obviated by refactoring.
@@ -875,6 +875,8 @@ OperandNo: 0 | |||
EXPECT_TRUE(I0->hasNUses(1u)); | |||
EXPECT_FALSE(I0->hasNUses(2u)); | |||
|
|||
// Check Value.getExpectedType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
EXPECT_EQ(S0->getExpectedValue(), | ||
cast<sandboxir::StoreInst>(S0)->getValueOperand()); | ||
EXPECT_EQ(Ret->getExpectedValue(), | ||
cast<sandboxir::ReturnInst>(Ret)->getReturnValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not checking the case where we return void. I would add a second function in the IR, with a:
define void @bar() {
ret void
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
@@ -4019,6 +4019,42 @@ class Function : public Constant { | |||
#endif | |||
}; | |||
|
|||
// Collector for SandboxIR related convenience functions that don't belong in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to move the SandboxIRUtils into a sperate file perhaps in SandboxIR/Utils.h
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Please take another look when you get a chance. |
const DataLayout &DL = M->getDataLayout(); | ||
// getNumBits for scalars | ||
// float | ||
EXPECT_EQ(sandboxir::SandboxIRUtils::getNumBits(F->getArg(0), DL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also be testing getNumBits()
on instruction that have an "unexpected" type? Because for the rest of them getting num bits is as simple as DL.getTypeSizeInBits(V->getType())
?
DL.getTypeSizeInBits(Type::getFloatTy(C))); | ||
EXPECT_EQ(sandboxir::SandboxIRUtils::getNumBits(F->getArg(1), DL), | ||
DL.getTypeSizeInBits(Type::getDoubleTy(C))); | ||
EXPECT_EQ(sandboxir::SandboxIRUtils::getNumBits(F->getArg(2), DL), 8u); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why check with a hard-coded number and not DL.getTypeSizeInBits(F->getArg(2)->getType())
as you did above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a touch subtle, and maybe it doesn't matter that much. But calling through to getType will always give whatever bit size of whatever LLVM type just happens to underlie the SB type. So if there is some error in how those two match and get bit sizes, it won't be found here.
Hard coding it assures that not only do the bitsizes match, the value it returns is the expected one in known cases.
@@ -4018,7 +4018,6 @@ class Function : public Constant { | |||
void dumpOS(raw_ostream &OS) const final; | |||
#endif | |||
}; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not modify this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/include/llvm/SandboxIR/Type.h
Outdated
|
||
// Friend all instruction classes because `create()` functions use LLVMTy. | ||
#define DEF_INSTR(ID, OPCODE, CLASS) friend class CLASS; | ||
#define DEF_CONST(ID, CLASS) friend class CLASS; | ||
#include "llvm/SandboxIR/SandboxIRValues.def" | ||
Context &Ctx; | ||
Context &Ctx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -938,7 +941,6 @@ define i32 @foo(i32 %arg0, i32 %arg1) { | |||
Replaced = Ret->replaceUsesOfWith(I0, Arg0); | |||
EXPECT_TRUE(Replaced); | |||
EXPECT_EQ(Ret->getOperand(0), Arg0); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo line deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -14,6 +14,7 @@ | |||
#include "llvm/IR/Function.h" | |||
#include "llvm/IR/Instruction.h" | |||
#include "llvm/IR/Module.h" | |||
#include "llvm/SandboxIR/Utils.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably forgot to git add the header :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor comments, looks good otherwise.
llvm/include/llvm/SandboxIR/Utils.h
Outdated
@@ -0,0 +1,52 @@ | |||
//===- SandboxIR.h ----------------------------------------------*- C++ -*-===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should say "Utils.h" instead of "SandboxIR.h"
// | ||
// Collector for SandboxIR related convenience functions that don't belong in | ||
// other classes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add header guards just like in SandboxIR.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/include/llvm/SandboxIR/Utils.h
Outdated
|
||
namespace llvm { | ||
|
||
namespace sandboxir { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: namespace llvm::sandboxir {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (incidentally, SandboxIR.h has it the other way.)
DL.getTypeSizeInBits(Type::getFloatTy(C))); | ||
EXPECT_EQ(sandboxir::Utils::getNumBits(F->getArg(1), DL), | ||
DL.getTypeSizeInBits(Type::getDoubleTy(C))); | ||
EXPECT_EQ(sandboxir::Utils::getNumBits(F->getArg(2), DL), 8u); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since there is a // float
comment above, perhaps this one needs a // integer
comment? Or drop both ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
llvm/include/llvm/SandboxIR/Utils.h
Outdated
@@ -1,4 +1,4 @@ | |||
//===- SandboxIR.h ----------------------------------------------*- C++ -*-===// | |||
//===- Utils.h ----------------------------------------------*- C++ -*-===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to make this 80-columns wide
llvm/include/llvm/SandboxIR/Utils.h
Outdated
} // namespace llvm | ||
} // namespace llvm::sandboxir | ||
|
||
#endif // LLVM_SANDBOXIR_TYPE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment should be // LLVM_SANDBOXIR_UTILS_H
✅ With the latest revision this PR passed the C/C++ code formatter. |
When vectorizing, the destination type and value of stores is more relevant than the type of the instruction itself. Similarly for return instructions. These functions provide a convenient way to do that without special-casing them everywhere, and avoids the need for friending any class that needs access to Value::LLVMTy to calculate it.
Open to better naming.