Skip to content

Commit 4553484

Browse files
committed
[Lint] Switch check to Linter
1 parent a099028 commit 4553484

File tree

4 files changed

+48
-41
lines changed

4 files changed

+48
-41
lines changed

llvm/lib/Analysis/Lint.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "llvm/IR/PassManager.h"
6868
#include "llvm/IR/Type.h"
6969
#include "llvm/IR/Value.h"
70+
#include "llvm/Support/AMDGPUAddrSpace.h"
7071
#include "llvm/Support/Casting.h"
7172
#include "llvm/Support/KnownBits.h"
7273
#include "llvm/Support/raw_ostream.h"
@@ -122,8 +123,10 @@ class Lint : public InstVisitor<Lint> {
122123
Value *findValueImpl(Value *V, bool OffsetOk,
123124
SmallPtrSetImpl<Value *> &Visited) const;
124125

126+
bool isConstantAddressSpace(unsigned AS) const;
125127
public:
126128
Module *Mod;
129+
Triple TT;
127130
const DataLayout *DL;
128131
AliasAnalysis *AA;
129132
AssumptionCache *AC;
@@ -135,7 +138,8 @@ class Lint : public InstVisitor<Lint> {
135138

136139
Lint(Module *Mod, const DataLayout *DL, AliasAnalysis *AA,
137140
AssumptionCache *AC, DominatorTree *DT, TargetLibraryInfo *TLI)
138-
: Mod(Mod), DL(DL), AA(AA), AC(AC), DT(DT), TLI(TLI),
141+
: Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())),
142+
DL(DL), AA(AA), AC(AC), DT(DT), TLI(TLI),
139143
MessagesStr(Messages) {}
140144

141145
void WriteValues(ArrayRef<const Value *> Vs) {
@@ -378,6 +382,36 @@ void Lint::visitReturnInst(ReturnInst &I) {
378382
}
379383
}
380384

385+
bool Lint::isConstantAddressSpace(unsigned AS) const {
386+
if (TT.isAMDGPU()) {
387+
switch(AS) {
388+
using namespace AMDGPUAS;
389+
case CONSTANT_ADDRESS:
390+
case CONSTANT_ADDRESS_32BIT:
391+
case CONSTANT_BUFFER_0:
392+
case CONSTANT_BUFFER_1:
393+
case CONSTANT_BUFFER_2:
394+
case CONSTANT_BUFFER_3:
395+
case CONSTANT_BUFFER_4:
396+
case CONSTANT_BUFFER_5:
397+
case CONSTANT_BUFFER_6:
398+
case CONSTANT_BUFFER_7:
399+
case CONSTANT_BUFFER_8:
400+
case CONSTANT_BUFFER_9:
401+
case CONSTANT_BUFFER_10:
402+
case CONSTANT_BUFFER_11:
403+
case CONSTANT_BUFFER_12:
404+
case CONSTANT_BUFFER_13:
405+
case CONSTANT_BUFFER_14:
406+
case CONSTANT_BUFFER_15:
407+
return true;
408+
default:
409+
return false;
410+
}
411+
}
412+
return false;
413+
}
414+
381415
// TODO: Check that the reference is in bounds.
382416
// TODO: Check readnone/readonly function attributes.
383417
void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
@@ -401,6 +435,9 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
401435
"Unusual: Address one pointer dereference", &I);
402436

403437
if (Flags & MemRef::Write) {
438+
Check(!isConstantAddressSpace(UnderlyingObject->getType()->getPointerAddressSpace()),
439+
"Undefined behavior: Write to const memory", &I);
440+
404441
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(UnderlyingObject))
405442
Check(!GV->isConstant(), "Undefined behavior: Write to read-only memory",
406443
&I);

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,33 +4224,6 @@ void Verifier::visitLoadInst(LoadInst &LI) {
42244224
visitInstruction(LI);
42254225
}
42264226

4227-
static bool isConstantAddressSpace(unsigned AS) {
4228-
switch (AS) {
4229-
using namespace AMDGPUAS;
4230-
case CONSTANT_ADDRESS:
4231-
case CONSTANT_ADDRESS_32BIT:
4232-
case CONSTANT_BUFFER_0:
4233-
case CONSTANT_BUFFER_1:
4234-
case CONSTANT_BUFFER_2:
4235-
case CONSTANT_BUFFER_3:
4236-
case CONSTANT_BUFFER_4:
4237-
case CONSTANT_BUFFER_5:
4238-
case CONSTANT_BUFFER_6:
4239-
case CONSTANT_BUFFER_7:
4240-
case CONSTANT_BUFFER_8:
4241-
case CONSTANT_BUFFER_9:
4242-
case CONSTANT_BUFFER_10:
4243-
case CONSTANT_BUFFER_11:
4244-
case CONSTANT_BUFFER_12:
4245-
case CONSTANT_BUFFER_13:
4246-
case CONSTANT_BUFFER_14:
4247-
case CONSTANT_BUFFER_15:
4248-
return true;
4249-
default:
4250-
return false;
4251-
}
4252-
}
4253-
42544227
void Verifier::visitStoreInst(StoreInst &SI) {
42554228
PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
42564229
Check(PTy, "Store operand must be a pointer.", &SI);
@@ -4273,10 +4246,6 @@ void Verifier::visitStoreInst(StoreInst &SI) {
42734246
Check(SI.getSyncScopeID() == SyncScope::System,
42744247
"Non-atomic store cannot have SynchronizationScope specified", &SI);
42754248
}
4276-
if (TT.isAMDGPU()) {
4277-
Check(!isConstantAddressSpace(SI.getPointerAddressSpace()),
4278-
"Store cannot be to constant addrspace", &SI);
4279-
}
42804249
visitInstruction(SI);
42814250
}
42824251

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not opt --mtriple=amdgcn --passes=lint --lint-abort-on-error %s -o - |& FileCheck %s
2+
; RUN: not opt --mtriple=amdgcn --mcpu=gfx1030 --passes=lint --lint-abort-on-error %s -o - |& FileCheck %s
3+
4+
define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {
5+
; CHECK: Undefined behavior: Write to const memory
6+
; CHECK-NEXT: store i32 %r, ptr addrspace(4) %out
7+
%r = add i32 %a, %b
8+
store i32 %r, ptr addrspace(4) %out
9+
ret void
10+
}

llvm/test/CodeGen/AMDGPU/const-store.ll

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)