Skip to content

Commit 63bbd65

Browse files
committed
Fix build/formatting.
1 parent 6ba8c9d commit 63bbd65

File tree

7 files changed

+62
-48
lines changed

7 files changed

+62
-48
lines changed

llvm/include/llvm/IR/Function.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,22 +1042,16 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
10421042
///
10431043
/// Note that this is the alignment of the code, not the alignment of a
10441044
/// function pointer.
1045-
MaybeAlign getAlign() const {
1046-
return GlobalObject::getAlign();
1047-
}
1045+
MaybeAlign getAlign() const { return GlobalObject::getAlign(); }
10481046

10491047
/// Sets the alignment attribute of the Function.
1050-
void setAlignment(Align Align) {
1051-
GlobalObject::setAlignment(Align);
1052-
}
1048+
void setAlignment(Align Align) { GlobalObject::setAlignment(Align); }
10531049

10541050
/// Sets the alignment attribute of the Function.
10551051
///
10561052
/// This method will be deprecated as the alignment property should always be
10571053
/// defined.
1058-
void setAlignment(MaybeAlign Align) {
1059-
GlobalObject::setAlignment(Align);
1060-
}
1054+
void setAlignment(MaybeAlign Align) { GlobalObject::setAlignment(Align); }
10611055

10621056
private:
10631057
void allocHungoffUselist();

llvm/include/llvm/IR/GlobalVariable.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,15 @@ class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> {
305305
}
306306

307307
/// Returns the alignment of the given variable.
308-
MaybeAlign getAlign() const {
309-
return GlobalObject::getAlign();
310-
}
308+
MaybeAlign getAlign() const { return GlobalObject::getAlign(); }
311309

312310
/// Sets the alignment attribute of the GlobalVariable.
313-
void setAlignment(Align Align) {
314-
GlobalObject::setAlignment(Align);
315-
}
311+
void setAlignment(Align Align) { GlobalObject::setAlignment(Align); }
316312

317313
/// Sets the alignment attribute of the GlobalVariable.
318314
/// This method will be deprecated as the alignment property should always be
319315
/// defined.
320-
void setAlignment(MaybeAlign Align) {
321-
GlobalObject::setAlignment(Align);
322-
}
316+
void setAlignment(MaybeAlign Align) { GlobalObject::setAlignment(Align); }
323317

324318
// Methods for support type inquiry through isa, cast, and dyn_cast:
325319
static bool classof(const Value *V) {

llvm/include/llvm/SandboxIR/Function.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class Function : public GlobalWithNodeAPI<Function, llvm::Function,
5858
}
5959
FunctionType *getFunctionType() const;
6060

61+
/// Returns the alignment of the given function.
62+
MaybeAlign getAlign() const {
63+
return cast<llvm::GlobalVariable>(Val)->getAlign();
64+
}
65+
66+
// TODO: Add missing: setAligment(Align)
67+
68+
/// Sets the alignment attribute of the Function.
69+
/// This method will be deprecated as the alignment property should always be
70+
/// defined.
71+
void setAlignment(MaybeAlign Align);
72+
6173
#ifndef NDEBUG
6274
void verify() const final {
6375
assert(isa<llvm::Function>(Val) && "Expected Function!");

llvm/lib/SandboxIR/Constant.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ PoisonValue *PoisonValue::getElementValue(unsigned Idx) const {
284284

285285
void GlobalVariable::setAlignment(MaybeAlign Align) {
286286
Ctx.getTracker()
287-
.emplaceIfTracking<
288-
GenericSetter<&GlobalVariable::getAlign, &GlobalVariable::setAlignment>>(
289-
this);
287+
.emplaceIfTracking<GenericSetter<&GlobalVariable::getAlign,
288+
&GlobalVariable::setAlignment>>(this);
290289
cast<llvm::GlobalVariable>(Val)->setAlignment(Align);
291290
}
292291

llvm/lib/SandboxIR/Function.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ FunctionType *Function::getFunctionType() const {
1717
Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));
1818
}
1919

20+
void Function::setAlignment(MaybeAlign Align) {
21+
Ctx.getTracker()
22+
.emplaceIfTracking<GenericSetter<&Function::getAlign,
23+
&Function::setAlignment>>(this);
24+
cast<llvm::GlobalVariable>(Val)->setAlignment(Align);
25+
}
26+
2027
#ifndef NDEBUG
2128
void Function::dumpNameAndArgs(raw_ostream &OS) const {
2229
auto *F = cast<llvm::Function>(Val);

llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ using namespace llvm;
1313

1414
static bool shouldReduceSection(GlobalObject &GO) { return GO.hasSection(); }
1515

16-
static bool shouldReduceAlign(GlobalObject &GO) {
17-
return GO.getAlign().has_value();
16+
static bool shouldReduceAlign(GlobalVariable *GV) {
17+
return GV->getAlign().has_value();
18+
}
19+
20+
static bool shouldReduceAlign(Function *F) {
21+
return F->getAlign().has_value();
1822
}
1923

2024
static bool shouldReduceComdat(GlobalObject &GO) { return GO.hasComdat(); }
@@ -23,8 +27,14 @@ void llvm::reduceGlobalObjectsDeltaPass(Oracle &O, ReducerWorkItem &Program) {
2327
for (auto &GO : Program.getModule().global_objects()) {
2428
if (shouldReduceSection(GO) && !O.shouldKeep())
2529
GO.setSection("");
26-
if (shouldReduceAlign(GO) && !O.shouldKeep())
27-
GO.setAlignment(MaybeAlign());
30+
if (auto *GV = dyn_cast<GlobalVariable>(&GO)) {
31+
if (shouldReduceAlign(GV) && !O.shouldKeep())
32+
GV->setAlignment(MaybeAlign());
33+
}
34+
if (auto *F = dyn_cast<Function>(&GO)) {
35+
if (shouldReduceAlign(F) && !O.shouldKeep())
36+
F->setAlignment(MaybeAlign());
37+
}
2838
if (shouldReduceComdat(GO) && !O.shouldKeep())
2939
GO.setComdat(nullptr);
3040
}

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,29 +1051,6 @@ define void @foo() {
10511051
auto *Call = cast<sandboxir::CallInst>(&*It++);
10521052
// Check classof(), creation.
10531053
auto *GO = cast<sandboxir::GlobalObject>(Call->getCalledOperand());
1054-
// Check getAlignment().
1055-
EXPECT_EQ(GO->getAlignment(), LLVMGO->getAlignment());
1056-
// Check getAlign().
1057-
EXPECT_EQ(GO->getAlign(), LLVMGO->getAlign());
1058-
// Check setAlignment().
1059-
auto OrigMaybeAlign = GO->getAlign();
1060-
auto NewMaybeAlign = MaybeAlign(128);
1061-
EXPECT_NE(NewMaybeAlign, OrigMaybeAlign);
1062-
GO->setAlignment(NewMaybeAlign);
1063-
EXPECT_EQ(GO->getAlign(), NewMaybeAlign);
1064-
GO->setAlignment(OrigMaybeAlign);
1065-
EXPECT_EQ(GO->getAlign(), OrigMaybeAlign);
1066-
// Check getGlobalObjectSubClassData().
1067-
EXPECT_EQ(GO->getGlobalObjectSubClassData(),
1068-
LLVMGO->getGlobalObjectSubClassData());
1069-
// Check setGlobalObjectSubClassData().
1070-
auto OrigGOSCD = GO->getGlobalObjectSubClassData();
1071-
auto NewGOSCD = 1u;
1072-
EXPECT_NE(NewGOSCD, OrigGOSCD);
1073-
GO->setGlobalObjectSubClassData(NewGOSCD);
1074-
EXPECT_EQ(GO->getGlobalObjectSubClassData(), NewGOSCD);
1075-
GO->setGlobalObjectSubClassData(OrigGOSCD);
1076-
EXPECT_EQ(GO->getGlobalObjectSubClassData(), OrigGOSCD);
10771054
// Check hasSection().
10781055
EXPECT_EQ(GO->hasSection(), LLVMGO->hasSection());
10791056
// Check getSection().
@@ -1284,6 +1261,16 @@ define void @foo() {
12841261
EXPECT_EQ(GV0->getCodeModelRaw(), LLVMGV0->getCodeModelRaw());
12851262
// Check getCodeModel().
12861263
EXPECT_EQ(GV0->getCodeModel(), LLVMGV0->getCodeModel());
1264+
// Check getAlign().
1265+
EXPECT_EQ(GV0->getAlign(), LLVMGV0->getAlign());
1266+
// Check setAlignment().
1267+
auto OrigMaybeAlign = GV0->getAlign();
1268+
auto NewMaybeAlign = MaybeAlign(128);
1269+
EXPECT_NE(NewMaybeAlign, OrigMaybeAlign);
1270+
GV0->setAlignment(NewMaybeAlign);
1271+
EXPECT_EQ(GV0->getAlign(), NewMaybeAlign);
1272+
GV0->setAlignment(OrigMaybeAlign);
1273+
EXPECT_EQ(GV0->getAlign(), OrigMaybeAlign);
12871274
}
12881275

12891276
TEST_F(SandboxIRTest, GlobalAlias) {
@@ -1855,6 +1842,17 @@ void @foo0(i32 %arg0, i32 %arg1) {
18551842
)IR");
18561843
}
18571844
#endif // NDEBUG
1845+
1846+
// Check getAlign().
1847+
EXPECT_EQ(F0->getAlign(), F0->getAlign());
1848+
// Check setAlignment().
1849+
auto OrigMaybeAlign = F0->getAlign();
1850+
auto NewMaybeAlign = MaybeAlign(128);
1851+
EXPECT_NE(NewMaybeAlign, OrigMaybeAlign);
1852+
F0->setAlignment(NewMaybeAlign);
1853+
EXPECT_EQ(F0->getAlign(), NewMaybeAlign);
1854+
F0->setAlignment(OrigMaybeAlign);
1855+
EXPECT_EQ(F0->getAlign(), OrigMaybeAlign);
18581856
}
18591857

18601858
TEST_F(SandboxIRTest, Module) {

0 commit comments

Comments
 (0)