Skip to content

[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

Merged
merged 8 commits into from
Sep 23, 2024

Conversation

Sterling-Augustine
Copy link
Contributor

@Sterling-Augustine Sterling-Augustine commented Sep 18, 2024

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.

…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.
Copy link
Contributor

@vporpo vporpo left a 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
Copy link
Contributor

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" ?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant comment?

Copy link
Contributor Author

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());
Copy link
Contributor

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
}

Copy link
Contributor Author

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
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Sterling-Augustine
Copy link
Contributor Author

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),
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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
};

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format ?

Copy link
Contributor Author

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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo line deletion.

Copy link
Contributor Author

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"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@vporpo vporpo left a 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.

@@ -0,0 +1,52 @@
//===- SandboxIR.h ----------------------------------------------*- C++ -*-===//
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


namespace llvm {

namespace sandboxir {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: namespace llvm::sandboxir {

Copy link
Contributor Author

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);
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,4 +1,4 @@
//===- SandboxIR.h ----------------------------------------------*- C++ -*-===//
//===- Utils.h ----------------------------------------------*- C++ -*-===//
Copy link
Contributor

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

} // namespace llvm
} // namespace llvm::sandboxir

#endif // LLVM_SANDBOXIR_TYPE_H
Copy link
Contributor

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

Copy link

github-actions bot commented Sep 20, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Sterling-Augustine Sterling-Augustine merged commit d1edef5 into llvm:main Sep 23, 2024
8 checks passed
@Sterling-Augustine Sterling-Augustine deleted the IrFixes branch October 7, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants